]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/9pfs: Add truncate to 9P_PROTO_2000U
authorMarc Rittinghaus <marc.rittinghaus@unikraft.io>
Wed, 12 Apr 2023 13:22:54 +0000 (15:22 +0200)
committerUnikraft <monkey@unikraft.io>
Wed, 26 Apr 2023 10:28:33 +0000 (10:28 +0000)
When providing a length in the stat structure the 9pfs server on the
host will truncate the file to the specified size. We use this to also
enable truncation for the 2000U protocol version. Since uk_9pfs_setattr
checks for the protocol to use, the check can be completely dropped in
uk_9pfs_truncate.

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <teodor.teugea@gmail.com>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #834

lib/9pfs/9pfs_vnops.c

index df405a09ee1a5081cbcabda2896b684e8b0a774f..4827150de85d9a97f8dfd8974508239584159a23 100644 (file)
@@ -898,17 +898,10 @@ static int uk_9pfs_fsync(struct vnode *vp, struct vfscore_file *fp)
 
 static int uk_9pfs_truncate(struct vnode *vp, off_t off)
 {
-       struct uk_9pfs_mount_data *md = UK_9PFS_MD(vp->v_mount);
-
-       if (md->proto == UK_9P_PROTO_2000L) {
-               struct vattr attr = {
-                   .va_mask = AT_SIZE,
-                   .va_size = off,
-               };
-               return uk_9pfs_setattr(vp, &attr);
-       } else {
-               return 0;
-       }
+       return uk_9pfs_setattr(vp, &(struct vattr){
+               .va_mask = AT_SIZE,
+               .va_size = off,
+       });
 }
 
 static int uk_9pfs_rename(struct vnode *dvp1, struct vnode *vp1, char *name1,