diff options
author | Jeff Darcy <jdarcy@redhat.com> | 2015-03-10 20:14:47 -0400 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2015-03-17 07:02:15 -0700 |
commit | 0d2bed70faed3c63f25ed9269dc55562973ef9b7 (patch) | |
tree | fee1995e88b7ae19d1cb27cf437ab76583d111e6 /libglusterfs/src | |
parent | 6b3704990257643da54100d8581856a7d2c72f86 (diff) |
every/where: add GF_FOP_IPC for inter-translator communication
Several features - e.g. encryption, erasure codes, or NSR - involve
multiple cooperating translators which sometimes need a "private" means
of communication amongst themselves. Historically we've used virtual or
synthetic xattrs, but that's not very elegant and clutters up the
getxattr/setxattr path which must also handle real xattr requests. This
new fop should address that.
The only argument is an int32_t "op" which should be recognized by the
target translator. It is recommended that translators using these
feature follow some convention regarding the ops that they define, to
avoid conflicts. Using a hash of the target translator's type string as
a base for a series of ops would probably be a good start. Any other
information can be passed in both directions using xdata.
The default behavior for this fop, as with any other, is to pass through
to FIRST_CHILD. That makes use of this fop "transparent" to other
translators that were written before it existed, but it also means that
it only really works with pass-through translators. If a routing
translator (such as DHT) or a fan-out translator (such as AFR) is
involved, the IPC might not reach its intended destination unless those
translators are modified to forward IPC fops along all paths.
If an IPC gets all the way to storage/posix it is considered an error,
much like an uncaught exception. We don't actually *do* anything in
that case, but we do log it send back an EOPNOTSUPP error. This makes
the "unrecognized opcode" condition distinguishable from the "no IPC
support" condition (which would yield an RPC error instead) so clients
can probe for the presence of a handler for their own favorite opcode
and either use that or use old-school xattrs depending on the result.
BUG: 1158628
Signed-off-by: Venky Shankar <vshankar@redhat.com>
Signed-off-by: Jeff Darcy <jdarcy@redhat.com>
Change-Id: I84af1b17babe5b30ec03ecf027ae37d09b873968
Reviewed-on: http://review.gluster.org/8812
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/Makefile.am | 2 | ||||
-rw-r--r-- | libglusterfs/src/call-stub.c | 55 | ||||
-rw-r--r-- | libglusterfs/src/call-stub.h | 10 | ||||
-rw-r--r-- | libglusterfs/src/defaults.c | 31 | ||||
-rw-r--r-- | libglusterfs/src/defaults.h | 9 | ||||
-rw-r--r-- | libglusterfs/src/globals.c | 3 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 3 | ||||
-rw-r--r-- | libglusterfs/src/syncop.c | 46 | ||||
-rw-r--r-- | libglusterfs/src/syncop.h | 4 | ||||
-rw-r--r-- | libglusterfs/src/xlator.c | 1 | ||||
-rw-r--r-- | libglusterfs/src/xlator.h | 10 |
11 files changed, 170 insertions, 4 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 3d1de02e894..02f4462e6b0 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -5,7 +5,7 @@ libglusterfs_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" \ -I$(top_srcdir)/rpc/rpc-lib/src/ -I$(CONTRIBDIR)/rbtree \ -I$(CONTRIBDIR)/libexecinfo ${ARGP_STANDALONE_CPPFLAGS} \ - -DSBIN_DIR=\"$(sbindir)\" + -DSBIN_DIR=\"$(sbindir)\" -lm libglusterfs_la_LIBADD = @LEXLIB@ $(ZLIB_LIBS) libglusterfs_la_LDFLAGS = -version-info $(LIBGLUSTERFS_LT_VERSION) diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c index 7e94ee3c001..ee2e7c93337 100644 --- a/libglusterfs/src/call-stub.c +++ b/libglusterfs/src/call-stub.c @@ -2297,7 +2297,53 @@ out: } -static void +call_stub_t * +fop_ipc_cbk_stub (call_frame_t *frame, fop_ipc_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + call_stub_t *stub = NULL; + + GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + + stub = stub_new (frame, 0, GF_FOP_IPC); + GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + + stub->fn_cbk.ipc = fn; + + stub->args_cbk.op_ret = op_ret; + stub->args_cbk.op_errno = op_errno; + + if (xdata) + stub->args_cbk.xdata = dict_ref (xdata); +out: + return stub; +} + +call_stub_t * +fop_ipc_stub (call_frame_t *frame, fop_ipc_t fn, + int32_t op, dict_t *xdata) +{ + call_stub_t *stub = NULL; + + GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + + stub = stub_new (frame, 1, GF_FOP_IPC); + GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + + stub->fn.ipc = fn; + + stub->args.cmd = op; + + if (xdata) + stub->args.xdata = dict_ref (xdata); +out: + return stub; + +} + + +void call_resume_wind (call_stub_t *stub) { GF_VALIDATE_OR_GOTO ("call-stub", stub, out); @@ -2529,6 +2575,10 @@ call_resume_wind (call_stub_t *stub) stub->args.fd, stub->args.offset, stub->args.size, stub->args.xdata); break; + case GF_FOP_IPC: + stub->fn.ipc (stub->frame, stub->frame->this, + stub->args.cmd, stub->args.xdata); + break; default: gf_log_callingfn ("call-stub", GF_LOG_ERROR, @@ -2736,6 +2786,9 @@ call_resume_unwind (call_stub_t *stub) STUB_UNWIND(stub, zerofill, &stub->args_cbk.prestat, &stub->args_cbk.poststat, stub->args_cbk.xdata); break; + case GF_FOP_IPC: + STUB_UNWIND (stub, ipc, stub->args_cbk.xdata); + break; default: gf_log_callingfn ("call-stub", GF_LOG_ERROR, diff --git a/libglusterfs/src/call-stub.h b/libglusterfs/src/call-stub.h index eba1413a1e6..fe110775fc6 100644 --- a/libglusterfs/src/call-stub.h +++ b/libglusterfs/src/call-stub.h @@ -72,6 +72,7 @@ typedef struct { fop_fallocate_t fallocate; fop_discard_t discard; fop_zerofill_t zerofill; + fop_ipc_t ipc; } fn; union { @@ -119,6 +120,7 @@ typedef struct { fop_fallocate_cbk_t fallocate; fop_discard_cbk_t discard; fop_zerofill_cbk_t zerofill; + fop_ipc_cbk_t ipc; } fn_cbk; struct { @@ -761,6 +763,14 @@ fop_zerofill_cbk_stub(call_frame_t *frame, struct iatt *statpre, struct iatt *statpost, dict_t *xdata); +call_stub_t * +fop_ipc_stub (call_frame_t *frame, fop_ipc_t fn, int32_t op, dict_t *xdata); + +call_stub_t * +fop_ipc_cbk_stub (call_frame_t *frame, fop_ipc_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata); + + void call_resume (call_stub_t *stub); void call_stub_destroy (call_stub_t *stub); void call_unwind_error (call_stub_t *stub, int op_ret, int op_errno); diff --git a/libglusterfs/src/defaults.c b/libglusterfs/src/defaults.c index a4f8f924b17..ac08a70cf32 100644 --- a/libglusterfs/src/defaults.c +++ b/libglusterfs/src/defaults.c @@ -1295,6 +1295,16 @@ default_getspec_cbk (call_frame_t *frame, void *cookie, xlator_t *this, return 0; } + +int32_t +default_ipc_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + STACK_UNWIND_STRICT (ipc, frame, op_ret, op_errno, xdata); + return 0; +} + + /* RESUME */ int32_t @@ -1726,6 +1736,17 @@ default_zerofill_resume(call_frame_t *frame, xlator_t *this, fd_t *fd, } +int32_t +default_ipc_resume (call_frame_t *frame, xlator_t *this, int32_t op, + dict_t *xdata) +{ + STACK_WIND (frame, default_ipc_cbk, + FIRST_CHILD(this), FIRST_CHILD(this)->fops->ipc, + op, xdata); + return 0; +} + + /* FOPS */ int32_t @@ -2162,6 +2183,16 @@ default_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t +default_ipc (call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata) +{ + STACK_WIND_TAIL (frame, + FIRST_CHILD(this), FIRST_CHILD(this)->fops->ipc, + op, xdata); + return 0; +} + + +int32_t default_forget (xlator_t *this, inode_t *inode) { gf_log_callingfn (this->name, GF_LOG_WARNING, "xlator does not " diff --git a/libglusterfs/src/defaults.h b/libglusterfs/src/defaults.h index 9bd5eb842ad..e29d62edfe1 100644 --- a/libglusterfs/src/defaults.h +++ b/libglusterfs/src/defaults.h @@ -263,6 +263,9 @@ int32_t default_zerofill(call_frame_t *frame, off_t offset, off_t len, dict_t *xdata); +int32_t default_ipc (call_frame_t *frame, xlator_t *this, int32_t op, + dict_t *xdata); + /* Resume */ int32_t default_getspec_resume (call_frame_t *frame, @@ -492,6 +495,9 @@ int32_t default_zerofill_resume(call_frame_t *frame, off_t offset, off_t len, dict_t *xdata); +int32_t default_ipc_resume (call_frame_t *frame, xlator_t *this, + int32_t op, dict_t *xdata); + /* _cbk_resume */ @@ -985,6 +991,9 @@ int32_t default_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *pre, struct iatt *post, dict_t *xdata); +int32_t default_ipc_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata); + int32_t default_getspec_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, char *spec_data); diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index 57467ecde1d..bd1165ec50c 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -70,7 +70,8 @@ const char *gf_fop_list[GF_FOP_MAXVALUE] = { [GF_FOP_FREMOVEXATTR]= "FREMOVEXATTR", [GF_FOP_FALLOCATE] = "FALLOCATE", [GF_FOP_DISCARD] = "DISCARD", - [GF_FOP_ZEROFILL] = "ZEROFILL", + [GF_FOP_ZEROFILL] = "ZEROFILL", + [GF_FOP_IPC] = "IPC", }; /* THIS */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index d5a604d0341..8d7659b5015 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -238,7 +238,7 @@ typedef enum { GF_FOP_WRITE, GF_FOP_STATFS, GF_FOP_FLUSH, - GF_FOP_FSYNC, /* 15 */ + GF_FOP_FSYNC, /* 16 */ GF_FOP_SETXATTR, GF_FOP_GETXATTR, GF_FOP_REMOVEXATTR, @@ -271,6 +271,7 @@ typedef enum { GF_FOP_FALLOCATE, GF_FOP_DISCARD, GF_FOP_ZEROFILL, + GF_FOP_IPC, GF_FOP_MAXVALUE, } glusterfs_fop_t; diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 9df462321aa..e3321cf6ddb 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -2417,6 +2417,52 @@ syncop_zerofill(xlator_t *subvol, fd_t *fd, off_t offset, off_t len) int +syncop_ipc_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata) +{ + struct syncargs *args = NULL; + + args = cookie; + + if (xdata) { + args->xdata = dict_ref(xdata); + } + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; +} + +int +syncop_ipc (xlator_t *subvol, int32_t op, dict_t *xdata_in, dict_t **xdata_out) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_ipc_cbk, subvol->fops->ipc, + op, xdata_in); + + if (args.xdata) { + if (xdata_out) { + /* + * We're passing this reference to the caller, along + * with the pointer itself. That means they're + * responsible for calling dict_unref at some point. + */ + *xdata_out = args.xdata; + } else { + dict_unref(args.xdata); + } + } + + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; +} + +int syncop_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, int op_errno, struct gf_flock *flock, dict_t *xdata) diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index ec0d8a917e8..7f8ec7345b0 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -435,4 +435,8 @@ int syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock); int syncop_inodelk (xlator_t *subvol, const char *volume, loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata_req, dict_t **xdata_rsp); + +int +syncop_ipc (xlator_t *subvol, int op, dict_t *xdata_in, dict_t **xdata_out); + #endif /* _SYNCOP_H */ diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index b58247e52bc..49af7d2e0e6 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -82,6 +82,7 @@ fill_defaults (xlator_t *xl) SET_DEFAULT_FOP (fallocate); SET_DEFAULT_FOP (discard); SET_DEFAULT_FOP (zerofill); + SET_DEFAULT_FOP (ipc); SET_DEFAULT_FOP (getspec); diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 8e52bbb3010..e953ec04372 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -443,6 +443,10 @@ typedef int32_t (*fop_zerofill_cbk_t) (call_frame_t *frame, struct iatt *preop_stbuf, struct iatt *postop_stbuf, dict_t *xdata); +typedef int32_t (*fop_ipc_cbk_t) (call_frame_t *frame, void *cookie, + xlator_t *this, int32_t op_ret, + int32_t op_errno, dict_t *xdata); + typedef int32_t (*fop_lookup_t) (call_frame_t *frame, xlator_t *this, loc_t *loc, @@ -674,6 +678,7 @@ typedef int32_t (*fop_discard_t) (call_frame_t *frame, off_t offset, size_t len, dict_t *xdata); + typedef int32_t (*fop_zerofill_t) (call_frame_t *frame, xlator_t *this, fd_t *fd, @@ -681,6 +686,9 @@ typedef int32_t (*fop_zerofill_t) (call_frame_t *frame, off_t len, dict_t *xdata); +typedef int32_t (*fop_ipc_t) (call_frame_t *frame, xlator_t *this, int32_t op, + dict_t *xdata); + struct xlator_fops { fop_lookup_t lookup; fop_stat_t stat; @@ -727,6 +735,7 @@ struct xlator_fops { fop_fallocate_t fallocate; fop_discard_t discard; fop_zerofill_t zerofill; + fop_ipc_t ipc; /* these entries are used for a typechecking hack in STACK_WIND _only_ */ fop_lookup_cbk_t lookup_cbk; @@ -774,6 +783,7 @@ struct xlator_fops { fop_fallocate_cbk_t fallocate_cbk; fop_discard_cbk_t discard_cbk; fop_zerofill_cbk_t zerofill_cbk; + fop_ipc_cbk_t ipc_cbk; }; typedef int32_t (*cbk_forget_t) (xlator_t *this, |