Make rpath thread safe
PATCH 1/1 Make rpath thread safe
Current rpath inline function is heavily used in all system calls. This function has a static buffer making it a non-thread safe function. This patch introduces new thread-safe routine and makes use of it.
Signed-off-by Venkateswararao Jujjuri "<[email protected]>
--- fsdev/file-op-9p.h | 7 -- hw/9pfs/virtio-9p-local.c | 135 +++++++++++++++++++--------------------- hw/9pfs/virtio-9p-posix-acl.c | 20 ++++-- hw/9pfs/virtio-9p-xattr-user.c | 9 ++- hw/9pfs/virtio-9p-xattr.c | 5 +- hw/9pfs/virtio-9p-xattr.h | 9 ++- hw/9pfs/virtio-9p.h | 5 ++ 7 files changed, 98 insertions(+), 92 deletions(-)
fsdev/file-op-9p.h +0 -7
@@ -97,11 +97,4 @@ typedef struct FileOperations void *opaque; } FileOperations; -static inline const char *rpath (FsContext *ctx,const char *path) -{ -/* FIXME: so wrong... */ -static char buffer[4096 ]; -snprintf (buffer,sizeof (buffer),"%s/%s" , ctx->fs_root, path); -return buffer; -}#endif
hw/9pfs/virtio-9p-local.c +64 -71
345 lines not on this page · raw message
hw/9pfs/virtio-9p-posix-acl.c +14 -6
@@ -26,7 +26,8 @@static ssize_t mp_pacl_getxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size) { -return lgetxattr (rpath (ctx, path),MAP_ACL_ACCESS , value, size); +char buffer[PATH_MAX ]; +return lgetxattr (nrpath (ctx, path, buffer),MAP_ACL_ACCESS , value, size); } static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,
@@ -50,14 +51,17 @@ static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path,static int mp_pacl_setxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size,int flags) { -return lsetxattr (rpath (ctx, path),MAP_ACL_ACCESS , value, size, flags); +char buffer[PATH_MAX ]; +return lsetxattr (nrpath (ctx, path, buffer),MAP_ACL_ACCESS , value, + size, flags); }static int mp_pacl_removexattr (FsContext *ctx,const char *path,const char *name) {int ret; - ret =lremovexattr (rpath (ctx, path),MAP_ACL_ACCESS ); +char buffer[PATH_MAX ]; + ret =lremovexattr (nrpath (ctx, path, buffer),MAP_ACL_ACCESS );if (ret ==-1 && errno ==ENODATA ) {/* * We don't get ENODATA error when trying to remove a
@@ -73,7 +77,8 @@ static int mp_pacl_removexattr(FsContext *ctx,static ssize_t mp_dacl_getxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size) { -return lgetxattr (rpath (ctx, path),MAP_ACL_DEFAULT , value, size); +char buffer[PATH_MAX ]; +return lgetxattr (nrpath (ctx, path, buffer),MAP_ACL_DEFAULT , value, size); } static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,
@@ -97,14 +102,17 @@ static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path,static int mp_dacl_setxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size,int flags) { -return lsetxattr (rpath (ctx, path),MAP_ACL_DEFAULT , value, size, flags); +char buffer[PATH_MAX ]; +return lsetxattr (nrpath (ctx, path, buffer),MAP_ACL_DEFAULT , value, + size, flags); }static int mp_dacl_removexattr (FsContext *ctx,const char *path,const char *name) {int ret; - ret =lremovexattr (rpath (ctx, path),MAP_ACL_DEFAULT ); +char buffer[PATH_MAX ]; + ret =lremovexattr (nrpath (ctx, path, buffer),MAP_ACL_DEFAULT );if (ret ==-1 && errno ==ENODATA ) {/* * We don't get ENODATA error when trying to remove a
hw/9pfs/virtio-9p-xattr-user.c +6 -3
@@ -21,6 +21,7 @@static ssize_t mp_user_getxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size) { +char buffer[PATH_MAX ];if (strncmp (name,"user.virtfs." ,12 ) ==0 ) {/* * Don't allow fetch of user.virtfs namesapce
@@ -29,7 +30,7 @@ static ssize_t mp_user_getxattr(FsContext *ctx, const char *path, errno =ENOATTR ;return -1 ; } -return lgetxattr (rpath (ctx, path), name, value, size); +return lgetxattr (nrpath (ctx, path, buffer), name, value, size); } static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,
@@ -67,6 +68,7 @@ static ssize_t mp_user_listxattr(FsContext *ctx, const char *path,static int mp_user_setxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size,int flags) { +char buffer[PATH_MAX ];if (strncmp (name,"user.virtfs." ,12 ) ==0 ) {/* * Don't allow fetch of user.virtfs namesapce
@@ -75,12 +77,13 @@ static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name, errno =EACCES ;return -1 ; } -return lsetxattr (rpath (ctx, path), name, value, size, flags); +return lsetxattr (nrpath (ctx, path, buffer), name, value, size, flags); }static int mp_user_removexattr (FsContext *ctx,const char *path,const char *name) { +char buffer[PATH_MAX ];if (strncmp (name,"user.virtfs." ,12 ) ==0 ) {/* * Don't allow fetch of user.virtfs namesapce
@@ -89,7 +92,7 @@ static int mp_user_removexattr(FsContext *ctx, errno =EACCES ;return -1 ; } -return lremovexattr (rpath (ctx, path), name); +return lremovexattr (nrpath (ctx, path, buffer), name); }XattrOperations mapped_user_xattr = {
hw/9pfs/virtio-9p-xattr.c +3 -2
@@ -66,20 +66,21 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, void *value, size_t vsize) { ssize_t size = 0; +char buffer[PATH_MAX ];void *ovalue = value;XattrOperations *xops;char *orig_value, *orig_value_start;ssize_t xattr_len, parsed_len =0 , attr_len;/* Get the actual len */ - xattr_len =llistxattr (rpath (ctx, path), value,0 ); + xattr_len =llistxattr (nrpath (ctx, path, buffer), value,0 );if (xattr_len <=0 ) {return xattr_len; }/* Now fetch the xattr and find the actual size */ orig_value =qemu_malloc (xattr_len); - xattr_len =llistxattr (rpath (ctx, path), orig_value, xattr_len); + xattr_len =llistxattr (nrpath (ctx, path, buffer), orig_value, xattr_len);/* store the orig pointer */ orig_value_start = orig_value;
hw/9pfs/virtio-9p-xattr.h +6 -3
@@ -54,20 +54,23 @@ ssize_t pt_listxattr(FsContext *ctx, const char *path, char *name, void *value,static inline ssize_t pt_getxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size) { -return lgetxattr (rpath (ctx, path), name, value, size); +char buffer[PATH_MAX ]; +return lgetxattr (nrpath (ctx, path, buffer), name, value, size); }static inline int pt_setxattr (FsContext *ctx,const char *path,const char *name,void *value,size_t size,int flags) { -return lsetxattr (rpath (ctx, path), name, value, size, flags); +char buffer[PATH_MAX ]; +return lsetxattr (nrpath (ctx, path, buffer), name, value, size, flags); }static inline int pt_removexattr (FsContext *ctx,const char *path,const char *name) { -return lremovexattr (rpath (ctx, path), name); +char buffer[PATH_MAX ]; +return lremovexattr (nrpath (ctx, path, buffer), name); } static inline ssize_t notsup_getxattr(FsContext *ctx, const char *path,
hw/9pfs/virtio-9p.h +5 -0
@@ -101,6 +101,11 @@ enum p9_proto_version {#define P9_NOTAG (u16)(~0)#define P9_NOFID (u32)(~0)#define P9_MAXWELEM 16 +static inline const char *nrpath (FsContext *ctx,const char *path,char *buffer) +{ +snprintf (buffer,PATH_MAX ,"%s/%s" , ctx->fs_root, path); +return buffer; +}/* * ample room for Twrite/Rread header
Signature · 1 line
1.7.1