From 3571066deedfe858ef37f09d6ad2160e5dd7b803 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Mon, 27 Jan 2014 00:58:45 -0800 Subject: syncops: add support for custom PID AFR self-heal needs to issue syncops with special PID. Extend the custom UID/GID support to include custom PIDs Change-Id: I736c0e177f862b029f203acc87f9eb46c8cb839b BUG: 1021686 Signed-off-by: Anand Avati Reviewed-on: http://review.gluster.org/6888 Tested-by: Gluster Build System Reviewed-by: Raghavendra Bhat --- libglusterfs/src/syncop.c | 40 ++++++++++++++++++++++++++++++++++++++++ libglusterfs/src/syncop.h | 11 +++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 7e78d4f6e..9705a7d54 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -169,6 +169,46 @@ out: return ret; } +int +syncopctx_setfspid (void *pid) +{ + struct syncopctx *opctx = NULL; + int ret = 0; + + /* In args check */ + if (!pid) { + ret = -1; + errno = EINVAL; + goto out; + } + + opctx = syncopctx_getctx (); + + /* alloc for this thread the first time */ + if (!opctx) { + opctx = GF_CALLOC (1, sizeof (*opctx), gf_common_mt_syncopctx); + if (!opctx) { + ret = -1; + goto out; + } + + ret = syncopctx_setctx (opctx); + if (ret != 0) { + GF_FREE (opctx); + opctx = NULL; + goto out; + } + } + +out: + if (opctx && pid) { + opctx->pid = *(pid_t *)pid; + opctx->valid |= SYNCOPCTX_PID; + } + + return ret; +} + static void __run (struct synctask *task) { diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index 574918b9c..16f3833ba 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -31,6 +31,7 @@ #define SYNCOPCTX_UID 0x00000001 #define SYNCOPCTX_GID 0x00000002 #define SYNCOPCTX_GROUPS 0x00000004 +#define SYNCOPCTX_PID 0x00000008 struct synctask; struct syncproc; @@ -164,6 +165,7 @@ struct syncopctx { int grpsize; int ngrps; gid_t *groups; + pid_t pid; }; #define __yawn(args) do { \ @@ -260,6 +262,7 @@ int synctask_setid (struct synctask *task, uid_t uid, gid_t gid); int syncopctx_setfsuid (void *uid); int syncopctx_setfsgid (void *gid); int syncopctx_setfsgroups (int count, const void *groups); +int syncopctx_setfspid (void *pid); static inline call_frame_t * syncop_create_frame (xlator_t *this) @@ -272,9 +275,13 @@ syncop_create_frame (xlator_t *this) if (!frame) return NULL; - frame->root->pid = getpid (); - opctx = syncopctx_getctx (); + + if (opctx && (opctx->valid & SYNCOPCTX_PID)) + frame->root->pid = opctx->pid; + else + frame->root->pid = getpid (); + if (opctx && (opctx->valid & SYNCOPCTX_UID)) frame->root->uid = opctx->uid; else -- cgit