9pfs: Introduce ftruncate file op

Add an ftruncate operation to the fs driver and use if when a fid has
a valid file descriptor. This is required to support more cases where
the client wants to do an action on an unlinked file which it still
has an open file decriptor for.

Only 9P2000.L was considered.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Message-Id: <20250312152933.383967-4-groug@kaod.org>
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
This commit is contained in:
Greg Kurz 2025-03-12 16:29:29 +01:00 committed by Christian Schoenebeck
parent f2bb367d2b
commit 0c798dd523
6 changed files with 44 additions and 1 deletions

View file

@ -1752,7 +1752,11 @@ static void coroutine_fn v9fs_setattr(void *opaque)
}
}
if (v9iattr.valid & (P9_ATTR_SIZE)) {
err = v9fs_co_truncate(pdu, &fidp->path, v9iattr.size);
if (fid_has_valid_file_handle(pdu->s, fidp)) {
err = v9fs_co_ftruncate(pdu, fidp, v9iattr.size);
} else {
err = v9fs_co_truncate(pdu, &fidp->path, v9iattr.size);
}
if (err < 0) {
goto out;
}