Server side implementation for TLINK
PATCH 1/1 Server side implementation for TLINK
Create a link.
SYNOPSIS
size[4] Tlink tag[2] dfid[4] oldpath[s] newpath[s]
size[4] Rlink tag[2]
DESCRIPTION
Create a link 'newpath' in directory pointed by dfid linking to oldpath.
Signed-off-by Venkateswararao Jujjuri <[email protected]>
--- hw/file-op-9p.h | 2 +- hw/virtio-9p-debug.c | 9 +++++++++ hw/virtio-9p-local.c | 2 +- hw/virtio-9p.c | 40 ++++++++++++++++++++++++++++++++-------- hw/virtio-9p.h | 2 ++ 5 files changed, 45 insertions(+), 10 deletions(-)
hw/file-op-9p.h +1 -1
@@ -55,7 +55,7 @@ typedef struct FileOperationsint (*utime)(FsContext *,const char *,const struct utimbuf *);int (*remove)(FsContext *,const char *);int (*symlink)(FsContext *,const char *,const char *,FsCred *); -int (*link)(FsContext *,const char *,const char *,FsCred *); +int (*link)(FsContext *,const char *,const char *);int (*setuid)(FsContext *,uid_t );int (*close)(FsContext *,int );int (*closedir)(FsContext *,DIR *);
hw/virtio-9p-debug.c +9 -0
@@ -463,6 +463,15 @@ void pprint_pdu(V9fsPDU *pdu)case P9_RCLUNK :fprintf (llogfile,"RCLUNK: (" );break ; +case P9_TLINK : +fprintf (llogfile,"TLINK: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_str (pdu,0 , &offset,", name" ); +pprint_str (pdu,0 , &offset,", linkname" ); +break ; +case P9_RLINK : +fprintf (llogfile,"RLINK: (" ); +break ;case P9_TREMOVE :fprintf (llogfile,"TREMOVE: (" );pprint_int32 (pdu,0 , &offset,"fid" );
hw/virtio-9p-local.c +1 -1
@@ -375,7 +375,7 @@ err_end: }static int local_link (FsContext *fs_ctx,const char *oldpath, -const char *newpath,FsCred *credp) +const char *newpath) {char *tmp =qemu_strdup (rpath (fs_ctx, oldpath));int err;
hw/virtio-9p.c +32 -8
@@ -212,14 +212,9 @@ static int v9fs_do_symlink(V9fsState *s, V9fsCreateState *vs) &cred); } -static int v9fs_do_link (V9fsState *s,V9fsFidState *nfidp,V9fsCreateState *vs) +static int v9fs_do_link (V9fsState *s,char *oldpath,char *fullname) { -FsCred cred; -cred_init (&cred); - cred.fc_uid = nfidp->uid; - cred.fc_mode = vs->perm &0777 ; - -return s->ops->link (&s->ctx, nfidp->path.data, vs->fullname.data, &cred); +return s->ops->link (&s->ctx, oldpath, fullname); }static int v9fs_do_truncate (V9fsState *s,V9fsString *path,off_t size)
@@ -1919,7 +1914,7 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) err = -errno;v9fs_post_create (s, vs, err); } - err =v9fs_do_link (s, nfidp, vs); + err =v9fs_do_link (s, nfidp->path.data, vs->fullname.data);v9fs_create_post_perms (s, vs, err); }else if (vs->perm &P9_STAT_MODE_DEVICE ) {char ctype;
@@ -1999,6 +1994,34 @@ out:qemu_free (vs); } +static void v9fs_link (V9fsState *s,V9fsPDU *pdu) +{ +int32_t dfid; +V9fsFidState *dfidp; +V9fsString name, fullname, oldname; +size_t offset =7 ; +int err =0 ; + +v9fs_string_init (&fullname); + +pdu_unmarshal (pdu, offset,"dss" , &dfid, &oldname, &name); + + dfidp =lookup_fid (s, dfid); +if (dfidp ==NULL ) { + err = -errno; + goto out; + } + +v9fs_string_sprintf (&fullname,"%s/%s" , dfidp->path.data, name.data); + err =v9fs_do_link (s, oldname.data, fullname.data); +v9fs_string_free (&fullname); + +out: +v9fs_string_free (&name); +v9fs_string_free (&oldname); +complete_pdu (s, pdu, err); +} +static void v9fs_flush (V9fsState *s,V9fsPDU *pdu) {/* A nop call with no return */
@@ -2354,6 +2377,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TAUTH] = v9fs_auth, #endif [P9_TFLUSH] = v9fs_flush, + [P9_TLINK] = v9fs_link, [P9_TCREATE] = v9fs_create, [P9_TWRITE] = v9fs_write, [P9_TWSTAT] = v9fs_wstat,
hw/virtio-9p.h +2 -0
@@ -17,6 +17,8 @@ enum {P9_RSTATFS ,P9_TREADDIR =40 ,P9_RREADDIR , +P9_TLINK =70 , +P9_RLINK ,P9_TVERSION =100 ,P9_RVERSION , P9_TAUTH = 102,
Signature · 1 line
1.6.5.2
Quoted 59 lines · Venkateswararao Jujjuri (JV)
Create a link.
SYNOPSIS
size[4] Tlink tag[2] dfid[4] oldpath[s] newpath[s]
size[4] Rlink tag[2]
DESCRIPTION
Create a link 'newpath' in directory pointed by dfid linking to oldpath.
Signed-off-by Venkateswararao Jujjuri <[email protected]>--- hw/file-op-9p.h | 2 +- hw/virtio-9p-debug.c | 9 +++++++++ hw/virtio-9p-local.c | 2 +- hw/virtio-9p.c | 40 ++++++++++++++++++++++++++++++++-------- hw/virtio-9p.h | 2 ++ 5 files changed, 45 insertions(+), 10 deletions(-)hw/file-op-9p.h +1
-1@@ -55,7 +55,7 @@ typedef struct FileOperationsint (*utime)(FsContext *,const char *,const struct utimbuf *);int (*remove)(FsContext *,const char *);int (*symlink)(FsContext *,const char *,const char *,FsCred *); -int (*link)(FsContext *,const char *,const char *,FsCred *); +int (*link)(FsContext *,const char *,const char *);int (*setuid)(FsContext *,uid_t );int (*close)(FsContext *,int );int (*closedir)(FsContext *,DIR *);hw/virtio-9p-debug.c +9
-0@@ -463,6 +463,15 @@ void pprint_pdu(V9fsPDU *pdu)case P9_RCLUNK :fprintf (llogfile,"RCLUNK: (" );break ; +case P9_TLINK : +fprintf (llogfile,"TLINK: (" ); +pprint_int32 (pdu,0 , &offset,"fid" ); +pprint_str (pdu,0 , &offset,", name" ); +pprint_str (pdu,0 , &offset,", linkname" ); +break ; +case P9_RLINK : +fprintf (llogfile,"RLINK: (" ); +break ;case P9_TREMOVE :fprintf (llogfile,"TREMOVE: (" );pprint_int32 (pdu,0 , &offset,"fid" );hw/virtio-9p-local.c +0
-0
hw/virtio-9p-local.c err_end: · line 381
Quoted 8 lines
hw/virtio-9p-local.c +1
-1@@ -375,7 +375,7 @@ err_end: }static int local_link (FsContext *fs_ctx,const char *oldpath, -const char *newpath,FsCred *credp) +const char *newpath) {char *tmp =qemu_strdup (rpath (fs_ctx, oldpath));int err;
I guess it would be good to make sure local_link use linkat with flags = 0 to ensure that we won't follow symlinks. But that can be seperate patch.
Quoted 88 lines
hw/virtio-9p.c +32
-8@@ -212,14 +212,9 @@ static int v9fs_do_symlink(V9fsState *s, V9fsCreateState *vs) &cred); } -static int v9fs_do_link (V9fsState *s,V9fsFidState *nfidp,V9fsCreateState *vs) +static int v9fs_do_link (V9fsState *s,char *oldpath,char *fullname) { -FsCred cred; -cred_init (&cred); - cred.fc_uid = nfidp->uid; - cred.fc_mode = vs->perm &0777 ; - -return s->ops->link (&s->ctx, nfidp->path.data, vs->fullname.data, &cred); +return s->ops->link (&s->ctx, oldpath, fullname); }static int v9fs_do_truncate (V9fsState *s,V9fsString *path,off_t size)@@ -1919,7 +1914,7 @@ static void v9fs_create_post_lstat(V9fsState *s, V9fsCreateState *vs, int err) err = -errno;v9fs_post_create (s, vs, err); } - err =v9fs_do_link (s, nfidp, vs); + err =v9fs_do_link (s, nfidp->path.data, vs->fullname.data);v9fs_create_post_perms (s, vs, err); }else if (vs->perm &P9_STAT_MODE_DEVICE ) {char ctype;@@ -1999,6 +1994,34 @@ out:qemu_free (vs); } +static void v9fs_link (V9fsState *s,V9fsPDU *pdu) +{ +int32_t dfid; +V9fsFidState *dfidp; +V9fsString name, fullname, oldname; +size_t offset =7 ; +int err =0 ; + +v9fs_string_init (&fullname); + +pdu_unmarshal (pdu, offset,"dss" , &dfid, &oldname, &name); + + dfidp =lookup_fid (s, dfid); +if (dfidp ==NULL ) { + err = -errno; + goto out; + } + +v9fs_string_sprintf (&fullname,"%s/%s" , dfidp->path.data, name.data); + err =v9fs_do_link (s, oldname.data, fullname.data); +v9fs_string_free (&fullname); + +out: +v9fs_string_free (&name); +v9fs_string_free (&oldname); +complete_pdu (s, pdu, err); +} +static void v9fs_flush (V9fsState *s,V9fsPDU *pdu) {/* A nop call with no return */ @@ -2354,6 +2377,7 @@ static pdu_handler_t *pdu_handlers[] = { [P9_TAUTH] = v9fs_auth, #endif [P9_TFLUSH] = v9fs_flush, + [P9_TLINK] = v9fs_link, [P9_TCREATE] = v9fs_create, [P9_TWRITE] = v9fs_write, [P9_TWSTAT] = v9fs_wstat,hw/virtio-9p.h +2
-0@@ -17,6 +17,8 @@ enum {P9_RSTATFS ,P9_TREADDIR =40 ,P9_RREADDIR , +P9_TLINK =70 , +P9_RLINK ,P9_TVERSION =100 ,P9_RVERSION , P9_TAUTH = 102,Signature · 1 line
1.6.5.2
-aneesh