diff options
Diffstat (limited to 'libglusterfs/src')
62 files changed, 33671 insertions, 34733 deletions
diff --git a/libglusterfs/src/atomic.h b/libglusterfs/src/atomic.h index 3fd3a8764bf..dbbdc309628 100644 --- a/libglusterfs/src/atomic.h +++ b/libglusterfs/src/atomic.h @@ -114,10 +114,14 @@ GF_ATOMIC_TYPE(SIZEOF_LONG, uintptr); /* gf_atomic_uintptr_t */ * builtin version depending on the size of the atomic structure. */ #define GF_ATOMIC_CHOOSE(_atomic, _op, _args...) \ ((sizeof(_atomic) > sizeof(uint64_t)) \ - ? ({ GF_ATOMIC_MACRO(GF_ATOMIC_LOCK_, _op) \ - (_atomic, ##_args); }) \ - : ({ GF_ATOMIC_MACRO(GF_ATOMIC_BASE_, _op) \ - (_atomic, ##_args); })) + ? ({ \ + GF_ATOMIC_MACRO(GF_ATOMIC_LOCK_, _op) \ + (_atomic, ##_args); \ + }) \ + : ({ \ + GF_ATOMIC_MACRO(GF_ATOMIC_BASE_, _op) \ + (_atomic, ##_args); \ + })) /* Macros to implement the mutex-based atomics. */ #define GF_ATOMIC_OP_PREPARE(_atomic, _name) \ diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c index a1b87bf5db2..7e2713fa384 100644 --- a/libglusterfs/src/call-stub.c +++ b/libglusterfs/src/call-stub.c @@ -16,2754 +16,2557 @@ #include "libglusterfs-messages.h" static call_stub_t * -stub_new (call_frame_t *frame, - char wind, - glusterfs_fop_t fop) +stub_new(call_frame_t *frame, char wind, glusterfs_fop_t fop) { - call_stub_t *new = NULL; + call_stub_t *new = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - new = mem_get0 (frame->this->ctx->stub_mem_pool); - GF_VALIDATE_OR_GOTO ("call-stub", new, out); + new = mem_get0(frame->this->ctx->stub_mem_pool); + GF_VALIDATE_OR_GOTO("call-stub", new, out); - new->frame = frame; - new->wind = wind; - new->fop = fop; - new->stub_mem_pool = frame->this->ctx->stub_mem_pool; - INIT_LIST_HEAD (&new->list); + new->frame = frame; + new->wind = wind; + new->fop = fop; + new->stub_mem_pool = frame->this->ctx->stub_mem_pool; + INIT_LIST_HEAD(&new->list); - INIT_LIST_HEAD (&new->args_cbk.entries); + INIT_LIST_HEAD(&new->args_cbk.entries); out: - return new; + return new; } - call_stub_t * -fop_lookup_stub (call_frame_t *frame, fop_lookup_t fn, loc_t *loc, - dict_t *xdata) +fop_lookup_stub(call_frame_t *frame, fop_lookup_t fn, loc_t *loc, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_LOOKUP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_LOOKUP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.lookup = fn; - args_lookup_store (&stub->args, loc, xdata); + stub->fn.lookup = fn; + args_lookup_store(&stub->args, loc, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_lookup_cbk_stub (call_frame_t *frame, fop_lookup_cbk_t fn, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, - dict_t *xdata, struct iatt *postparent) +fop_lookup_cbk_stub(call_frame_t *frame, fop_lookup_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + dict_t *xdata, struct iatt *postparent) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_LOOKUP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_LOOKUP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.lookup = fn; - args_lookup_cbk_store (&stub->args_cbk, op_ret, op_errno, inode, - buf, xdata, postparent); + stub->fn_cbk.lookup = fn; + args_lookup_cbk_store(&stub->args_cbk, op_ret, op_errno, inode, buf, xdata, + postparent); out: - return stub; + return stub; } - call_stub_t * -fop_stat_stub (call_frame_t *frame, fop_stat_t fn, - loc_t *loc, dict_t *xdata) +fop_stat_stub(call_frame_t *frame, fop_stat_t fn, loc_t *loc, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_STAT); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_STAT); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.stat = fn; - args_stat_store (&stub->args, loc, xdata); + stub->fn.stat = fn; + args_stat_store(&stub->args, loc, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_stat_cbk_stub (call_frame_t *frame, fop_stat_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *buf, dict_t *xdata) +fop_stat_cbk_stub(call_frame_t *frame, fop_stat_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *buf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_STAT); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_STAT); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.stat = fn; - args_stat_cbk_store (&stub->args_cbk, op_ret, op_errno, buf, - xdata); + stub->fn_cbk.stat = fn; + args_stat_cbk_store(&stub->args_cbk, op_ret, op_errno, buf, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fstat_stub (call_frame_t *frame, fop_fstat_t fn, - fd_t *fd, dict_t *xdata) +fop_fstat_stub(call_frame_t *frame, fop_fstat_t fn, fd_t *fd, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_FSTAT); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FSTAT); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fstat = fn; - args_fstat_store (&stub->args, fd, xdata); + stub->fn.fstat = fn; + args_fstat_store(&stub->args, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fstat_cbk_stub (call_frame_t *frame, fop_fstat_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *buf, dict_t *xdata) +fop_fstat_cbk_stub(call_frame_t *frame, fop_fstat_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *buf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FSTAT); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FSTAT); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fstat = fn; - args_fstat_cbk_store (&stub->args_cbk, op_ret, op_errno, buf, - xdata); + stub->fn_cbk.fstat = fn; + args_fstat_cbk_store(&stub->args_cbk, op_ret, op_errno, buf, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_truncate_stub (call_frame_t *frame, fop_truncate_t fn, - loc_t *loc, off_t off, dict_t *xdata) +fop_truncate_stub(call_frame_t *frame, fop_truncate_t fn, loc_t *loc, off_t off, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_TRUNCATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_TRUNCATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.truncate = fn; - args_truncate_store (&stub->args, loc, off, xdata); + stub->fn.truncate = fn; + args_truncate_store(&stub->args, loc, off, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_truncate_cbk_stub (call_frame_t *frame, fop_truncate_cbk_t fn, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +fop_truncate_cbk_stub(call_frame_t *frame, fop_truncate_cbk_t fn, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_TRUNCATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_TRUNCATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.truncate = fn; - args_truncate_cbk_store (&stub->args_cbk, op_ret, op_errno, - prebuf, postbuf, xdata); + stub->fn_cbk.truncate = fn; + args_truncate_cbk_store(&stub->args_cbk, op_ret, op_errno, prebuf, postbuf, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_ftruncate_stub (call_frame_t *frame, fop_ftruncate_t fn, - fd_t *fd, off_t off, dict_t *xdata) +fop_ftruncate_stub(call_frame_t *frame, fop_ftruncate_t fn, fd_t *fd, off_t off, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_FTRUNCATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FTRUNCATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.ftruncate = fn; - args_ftruncate_store (&stub->args, fd, off, xdata); + stub->fn.ftruncate = fn; + args_ftruncate_store(&stub->args, fd, off, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_ftruncate_cbk_stub (call_frame_t *frame, fop_ftruncate_cbk_t fn, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +fop_ftruncate_cbk_stub(call_frame_t *frame, fop_ftruncate_cbk_t fn, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FTRUNCATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FTRUNCATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.ftruncate = fn; - args_ftruncate_cbk_store (&stub->args_cbk, op_ret, op_errno, - prebuf, postbuf, xdata); + stub->fn_cbk.ftruncate = fn; + args_ftruncate_cbk_store(&stub->args_cbk, op_ret, op_errno, prebuf, postbuf, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_access_stub (call_frame_t *frame, fop_access_t fn, - loc_t *loc, int32_t mask, dict_t *xdata) +fop_access_stub(call_frame_t *frame, fop_access_t fn, loc_t *loc, int32_t mask, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_ACCESS); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_ACCESS); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.access = fn; - args_access_store (&stub->args, loc, mask, xdata); + stub->fn.access = fn; + args_access_store(&stub->args, loc, mask, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_access_cbk_stub (call_frame_t *frame, fop_access_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_access_cbk_stub(call_frame_t *frame, fop_access_cbk_t fn, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_ACCESS); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_ACCESS); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.access = fn; - args_access_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.access = fn; + args_access_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readlink_stub (call_frame_t *frame, fop_readlink_t fn, - loc_t *loc, size_t size, dict_t *xdata) +fop_readlink_stub(call_frame_t *frame, fop_readlink_t fn, loc_t *loc, + size_t size, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_READLINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_READLINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.readlink = fn; - args_readlink_store (&stub->args, loc, size, xdata); + stub->fn.readlink = fn; + args_readlink_store(&stub->args, loc, size, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readlink_cbk_stub (call_frame_t *frame, fop_readlink_cbk_t fn, - int32_t op_ret, int32_t op_errno, - const char *path, struct iatt *stbuf, dict_t *xdata) +fop_readlink_cbk_stub(call_frame_t *frame, fop_readlink_cbk_t fn, + int32_t op_ret, int32_t op_errno, const char *path, + struct iatt *stbuf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_READLINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_READLINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.readlink = fn; - args_readlink_cbk_store (&stub->args_cbk, op_ret, op_errno, path, - stbuf, xdata); + stub->fn_cbk.readlink = fn; + args_readlink_cbk_store(&stub->args_cbk, op_ret, op_errno, path, stbuf, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_mknod_stub (call_frame_t *frame, fop_mknod_t fn, loc_t *loc, mode_t mode, - dev_t rdev, mode_t umask, dict_t *xdata) +fop_mknod_stub(call_frame_t *frame, fop_mknod_t fn, loc_t *loc, mode_t mode, + dev_t rdev, mode_t umask, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_MKNOD); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_MKNOD); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.mknod = fn; - args_mknod_store (&stub->args, loc, mode, rdev, umask, xdata); + stub->fn.mknod = fn; + args_mknod_store(&stub->args, loc, mode, rdev, umask, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_mknod_cbk_stub (call_frame_t *frame, fop_mknod_cbk_t fn, int32_t op_ret, - int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +fop_mknod_cbk_stub(call_frame_t *frame, fop_mknod_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_MKNOD); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_MKNOD); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.mknod = fn; - args_mknod_cbk_store (&stub->args_cbk, op_ret, op_errno, inode, buf, - preparent, postparent, xdata); + stub->fn_cbk.mknod = fn; + args_mknod_cbk_store(&stub->args_cbk, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_mkdir_stub (call_frame_t *frame, fop_mkdir_t fn, - loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata) +fop_mkdir_stub(call_frame_t *frame, fop_mkdir_t fn, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_MKDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_MKDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.mkdir = fn; - args_mkdir_store (&stub->args, loc, mode, umask, xdata); + stub->fn.mkdir = fn; + args_mkdir_store(&stub->args, loc, mode, umask, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_mkdir_cbk_stub (call_frame_t *frame, fop_mkdir_cbk_t fn, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +fop_mkdir_cbk_stub(call_frame_t *frame, fop_mkdir_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_MKDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_MKDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.mkdir = fn; - args_mkdir_cbk_store (&stub->args_cbk, op_ret, op_errno, inode, - buf, preparent, postparent, xdata); + stub->fn_cbk.mkdir = fn; + args_mkdir_cbk_store(&stub->args_cbk, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_unlink_stub (call_frame_t *frame, fop_unlink_t fn, - loc_t *loc, int xflag, dict_t *xdata) +fop_unlink_stub(call_frame_t *frame, fop_unlink_t fn, loc_t *loc, int xflag, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_UNLINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_UNLINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.unlink = fn; - args_unlink_store (&stub->args, loc, xflag, xdata); + stub->fn.unlink = fn; + args_unlink_store(&stub->args, loc, xflag, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_unlink_cbk_stub (call_frame_t *frame, fop_unlink_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +fop_unlink_cbk_stub(call_frame_t *frame, fop_unlink_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_UNLINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_UNLINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.unlink = fn; - args_unlink_cbk_store (&stub->args_cbk, op_ret, op_errno, preparent, - postparent, xdata); + stub->fn_cbk.unlink = fn; + args_unlink_cbk_store(&stub->args_cbk, op_ret, op_errno, preparent, + postparent, xdata); out: - return stub; + return stub; } - - call_stub_t * -fop_rmdir_stub (call_frame_t *frame, fop_rmdir_t fn, - loc_t *loc, int flags, dict_t *xdata) +fop_rmdir_stub(call_frame_t *frame, fop_rmdir_t fn, loc_t *loc, int flags, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_RMDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_RMDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.rmdir = fn; - args_rmdir_store (&stub->args, loc, flags, xdata); + stub->fn.rmdir = fn; + args_rmdir_store(&stub->args, loc, flags, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_rmdir_cbk_stub (call_frame_t *frame, fop_rmdir_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +fop_rmdir_cbk_stub(call_frame_t *frame, fop_rmdir_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_RMDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_RMDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.rmdir = fn; - args_rmdir_cbk_store (&stub->args_cbk, op_ret, op_errno, preparent, - postparent, xdata); + stub->fn_cbk.rmdir = fn; + args_rmdir_cbk_store(&stub->args_cbk, op_ret, op_errno, preparent, + postparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_symlink_stub (call_frame_t *frame, fop_symlink_t fn, - const char *linkname, loc_t *loc, mode_t umask, dict_t *xdata) +fop_symlink_stub(call_frame_t *frame, fop_symlink_t fn, const char *linkname, + loc_t *loc, mode_t umask, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); - GF_VALIDATE_OR_GOTO ("call-stub", linkname, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", linkname, out); - stub = stub_new (frame, 1, GF_FOP_SYMLINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_SYMLINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.symlink = fn; - args_symlink_store (&stub->args, linkname, loc, umask, xdata); + stub->fn.symlink = fn; + args_symlink_store(&stub->args, linkname, loc, umask, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_symlink_cbk_stub (call_frame_t *frame, fop_symlink_cbk_t fn, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +fop_symlink_cbk_stub(call_frame_t *frame, fop_symlink_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_SYMLINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_SYMLINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.symlink = fn; - args_symlink_cbk_store (&stub->args_cbk, op_ret, op_errno, inode, buf, - preparent, postparent, xdata); + stub->fn_cbk.symlink = fn; + args_symlink_cbk_store(&stub->args_cbk, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_rename_stub (call_frame_t *frame, fop_rename_t fn, - loc_t *oldloc, loc_t *newloc, dict_t *xdata) +fop_rename_stub(call_frame_t *frame, fop_rename_t fn, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", oldloc, out); - GF_VALIDATE_OR_GOTO ("call-stub", newloc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", oldloc, out); + GF_VALIDATE_OR_GOTO("call-stub", newloc, out); - stub = stub_new (frame, 1, GF_FOP_RENAME); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_RENAME); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.rename = fn; - args_rename_store (&stub->args, oldloc, newloc, xdata); + stub->fn.rename = fn; + args_rename_store(&stub->args, oldloc, newloc, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_rename_cbk_stub (call_frame_t *frame, fop_rename_cbk_t fn, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent, - dict_t *xdata) +fop_rename_cbk_stub(call_frame_t *frame, fop_rename_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_RENAME); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_RENAME); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.rename = fn; - args_rename_cbk_store (&stub->args_cbk, op_ret, op_errno, buf, - preoldparent, postoldparent, prenewparent, - postnewparent, xdata); + stub->fn_cbk.rename = fn; + args_rename_cbk_store(&stub->args_cbk, op_ret, op_errno, buf, preoldparent, + postoldparent, prenewparent, postnewparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_link_stub (call_frame_t *frame, fop_link_t fn, - loc_t *oldloc, loc_t *newloc, dict_t *xdata) +fop_link_stub(call_frame_t *frame, fop_link_t fn, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", oldloc, out); - GF_VALIDATE_OR_GOTO ("call-stub", newloc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", oldloc, out); + GF_VALIDATE_OR_GOTO("call-stub", newloc, out); - stub = stub_new (frame, 1, GF_FOP_LINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_LINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.link = fn; - args_link_store (&stub->args, oldloc, newloc, xdata); + stub->fn.link = fn; + args_link_store(&stub->args, oldloc, newloc, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_link_cbk_stub (call_frame_t *frame, fop_link_cbk_t fn, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +fop_link_cbk_stub(call_frame_t *frame, fop_link_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_LINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_LINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.link = fn; - args_link_cbk_store (&stub->args_cbk, op_ret, op_errno, - inode, buf, preparent, postparent, xdata); + stub->fn_cbk.link = fn; + args_link_cbk_store(&stub->args_cbk, op_ret, op_errno, inode, buf, + preparent, postparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_create_stub (call_frame_t *frame, fop_create_t fn, - loc_t *loc, int32_t flags, mode_t mode, - mode_t umask, fd_t *fd, dict_t *xdata) +fop_create_stub(call_frame_t *frame, fop_create_t fn, loc_t *loc, int32_t flags, + mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_CREATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_CREATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.create = fn; - args_create_store (&stub->args, loc, flags, mode, - umask, fd, xdata); + stub->fn.create = fn; + args_create_store(&stub->args, loc, flags, mode, umask, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_create_cbk_stub (call_frame_t *frame, fop_create_cbk_t fn, - int32_t op_ret, int32_t op_errno, - fd_t *fd, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +fop_create_cbk_stub(call_frame_t *frame, fop_create_cbk_t fn, int32_t op_ret, + int32_t op_errno, fd_t *fd, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_CREATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_CREATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.create = fn; - args_create_cbk_store (&stub->args_cbk, op_ret, op_errno, fd, inode, - buf, preparent, postparent, xdata); + stub->fn_cbk.create = fn; + args_create_cbk_store(&stub->args_cbk, op_ret, op_errno, fd, inode, buf, + preparent, postparent, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_open_stub (call_frame_t *frame, fop_open_t fn, - loc_t *loc, int32_t flags, fd_t *fd, dict_t *xdata) +fop_open_stub(call_frame_t *frame, fop_open_t fn, loc_t *loc, int32_t flags, + fd_t *fd, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_OPEN); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_OPEN); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.open = fn; - args_open_store (&stub->args, loc, flags, fd, xdata); + stub->fn.open = fn; + args_open_store(&stub->args, loc, flags, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_open_cbk_stub (call_frame_t *frame, fop_open_cbk_t fn, - int32_t op_ret, int32_t op_errno, - fd_t *fd, dict_t *xdata) +fop_open_cbk_stub(call_frame_t *frame, fop_open_cbk_t fn, int32_t op_ret, + int32_t op_errno, fd_t *fd, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_OPEN); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_OPEN); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.open = fn; - args_open_cbk_store (&stub->args_cbk, op_ret, op_errno, fd, xdata); + stub->fn_cbk.open = fn; + args_open_cbk_store(&stub->args_cbk, op_ret, op_errno, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readv_stub (call_frame_t *frame, fop_readv_t fn, - fd_t *fd, size_t size, off_t off, uint32_t flags, - dict_t *xdata) +fop_readv_stub(call_frame_t *frame, fop_readv_t fn, fd_t *fd, size_t size, + off_t off, uint32_t flags, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_READ); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_READ); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.readv = fn; - args_readv_store (&stub->args, fd, size, off, flags, xdata); + stub->fn.readv = fn; + args_readv_store(&stub->args, fd, size, off, flags, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readv_cbk_stub (call_frame_t *frame, fop_readv_cbk_t fn, - int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *stbuf, - struct iobref *iobref, dict_t *xdata) +fop_readv_cbk_stub(call_frame_t *frame, fop_readv_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iovec *vector, int32_t count, + struct iatt *stbuf, struct iobref *iobref, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_READ); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_READ); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.readv = fn; - args_readv_cbk_store (&stub->args_cbk, op_ret, op_errno, vector, - count, stbuf, iobref, xdata); + stub->fn_cbk.readv = fn; + args_readv_cbk_store(&stub->args_cbk, op_ret, op_errno, vector, count, + stbuf, iobref, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_writev_stub (call_frame_t *frame, fop_writev_t fn, - fd_t *fd, struct iovec *vector, int32_t count, off_t off, - uint32_t flags, struct iobref *iobref, dict_t *xdata) +fop_writev_stub(call_frame_t *frame, fop_writev_t fn, fd_t *fd, + struct iovec *vector, int32_t count, off_t off, uint32_t flags, + struct iobref *iobref, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", vector, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", vector, out); - stub = stub_new (frame, 1, GF_FOP_WRITE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_WRITE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.writev = fn; - args_writev_store (&stub->args, fd, vector, count, off, flags, - iobref, xdata); + stub->fn.writev = fn; + args_writev_store(&stub->args, fd, vector, count, off, flags, iobref, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_writev_cbk_stub (call_frame_t *frame, fop_writev_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +fop_writev_cbk_stub(call_frame_t *frame, fop_writev_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *prebuf, struct iatt *postbuf, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_WRITE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_WRITE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.writev = fn; - args_writev_cbk_store (&stub->args_cbk, op_ret, op_errno, - prebuf, postbuf, xdata); + stub->fn_cbk.writev = fn; + args_writev_cbk_store(&stub->args_cbk, op_ret, op_errno, prebuf, postbuf, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_flush_stub (call_frame_t *frame, fop_flush_t fn, - fd_t *fd, dict_t *xdata) +fop_flush_stub(call_frame_t *frame, fop_flush_t fn, fd_t *fd, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_FLUSH); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FLUSH); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.flush = fn; - args_flush_store (&stub->args, fd, xdata); + stub->fn.flush = fn; + args_flush_store(&stub->args, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_flush_cbk_stub (call_frame_t *frame, fop_flush_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_flush_cbk_stub(call_frame_t *frame, fop_flush_cbk_t fn, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FLUSH); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FLUSH); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.flush = fn; - args_flush_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.flush = fn; + args_flush_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsync_stub (call_frame_t *frame, fop_fsync_t fn, - fd_t *fd, int32_t datasync, dict_t *xdata) +fop_fsync_stub(call_frame_t *frame, fop_fsync_t fn, fd_t *fd, int32_t datasync, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_FSYNC); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FSYNC); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fsync = fn; - args_fsync_store (&stub->args, fd, datasync, xdata); + stub->fn.fsync = fn; + args_fsync_store(&stub->args, fd, datasync, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsync_cbk_stub (call_frame_t *frame, fop_fsync_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +fop_fsync_cbk_stub(call_frame_t *frame, fop_fsync_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *prebuf, struct iatt *postbuf, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FSYNC); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FSYNC); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fsync = fn; - args_fsync_cbk_store (&stub->args_cbk, op_ret, op_errno, - prebuf, postbuf, xdata); + stub->fn_cbk.fsync = fn; + args_fsync_cbk_store(&stub->args_cbk, op_ret, op_errno, prebuf, postbuf, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_opendir_stub (call_frame_t *frame, fop_opendir_t fn, - loc_t *loc, fd_t *fd, dict_t *xdata) +fop_opendir_stub(call_frame_t *frame, fop_opendir_t fn, loc_t *loc, fd_t *fd, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_OPENDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_OPENDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.opendir = fn; - args_opendir_store (&stub->args, loc, fd, xdata); + stub->fn.opendir = fn; + args_opendir_store(&stub->args, loc, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_opendir_cbk_stub (call_frame_t *frame, fop_opendir_cbk_t fn, - int32_t op_ret, int32_t op_errno, - fd_t *fd, dict_t *xdata) +fop_opendir_cbk_stub(call_frame_t *frame, fop_opendir_cbk_t fn, int32_t op_ret, + int32_t op_errno, fd_t *fd, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_OPENDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_OPENDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.opendir = fn; - args_opendir_cbk_store (&stub->args_cbk, op_ret, op_errno, fd, xdata); + stub->fn_cbk.opendir = fn; + args_opendir_cbk_store(&stub->args_cbk, op_ret, op_errno, fd, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsyncdir_stub (call_frame_t *frame, fop_fsyncdir_t fn, - fd_t *fd, int32_t datasync, dict_t *xdata) +fop_fsyncdir_stub(call_frame_t *frame, fop_fsyncdir_t fn, fd_t *fd, + int32_t datasync, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_FSYNCDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FSYNCDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fsyncdir = fn; - args_fsyncdir_store (&stub->args, fd, datasync, xdata); + stub->fn.fsyncdir = fn; + args_fsyncdir_store(&stub->args, fd, datasync, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsyncdir_cbk_stub (call_frame_t *frame, fop_fsyncdir_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_fsyncdir_cbk_stub(call_frame_t *frame, fop_fsyncdir_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FSYNCDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FSYNCDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fsyncdir = fn; - args_fsyncdir_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.fsyncdir = fn; + args_fsyncdir_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_statfs_stub (call_frame_t *frame, fop_statfs_t fn, - loc_t *loc, dict_t *xdata) +fop_statfs_stub(call_frame_t *frame, fop_statfs_t fn, loc_t *loc, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_STATFS); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_STATFS); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.statfs = fn; - args_statfs_store (&stub->args, loc, xdata); + stub->fn.statfs = fn; + args_statfs_store(&stub->args, loc, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_statfs_cbk_stub (call_frame_t *frame, fop_statfs_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct statvfs *buf, dict_t *xdata) +fop_statfs_cbk_stub(call_frame_t *frame, fop_statfs_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct statvfs *buf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_STATFS); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_STATFS); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.statfs = fn; - args_statfs_cbk_store (&stub->args_cbk, op_ret, op_errno, buf, xdata); + stub->fn_cbk.statfs = fn; + args_statfs_cbk_store(&stub->args_cbk, op_ret, op_errno, buf, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_setxattr_stub (call_frame_t *frame, fop_setxattr_t fn, - loc_t *loc, dict_t *dict, - int32_t flags, dict_t *xdata) +fop_setxattr_stub(call_frame_t *frame, fop_setxattr_t fn, loc_t *loc, + dict_t *dict, int32_t flags, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_SETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_SETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.setxattr = fn; - args_setxattr_store (&stub->args, loc, dict, flags, xdata); + stub->fn.setxattr = fn; + args_setxattr_store(&stub->args, loc, dict, flags, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_setxattr_cbk_stub (call_frame_t *frame, - fop_setxattr_cbk_t fn, - int32_t op_ret, - int32_t op_errno, dict_t *xdata) +fop_setxattr_cbk_stub(call_frame_t *frame, fop_setxattr_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_SETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_SETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.setxattr = fn; - args_setxattr_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.setxattr = fn; + args_setxattr_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_getxattr_stub (call_frame_t *frame, fop_getxattr_t fn, - loc_t *loc, const char *name, dict_t *xdata) +fop_getxattr_stub(call_frame_t *frame, fop_getxattr_t fn, loc_t *loc, + const char *name, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); - stub = stub_new (frame, 1, GF_FOP_GETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_GETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.getxattr = fn; - args_getxattr_store (&stub->args, loc, name, xdata); + stub->fn.getxattr = fn; + args_getxattr_store(&stub->args, loc, name, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_getxattr_cbk_stub (call_frame_t *frame, fop_getxattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, - dict_t *dict, dict_t *xdata) +fop_getxattr_cbk_stub(call_frame_t *frame, fop_getxattr_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_GETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_GETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.getxattr = fn; - args_getxattr_cbk_store (&stub->args_cbk, op_ret, op_errno, dict, - xdata); + stub->fn_cbk.getxattr = fn; + args_getxattr_cbk_store(&stub->args_cbk, op_ret, op_errno, dict, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsetxattr_stub (call_frame_t *frame, fop_fsetxattr_t fn, - fd_t *fd, dict_t *dict, int32_t flags, dict_t *xdata) +fop_fsetxattr_stub(call_frame_t *frame, fop_fsetxattr_t fn, fd_t *fd, + dict_t *dict, int32_t flags, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fd, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fd, out); - stub = stub_new (frame, 1, GF_FOP_FSETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FSETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fsetxattr = fn; - args_fsetxattr_store (&stub->args, fd, dict, flags, xdata); + stub->fn.fsetxattr = fn; + args_fsetxattr_store(&stub->args, fd, dict, flags, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsetxattr_cbk_stub (call_frame_t *frame, fop_fsetxattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_fsetxattr_cbk_stub(call_frame_t *frame, fop_fsetxattr_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FSETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FSETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fsetxattr = fn; - args_fsetxattr_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.fsetxattr = fn; + args_fsetxattr_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fgetxattr_stub (call_frame_t *frame, fop_fgetxattr_t fn, - fd_t *fd, const char *name, dict_t *xdata) +fop_fgetxattr_stub(call_frame_t *frame, fop_fgetxattr_t fn, fd_t *fd, + const char *name, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fd, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fd, out); - stub = stub_new (frame, 1, GF_FOP_FGETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FGETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fgetxattr = fn; - args_fgetxattr_store (&stub->args, fd, name, xdata); + stub->fn.fgetxattr = fn; + args_fgetxattr_store(&stub->args, fd, name, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fgetxattr_cbk_stub (call_frame_t *frame, fop_fgetxattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, - dict_t *dict, dict_t *xdata) +fop_fgetxattr_cbk_stub(call_frame_t *frame, fop_fgetxattr_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_GETXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_GETXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fgetxattr = fn; - args_fgetxattr_cbk_store (&stub->args_cbk, op_ret, op_errno, dict, - xdata); + stub->fn_cbk.fgetxattr = fn; + args_fgetxattr_cbk_store(&stub->args_cbk, op_ret, op_errno, dict, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_removexattr_stub (call_frame_t *frame, fop_removexattr_t fn, - loc_t *loc, const char *name, dict_t *xdata) +fop_removexattr_stub(call_frame_t *frame, fop_removexattr_t fn, loc_t *loc, + const char *name, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", loc, out); - GF_VALIDATE_OR_GOTO ("call-stub", name, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", loc, out); + GF_VALIDATE_OR_GOTO("call-stub", name, out); - stub = stub_new (frame, 1, GF_FOP_REMOVEXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_REMOVEXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.removexattr = fn; - args_removexattr_store (&stub->args, loc, name, xdata); + stub->fn.removexattr = fn; + args_removexattr_store(&stub->args, loc, name, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_removexattr_cbk_stub (call_frame_t *frame, fop_removexattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_removexattr_cbk_stub(call_frame_t *frame, fop_removexattr_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_REMOVEXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_REMOVEXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.removexattr = fn; - args_removexattr_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.removexattr = fn; + args_removexattr_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fremovexattr_stub (call_frame_t *frame, fop_fremovexattr_t fn, - fd_t *fd, const char *name, dict_t *xdata) +fop_fremovexattr_stub(call_frame_t *frame, fop_fremovexattr_t fn, fd_t *fd, + const char *name, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fd, out); - GF_VALIDATE_OR_GOTO ("call-stub", name, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fd, out); + GF_VALIDATE_OR_GOTO("call-stub", name, out); - stub = stub_new (frame, 1, GF_FOP_FREMOVEXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FREMOVEXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fremovexattr = fn; - args_fremovexattr_store (&stub->args, fd, name, xdata); + stub->fn.fremovexattr = fn; + args_fremovexattr_store(&stub->args, fd, name, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fremovexattr_cbk_stub (call_frame_t *frame, fop_fremovexattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_fremovexattr_cbk_stub(call_frame_t *frame, fop_fremovexattr_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FREMOVEXATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FREMOVEXATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fremovexattr = fn; - args_fremovexattr_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.fremovexattr = fn; + args_fremovexattr_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_lk_stub (call_frame_t *frame, fop_lk_t fn, - fd_t *fd, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) +fop_lk_stub(call_frame_t *frame, fop_lk_t fn, fd_t *fd, int32_t cmd, + struct gf_flock *lock, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", lock, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", lock, out); - stub = stub_new (frame, 1, GF_FOP_LK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_LK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.lk = fn; - args_lk_store (&stub->args, fd, cmd, lock, xdata); + stub->fn.lk = fn; + args_lk_store(&stub->args, fd, cmd, lock, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_lk_cbk_stub (call_frame_t *frame, fop_lk_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct gf_flock *lock, dict_t *xdata) +fop_lk_cbk_stub(call_frame_t *frame, fop_lk_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct gf_flock *lock, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_LK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_LK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.lk = fn; - args_lk_cbk_store (&stub->args_cbk, op_ret, op_errno, lock, xdata); + stub->fn_cbk.lk = fn; + args_lk_cbk_store(&stub->args_cbk, op_ret, op_errno, lock, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_inodelk_stub (call_frame_t *frame, fop_inodelk_t fn, - const char *volume, loc_t *loc, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) +fop_inodelk_stub(call_frame_t *frame, fop_inodelk_t fn, const char *volume, + loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", lock, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", lock, out); - stub = stub_new (frame, 1, GF_FOP_INODELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_INODELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.inodelk = fn; - args_inodelk_store (&stub->args, volume, loc, cmd, - lock, xdata); + stub->fn.inodelk = fn; + args_inodelk_store(&stub->args, volume, loc, cmd, lock, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_inodelk_cbk_stub (call_frame_t *frame, fop_inodelk_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_inodelk_cbk_stub(call_frame_t *frame, fop_inodelk_cbk_t fn, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_INODELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_INODELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.inodelk = fn; - args_inodelk_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.inodelk = fn; + args_inodelk_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_finodelk_stub (call_frame_t *frame, fop_finodelk_t fn, - const char *volume, fd_t *fd, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) +fop_finodelk_stub(call_frame_t *frame, fop_finodelk_t fn, const char *volume, + fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", lock, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", lock, out); - stub = stub_new (frame, 1, GF_FOP_FINODELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FINODELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.finodelk = fn; - args_finodelk_store (&stub->args, volume, fd, cmd, - lock, xdata); + stub->fn.finodelk = fn; + args_finodelk_store(&stub->args, volume, fd, cmd, lock, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_finodelk_cbk_stub (call_frame_t *frame, fop_inodelk_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_finodelk_cbk_stub(call_frame_t *frame, fop_inodelk_cbk_t fn, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FINODELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FINODELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.finodelk = fn; - args_finodelk_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.finodelk = fn; + args_finodelk_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_entrylk_stub (call_frame_t *frame, fop_entrylk_t fn, - const char *volume, loc_t *loc, const char *name, - entrylk_cmd cmd, entrylk_type type, dict_t *xdata) +fop_entrylk_stub(call_frame_t *frame, fop_entrylk_t fn, const char *volume, + loc_t *loc, const char *name, entrylk_cmd cmd, + entrylk_type type, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_ENTRYLK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_ENTRYLK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.entrylk = fn; - args_entrylk_store (&stub->args, volume, loc, name, cmd, type, xdata); + stub->fn.entrylk = fn; + args_entrylk_store(&stub->args, volume, loc, name, cmd, type, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_entrylk_cbk_stub (call_frame_t *frame, fop_entrylk_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_entrylk_cbk_stub(call_frame_t *frame, fop_entrylk_cbk_t fn, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_ENTRYLK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_ENTRYLK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.entrylk = fn; - args_entrylk_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.entrylk = fn; + args_entrylk_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fentrylk_stub (call_frame_t *frame, fop_fentrylk_t fn, - const char *volume, fd_t *fd, const char *name, - entrylk_cmd cmd, entrylk_type type, dict_t *xdata) +fop_fentrylk_stub(call_frame_t *frame, fop_fentrylk_t fn, const char *volume, + fd_t *fd, const char *name, entrylk_cmd cmd, + entrylk_type type, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 1, GF_FOP_FENTRYLK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FENTRYLK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fentrylk = fn; - args_fentrylk_store (&stub->args, volume, fd, name, cmd, type, xdata); + stub->fn.fentrylk = fn; + args_fentrylk_store(&stub->args, volume, fd, name, cmd, type, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fentrylk_cbk_stub (call_frame_t *frame, fop_fentrylk_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_fentrylk_cbk_stub(call_frame_t *frame, fop_fentrylk_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FENTRYLK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FENTRYLK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fentrylk = fn; - args_fentrylk_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + stub->fn_cbk.fentrylk = fn; + args_fentrylk_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readdirp_cbk_stub (call_frame_t *frame, fop_readdirp_cbk_t fn, - int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries, dict_t *xdata) +fop_readdirp_cbk_stub(call_frame_t *frame, fop_readdirp_cbk_t fn, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_READDIRP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_READDIRP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.readdirp = fn; - args_readdirp_cbk_store (&stub->args_cbk, op_ret, op_errno, entries, - xdata); + stub->fn_cbk.readdirp = fn; + args_readdirp_cbk_store(&stub->args_cbk, op_ret, op_errno, entries, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readdir_cbk_stub (call_frame_t *frame, fop_readdir_cbk_t fn, - int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries, dict_t *xdata) +fop_readdir_cbk_stub(call_frame_t *frame, fop_readdir_cbk_t fn, int32_t op_ret, + int32_t op_errno, gf_dirent_t *entries, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_READDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_READDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.readdir = fn; - args_readdir_cbk_store (&stub->args_cbk, op_ret, op_errno, entries, - xdata); + stub->fn_cbk.readdir = fn; + args_readdir_cbk_store(&stub->args_cbk, op_ret, op_errno, entries, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readdir_stub (call_frame_t *frame, fop_readdir_t fn, - fd_t *fd, size_t size, - off_t off, dict_t *xdata) +fop_readdir_stub(call_frame_t *frame, fop_readdir_t fn, fd_t *fd, size_t size, + off_t off, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - stub = stub_new (frame, 1, GF_FOP_READDIR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_READDIR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.readdir = fn; - args_readdir_store (&stub->args, fd, size, off, xdata); + stub->fn.readdir = fn; + args_readdir_store(&stub->args, fd, size, off, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_readdirp_stub (call_frame_t *frame, fop_readdirp_t fn, - fd_t *fd, size_t size, off_t off, dict_t *xdata) +fop_readdirp_stub(call_frame_t *frame, fop_readdirp_t fn, fd_t *fd, size_t size, + off_t off, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - stub = stub_new (frame, 1, GF_FOP_READDIRP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_READDIRP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.readdirp = fn; - args_readdirp_store (&stub->args, fd, size, off, xdata); + stub->fn.readdirp = fn; + args_readdirp_store(&stub->args, fd, size, off, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_rchecksum_stub (call_frame_t *frame, fop_rchecksum_t fn, - fd_t *fd, off_t offset, int32_t len, dict_t *xdata) +fop_rchecksum_stub(call_frame_t *frame, fop_rchecksum_t fn, fd_t *fd, + off_t offset, int32_t len, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fd, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fd, out); - stub = stub_new (frame, 1, GF_FOP_RCHECKSUM); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_RCHECKSUM); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.rchecksum = fn; - args_rchecksum_store (&stub->args, fd, offset, len, xdata); + stub->fn.rchecksum = fn; + args_rchecksum_store(&stub->args, fd, offset, len, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_rchecksum_cbk_stub (call_frame_t *frame, fop_rchecksum_cbk_t fn, - int32_t op_ret, int32_t op_errno, - uint32_t weak_checksum, uint8_t *strong_checksum, - dict_t *xdata) +fop_rchecksum_cbk_stub(call_frame_t *frame, fop_rchecksum_cbk_t fn, + int32_t op_ret, int32_t op_errno, uint32_t weak_checksum, + uint8_t *strong_checksum, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_RCHECKSUM); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_RCHECKSUM); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.rchecksum = fn; - args_rchecksum_cbk_store (&stub->args_cbk, op_ret, op_errno, - weak_checksum, strong_checksum, xdata); + stub->fn_cbk.rchecksum = fn; + args_rchecksum_cbk_store(&stub->args_cbk, op_ret, op_errno, weak_checksum, + strong_checksum, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_xattrop_cbk_stub (call_frame_t *frame, fop_xattrop_cbk_t fn, int32_t op_ret, - int32_t op_errno, dict_t *xattr, dict_t *xdata) +fop_xattrop_cbk_stub(call_frame_t *frame, fop_xattrop_cbk_t fn, int32_t op_ret, + int32_t op_errno, dict_t *xattr, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_XATTROP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_XATTROP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.xattrop = fn; - args_xattrop_cbk_store (&stub->args_cbk, op_ret, op_errno, xattr, - xdata); + stub->fn_cbk.xattrop = fn; + args_xattrop_cbk_store(&stub->args_cbk, op_ret, op_errno, xattr, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fxattrop_cbk_stub (call_frame_t *frame, fop_fxattrop_cbk_t fn, - int32_t op_ret, int32_t op_errno, - dict_t *xattr, dict_t *xdata) +fop_fxattrop_cbk_stub(call_frame_t *frame, fop_fxattrop_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xattr, + dict_t *xdata) { - call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + call_stub_t *stub = NULL; + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FXATTROP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FXATTROP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fxattrop = fn; - args_xattrop_cbk_store (&stub->args_cbk, op_ret, op_errno, xattr, - xdata); + stub->fn_cbk.fxattrop = fn; + args_xattrop_cbk_store(&stub->args_cbk, op_ret, op_errno, xattr, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_xattrop_stub (call_frame_t *frame, fop_xattrop_t fn, - loc_t *loc, gf_xattrop_flags_t optype, - dict_t *xattr, dict_t *xdata) +fop_xattrop_stub(call_frame_t *frame, fop_xattrop_t fn, loc_t *loc, + gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", xattr, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", xattr, out); - stub = stub_new (frame, 1, GF_FOP_XATTROP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_XATTROP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.xattrop = fn; - args_xattrop_store (&stub->args, loc, optype, xattr, xdata); + stub->fn.xattrop = fn; + args_xattrop_store(&stub->args, loc, optype, xattr, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fxattrop_stub (call_frame_t *frame, fop_fxattrop_t fn, - fd_t *fd, gf_xattrop_flags_t optype, - dict_t *xattr, dict_t *xdata) +fop_fxattrop_stub(call_frame_t *frame, fop_fxattrop_t fn, fd_t *fd, + gf_xattrop_flags_t optype, dict_t *xattr, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", xattr, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", xattr, out); - stub = stub_new (frame, 1, GF_FOP_FXATTROP); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FXATTROP); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fxattrop = fn; - args_fxattrop_store (&stub->args, fd, optype, xattr, xdata); + stub->fn.fxattrop = fn; + args_fxattrop_store(&stub->args, fd, optype, xattr, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_setattr_cbk_stub (call_frame_t *frame, fop_setattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +fop_setattr_cbk_stub(call_frame_t *frame, fop_setattr_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_SETATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_SETATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.setattr = fn; - args_setattr_cbk_store (&stub->args_cbk, op_ret, op_errno, statpre, - statpost, xdata); + stub->fn_cbk.setattr = fn; + args_setattr_cbk_store(&stub->args_cbk, op_ret, op_errno, statpre, statpost, + xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsetattr_cbk_stub (call_frame_t *frame, fop_setattr_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +fop_fsetattr_cbk_stub(call_frame_t *frame, fop_setattr_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FSETATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FSETATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fsetattr = fn; - args_fsetattr_cbk_store (&stub->args_cbk, op_ret, op_errno, statpre, - statpost, xdata); + stub->fn_cbk.fsetattr = fn; + args_fsetattr_cbk_store(&stub->args_cbk, op_ret, op_errno, statpre, + statpost, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_setattr_stub (call_frame_t *frame, fop_setattr_t fn, - loc_t *loc, struct iatt *stbuf, - int32_t valid, dict_t *xdata) +fop_setattr_stub(call_frame_t *frame, fop_setattr_t fn, loc_t *loc, + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_SETATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_SETATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.setattr = fn; - args_setattr_store (&stub->args, loc, stbuf, valid, xdata); + stub->fn.setattr = fn; + args_setattr_store(&stub->args, loc, stbuf, valid, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_fsetattr_stub (call_frame_t *frame, fop_fsetattr_t fn, - fd_t *fd, struct iatt *stbuf, - int32_t valid, dict_t *xdata) +fop_fsetattr_stub(call_frame_t *frame, fop_fsetattr_t fn, fd_t *fd, + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_FSETATTR); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FSETATTR); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fsetattr = fn; - args_fsetattr_store (&stub->args, fd, stbuf, valid, xdata); + stub->fn.fsetattr = fn; + args_fsetattr_store(&stub->args, fd, stbuf, valid, xdata); out: - return stub; + return stub; } call_stub_t * fop_fallocate_cbk_stub(call_frame_t *frame, fop_fallocate_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) + int32_t op_ret, int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_FALLOCATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_FALLOCATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.fallocate = fn; + stub->fn_cbk.fallocate = fn; - args_fallocate_cbk_store (&stub->args_cbk, op_ret, op_errno, statpre, - statpost, xdata); + args_fallocate_cbk_store(&stub->args_cbk, op_ret, op_errno, statpre, + statpost, xdata); out: - return stub; + return stub; } call_stub_t * fop_fallocate_stub(call_frame_t *frame, fop_fallocate_t fn, fd_t *fd, - int32_t mode, off_t offset, size_t len, dict_t *xdata) + int32_t mode, off_t offset, size_t len, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_FALLOCATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_FALLOCATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.fallocate = fn; - args_fallocate_store (&stub->args, fd, mode, offset, len, xdata); + stub->fn.fallocate = fn; + args_fallocate_store(&stub->args, fd, mode, offset, len, xdata); out: - return stub; - + return stub; } call_stub_t * -fop_discard_cbk_stub(call_frame_t *frame, fop_discard_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +fop_discard_cbk_stub(call_frame_t *frame, fop_discard_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_DISCARD); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_DISCARD); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.discard = fn; + stub->fn_cbk.discard = fn; - args_discard_cbk_store (&stub->args_cbk, op_ret, op_errno, statpre, - statpost, xdata); + args_discard_cbk_store(&stub->args_cbk, op_ret, op_errno, statpre, statpost, + xdata); out: - return stub; + return stub; } call_stub_t * -fop_discard_stub(call_frame_t *frame, fop_discard_t fn, fd_t *fd, - off_t offset, size_t len, dict_t *xdata) +fop_discard_stub(call_frame_t *frame, fop_discard_t fn, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_DISCARD); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_DISCARD); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.discard = fn; - args_discard_store (&stub->args, fd, offset, len, xdata); + stub->fn.discard = fn; + args_discard_store(&stub->args, fd, offset, len, xdata); out: - return stub; - + return stub; } call_stub_t * fop_zerofill_cbk_stub(call_frame_t *frame, fop_zerofill_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) + int32_t op_ret, int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_ZEROFILL); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_ZEROFILL); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.zerofill = fn; + stub->fn_cbk.zerofill = fn; - args_zerofill_cbk_store (&stub->args_cbk, op_ret, op_errno, statpre, - statpost, xdata); + args_zerofill_cbk_store(&stub->args_cbk, op_ret, op_errno, statpre, + statpost, xdata); out: - return stub; + return stub; } call_stub_t * fop_zerofill_stub(call_frame_t *frame, fop_zerofill_t fn, fd_t *fd, - off_t offset, off_t len, dict_t *xdata) + off_t offset, off_t len, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_ZEROFILL); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_ZEROFILL); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.zerofill = fn; - args_zerofill_store (&stub->args, fd, offset, len, xdata); + stub->fn.zerofill = fn; + args_zerofill_store(&stub->args, fd, offset, len, xdata); out: - return stub; - + return stub; } - 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) +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; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + 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 = stub_new(frame, 0, GF_FOP_IPC); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.ipc = fn; + stub->fn_cbk.ipc = fn; - args_ipc_cbk_store (&stub->args_cbk, op_ret, op_errno, xdata); + args_ipc_cbk_store(&stub->args_cbk, op_ret, op_errno, xdata); out: - return stub; + return stub; } call_stub_t * -fop_ipc_stub (call_frame_t *frame, fop_ipc_t fn, - int32_t op, dict_t *xdata) +fop_ipc_stub(call_frame_t *frame, fop_ipc_t fn, int32_t op, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + 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 = stub_new(frame, 1, GF_FOP_IPC); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.ipc = fn; - args_ipc_store (&stub->args, op, xdata); + stub->fn.ipc = fn; + args_ipc_store(&stub->args, op, xdata); out: - return stub; - + return stub; } call_stub_t * -fop_lease_cbk_stub (call_frame_t *frame, fop_lease_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct gf_lease *lease, dict_t *xdata) +fop_lease_cbk_stub(call_frame_t *frame, fop_lease_cbk_t fn, int32_t op_ret, + int32_t op_errno, struct gf_lease *lease, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_LEASE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_LEASE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.lease = fn; - args_lease_cbk_store (&stub->args_cbk, op_ret, op_errno, lease, xdata); + stub->fn_cbk.lease = fn; + args_lease_cbk_store(&stub->args_cbk, op_ret, op_errno, lease, xdata); out: - return stub; + return stub; } call_stub_t * -fop_lease_stub (call_frame_t *frame, fop_lease_t fn, - loc_t *loc, struct gf_lease *lease, dict_t *xdata) +fop_lease_stub(call_frame_t *frame, fop_lease_t fn, loc_t *loc, + struct gf_lease *lease, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); - GF_VALIDATE_OR_GOTO ("call-stub", lease, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", lease, out); - stub = stub_new (frame, 1, GF_FOP_LEASE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_LEASE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.lease = fn; - args_lease_store (&stub->args, loc, lease, xdata); + stub->fn.lease = fn; + args_lease_store(&stub->args, loc, lease, xdata); out: - return stub; - + return stub; } call_stub_t * -fop_seek_cbk_stub (call_frame_t *frame, fop_seek_cbk_t fn, - int32_t op_ret, int32_t op_errno, off_t offset, - dict_t *xdata) +fop_seek_cbk_stub(call_frame_t *frame, fop_seek_cbk_t fn, int32_t op_ret, + int32_t op_errno, off_t offset, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_SEEK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_SEEK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.seek = fn; + stub->fn_cbk.seek = fn; - args_seek_cbk_store (&stub->args_cbk, op_ret, op_errno, offset, xdata); + args_seek_cbk_store(&stub->args_cbk, op_ret, op_errno, offset, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_seek_stub (call_frame_t *frame, fop_seek_t fn, fd_t *fd, - off_t offset, gf_seek_what_t what, dict_t *xdata) +fop_seek_stub(call_frame_t *frame, fop_seek_t fn, fd_t *fd, off_t offset, + gf_seek_what_t what, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_SEEK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_SEEK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.seek = fn; - args_seek_store (&stub->args, fd, offset, what, xdata); + stub->fn.seek = fn; + args_seek_store(&stub->args, fd, offset, what, xdata); out: - return stub; - + return stub; } call_stub_t * -fop_getactivelk_cbk_stub (call_frame_t *frame, fop_getactivelk_cbk_t fn, - int32_t op_ret, int32_t op_errno, - lock_migration_info_t *lmi, dict_t *xdata) +fop_getactivelk_cbk_stub(call_frame_t *frame, fop_getactivelk_cbk_t fn, + int32_t op_ret, int32_t op_errno, + lock_migration_info_t *lmi, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_GETACTIVELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_GETACTIVELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.getactivelk = fn; + stub->fn_cbk.getactivelk = fn; - args_getactivelk_cbk_store (&stub->args_cbk, op_ret, op_errno, lmi, - xdata); + args_getactivelk_cbk_store(&stub->args_cbk, op_ret, op_errno, lmi, xdata); out: - return stub; + return stub; } - call_stub_t * -fop_getactivelk_stub (call_frame_t *frame, fop_getactivelk_t fn, loc_t *loc, - dict_t *xdata) +fop_getactivelk_stub(call_frame_t *frame, fop_getactivelk_t fn, loc_t *loc, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_GETACTIVELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_GETACTIVELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.getactivelk = fn; + stub->fn.getactivelk = fn; - loc_copy (&stub->args.loc, loc); + loc_copy(&stub->args.loc, loc); - if (xdata) - stub->args.xdata = dict_ref (xdata); + if (xdata) + stub->args.xdata = dict_ref(xdata); out: - return stub; - + return stub; } call_stub_t * -fop_setactivelk_cbk_stub (call_frame_t *frame, fop_setactivelk_cbk_t fn, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +fop_setactivelk_cbk_stub(call_frame_t *frame, fop_setactivelk_cbk_t fn, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_SETACTIVELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_SETACTIVELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.setactivelk = fn; - stub->args_cbk.op_ret = op_ret; - stub->args_cbk.op_errno = op_errno; + stub->fn_cbk.setactivelk = fn; + stub->args_cbk.op_ret = op_ret; + stub->args_cbk.op_errno = op_errno; - if (xdata) - stub->args.xdata = dict_ref (xdata); + if (xdata) + stub->args.xdata = dict_ref(xdata); out: - return stub; + return stub; } call_stub_t * -fop_setactivelk_stub (call_frame_t *frame, fop_setactivelk_t fn, - loc_t *loc, lock_migration_info_t *locklist, - dict_t *xdata) +fop_setactivelk_stub(call_frame_t *frame, fop_setactivelk_t fn, loc_t *loc, + lock_migration_info_t *locklist, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_SETACTIVELK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_SETACTIVELK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.setactivelk = fn; + stub->fn.setactivelk = fn; - args_setactivelk_store (&stub->args, loc, locklist, xdata); + args_setactivelk_store(&stub->args, loc, locklist, xdata); out: - return stub; - + return stub; } call_stub_t * -fop_put_stub (call_frame_t *frame, fop_put_t fn, - loc_t *loc, mode_t mode, mode_t umask, uint32_t flags, - struct iovec *vector, int32_t count, off_t offset, - struct iobref *iobref, dict_t *xattr, dict_t *xdata) +fop_put_stub(call_frame_t *frame, fop_put_t fn, loc_t *loc, mode_t mode, + mode_t umask, uint32_t flags, struct iovec *vector, int32_t count, + off_t offset, struct iobref *iobref, dict_t *xattr, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", vector, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", vector, out); - stub = stub_new (frame, 1, GF_FOP_PUT); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_PUT); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.put = fn; - args_put_store (&stub->args, loc, mode, umask, flags, vector, - count, offset, iobref, xattr, xdata); + stub->fn.put = fn; + args_put_store(&stub->args, loc, mode, umask, flags, vector, count, offset, + iobref, xattr, xdata); out: - return stub; + return stub; } call_stub_t * -fop_put_cbk_stub (call_frame_t *frame, fop_put_cbk_t fn, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +fop_put_cbk_stub(call_frame_t *frame, fop_put_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_PUT); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_PUT); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.put = fn; - args_put_cbk_store (&stub->args_cbk, op_ret, op_errno, inode, - buf, preparent, postparent, xdata); + stub->fn_cbk.put = fn; + args_put_cbk_store(&stub->args_cbk, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); out: - return stub; + return stub; } call_stub_t * -fop_icreate_stub (call_frame_t *frame, fop_icreate_t fn, - loc_t *loc, mode_t mode, dict_t *xdata) +fop_icreate_stub(call_frame_t *frame, fop_icreate_t fn, loc_t *loc, mode_t mode, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_ICREATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_ICREATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.icreate = fn; + stub->fn.icreate = fn; - stub->args.mode = mode; - if (loc) - loc_copy (&stub->args.loc, loc); - if (xdata) - stub->args.xdata = dict_ref (xdata); + stub->args.mode = mode; + if (loc) + loc_copy(&stub->args.loc, loc); + if (xdata) + stub->args.xdata = dict_ref(xdata); - out: - return stub; +out: + return stub; } static void -args_icreate_store_cbk (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, dict_t *xdata) +args_icreate_store_cbk(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (xdata) + args->xdata = dict_ref(xdata); } call_stub_t * -fop_icreate_cbk_stub (call_frame_t *frame, - fop_icreate_cbk_t fn, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, dict_t *xdata) +fop_icreate_cbk_stub(call_frame_t *frame, fop_icreate_cbk_t fn, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_ICREATE); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_ICREATE); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.icreate = fn; - args_icreate_store_cbk (&stub->args_cbk, - op_ret, op_errno, inode, buf, xdata); + stub->fn_cbk.icreate = fn; + args_icreate_store_cbk(&stub->args_cbk, op_ret, op_errno, inode, buf, + xdata); - out: - return stub; +out: + return stub; } call_stub_t * -fop_namelink_stub (call_frame_t *frame, - fop_namelink_t fn, loc_t *loc, dict_t *xdata) +fop_namelink_stub(call_frame_t *frame, fop_namelink_t fn, loc_t *loc, + dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); - GF_VALIDATE_OR_GOTO ("call-stub", fn, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", fn, out); - stub = stub_new (frame, 1, GF_FOP_NAMELINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 1, GF_FOP_NAMELINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn.namelink = fn; + stub->fn.namelink = fn; - if (loc) - loc_copy (&stub->args.loc, loc); - if (xdata) - stub->args.xdata = dict_ref (xdata); + if (loc) + loc_copy(&stub->args.loc, loc); + if (xdata) + stub->args.xdata = dict_ref(xdata); - out: - return stub; +out: + return stub; } static void -args_namelink_store_cbk (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +args_namelink_store_cbk(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; + args->op_ret = op_ret; + args->op_errno = op_errno; - if (prebuf) - args->prestat = *prebuf; - if (postbuf) - args->poststat = *postbuf; - if (xdata) - args->xdata = dict_ref (xdata); + if (prebuf) + args->prestat = *prebuf; + if (postbuf) + args->poststat = *postbuf; + if (xdata) + args->xdata = dict_ref(xdata); } call_stub_t * -fop_namelink_cbk_stub (call_frame_t *frame, - fop_namelink_cbk_t fn, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +fop_namelink_cbk_stub(call_frame_t *frame, fop_namelink_cbk_t fn, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - call_stub_t *stub = NULL; + call_stub_t *stub = NULL; - GF_VALIDATE_OR_GOTO ("call-stub", frame, out); + GF_VALIDATE_OR_GOTO("call-stub", frame, out); - stub = stub_new (frame, 0, GF_FOP_NAMELINK); - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + stub = stub_new(frame, 0, GF_FOP_NAMELINK); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - stub->fn_cbk.namelink = fn; - args_namelink_store_cbk (&stub->args_cbk, - op_ret, op_errno, prebuf, postbuf, xdata); + stub->fn_cbk.namelink = fn; + args_namelink_store_cbk(&stub->args_cbk, op_ret, op_errno, prebuf, postbuf, + xdata); - out: - return stub; +out: + return stub; } void -call_resume_wind (call_stub_t *stub) +call_resume_wind(call_stub_t *stub) { - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - switch (stub->fop) { + switch (stub->fop) { case GF_FOP_OPEN: - stub->fn.open (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.flags, - stub->args.fd, stub->args.xdata); - break; + stub->fn.open(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.flags, stub->args.fd, stub->args.xdata); + break; case GF_FOP_CREATE: - stub->fn.create (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.flags, - stub->args.mode, stub->args.umask, - stub->args.fd, stub->args.xdata); - break; + stub->fn.create(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.flags, stub->args.mode, stub->args.umask, + stub->args.fd, stub->args.xdata); + break; case GF_FOP_STAT: - stub->fn.stat (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.xdata); - break; + stub->fn.stat(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.xdata); + break; case GF_FOP_READLINK: - stub->fn.readlink (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.size, - stub->args.xdata); - break; + stub->fn.readlink(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.size, stub->args.xdata); + break; case GF_FOP_MKNOD: - stub->fn.mknod (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.mode, - stub->args.rdev, stub->args.umask, - stub->args.xdata); - break; + stub->fn.mknod(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.mode, stub->args.rdev, stub->args.umask, + stub->args.xdata); + break; case GF_FOP_MKDIR: - stub->fn.mkdir (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.mode, - stub->args.umask, stub->args.xdata); - break; + stub->fn.mkdir(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.mode, stub->args.umask, stub->args.xdata); + break; case GF_FOP_UNLINK: - stub->fn.unlink (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.xflag, - stub->args.xdata); - break; + stub->fn.unlink(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.xflag, stub->args.xdata); + break; case GF_FOP_RMDIR: - stub->fn.rmdir (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.flags, - stub->args.xdata); - break; + stub->fn.rmdir(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.flags, stub->args.xdata); + break; case GF_FOP_SYMLINK: - stub->fn.symlink (stub->frame, stub->frame->this, - stub->args.linkname, &stub->args.loc, - stub->args.umask, stub->args.xdata); - break; + stub->fn.symlink(stub->frame, stub->frame->this, + stub->args.linkname, &stub->args.loc, + stub->args.umask, stub->args.xdata); + break; case GF_FOP_RENAME: - stub->fn.rename (stub->frame, stub->frame->this, - &stub->args.loc, &stub->args.loc2, - stub->args.xdata); - break; + stub->fn.rename(stub->frame, stub->frame->this, &stub->args.loc, + &stub->args.loc2, stub->args.xdata); + break; case GF_FOP_LINK: - stub->fn.link (stub->frame, stub->frame->this, - &stub->args.loc, &stub->args.loc2, - stub->args.xdata); - break; + stub->fn.link(stub->frame, stub->frame->this, &stub->args.loc, + &stub->args.loc2, stub->args.xdata); + break; case GF_FOP_TRUNCATE: - stub->fn.truncate (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.offset, - stub->args.xdata); - break; + stub->fn.truncate(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.offset, stub->args.xdata); + break; case GF_FOP_READ: - stub->fn.readv (stub->frame, stub->frame->this, - stub->args.fd, stub->args.size, - stub->args.offset, stub->args.flags, - stub->args.xdata); - break; + stub->fn.readv(stub->frame, stub->frame->this, stub->args.fd, + stub->args.size, stub->args.offset, stub->args.flags, + stub->args.xdata); + break; case GF_FOP_WRITE: - stub->fn.writev (stub->frame, stub->frame->this, - stub->args.fd, stub->args.vector, - stub->args.count, stub->args.offset, - stub->args.flags, stub->args.iobref, - stub->args.xdata); - break; + stub->fn.writev(stub->frame, stub->frame->this, stub->args.fd, + stub->args.vector, stub->args.count, + stub->args.offset, stub->args.flags, + stub->args.iobref, stub->args.xdata); + break; case GF_FOP_STATFS: - stub->fn.statfs (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.xdata); - break; + stub->fn.statfs(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.xdata); + break; case GF_FOP_FLUSH: - stub->fn.flush (stub->frame, stub->frame->this, - stub->args.fd, stub->args.xdata); - break; + stub->fn.flush(stub->frame, stub->frame->this, stub->args.fd, + stub->args.xdata); + break; case GF_FOP_FSYNC: - stub->fn.fsync (stub->frame, stub->frame->this, - stub->args.fd, stub->args.datasync, - stub->args.xdata); - break; + stub->fn.fsync(stub->frame, stub->frame->this, stub->args.fd, + stub->args.datasync, stub->args.xdata); + break; case GF_FOP_SETXATTR: - stub->fn.setxattr (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.xattr, - stub->args.flags, stub->args.xdata); - break; + stub->fn.setxattr(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.xattr, stub->args.flags, + stub->args.xdata); + break; case GF_FOP_GETXATTR: - stub->fn.getxattr (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.name, - stub->args.xdata); - break; + stub->fn.getxattr(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.name, stub->args.xdata); + break; case GF_FOP_FSETXATTR: - stub->fn.fsetxattr (stub->frame, stub->frame->this, - stub->args.fd, stub->args.xattr, - stub->args.flags, stub->args.xdata); - break; + stub->fn.fsetxattr(stub->frame, stub->frame->this, stub->args.fd, + stub->args.xattr, stub->args.flags, + stub->args.xdata); + break; case GF_FOP_FGETXATTR: - stub->fn.fgetxattr (stub->frame, stub->frame->this, - stub->args.fd, stub->args.name, - stub->args.xdata); - break; + stub->fn.fgetxattr(stub->frame, stub->frame->this, stub->args.fd, + stub->args.name, stub->args.xdata); + break; case GF_FOP_REMOVEXATTR: - stub->fn.removexattr (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.name, - stub->args.xdata); - break; + stub->fn.removexattr(stub->frame, stub->frame->this, + &stub->args.loc, stub->args.name, + stub->args.xdata); + break; case GF_FOP_FREMOVEXATTR: - stub->fn.fremovexattr (stub->frame, stub->frame->this, - stub->args.fd, stub->args.name, - stub->args.xdata); - break; + stub->fn.fremovexattr(stub->frame, stub->frame->this, stub->args.fd, + stub->args.name, stub->args.xdata); + break; case GF_FOP_OPENDIR: - stub->fn.opendir (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.fd, - stub->args.xdata); - break; + stub->fn.opendir(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.fd, stub->args.xdata); + break; case GF_FOP_FSYNCDIR: - stub->fn.fsyncdir (stub->frame, stub->frame->this, - stub->args.fd, stub->args.datasync, - stub->args.xdata); - break; + stub->fn.fsyncdir(stub->frame, stub->frame->this, stub->args.fd, + stub->args.datasync, stub->args.xdata); + break; case GF_FOP_ACCESS: - stub->fn.access (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.mask, - stub->args.xdata); - break; + stub->fn.access(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.mask, stub->args.xdata); + break; case GF_FOP_FTRUNCATE: - stub->fn.ftruncate (stub->frame, stub->frame->this, - stub->args.fd, stub->args.offset, - stub->args.xdata); - break; + stub->fn.ftruncate(stub->frame, stub->frame->this, stub->args.fd, + stub->args.offset, stub->args.xdata); + break; case GF_FOP_FSTAT: - stub->fn.fstat (stub->frame, stub->frame->this, - stub->args.fd, stub->args.xdata); - break; + stub->fn.fstat(stub->frame, stub->frame->this, stub->args.fd, + stub->args.xdata); + break; case GF_FOP_LK: - stub->fn.lk (stub->frame, stub->frame->this, - stub->args.fd, stub->args.cmd, - &stub->args.lock, stub->args.xdata); - break; + stub->fn.lk(stub->frame, stub->frame->this, stub->args.fd, + stub->args.cmd, &stub->args.lock, stub->args.xdata); + break; case GF_FOP_INODELK: - stub->fn.inodelk (stub->frame, stub->frame->this, - stub->args.volume, &stub->args.loc, - stub->args.cmd, &stub->args.lock, - stub->args.xdata); - break; + stub->fn.inodelk(stub->frame, stub->frame->this, stub->args.volume, + &stub->args.loc, stub->args.cmd, &stub->args.lock, + stub->args.xdata); + break; case GF_FOP_FINODELK: - stub->fn.finodelk (stub->frame, stub->frame->this, - stub->args.volume, stub->args.fd, - stub->args.cmd, &stub->args.lock, - stub->args.xdata); - break; + stub->fn.finodelk(stub->frame, stub->frame->this, stub->args.volume, + stub->args.fd, stub->args.cmd, &stub->args.lock, + stub->args.xdata); + break; case GF_FOP_ENTRYLK: - stub->fn.entrylk (stub->frame, stub->frame->this, - stub->args.volume, &stub->args.loc, - stub->args.name, stub->args.entrylkcmd, - stub->args.entrylktype, stub->args.xdata); - break; + stub->fn.entrylk(stub->frame, stub->frame->this, stub->args.volume, + &stub->args.loc, stub->args.name, + stub->args.entrylkcmd, stub->args.entrylktype, + stub->args.xdata); + break; case GF_FOP_FENTRYLK: - stub->fn.fentrylk (stub->frame, stub->frame->this, - stub->args.volume, stub->args.fd, - stub->args.name, stub->args.entrylkcmd, - stub->args.entrylktype, stub->args.xdata); - break; + stub->fn.fentrylk(stub->frame, stub->frame->this, stub->args.volume, + stub->args.fd, stub->args.name, + stub->args.entrylkcmd, stub->args.entrylktype, + stub->args.xdata); + break; case GF_FOP_LOOKUP: - stub->fn.lookup (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.xdata); - break; + stub->fn.lookup(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.xdata); + break; case GF_FOP_RCHECKSUM: - stub->fn.rchecksum (stub->frame, stub->frame->this, - stub->args.fd, stub->args.offset, - stub->args.size, stub->args.xdata); - break; + stub->fn.rchecksum(stub->frame, stub->frame->this, stub->args.fd, + stub->args.offset, stub->args.size, + stub->args.xdata); + break; case GF_FOP_READDIR: - stub->fn.readdir (stub->frame, stub->frame->this, - stub->args.fd, stub->args.size, - stub->args.offset, stub->args.xdata); - break; + stub->fn.readdir(stub->frame, stub->frame->this, stub->args.fd, + stub->args.size, stub->args.offset, + stub->args.xdata); + break; case GF_FOP_READDIRP: - stub->fn.readdirp (stub->frame, stub->frame->this, - stub->args.fd, stub->args.size, - stub->args.offset, stub->args.xdata); - break; + stub->fn.readdirp(stub->frame, stub->frame->this, stub->args.fd, + stub->args.size, stub->args.offset, + stub->args.xdata); + break; case GF_FOP_XATTROP: - stub->fn.xattrop (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.optype, - stub->args.xattr, stub->args.xdata); - break; + stub->fn.xattrop(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.optype, stub->args.xattr, + stub->args.xdata); + break; case GF_FOP_FXATTROP: - stub->fn.fxattrop (stub->frame, stub->frame->this, - stub->args.fd, stub->args.optype, - stub->args.xattr, stub->args.xdata); - break; + stub->fn.fxattrop(stub->frame, stub->frame->this, stub->args.fd, + stub->args.optype, stub->args.xattr, + stub->args.xdata); + break; case GF_FOP_SETATTR: - stub->fn.setattr (stub->frame, stub->frame->this, - &stub->args.loc, &stub->args.stat, - stub->args.valid, stub->args.xdata); - break; + stub->fn.setattr(stub->frame, stub->frame->this, &stub->args.loc, + &stub->args.stat, stub->args.valid, + stub->args.xdata); + break; case GF_FOP_FSETATTR: - stub->fn.fsetattr (stub->frame, stub->frame->this, - stub->args.fd, &stub->args.stat, - stub->args.valid, stub->args.xdata); - break; - case GF_FOP_FALLOCATE: - stub->fn.fallocate(stub->frame, stub->frame->this, - stub->args.fd, stub->args.flags, - stub->args.offset, stub->args.size, - stub->args.xdata); - break; - case GF_FOP_DISCARD: - stub->fn.discard(stub->frame, stub->frame->this, - stub->args.fd, stub->args.offset, - stub->args.size, stub->args.xdata); - break; + stub->fn.fsetattr(stub->frame, stub->frame->this, stub->args.fd, + &stub->args.stat, stub->args.valid, + stub->args.xdata); + break; + case GF_FOP_FALLOCATE: + stub->fn.fallocate(stub->frame, stub->frame->this, stub->args.fd, + stub->args.flags, stub->args.offset, + stub->args.size, stub->args.xdata); + break; + case GF_FOP_DISCARD: + stub->fn.discard(stub->frame, stub->frame->this, stub->args.fd, + stub->args.offset, stub->args.size, + stub->args.xdata); + break; case GF_FOP_ZEROFILL: - stub->fn.zerofill(stub->frame, stub->frame->this, - stub->args.fd, stub->args.offset, - stub->args.size, stub->args.xdata); - break; + stub->fn.zerofill(stub->frame, stub->frame->this, 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; + stub->fn.ipc(stub->frame, stub->frame->this, stub->args.cmd, + stub->args.xdata); + break; case GF_FOP_SEEK: - stub->fn.seek (stub->frame, stub->frame->this, - stub->args.fd, stub->args.offset, - stub->args.what, stub->args.xdata); - break; + stub->fn.seek(stub->frame, stub->frame->this, stub->args.fd, + stub->args.offset, stub->args.what, stub->args.xdata); + break; case GF_FOP_LEASE: - stub->fn.lease (stub->frame, stub->frame->this, - &stub->args.loc, &stub->args.lease, - stub->args.xdata); - break; + stub->fn.lease(stub->frame, stub->frame->this, &stub->args.loc, + &stub->args.lease, stub->args.xdata); + break; case GF_FOP_GETACTIVELK: - stub->fn.getactivelk (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.xdata); - break; + stub->fn.getactivelk(stub->frame, stub->frame->this, + &stub->args.loc, stub->args.xdata); + break; case GF_FOP_SETACTIVELK: - stub->fn.setactivelk (stub->frame, stub->frame->this, - &stub->args.loc, &stub->args.locklist, - stub->args.xdata); - break; + stub->fn.setactivelk(stub->frame, stub->frame->this, + &stub->args.loc, &stub->args.locklist, + stub->args.xdata); + break; case GF_FOP_PUT: - stub->fn.put (stub->frame, stub->frame->this, - &stub->args.loc, stub->args.mode, stub->args.umask, - stub->args.flags, stub->args.vector, - stub->args.count, stub->args.offset, - stub->args.iobref, stub->args.xattr, - stub->args.xdata); - break; + stub->fn.put(stub->frame, stub->frame->this, &stub->args.loc, + stub->args.mode, stub->args.umask, stub->args.flags, + stub->args.vector, stub->args.count, stub->args.offset, + stub->args.iobref, stub->args.xattr, stub->args.xdata); + break; default: - gf_msg_callingfn ("call-stub", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ENTRY, "Invalid value of FOP" - " (%d)", stub->fop); - break; - } -out: - return; -} - - -#define STUB_UNWIND(stb, fop, args ...) do { \ - if (stb->fn_cbk.fop) \ - stb->fn_cbk.fop (stb->frame, stb->frame->cookie, \ - stb->frame->this, stb->args_cbk.op_ret, \ - stb->args_cbk.op_errno, args); \ - else \ - STACK_UNWIND_STRICT (fop, stb->frame, stb->args_cbk.op_ret, \ - stb->args_cbk.op_errno, args); \ - } while (0) - + gf_msg_callingfn("call-stub", GF_LOG_ERROR, EINVAL, + LG_MSG_INVALID_ENTRY, + "Invalid value of FOP" + " (%d)", + stub->fop); + break; + } +out: + return; +} + +#define STUB_UNWIND(stb, fop, args...) \ + do { \ + if (stb->fn_cbk.fop) \ + stb->fn_cbk.fop(stb->frame, stb->frame->cookie, stb->frame->this, \ + stb->args_cbk.op_ret, stb->args_cbk.op_errno, \ + args); \ + else \ + STACK_UNWIND_STRICT(fop, stb->frame, stb->args_cbk.op_ret, \ + stb->args_cbk.op_errno, args); \ + } while (0) static void -call_resume_unwind (call_stub_t *stub) +call_resume_unwind(call_stub_t *stub) { - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - switch (stub->fop) { + switch (stub->fop) { case GF_FOP_OPEN: - STUB_UNWIND (stub, open, stub->args_cbk.fd, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, open, stub->args_cbk.fd, stub->args_cbk.xdata); + break; case GF_FOP_CREATE: - STUB_UNWIND (stub, create, stub->args_cbk.fd, - stub->args_cbk.inode, &stub->args_cbk.stat, - &stub->args_cbk.preparent, - &stub->args_cbk.postparent, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, create, stub->args_cbk.fd, stub->args_cbk.inode, + &stub->args_cbk.stat, &stub->args_cbk.preparent, + &stub->args_cbk.postparent, stub->args_cbk.xdata); + break; case GF_FOP_STAT: - STUB_UNWIND (stub, stat, &stub->args_cbk.stat, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, stat, &stub->args_cbk.stat, stub->args_cbk.xdata); + break; case GF_FOP_READLINK: - STUB_UNWIND (stub, readlink, stub->args_cbk.buf, - &stub->args_cbk.stat, stub->args.xdata); - break; + STUB_UNWIND(stub, readlink, stub->args_cbk.buf, + &stub->args_cbk.stat, stub->args.xdata); + break; case GF_FOP_MKNOD: - STUB_UNWIND (stub, mknod, stub->args_cbk.inode, - &stub->args_cbk.stat, &stub->args_cbk.preparent, - &stub->args_cbk.postparent, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, mknod, stub->args_cbk.inode, &stub->args_cbk.stat, + &stub->args_cbk.preparent, &stub->args_cbk.postparent, + stub->args_cbk.xdata); + break; case GF_FOP_MKDIR: - STUB_UNWIND (stub, mkdir, stub->args_cbk.inode, - &stub->args_cbk.stat, &stub->args_cbk.preparent, - &stub->args_cbk.postparent, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, mkdir, stub->args_cbk.inode, &stub->args_cbk.stat, + &stub->args_cbk.preparent, &stub->args_cbk.postparent, + stub->args_cbk.xdata); + break; case GF_FOP_UNLINK: - STUB_UNWIND (stub, unlink, &stub->args_cbk.preparent, - &stub->args_cbk.postparent, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, unlink, &stub->args_cbk.preparent, + &stub->args_cbk.postparent, stub->args_cbk.xdata); + break; case GF_FOP_RMDIR: - STUB_UNWIND (stub, rmdir, &stub->args_cbk.preparent, - &stub->args_cbk.postparent, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, rmdir, &stub->args_cbk.preparent, + &stub->args_cbk.postparent, stub->args_cbk.xdata); + break; case GF_FOP_SYMLINK: - STUB_UNWIND (stub, symlink, stub->args_cbk.inode, - &stub->args_cbk.stat, &stub->args_cbk.preparent, - &stub->args_cbk.postparent, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, symlink, stub->args_cbk.inode, + &stub->args_cbk.stat, &stub->args_cbk.preparent, + &stub->args_cbk.postparent, stub->args_cbk.xdata); + break; case GF_FOP_RENAME: - STUB_UNWIND (stub, rename, &stub->args_cbk.stat, - &stub->args_cbk.preparent, - &stub->args_cbk.postparent, - &stub->args_cbk.preparent2, - &stub->args_cbk.postparent2, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, rename, &stub->args_cbk.stat, + &stub->args_cbk.preparent, &stub->args_cbk.postparent, + &stub->args_cbk.preparent2, &stub->args_cbk.postparent2, + stub->args_cbk.xdata); + break; case GF_FOP_LINK: - STUB_UNWIND (stub, link, stub->args_cbk.inode, - &stub->args_cbk.stat, &stub->args_cbk.preparent, - &stub->args_cbk.postparent, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, link, stub->args_cbk.inode, &stub->args_cbk.stat, + &stub->args_cbk.preparent, &stub->args_cbk.postparent, + stub->args_cbk.xdata); + break; case GF_FOP_TRUNCATE: - STUB_UNWIND (stub, truncate, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, truncate, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; case GF_FOP_READ: - STUB_UNWIND (stub, readv, stub->args_cbk.vector, - stub->args_cbk.count, &stub->args_cbk.stat, - stub->args_cbk.iobref, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, readv, stub->args_cbk.vector, + stub->args_cbk.count, &stub->args_cbk.stat, + stub->args_cbk.iobref, stub->args_cbk.xdata); + break; case GF_FOP_WRITE: - STUB_UNWIND (stub, writev, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, writev, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; case GF_FOP_STATFS: - STUB_UNWIND (stub, statfs, &stub->args_cbk.statvfs, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, statfs, &stub->args_cbk.statvfs, + stub->args_cbk.xdata); + break; case GF_FOP_FLUSH: - STUB_UNWIND (stub, flush, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, flush, stub->args_cbk.xdata); + break; case GF_FOP_FSYNC: - STUB_UNWIND (stub, fsync, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fsync, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; case GF_FOP_SETXATTR: - STUB_UNWIND (stub, setxattr, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, setxattr, stub->args_cbk.xdata); + break; case GF_FOP_GETXATTR: - STUB_UNWIND (stub, getxattr, stub->args_cbk.xattr, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, getxattr, stub->args_cbk.xattr, + stub->args_cbk.xdata); + break; case GF_FOP_FSETXATTR: - STUB_UNWIND (stub, fsetxattr, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fsetxattr, stub->args_cbk.xdata); + break; case GF_FOP_FGETXATTR: - STUB_UNWIND (stub, fgetxattr, stub->args_cbk.xattr, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fgetxattr, stub->args_cbk.xattr, + stub->args_cbk.xdata); + break; case GF_FOP_REMOVEXATTR: - STUB_UNWIND (stub, removexattr, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, removexattr, stub->args_cbk.xdata); + break; case GF_FOP_FREMOVEXATTR: - STUB_UNWIND (stub, fremovexattr, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fremovexattr, stub->args_cbk.xdata); + break; case GF_FOP_OPENDIR: - STUB_UNWIND (stub, opendir, stub->args_cbk.fd, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, opendir, stub->args_cbk.fd, stub->args_cbk.xdata); + break; case GF_FOP_FSYNCDIR: - STUB_UNWIND (stub, fsyncdir, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fsyncdir, stub->args_cbk.xdata); + break; case GF_FOP_ACCESS: - STUB_UNWIND (stub, access, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, access, stub->args_cbk.xdata); + break; case GF_FOP_FTRUNCATE: - STUB_UNWIND (stub, ftruncate, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, ftruncate, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; case GF_FOP_FSTAT: - STUB_UNWIND (stub, fstat, &stub->args_cbk.stat, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fstat, &stub->args_cbk.stat, + stub->args_cbk.xdata); + break; case GF_FOP_LK: - STUB_UNWIND (stub, lk, &stub->args_cbk.lock, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, lk, &stub->args_cbk.lock, stub->args_cbk.xdata); + break; case GF_FOP_INODELK: - STUB_UNWIND (stub, inodelk, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, inodelk, stub->args_cbk.xdata); + break; case GF_FOP_FINODELK: - STUB_UNWIND (stub, finodelk, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, finodelk, stub->args_cbk.xdata); + break; case GF_FOP_ENTRYLK: - STUB_UNWIND (stub, entrylk, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, entrylk, stub->args_cbk.xdata); + break; case GF_FOP_FENTRYLK: - STUB_UNWIND (stub, fentrylk, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fentrylk, stub->args_cbk.xdata); + break; case GF_FOP_LOOKUP: - STUB_UNWIND (stub, lookup, stub->args_cbk.inode, - &stub->args_cbk.stat, stub->args_cbk.xdata, - &stub->args_cbk.postparent); - break; + STUB_UNWIND(stub, lookup, stub->args_cbk.inode, + &stub->args_cbk.stat, stub->args_cbk.xdata, + &stub->args_cbk.postparent); + break; case GF_FOP_RCHECKSUM: - STUB_UNWIND (stub, rchecksum, stub->args_cbk.weak_checksum, - stub->args_cbk.strong_checksum, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, rchecksum, stub->args_cbk.weak_checksum, + stub->args_cbk.strong_checksum, stub->args_cbk.xdata); + break; case GF_FOP_READDIR: - STUB_UNWIND (stub, readdir, &stub->args_cbk.entries, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, readdir, &stub->args_cbk.entries, + stub->args_cbk.xdata); + break; case GF_FOP_READDIRP: - STUB_UNWIND (stub, readdir, &stub->args_cbk.entries, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, readdir, &stub->args_cbk.entries, + stub->args_cbk.xdata); + break; case GF_FOP_XATTROP: - STUB_UNWIND (stub, xattrop, stub->args_cbk.xattr, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, xattrop, stub->args_cbk.xattr, + stub->args_cbk.xdata); + break; case GF_FOP_FXATTROP: - STUB_UNWIND (stub, fxattrop, stub->args_cbk.xattr, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fxattrop, stub->args_cbk.xattr, + stub->args_cbk.xdata); + break; case GF_FOP_SETATTR: - STUB_UNWIND (stub, setattr, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, setattr, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; case GF_FOP_FSETATTR: - STUB_UNWIND (stub, fsetattr, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; - case GF_FOP_FALLOCATE: - STUB_UNWIND(stub, fallocate, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; - case GF_FOP_DISCARD: - STUB_UNWIND(stub, discard, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, fsetattr, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; + case GF_FOP_FALLOCATE: + STUB_UNWIND(stub, fallocate, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; + case GF_FOP_DISCARD: + STUB_UNWIND(stub, discard, &stub->args_cbk.prestat, + &stub->args_cbk.poststat, stub->args_cbk.xdata); + break; case GF_FOP_ZEROFILL: - STUB_UNWIND(stub, zerofill, &stub->args_cbk.prestat, - &stub->args_cbk.poststat, stub->args_cbk.xdata); - break; + 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; + STUB_UNWIND(stub, ipc, stub->args_cbk.xdata); + break; case GF_FOP_SEEK: - STUB_UNWIND (stub, seek, stub->args_cbk.offset, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, seek, stub->args_cbk.offset, + stub->args_cbk.xdata); + break; case GF_FOP_LEASE: - STUB_UNWIND (stub, lease, &stub->args_cbk.lease, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, lease, &stub->args_cbk.lease, + stub->args_cbk.xdata); + break; case GF_FOP_GETACTIVELK: - STUB_UNWIND (stub, getactivelk, &stub->args_cbk.locklist, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, getactivelk, &stub->args_cbk.locklist, + stub->args_cbk.xdata); + break; case GF_FOP_SETACTIVELK: - STUB_UNWIND (stub, setactivelk, stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, setactivelk, stub->args_cbk.xdata); + break; case GF_FOP_PUT: - STUB_UNWIND (stub, put, stub->args_cbk.inode, - &stub->args_cbk.stat, - &stub->args_cbk.preparent, - &stub->args_cbk.postparent, - stub->args_cbk.xdata); - break; + STUB_UNWIND(stub, put, stub->args_cbk.inode, &stub->args_cbk.stat, + &stub->args_cbk.preparent, &stub->args_cbk.postparent, + stub->args_cbk.xdata); + break; default: - gf_msg_callingfn ("call-stub", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ENTRY, "Invalid value of FOP" - " (%d)", stub->fop); - break; - } + gf_msg_callingfn("call-stub", GF_LOG_ERROR, EINVAL, + LG_MSG_INVALID_ENTRY, + "Invalid value of FOP" + " (%d)", + stub->fop); + break; + } out: - return; + return; } - static void -call_stub_wipe_args (call_stub_t *stub) +call_stub_wipe_args(call_stub_t *stub) { - args_wipe (&stub->args); + args_wipe(&stub->args); } static void -call_stub_wipe_args_cbk (call_stub_t *stub) +call_stub_wipe_args_cbk(call_stub_t *stub) { - args_cbk_wipe (&stub->args_cbk); + args_cbk_wipe(&stub->args_cbk); } - void -call_stub_destroy (call_stub_t *stub) +call_stub_destroy(call_stub_t *stub) { - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - if (stub->wind) - call_stub_wipe_args (stub); - else - call_stub_wipe_args_cbk (stub); + if (stub->wind) + call_stub_wipe_args(stub); + else + call_stub_wipe_args_cbk(stub); - stub->stub_mem_pool = NULL; + stub->stub_mem_pool = NULL; - mem_put (stub); + mem_put(stub); out: - return; + return; } - void -call_resume (call_stub_t *stub) +call_resume(call_stub_t *stub) { - xlator_t *old_THIS = NULL; + xlator_t *old_THIS = NULL; - errno = EINVAL; - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + errno = EINVAL; + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - list_del_init (&stub->list); + list_del_init(&stub->list); - old_THIS = THIS; - THIS = stub->frame->this; - { - if (stub->wind) - call_resume_wind (stub); - else - call_resume_unwind (stub); - } - THIS = old_THIS; + old_THIS = THIS; + THIS = stub->frame->this; + { + if (stub->wind) + call_resume_wind(stub); + else + call_resume_unwind(stub); + } + THIS = old_THIS; - call_stub_destroy (stub); + call_stub_destroy(stub); out: - return; + return; } - void -call_unwind_error (call_stub_t *stub, int op_ret, int op_errno) +call_unwind_error(call_stub_t *stub, int op_ret, int op_errno) { - xlator_t *old_THIS = NULL; - - list_del_init (&stub->list); + xlator_t *old_THIS = NULL; - old_THIS = THIS; - THIS = stub->frame->this; - { - stub->args_cbk.op_ret = op_ret; - stub->args_cbk.op_errno = op_errno; - call_resume_unwind (stub); - } - THIS = old_THIS; + list_del_init(&stub->list); - call_stub_destroy (stub); + old_THIS = THIS; + THIS = stub->frame->this; + { + stub->args_cbk.op_ret = op_ret; + stub->args_cbk.op_errno = op_errno; + call_resume_unwind(stub); + } + THIS = old_THIS; - return; + call_stub_destroy(stub); + return; } - void -call_unwind_error_keep_stub (call_stub_t *stub, int op_ret, int op_errno) +call_unwind_error_keep_stub(call_stub_t *stub, int op_ret, int op_errno) { - xlator_t *old_THIS = NULL; + xlator_t *old_THIS = NULL; - list_del_init (&stub->list); + list_del_init(&stub->list); - old_THIS = THIS; - THIS = stub->frame->this; - { - stub->args_cbk.op_ret = op_ret; - stub->args_cbk.op_errno = op_errno; - call_resume_unwind (stub); - } - - THIS = old_THIS; + old_THIS = THIS; + THIS = stub->frame->this; + { + stub->args_cbk.op_ret = op_ret; + stub->args_cbk.op_errno = op_errno; + call_resume_unwind(stub); + } - return; + THIS = old_THIS; + return; } void -call_resume_keep_stub (call_stub_t *stub) +call_resume_keep_stub(call_stub_t *stub) { - xlator_t *old_THIS = NULL; + xlator_t *old_THIS = NULL; - errno = EINVAL; - GF_VALIDATE_OR_GOTO ("call-stub", stub, out); + errno = EINVAL; + GF_VALIDATE_OR_GOTO("call-stub", stub, out); - list_del_init (&stub->list); + list_del_init(&stub->list); - old_THIS = THIS; - THIS = stub->frame->this; - { - if (stub->wind) - call_resume_wind (stub); - else - call_resume_unwind (stub); - } + old_THIS = THIS; + THIS = stub->frame->this; + { + if (stub->wind) + call_resume_wind(stub); + else + call_resume_unwind(stub); + } - THIS = old_THIS; + THIS = old_THIS; out: - return; + return; } diff --git a/libglusterfs/src/checksum.c b/libglusterfs/src/checksum.c index 561ca04e48b..acdaed04ae2 100644 --- a/libglusterfs/src/checksum.c +++ b/libglusterfs/src/checksum.c @@ -22,24 +22,23 @@ * data. Thus int32_t and uint32_t are sufficient */ uint32_t -gf_rsync_weak_checksum (unsigned char *buf, size_t len) +gf_rsync_weak_checksum(unsigned char *buf, size_t len) { - return adler32 (0, buf, len); + return adler32(0, buf, len); } - /* * The "strong" checksum required for the rsync algorithm. */ void -gf_rsync_strong_checksum (unsigned char *data, size_t len, - unsigned char *sha256_md) +gf_rsync_strong_checksum(unsigned char *data, size_t len, + unsigned char *sha256_md) { - SHA256((const unsigned char *)data, len, sha256_md); + SHA256((const unsigned char *)data, len, sha256_md); } void -gf_rsync_md5_checksum (unsigned char *data, size_t len, unsigned char *md5) +gf_rsync_md5_checksum(unsigned char *data, size_t len, unsigned char *md5) { - MD5 (data, len, md5); + MD5(data, len, md5); } diff --git a/libglusterfs/src/circ-buff.c b/libglusterfs/src/circ-buff.c index 6259282a917..cb37ed30ea2 100644 --- a/libglusterfs/src/circ-buff.c +++ b/libglusterfs/src/circ-buff.c @@ -12,190 +12,182 @@ #include "libglusterfs-messages.h" void -cb_destroy_data (circular_buffer_t *cb, - void (*destroy_buffer_data) (void *data)) +cb_destroy_data(circular_buffer_t *cb, void (*destroy_buffer_data)(void *data)) { - if (destroy_buffer_data) - destroy_buffer_data (cb->data); - GF_FREE (cb->data); - return; + if (destroy_buffer_data) + destroy_buffer_data(cb->data); + GF_FREE(cb->data); + return; } - /* hold lock while calling this function */ int -__cb_add_entry_buffer (buffer_t *buffer, void *item) +__cb_add_entry_buffer(buffer_t *buffer, void *item) { - circular_buffer_t *ptr = NULL; - int ret = -1; - //DO we really need the assert here? - GF_ASSERT (buffer->used_len <= buffer->size_buffer); - - if (buffer->use_once == _gf_true && - buffer->used_len == buffer->size_buffer) { - gf_msg ("circ-buff", GF_LOG_WARNING, 0, LG_MSG_BUFFER_ERROR, - "buffer %p is use once buffer", buffer); - return -1; - } else { - if (buffer->used_len == buffer->size_buffer) { - if (buffer->cb[buffer->w_index]) { - ptr = buffer->cb[buffer->w_index]; - if (ptr->data) { - cb_destroy_data (ptr, - buffer->destroy_buffer_data); - ptr->data = NULL; - GF_FREE (ptr); - } - buffer->cb[buffer->w_index] = NULL; - ptr = NULL; - } + circular_buffer_t *ptr = NULL; + int ret = -1; + // DO we really need the assert here? + GF_ASSERT(buffer->used_len <= buffer->size_buffer); + + if (buffer->use_once == _gf_true && + buffer->used_len == buffer->size_buffer) { + gf_msg("circ-buff", GF_LOG_WARNING, 0, LG_MSG_BUFFER_ERROR, + "buffer %p is use once buffer", buffer); + return -1; + } else { + if (buffer->used_len == buffer->size_buffer) { + if (buffer->cb[buffer->w_index]) { + ptr = buffer->cb[buffer->w_index]; + if (ptr->data) { + cb_destroy_data(ptr, buffer->destroy_buffer_data); + ptr->data = NULL; + GF_FREE(ptr); } - - buffer->cb[buffer->w_index] = - GF_CALLOC (1, sizeof (circular_buffer_t), - gf_common_mt_circular_buffer_t); - if (!buffer->cb[buffer->w_index]) - return -1; - - buffer->cb[buffer->w_index]->data = item; - ret = gettimeofday (&buffer->cb[buffer->w_index]->tv, NULL); - if (ret == -1) - gf_msg_callingfn ("circ-buff", GF_LOG_WARNING, 0, - LG_MSG_GETTIMEOFDAY_FAILED, - "getting time of the day failed"); - buffer->w_index++; - buffer->w_index %= buffer->size_buffer; - //used_buffer size cannot be greater than the total buffer size - - if (buffer->used_len < buffer->size_buffer) - buffer->used_len++; - return buffer->w_index; + buffer->cb[buffer->w_index] = NULL; + ptr = NULL; + } } + + buffer->cb[buffer->w_index] = GF_CALLOC(1, sizeof(circular_buffer_t), + gf_common_mt_circular_buffer_t); + if (!buffer->cb[buffer->w_index]) + return -1; + + buffer->cb[buffer->w_index]->data = item; + ret = gettimeofday(&buffer->cb[buffer->w_index]->tv, NULL); + if (ret == -1) + gf_msg_callingfn("circ-buff", GF_LOG_WARNING, 0, + LG_MSG_GETTIMEOFDAY_FAILED, + "getting time of the day failed"); + buffer->w_index++; + buffer->w_index %= buffer->size_buffer; + // used_buffer size cannot be greater than the total buffer size + + if (buffer->used_len < buffer->size_buffer) + buffer->used_len++; + return buffer->w_index; + } } int -cb_add_entry_buffer (buffer_t *buffer, void *item) +cb_add_entry_buffer(buffer_t *buffer, void *item) { - int write_index = -1; + int write_index = -1; - pthread_mutex_lock (&buffer->lock); - { - write_index = __cb_add_entry_buffer (buffer, item); - } - pthread_mutex_unlock (&buffer->lock); + pthread_mutex_lock(&buffer->lock); + { + write_index = __cb_add_entry_buffer(buffer, item); + } + pthread_mutex_unlock(&buffer->lock); - return write_index; + return write_index; } void -cb_buffer_show (buffer_t *buffer) +cb_buffer_show(buffer_t *buffer) { - pthread_mutex_lock (&buffer->lock); - { - gf_msg_debug ("circ-buff", 0, "w_index: %d, size: %" - GF_PRI_SIZET" used_buffer: %d", buffer->w_index, - buffer->size_buffer, buffer->used_len); - } - pthread_mutex_unlock (&buffer->lock); + pthread_mutex_lock(&buffer->lock); + { + gf_msg_debug("circ-buff", 0, + "w_index: %d, size: %" GF_PRI_SIZET " used_buffer: %d", + buffer->w_index, buffer->size_buffer, buffer->used_len); + } + pthread_mutex_unlock(&buffer->lock); } void -cb_buffer_dump (buffer_t *buffer, void *data, - int (fn) (circular_buffer_t *buffer, void *data)) +cb_buffer_dump(buffer_t *buffer, void *data, + int(fn)(circular_buffer_t *buffer, void *data)) { - int index = 0; - circular_buffer_t *entry = NULL; - int entries = 0; - int ul = 0; - int w_ind = 0; - int size_buff = 0; - int i = 0; - - ul = buffer->used_len; - w_ind = buffer->w_index; - size_buff = buffer->size_buffer; - - pthread_mutex_lock (&buffer->lock); - { - if (buffer->use_once == _gf_false) { - index = (size_buff + (w_ind - ul))%size_buff; - for (entries = 0; entries < buffer->used_len; - entries++) { - entry = buffer->cb[index]; - if (entry) - fn (entry, data); - else - gf_msg_callingfn ("circ-buff", - GF_LOG_WARNING, 0, - LG_MSG_NULL_PTR, - "Null entry in " - "circular buffer at " - "index %d.", index); - - index++; - index %= buffer->size_buffer; - } - } else { - for (i = 0; i < buffer->used_len ; i++) { - entry = buffer->cb[i]; - fn (entry, data); - } - } + int index = 0; + circular_buffer_t *entry = NULL; + int entries = 0; + int ul = 0; + int w_ind = 0; + int size_buff = 0; + int i = 0; + + ul = buffer->used_len; + w_ind = buffer->w_index; + size_buff = buffer->size_buffer; + + pthread_mutex_lock(&buffer->lock); + { + if (buffer->use_once == _gf_false) { + index = (size_buff + (w_ind - ul)) % size_buff; + for (entries = 0; entries < buffer->used_len; entries++) { + entry = buffer->cb[index]; + if (entry) + fn(entry, data); + else + gf_msg_callingfn("circ-buff", GF_LOG_WARNING, 0, + LG_MSG_NULL_PTR, + "Null entry in " + "circular buffer at " + "index %d.", + index); + + index++; + index %= buffer->size_buffer; + } + } else { + for (i = 0; i < buffer->used_len; i++) { + entry = buffer->cb[i]; + fn(entry, data); + } } - pthread_mutex_unlock (&buffer->lock); + } + pthread_mutex_unlock(&buffer->lock); } buffer_t * -cb_buffer_new (size_t buffer_size, gf_boolean_t use_once, - void (*destroy_buffer_data) (void *data)) +cb_buffer_new(size_t buffer_size, gf_boolean_t use_once, + void (*destroy_buffer_data)(void *data)) { - buffer_t *buffer = NULL; - - buffer = GF_CALLOC (1, sizeof (*buffer), gf_common_mt_buffer_t); - if (!buffer) { - goto out; - } - - buffer->cb = GF_CALLOC (buffer_size, - sizeof (circular_buffer_t *), - gf_common_mt_circular_buffer_t); - if (!buffer->cb) { - GF_FREE (buffer); - buffer = NULL; - goto out; - } - - buffer->w_index = 0; - buffer->size_buffer = buffer_size; - buffer->use_once = use_once; - buffer->used_len = 0; - buffer->destroy_buffer_data = destroy_buffer_data; - pthread_mutex_init (&buffer->lock, NULL); + buffer_t *buffer = NULL; + + buffer = GF_CALLOC(1, sizeof(*buffer), gf_common_mt_buffer_t); + if (!buffer) { + goto out; + } + + buffer->cb = GF_CALLOC(buffer_size, sizeof(circular_buffer_t *), + gf_common_mt_circular_buffer_t); + if (!buffer->cb) { + GF_FREE(buffer); + buffer = NULL; + goto out; + } + + buffer->w_index = 0; + buffer->size_buffer = buffer_size; + buffer->use_once = use_once; + buffer->used_len = 0; + buffer->destroy_buffer_data = destroy_buffer_data; + pthread_mutex_init(&buffer->lock, NULL); out: - return buffer; + return buffer; } void -cb_buffer_destroy (buffer_t *buffer) +cb_buffer_destroy(buffer_t *buffer) { - int i = 0; - circular_buffer_t *ptr = NULL; - if (buffer) { - if (buffer->cb) { - for (i = 0; i < buffer->used_len ; i++) { - ptr = buffer->cb[i]; - if (ptr->data) { - cb_destroy_data (ptr, - buffer->destroy_buffer_data); - ptr->data = NULL; - GF_FREE (ptr); - } - } - GF_FREE (buffer->cb); + int i = 0; + circular_buffer_t *ptr = NULL; + if (buffer) { + if (buffer->cb) { + for (i = 0; i < buffer->used_len; i++) { + ptr = buffer->cb[i]; + if (ptr->data) { + cb_destroy_data(ptr, buffer->destroy_buffer_data); + ptr->data = NULL; + GF_FREE(ptr); } - pthread_mutex_destroy (&buffer->lock); - GF_FREE (buffer); + } + GF_FREE(buffer->cb); } + pthread_mutex_destroy(&buffer->lock); + GF_FREE(buffer); + } } - diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c index 844acbc459c..35e0beda8d6 100644 --- a/libglusterfs/src/client_t.c +++ b/libglusterfs/src/client_t.c @@ -17,648 +17,625 @@ #include "libglusterfs-messages.h" static int -gf_client_chain_client_entries (cliententry_t *entries, uint32_t startidx, - uint32_t endcount) +gf_client_chain_client_entries(cliententry_t *entries, uint32_t startidx, + uint32_t endcount) { - uint32_t i = 0; + uint32_t i = 0; - if (!entries) { - gf_msg_callingfn ("client_t", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!entries"); - return -1; - } + if (!entries) { + gf_msg_callingfn("client_t", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!entries"); + return -1; + } - /* Chain only till the second to last entry because we want to - * ensure that the last entry has GF_CLIENTTABLE_END. - */ - for (i = startidx; i < (endcount - 1); i++) - entries[i].next_free = i + 1; + /* Chain only till the second to last entry because we want to + * ensure that the last entry has GF_CLIENTTABLE_END. + */ + for (i = startidx; i < (endcount - 1); i++) + entries[i].next_free = i + 1; - /* i has already been incremented up to the last entry. */ - entries[i].next_free = GF_CLIENTTABLE_END; + /* i has already been incremented up to the last entry. */ + entries[i].next_free = GF_CLIENTTABLE_END; - return 0; + return 0; } - static int -gf_client_clienttable_expand (clienttable_t *clienttable, uint32_t nr) +gf_client_clienttable_expand(clienttable_t *clienttable, uint32_t nr) { - cliententry_t *oldclients = NULL; - uint32_t oldmax_clients = -1; - int ret = -1; - - if (clienttable == NULL || nr <= clienttable->max_clients) { - gf_msg_callingfn ("client_t", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - ret = EINVAL; - goto out; - } - - oldclients = clienttable->cliententries; - oldmax_clients = clienttable->max_clients; - - clienttable->cliententries = GF_CALLOC (nr, sizeof (cliententry_t), - gf_common_mt_cliententry_t); - if (!clienttable->cliententries) { - clienttable->cliententries = oldclients; - ret = 0; - goto out; - } - clienttable->max_clients = nr; - - if (oldclients) { - uint32_t cpy = oldmax_clients * sizeof (cliententry_t); - memcpy (clienttable->cliententries, oldclients, cpy); - } - - gf_client_chain_client_entries (clienttable->cliententries, - oldmax_clients, - clienttable->max_clients); - - /* Now that expansion is done, we must update the client list - * head pointer so that the client allocation functions can continue - * using the expanded table. - */ - clienttable->first_free = oldmax_clients; - GF_FREE (oldclients); + cliententry_t *oldclients = NULL; + uint32_t oldmax_clients = -1; + int ret = -1; + + if (clienttable == NULL || nr <= clienttable->max_clients) { + gf_msg_callingfn("client_t", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + ret = EINVAL; + goto out; + } + + oldclients = clienttable->cliententries; + oldmax_clients = clienttable->max_clients; + + clienttable->cliententries = GF_CALLOC(nr, sizeof(cliententry_t), + gf_common_mt_cliententry_t); + if (!clienttable->cliententries) { + clienttable->cliententries = oldclients; ret = 0; + goto out; + } + clienttable->max_clients = nr; + + if (oldclients) { + uint32_t cpy = oldmax_clients * sizeof(cliententry_t); + memcpy(clienttable->cliententries, oldclients, cpy); + } + + gf_client_chain_client_entries(clienttable->cliententries, oldmax_clients, + clienttable->max_clients); + + /* Now that expansion is done, we must update the client list + * head pointer so that the client allocation functions can continue + * using the expanded table. + */ + clienttable->first_free = oldmax_clients; + GF_FREE(oldclients); + ret = 0; out: - return ret; + return ret; } - clienttable_t * -gf_clienttable_alloc (void) +gf_clienttable_alloc(void) { - clienttable_t *clienttable = NULL; - int result = 0; - - clienttable = - GF_CALLOC (1, sizeof (clienttable_t), gf_common_mt_clienttable_t); - if (!clienttable) - return NULL; - - LOCK_INIT (&clienttable->lock); - - result = gf_client_clienttable_expand (clienttable, - GF_CLIENTTABLE_INITIAL_SIZE); - if (result != 0) { - gf_msg ("client_t", GF_LOG_ERROR, 0, - LG_MSG_EXPAND_CLIENT_TABLE_FAILED, - "gf_client_clienttable_expand failed"); - GF_FREE (clienttable); - return NULL; - } - - return clienttable; + clienttable_t *clienttable = NULL; + int result = 0; + + clienttable = GF_CALLOC(1, sizeof(clienttable_t), + gf_common_mt_clienttable_t); + if (!clienttable) + return NULL; + + LOCK_INIT(&clienttable->lock); + + result = gf_client_clienttable_expand(clienttable, + GF_CLIENTTABLE_INITIAL_SIZE); + if (result != 0) { + gf_msg("client_t", GF_LOG_ERROR, 0, LG_MSG_EXPAND_CLIENT_TABLE_FAILED, + "gf_client_clienttable_expand failed"); + GF_FREE(clienttable); + return NULL; + } + + return clienttable; } - void -gf_client_clienttable_destroy (clienttable_t *clienttable) +gf_client_clienttable_destroy(clienttable_t *clienttable) { - client_t *client = NULL; - cliententry_t *cliententries = NULL; - uint32_t client_count = 0; - int32_t i = 0; - - if (!clienttable) { - gf_msg_callingfn ("client_t", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!clienttable"); - return; - } - - LOCK (&clienttable->lock); - { - client_count = clienttable->max_clients; - clienttable->max_clients = 0; - cliententries = clienttable->cliententries; - clienttable->cliententries = NULL; - } - UNLOCK (&clienttable->lock); - - if (cliententries != NULL) { - for (i = 0; i < client_count; i++) { - client = cliententries[i].client; - if (client != NULL) { - gf_client_unref (client); - } - } - - GF_FREE (cliententries); - LOCK_DESTROY (&clienttable->lock); - GF_FREE (clienttable); - } + client_t *client = NULL; + cliententry_t *cliententries = NULL; + uint32_t client_count = 0; + int32_t i = 0; + + if (!clienttable) { + gf_msg_callingfn("client_t", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!clienttable"); + return; + } + + LOCK(&clienttable->lock); + { + client_count = clienttable->max_clients; + clienttable->max_clients = 0; + cliententries = clienttable->cliententries; + clienttable->cliententries = NULL; + } + UNLOCK(&clienttable->lock); + + if (cliententries != NULL) { + for (i = 0; i < client_count; i++) { + client = cliententries[i].client; + if (client != NULL) { + gf_client_unref(client); + } + } + + GF_FREE(cliententries); + LOCK_DESTROY(&clienttable->lock); + GF_FREE(clienttable); + } } - /* * Increments ref.bind if the client is already present or creates a new * client with ref.bind = 1,ref.count = 1 it signifies that * as long as ref.bind is > 0 client should be alive. */ client_t * -gf_client_get (xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid, - char *subdir_mount) +gf_client_get(xlator_t *this, struct rpcsvc_auth_data *cred, char *client_uid, + char *subdir_mount) { - client_t *client = NULL; - cliententry_t *cliententry = NULL; - clienttable_t *clienttable = NULL; - unsigned int i = 0; - - if (this == NULL || client_uid == NULL) { - gf_msg_callingfn ("client_t", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - errno = EINVAL; - return NULL; - } - - clienttable = this->ctx->clienttable; - - LOCK (&clienttable->lock); - { - for (; i < clienttable->max_clients; i++) { - client = clienttable->cliententries[i].client; - if (client == NULL) - continue; - /* - * look for matching client_uid, _and_ - * if auth was used, matching auth flavour and data - */ - if (strcmp (client_uid, client->client_uid) == 0 && - (cred->flavour != AUTH_NONE && - (cred->flavour == client->auth.flavour && - (size_t) cred->datalen == client->auth.len && - memcmp (cred->authdata, - client->auth.data, - client->auth.len) == 0))) { - GF_ATOMIC_INC (client->bind); - goto unlock; - } - } - - client = GF_CALLOC (1, sizeof(client_t), gf_common_mt_client_t); - if (client == NULL) { - errno = ENOMEM; - goto unlock; - } - - client->this = this; - if (subdir_mount != NULL) - client->subdir_mount = gf_strdup (subdir_mount); - - LOCK_INIT (&client->scratch_ctx.lock); - - client->client_uid = gf_strdup (client_uid); - if (client->client_uid == NULL) { - GF_FREE (client); - client = NULL; - errno = ENOMEM; - goto unlock; - } - client->scratch_ctx.count = GF_CLIENTCTX_INITIAL_SIZE; - client->scratch_ctx.ctx = - GF_CALLOC (GF_CLIENTCTX_INITIAL_SIZE, - sizeof (struct client_ctx), - gf_common_mt_client_ctx); - if (client->scratch_ctx.ctx == NULL) { - GF_FREE (client->client_uid); - GF_FREE (client); - client = NULL; - errno = ENOMEM; - goto unlock; - } - - GF_ATOMIC_INIT (client->bind, 1); - GF_ATOMIC_INIT (client->count, 1); - - client->auth.flavour = cred->flavour; - if (cred->flavour != AUTH_NONE) { - client->auth.data = - GF_MALLOC (cred->datalen, - gf_common_mt_client_t); - if (client->auth.data == NULL) { - GF_FREE (client->scratch_ctx.ctx); - GF_FREE (client->client_uid); - GF_FREE (client); - client = NULL; - errno = ENOMEM; - goto unlock; - } - memcpy (client->auth.data, cred->authdata, - cred->datalen); - client->auth.len = cred->datalen; - } - - client->tbl_index = clienttable->first_free; - cliententry = &clienttable->cliententries[clienttable->first_free]; - if (cliententry->next_free == GF_CLIENTTABLE_END) { - int result = - gf_client_clienttable_expand (clienttable, - clienttable->max_clients + - GF_CLIENTTABLE_INITIAL_SIZE); - if (result != 0) { - GF_FREE (client->scratch_ctx.ctx); - GF_FREE (client->client_uid); - GF_FREE (client); - client = NULL; - errno = result; - goto unlock; - } - cliententry = &clienttable->cliententries[client->tbl_index]; - cliententry->next_free = clienttable->first_free; - } - cliententry->client = client; - clienttable->first_free = cliententry->next_free; - cliententry->next_free = GF_CLIENTENTRY_ALLOCATED; - } + client_t *client = NULL; + cliententry_t *cliententry = NULL; + clienttable_t *clienttable = NULL; + unsigned int i = 0; + + if (this == NULL || client_uid == NULL) { + gf_msg_callingfn("client_t", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + errno = EINVAL; + return NULL; + } + + clienttable = this->ctx->clienttable; + + LOCK(&clienttable->lock); + { + for (; i < clienttable->max_clients; i++) { + client = clienttable->cliententries[i].client; + if (client == NULL) + continue; + /* + * look for matching client_uid, _and_ + * if auth was used, matching auth flavour and data + */ + if (strcmp(client_uid, client->client_uid) == 0 && + (cred->flavour != AUTH_NONE && + (cred->flavour == client->auth.flavour && + (size_t)cred->datalen == client->auth.len && + memcmp(cred->authdata, client->auth.data, client->auth.len) == + 0))) { + GF_ATOMIC_INC(client->bind); + goto unlock; + } + } + + client = GF_CALLOC(1, sizeof(client_t), gf_common_mt_client_t); + if (client == NULL) { + errno = ENOMEM; + goto unlock; + } + + client->this = this; + if (subdir_mount != NULL) + client->subdir_mount = gf_strdup(subdir_mount); + + LOCK_INIT(&client->scratch_ctx.lock); + + client->client_uid = gf_strdup(client_uid); + if (client->client_uid == NULL) { + GF_FREE(client); + client = NULL; + errno = ENOMEM; + goto unlock; + } + client->scratch_ctx.count = GF_CLIENTCTX_INITIAL_SIZE; + client->scratch_ctx.ctx = GF_CALLOC(GF_CLIENTCTX_INITIAL_SIZE, + sizeof(struct client_ctx), + gf_common_mt_client_ctx); + if (client->scratch_ctx.ctx == NULL) { + GF_FREE(client->client_uid); + GF_FREE(client); + client = NULL; + errno = ENOMEM; + goto unlock; + } + + GF_ATOMIC_INIT(client->bind, 1); + GF_ATOMIC_INIT(client->count, 1); + + client->auth.flavour = cred->flavour; + if (cred->flavour != AUTH_NONE) { + client->auth.data = GF_MALLOC(cred->datalen, gf_common_mt_client_t); + if (client->auth.data == NULL) { + GF_FREE(client->scratch_ctx.ctx); + GF_FREE(client->client_uid); + GF_FREE(client); + client = NULL; + errno = ENOMEM; + goto unlock; + } + memcpy(client->auth.data, cred->authdata, cred->datalen); + client->auth.len = cred->datalen; + } + + client->tbl_index = clienttable->first_free; + cliententry = &clienttable->cliententries[clienttable->first_free]; + if (cliententry->next_free == GF_CLIENTTABLE_END) { + int result = gf_client_clienttable_expand( + clienttable, + clienttable->max_clients + GF_CLIENTTABLE_INITIAL_SIZE); + if (result != 0) { + GF_FREE(client->scratch_ctx.ctx); + GF_FREE(client->client_uid); + GF_FREE(client); + client = NULL; + errno = result; + goto unlock; + } + cliententry = &clienttable->cliententries[client->tbl_index]; + cliententry->next_free = clienttable->first_free; + } + cliententry->client = client; + clienttable->first_free = cliententry->next_free; + cliententry->next_free = GF_CLIENTENTRY_ALLOCATED; + } unlock: - UNLOCK (&clienttable->lock); - - if (client) - gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_BIND_REF, - "%s: bind_ref: %"GF_PRI_ATOMIC", ref: " - "%"GF_PRI_ATOMIC, client->client_uid, - GF_ATOMIC_GET (client->bind), - GF_ATOMIC_GET (client->count)); - return client; + UNLOCK(&clienttable->lock); + + if (client) + gf_msg_callingfn("client_t", GF_LOG_DEBUG, 0, LG_MSG_BIND_REF, + "%s: bind_ref: %" GF_PRI_ATOMIC + ", ref: " + "%" GF_PRI_ATOMIC, + client->client_uid, GF_ATOMIC_GET(client->bind), + GF_ATOMIC_GET(client->count)); + return client; } void -gf_client_put (client_t *client, gf_boolean_t *detached) +gf_client_put(client_t *client, gf_boolean_t *detached) { - gf_boolean_t unref = _gf_false; - int bind_ref; - - if (client == NULL) - goto out; - + gf_boolean_t unref = _gf_false; + int bind_ref; + + if (client == NULL) + goto out; + + if (detached) + *detached = _gf_false; + + bind_ref = GF_ATOMIC_DEC(client->bind); + if (bind_ref == 0) + unref = _gf_true; + + gf_msg_callingfn("client_t", GF_LOG_DEBUG, 0, LG_MSG_BIND_REF, + "%s: " + "bind_ref: %" GF_PRI_ATOMIC ", ref: %" GF_PRI_ATOMIC + ", " + "unref: %d", + client->client_uid, GF_ATOMIC_GET(client->bind), + GF_ATOMIC_GET(client->count), unref); + if (unref) { if (detached) - *detached = _gf_false; - - bind_ref = GF_ATOMIC_DEC (client->bind); - if (bind_ref == 0) - unref = _gf_true; - - gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_BIND_REF, "%s: " - "bind_ref: %"GF_PRI_ATOMIC", ref: %"GF_PRI_ATOMIC", " - "unref: %d", client->client_uid, - GF_ATOMIC_GET (client->bind), - GF_ATOMIC_GET (client->count), unref); - if (unref) { - if (detached) - *detached = _gf_true; - gf_client_unref (client); - } + *detached = _gf_true; + gf_client_unref(client); + } out: - return; + return; } client_t * -gf_client_ref (client_t *client) +gf_client_ref(client_t *client) { - if (!client) { - gf_msg_callingfn ("client_t", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "null client"); - return NULL; - } - - GF_ATOMIC_INC (client->count); - gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_REF_COUNT, "%s: " - "ref-count %"GF_PRI_ATOMIC, client->client_uid, - GF_ATOMIC_GET (client->count)); - return client; + if (!client) { + gf_msg_callingfn("client_t", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "null client"); + return NULL; + } + + GF_ATOMIC_INC(client->count); + gf_msg_callingfn("client_t", GF_LOG_DEBUG, 0, LG_MSG_REF_COUNT, + "%s: " + "ref-count %" GF_PRI_ATOMIC, + client->client_uid, GF_ATOMIC_GET(client->count)); + return client; } - static void -gf_client_destroy_recursive (xlator_t *xl, client_t *client) +gf_client_destroy_recursive(xlator_t *xl, client_t *client) { - xlator_list_t *trav; + xlator_list_t *trav; - if (!xl->call_cleanup && xl->cbks->client_destroy) { - xl->cbks->client_destroy (xl, client); - } + if (!xl->call_cleanup && xl->cbks->client_destroy) { + xl->cbks->client_destroy(xl, client); + } - for (trav = xl->children; trav; trav = trav->next) { - gf_client_destroy_recursive (trav->xlator, client); - } + for (trav = xl->children; trav; trav = trav->next) { + gf_client_destroy_recursive(trav->xlator, client); + } } - static void -client_destroy (client_t *client) +client_destroy(client_t *client) { - clienttable_t *clienttable = NULL; - glusterfs_graph_t *gtrav = NULL; - - if (client == NULL){ - gf_msg_callingfn ("xlator", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - goto out; - } - - clienttable = client->this->ctx->clienttable; - - LOCK_DESTROY (&client->scratch_ctx.lock); - - LOCK (&clienttable->lock); - { - clienttable->cliententries[client->tbl_index].client = NULL; - clienttable->cliententries[client->tbl_index].next_free = - clienttable->first_free; - clienttable->first_free = client->tbl_index; - } - UNLOCK (&clienttable->lock); - - list_for_each_entry (gtrav, &client->this->ctx->graphs, list) { - gf_client_destroy_recursive (gtrav->top, client); - } - - if (client->subdir_inode) - inode_unref (client->subdir_inode); - - GF_FREE (client->auth.data); - GF_FREE (client->auth.username); - GF_FREE (client->auth.passwd); - GF_FREE (client->scratch_ctx.ctx); - GF_FREE (client->client_uid); - GF_FREE (client->subdir_mount); - GF_FREE (client->client_name); - GF_FREE (client); + clienttable_t *clienttable = NULL; + glusterfs_graph_t *gtrav = NULL; + + if (client == NULL) { + gf_msg_callingfn("xlator", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + goto out; + } + + clienttable = client->this->ctx->clienttable; + + LOCK_DESTROY(&client->scratch_ctx.lock); + + LOCK(&clienttable->lock); + { + clienttable->cliententries[client->tbl_index].client = NULL; + clienttable->cliententries[client->tbl_index] + .next_free = clienttable->first_free; + clienttable->first_free = client->tbl_index; + } + UNLOCK(&clienttable->lock); + + list_for_each_entry(gtrav, &client->this->ctx->graphs, list) + { + gf_client_destroy_recursive(gtrav->top, client); + } + + if (client->subdir_inode) + inode_unref(client->subdir_inode); + + GF_FREE(client->auth.data); + GF_FREE(client->auth.username); + GF_FREE(client->auth.passwd); + GF_FREE(client->scratch_ctx.ctx); + GF_FREE(client->client_uid); + GF_FREE(client->subdir_mount); + GF_FREE(client->client_name); + GF_FREE(client); out: - return; + return; } static int -gf_client_disconnect_recursive (xlator_t *xl, client_t *client) +gf_client_disconnect_recursive(xlator_t *xl, client_t *client) { - int ret = 0; - xlator_list_t *trav; + int ret = 0; + xlator_list_t *trav; - if (!xl->call_cleanup && xl->cbks->client_disconnect) { - ret = xl->cbks->client_disconnect (xl, client); - } + if (!xl->call_cleanup && xl->cbks->client_disconnect) { + ret = xl->cbks->client_disconnect(xl, client); + } - for (trav = xl->children; trav; trav = trav->next) { - ret |= gf_client_disconnect_recursive (trav->xlator, client); - } + for (trav = xl->children; trav; trav = trav->next) { + ret |= gf_client_disconnect_recursive(trav->xlator, client); + } - return ret; + return ret; } - int -gf_client_disconnect (client_t *client) +gf_client_disconnect(client_t *client) { - int ret = 0; - glusterfs_graph_t *gtrav = NULL; + int ret = 0; + glusterfs_graph_t *gtrav = NULL; - list_for_each_entry (gtrav, &client->this->ctx->graphs, list) { - ret |= gf_client_disconnect_recursive (gtrav->top, client); - } + list_for_each_entry(gtrav, &client->this->ctx->graphs, list) + { + ret |= gf_client_disconnect_recursive(gtrav->top, client); + } - return ret; + return ret; } - void -gf_client_unref (client_t *client) +gf_client_unref(client_t *client) { - uint64_t refcount; - - if (!client) { - gf_msg_callingfn ("client_t", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "client is NULL"); - return; - } + uint64_t refcount; - refcount = GF_ATOMIC_DEC (client->count); - gf_msg_callingfn ("client_t", GF_LOG_DEBUG, 0, LG_MSG_REF_COUNT, "%s: " - "ref-count %"GF_PRI_ATOMIC, client->client_uid, - refcount); - if (refcount == 0) { - gf_msg (THIS->name, GF_LOG_INFO, 0, LG_MSG_DISCONNECT_CLIENT, - "Shutting down connection %s", client->client_uid); - client_destroy (client); - } + if (!client) { + gf_msg_callingfn("client_t", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "client is NULL"); + return; + } + + refcount = GF_ATOMIC_DEC(client->count); + gf_msg_callingfn("client_t", GF_LOG_DEBUG, 0, LG_MSG_REF_COUNT, + "%s: " + "ref-count %" GF_PRI_ATOMIC, + client->client_uid, refcount); + if (refcount == 0) { + gf_msg(THIS->name, GF_LOG_INFO, 0, LG_MSG_DISCONNECT_CLIENT, + "Shutting down connection %s", client->client_uid); + client_destroy(client); + } } - static int -__client_ctx_get_int (client_t *client, void *key, void **value) +__client_ctx_get_int(client_t *client, void *key, void **value) { - int index = 0; - int ret = 0; + int index = 0; + int ret = 0; - for (index = 0; index < client->scratch_ctx.count; index++) { - if (client->scratch_ctx.ctx[index].ctx_key == key) - break; - } + for (index = 0; index < client->scratch_ctx.count; index++) { + if (client->scratch_ctx.ctx[index].ctx_key == key) + break; + } - if (index == client->scratch_ctx.count) { - ret = -1; - goto out; - } + if (index == client->scratch_ctx.count) { + ret = -1; + goto out; + } - if (value) - *value = client->scratch_ctx.ctx[index].ctx_value; + if (value) + *value = client->scratch_ctx.ctx[index].ctx_value; out: - return ret; + return ret; } - static int -__client_ctx_set_int (client_t *client, void *key, void *value) +__client_ctx_set_int(client_t *client, void *key, void *value) { - int index = 0; - int ret = 0; - int set_idx = -1; - - for (index = 0; index < client->scratch_ctx.count; index++) { - if (!client->scratch_ctx.ctx[index].ctx_key) { - if (set_idx == -1) - set_idx = index; - /* don't break, to check if key already exists - further on */ - } - if (client->scratch_ctx.ctx[index].ctx_key == key) { - set_idx = index; - break; - } - } + int index = 0; + int ret = 0; + int set_idx = -1; - if (set_idx == -1) { - ret = -1; - goto out; + for (index = 0; index < client->scratch_ctx.count; index++) { + if (!client->scratch_ctx.ctx[index].ctx_key) { + if (set_idx == -1) + set_idx = index; + /* don't break, to check if key already exists + further on */ + } + if (client->scratch_ctx.ctx[index].ctx_key == key) { + set_idx = index; + break; } + } - client->scratch_ctx.ctx[set_idx].ctx_key = key; - client->scratch_ctx.ctx[set_idx].ctx_value = value; + if (set_idx == -1) { + ret = -1; + goto out; + } + + client->scratch_ctx.ctx[set_idx].ctx_key = key; + client->scratch_ctx.ctx[set_idx].ctx_value = value; out: - return ret; + return ret; } - /*will return success with old value if exist*/ void * -client_ctx_set (client_t *client, void *key, void *value) +client_ctx_set(client_t *client, void *key, void *value) { - int ret = 0; - void *ret_value = NULL; - - if (!client || !key || !value) - return NULL; - - LOCK (&client->scratch_ctx.lock); - { - ret = __client_ctx_get_int (client, key, &ret_value); - if (!ret && ret_value) { - UNLOCK (&client->scratch_ctx.lock); - return ret_value; - } + int ret = 0; + void *ret_value = NULL; + + if (!client || !key || !value) + return NULL; - ret = __client_ctx_set_int (client, key, value); + LOCK(&client->scratch_ctx.lock); + { + ret = __client_ctx_get_int(client, key, &ret_value); + if (!ret && ret_value) { + UNLOCK(&client->scratch_ctx.lock); + return ret_value; } - UNLOCK (&client->scratch_ctx.lock); - if (ret) - return NULL; - return value; -} + ret = __client_ctx_set_int(client, key, value); + } + UNLOCK(&client->scratch_ctx.lock); + if (ret) + return NULL; + return value; +} int -client_ctx_get (client_t *client, void *key, void **value) +client_ctx_get(client_t *client, void *key, void **value) { - int ret = 0; + int ret = 0; - if (!client || !key) - return -1; + if (!client || !key) + return -1; - LOCK (&client->scratch_ctx.lock); - { - ret = __client_ctx_get_int (client, key, value); - } - UNLOCK (&client->scratch_ctx.lock); + LOCK(&client->scratch_ctx.lock); + { + ret = __client_ctx_get_int(client, key, value); + } + UNLOCK(&client->scratch_ctx.lock); - return ret; + return ret; } - static int -__client_ctx_del_int (client_t *client, void *key, void **value) +__client_ctx_del_int(client_t *client, void *key, void **value) { - int index = 0; - int ret = 0; + int index = 0; + int ret = 0; - for (index = 0; index < client->scratch_ctx.count; index++) { - if (client->scratch_ctx.ctx[index].ctx_key == key) - break; - } + for (index = 0; index < client->scratch_ctx.count; index++) { + if (client->scratch_ctx.ctx[index].ctx_key == key) + break; + } - if (index == client->scratch_ctx.count) { - ret = -1; - goto out; - } + if (index == client->scratch_ctx.count) { + ret = -1; + goto out; + } - if (value) - *value = client->scratch_ctx.ctx[index].ctx_value; + if (value) + *value = client->scratch_ctx.ctx[index].ctx_value; - client->scratch_ctx.ctx[index].ctx_key = 0; - client->scratch_ctx.ctx[index].ctx_value = 0; + client->scratch_ctx.ctx[index].ctx_key = 0; + client->scratch_ctx.ctx[index].ctx_value = 0; out: - return ret; + return ret; } - int -client_ctx_del (client_t *client, void *key, void **value) +client_ctx_del(client_t *client, void *key, void **value) { - int ret = 0; + int ret = 0; - if (!client || !key) - return -1; + if (!client || !key) + return -1; - LOCK (&client->scratch_ctx.lock); - { - ret = __client_ctx_del_int (client, key, value); - } - UNLOCK (&client->scratch_ctx.lock); + LOCK(&client->scratch_ctx.lock); + { + ret = __client_ctx_del_int(client, key, value); + } + UNLOCK(&client->scratch_ctx.lock); - return ret; + return ret; } - void -client_dump (client_t *client, char *prefix) +client_dump(client_t *client, char *prefix) { - if (!client) - return; + if (!client) + return; - gf_proc_dump_write("refcount", GF_PRI_ATOMIC, - GF_ATOMIC_GET (client->count)); + gf_proc_dump_write("refcount", GF_PRI_ATOMIC, GF_ATOMIC_GET(client->count)); } - void -cliententry_dump (cliententry_t *cliententry, char *prefix) +cliententry_dump(cliententry_t *cliententry, char *prefix) { - if (!cliententry) - return; + if (!cliententry) + return; - if (GF_CLIENTENTRY_ALLOCATED != cliententry->next_free) - return; + if (GF_CLIENTENTRY_ALLOCATED != cliententry->next_free) + return; - if (cliententry->client) - client_dump(cliententry->client, prefix); + if (cliententry->client) + client_dump(cliententry->client, prefix); } - void -clienttable_dump (clienttable_t *clienttable, char *prefix) +clienttable_dump(clienttable_t *clienttable, char *prefix) { - int i = 0; - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN] = {0}; - - if (!clienttable) - return; - - ret = TRY_LOCK (&clienttable->lock); - { - if (ret) { - gf_msg ("client_t", GF_LOG_WARNING, 0, - LG_MSG_LOCK_FAILED, - "Unable to acquire lock"); - return; - } - gf_proc_dump_build_key(key, prefix, "maxclients"); - gf_proc_dump_write(key, "%d", clienttable->max_clients); - gf_proc_dump_build_key(key, prefix, "first_free"); - gf_proc_dump_write(key, "%d", clienttable->first_free); - for ( i = 0 ; i < clienttable->max_clients; i++) { - if (GF_CLIENTENTRY_ALLOCATED == - clienttable->cliententries[i].next_free) { - gf_proc_dump_build_key(key, prefix, - "cliententry[%d]", i); - gf_proc_dump_add_section(key); - cliententry_dump(&clienttable->cliententries[i], - key); - } - } - } - UNLOCK(&clienttable->lock); -} + int i = 0; + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = {0}; + if (!clienttable) + return; + + ret = TRY_LOCK(&clienttable->lock); + { + if (ret) { + gf_msg("client_t", GF_LOG_WARNING, 0, LG_MSG_LOCK_FAILED, + "Unable to acquire lock"); + return; + } + gf_proc_dump_build_key(key, prefix, "maxclients"); + gf_proc_dump_write(key, "%d", clienttable->max_clients); + gf_proc_dump_build_key(key, prefix, "first_free"); + gf_proc_dump_write(key, "%d", clienttable->first_free); + for (i = 0; i < clienttable->max_clients; i++) { + if (GF_CLIENTENTRY_ALLOCATED == + clienttable->cliententries[i].next_free) { + gf_proc_dump_build_key(key, prefix, "cliententry[%d]", i); + gf_proc_dump_add_section(key); + cliententry_dump(&clienttable->cliententries[i], key); + } + } + } + UNLOCK(&clienttable->lock); +} void -client_ctx_dump (client_t *client, char *prefix) +client_ctx_dump(client_t *client, char *prefix) { #if 0 /* TBD, FIXME */ struct client_ctx *client_ctx = NULL; @@ -701,254 +678,241 @@ out: #endif } - /* * the following functions are here to preserve legacy behavior of the * protocol/server xlator dump, but perhaps they should just be folded * into the client dump instead? */ int -gf_client_dump_fdtables_to_dict (xlator_t *this, dict_t *dict) +gf_client_dump_fdtables_to_dict(xlator_t *this, dict_t *dict) { - clienttable_t *clienttable = NULL; - int count = 0; - int ret = -1; + clienttable_t *clienttable = NULL; + int count = 0; + int ret = -1; #ifdef NOTYET - client_t *client = NULL; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; + client_t *client = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; #endif - GF_VALIDATE_OR_GOTO (THIS->name, this, out); - GF_VALIDATE_OR_GOTO (this->name, dict, out); + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + GF_VALIDATE_OR_GOTO(this->name, dict, out); - clienttable = this->ctx->clienttable; + clienttable = this->ctx->clienttable; - if (!clienttable) - return -1; + if (!clienttable) + return -1; #ifdef NOTYET - ret = TRY_LOCK (&clienttable->lock); - { - if (ret) { - gf_msg ("client_t", GF_LOG_WARNING, 0, - LG_MSG_LOCK_FAILED, - "Unable to acquire lock"); - return -1; - } - for ( ; count < clienttable->max_clients; count++) { - if (GF_CLIENTENTRY_ALLOCATED != - clienttable->cliententries[count].next_free) - continue; - client = clienttable->cliententries[count].client; - if (client->bound_xl && - !strcmp (client->bound_xl->name, this->name)) { - snprintf (key, sizeof (key), "conn%d", count++); - fdtable_dump_to_dict (client->server_ctx. - fdtable, - key, dict); - } - } - } - UNLOCK(&clienttable->lock); + ret = TRY_LOCK(&clienttable->lock); + { + if (ret) { + gf_msg("client_t", GF_LOG_WARNING, 0, LG_MSG_LOCK_FAILED, + "Unable to acquire lock"); + return -1; + } + for (; count < clienttable->max_clients; count++) { + if (GF_CLIENTENTRY_ALLOCATED != + clienttable->cliententries[count].next_free) + continue; + client = clienttable->cliententries[count].client; + if (client->bound_xl && + !strcmp(client->bound_xl->name, this->name)) { + snprintf(key, sizeof(key), "conn%d", count++); + fdtable_dump_to_dict(client->server_ctx.fdtable, key, dict); + } + } + } + UNLOCK(&clienttable->lock); #endif - ret = dict_set_int32 (dict, "conncount", count); + ret = dict_set_int32(dict, "conncount", count); out: - return ret; + return ret; } int -gf_client_dump_fdtables (xlator_t *this) +gf_client_dump_fdtables(xlator_t *this) { - client_t *client = NULL; - clienttable_t *clienttable = NULL; - int count = 1; - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - - GF_VALIDATE_OR_GOTO (THIS->name, this, out); - - clienttable = this->ctx->clienttable; - - if (!clienttable) - return -1; - - ret = TRY_LOCK (&clienttable->lock); - { - if (ret) { - gf_msg ("client_t", GF_LOG_WARNING, 0, - LG_MSG_LOCK_FAILED, - "Unable to acquire lock"); - return -1; - } - - - for ( ; count < clienttable->max_clients; count++) { - if (GF_CLIENTENTRY_ALLOCATED != - clienttable->cliententries[count].next_free) - continue; - client = clienttable->cliententries[count].client; - if (client->client_uid) { - gf_proc_dump_build_key (key, "conn", - "%d.id", count); - gf_proc_dump_write (key, "%s", - client->client_uid); - } - - if (client->subdir_mount) { - gf_proc_dump_build_key (key, "conn", - "%d.subdir", count); - gf_proc_dump_write (key, "%s", - client->subdir_mount); - } - gf_proc_dump_build_key (key, "conn", "%d.ref", - count); - gf_proc_dump_write (key, GF_PRI_ATOMIC, - GF_ATOMIC_GET (client->count)); - if (client->bound_xl) { - gf_proc_dump_build_key (key, "conn", - "%d.bound_xl", count); - gf_proc_dump_write (key, "%s", - client->bound_xl->name); - } + client_t *client = NULL; + clienttable_t *clienttable = NULL; + int count = 1; + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + + clienttable = this->ctx->clienttable; + + if (!clienttable) + return -1; + + ret = TRY_LOCK(&clienttable->lock); + { + if (ret) { + gf_msg("client_t", GF_LOG_WARNING, 0, LG_MSG_LOCK_FAILED, + "Unable to acquire lock"); + return -1; + } + + for (; count < clienttable->max_clients; count++) { + if (GF_CLIENTENTRY_ALLOCATED != + clienttable->cliententries[count].next_free) + continue; + client = clienttable->cliententries[count].client; + if (client->client_uid) { + gf_proc_dump_build_key(key, "conn", "%d.id", count); + gf_proc_dump_write(key, "%s", client->client_uid); + } + + if (client->subdir_mount) { + gf_proc_dump_build_key(key, "conn", "%d.subdir", count); + gf_proc_dump_write(key, "%s", client->subdir_mount); + } + gf_proc_dump_build_key(key, "conn", "%d.ref", count); + gf_proc_dump_write(key, GF_PRI_ATOMIC, + GF_ATOMIC_GET(client->count)); + if (client->bound_xl) { + gf_proc_dump_build_key(key, "conn", "%d.bound_xl", count); + gf_proc_dump_write(key, "%s", client->bound_xl->name); + } #ifdef NOTYET - gf_proc_dump_build_key (key, "conn","%d.id", count); - fdtable_dump (client->server_ctx.fdtable, key); + gf_proc_dump_build_key(key, "conn", "%d.id", count); + fdtable_dump(client->server_ctx.fdtable, key); #endif - } } + } - UNLOCK(&clienttable->lock); + UNLOCK(&clienttable->lock); - ret = 0; + ret = 0; out: - return ret; + return ret; } - int -gf_client_dump_inodes_to_dict (xlator_t *this, dict_t *dict) +gf_client_dump_inodes_to_dict(xlator_t *this, dict_t *dict) { - client_t *client = NULL; - clienttable_t *clienttable = NULL; - xlator_t *prev_bound_xl = NULL; - char key[32] = {0,}; - int count = 0; - int ret = -1; - - GF_VALIDATE_OR_GOTO (THIS->name, this, out); - GF_VALIDATE_OR_GOTO (this->name, dict, out); - - clienttable = this->ctx->clienttable; - - if (!clienttable) - return -1; - - ret = LOCK (&clienttable->lock); - { - if (ret) { - gf_msg ("client_t", GF_LOG_WARNING, 0, - LG_MSG_LOCK_FAILED, - "Unable to acquire lock"); - return -1; - } - for ( ; count < clienttable->max_clients; count++) { - if (GF_CLIENTENTRY_ALLOCATED != - clienttable->cliententries[count].next_free) - continue; - client = clienttable->cliententries[count].client; - if (!strcmp (client->bound_xl->name, this->name)) { - if (client->bound_xl && client->bound_xl-> - itable) { - /* Presently every brick contains only - * one bound_xl for all connections. - * This will lead to duplicating of - * the inode lists, if listing is - * done for every connection. This - * simple check prevents duplication - * in the present case. If need arises - * the check can be improved. - */ - if (client->bound_xl == prev_bound_xl) - continue; - prev_bound_xl = client->bound_xl; - - snprintf (key, sizeof (key), "conn%d", - count); - inode_table_dump_to_dict (client-> - bound_xl->itable, - key, dict); - } - } + client_t *client = NULL; + clienttable_t *clienttable = NULL; + xlator_t *prev_bound_xl = NULL; + char key[32] = { + 0, + }; + int count = 0; + int ret = -1; + + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + GF_VALIDATE_OR_GOTO(this->name, dict, out); + + clienttable = this->ctx->clienttable; + + if (!clienttable) + return -1; + + ret = LOCK(&clienttable->lock); + { + if (ret) { + gf_msg("client_t", GF_LOG_WARNING, 0, LG_MSG_LOCK_FAILED, + "Unable to acquire lock"); + return -1; + } + for (; count < clienttable->max_clients; count++) { + if (GF_CLIENTENTRY_ALLOCATED != + clienttable->cliententries[count].next_free) + continue; + client = clienttable->cliententries[count].client; + if (!strcmp(client->bound_xl->name, this->name)) { + if (client->bound_xl && client->bound_xl->itable) { + /* Presently every brick contains only + * one bound_xl for all connections. + * This will lead to duplicating of + * the inode lists, if listing is + * done for every connection. This + * simple check prevents duplication + * in the present case. If need arises + * the check can be improved. + */ + if (client->bound_xl == prev_bound_xl) + continue; + prev_bound_xl = client->bound_xl; + + snprintf(key, sizeof(key), "conn%d", count); + inode_table_dump_to_dict(client->bound_xl->itable, key, + dict); } + } } - UNLOCK(&clienttable->lock); + } + UNLOCK(&clienttable->lock); - ret = dict_set_int32 (dict, "conncount", count); + ret = dict_set_int32(dict, "conncount", count); out: - if (prev_bound_xl) - prev_bound_xl = NULL; - return ret; + if (prev_bound_xl) + prev_bound_xl = NULL; + return ret; } int -gf_client_dump_inodes (xlator_t *this) +gf_client_dump_inodes(xlator_t *this) { - client_t *client = NULL; - clienttable_t *clienttable = NULL; - xlator_t *prev_bound_xl = NULL; - int count = 0; - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - - GF_VALIDATE_OR_GOTO (THIS->name, this, out); - - clienttable = this->ctx->clienttable; - - if (!clienttable) - goto out; - - ret = TRY_LOCK (&clienttable->lock); - { - if (ret) { - gf_msg ("client_t", GF_LOG_WARNING, 0, - LG_MSG_LOCK_FAILED, - "Unable to acquire lock"); - goto out; - } - - for ( ; count < clienttable->max_clients; count++) { - if (GF_CLIENTENTRY_ALLOCATED != - clienttable->cliententries[count].next_free) - continue; - client = clienttable->cliententries[count].client; - if (client->bound_xl && client->bound_xl->itable) { - /* Presently every brick contains only - * one bound_xl for all connections. - * This will lead to duplicating of - * the inode lists, if listing is - * done for every connection. This - * simple check prevents duplication - * in the present case. If need arises - * the check can be improved. - */ - if (client->bound_xl == prev_bound_xl) - continue; - prev_bound_xl = client->bound_xl; - - gf_proc_dump_build_key(key, "conn", - "%d.bound_xl.%s", count, - client->bound_xl->name); - inode_table_dump(client->bound_xl->itable,key); - } - } - } - UNLOCK(&clienttable->lock); - - ret = 0; + client_t *client = NULL; + clienttable_t *clienttable = NULL; + xlator_t *prev_bound_xl = NULL; + int count = 0; + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + + GF_VALIDATE_OR_GOTO(THIS->name, this, out); + + clienttable = this->ctx->clienttable; + + if (!clienttable) + goto out; + + ret = TRY_LOCK(&clienttable->lock); + { + if (ret) { + gf_msg("client_t", GF_LOG_WARNING, 0, LG_MSG_LOCK_FAILED, + "Unable to acquire lock"); + goto out; + } + + for (; count < clienttable->max_clients; count++) { + if (GF_CLIENTENTRY_ALLOCATED != + clienttable->cliententries[count].next_free) + continue; + client = clienttable->cliententries[count].client; + if (client->bound_xl && client->bound_xl->itable) { + /* Presently every brick contains only + * one bound_xl for all connections. + * This will lead to duplicating of + * the inode lists, if listing is + * done for every connection. This + * simple check prevents duplication + * in the present case. If need arises + * the check can be improved. + */ + if (client->bound_xl == prev_bound_xl) + continue; + prev_bound_xl = client->bound_xl; + + gf_proc_dump_build_key(key, "conn", "%d.bound_xl.%s", count, + client->bound_xl->name); + inode_table_dump(client->bound_xl->itable, key); + } + } + } + UNLOCK(&clienttable->lock); + + ret = 0; out: - return ret; + return ret; } - diff --git a/libglusterfs/src/cluster-syncop.c b/libglusterfs/src/cluster-syncop.c index aa9cea75ba3..dab00577886 100644 --- a/libglusterfs/src/cluster-syncop.c +++ b/libglusterfs/src/cluster-syncop.c @@ -17,539 +17,496 @@ #include "cluster-syncop.h" #include "defaults.h" -#define FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fop, args ...) do {\ - int __i = 0; \ - int __count = 0; \ - cluster_local_t __local = {0,}; \ - void *__old_local = frame->local; \ - \ - __local.replies = replies; \ - memset (output, 0, numsubvols); \ - cluster_replies_wipe (replies, numsubvols); \ - for (__i = 0; __i < numsubvols; __i++) \ - INIT_LIST_HEAD (&replies[__i].entries.list); \ - if (syncbarrier_init (&__local.barrier)) \ - break; \ - frame->local = &__local; \ - for (__i = 0; __i < numsubvols; __i++) { \ - if (on[__i]) { \ - __count++; \ - } \ - } \ - __local.barrier.waitfor = __count; \ - for (__i = 0; __i < numsubvols; __i++) { \ - if (!on[__i]) \ - continue; \ - STACK_WIND_COOKIE (frame, cluster_##fop##_cbk, \ - (void *)(long) __i, subvols[__i], \ - subvols[__i]->fops->fop, args); \ - } \ - syncbarrier_wait (&__local.barrier, __count); \ - syncbarrier_destroy (&__local.barrier); \ - frame->local = __old_local; \ - STACK_RESET (frame->root); \ - } while (0) - -#define FOP_SEQ(subvols, on, numsubvols, replies, output, frame, fop, args ...) do {\ - int __i = 0; \ - \ - cluster_local_t __local = {0,}; \ - void *__old_local = frame->local; \ - __local.replies = replies; \ - memset (output, 0, numsubvols); \ - cluster_replies_wipe (replies, numsubvols); \ - for (__i = 0; __i < numsubvols; __i++) \ - INIT_LIST_HEAD (&replies[__i].entries.list); \ - if (syncbarrier_init (&__local.barrier)) \ - break; \ - frame->local = &__local; \ - for (__i = 0; __i < numsubvols; __i++) { \ - if (!on[__i]) \ - continue; \ - STACK_WIND_COOKIE (frame, cluster_##fop##_cbk, \ - (void *)(long) __i, subvols[__i], \ - subvols[__i]->fops->fop, args); \ - syncbarrier_wait (&__local.barrier, 1); \ - } \ - syncbarrier_destroy (&__local.barrier); \ - frame->local = __old_local; \ - STACK_RESET (frame->root); \ - } while (0) - -#define FOP_CBK(fop, frame, cookie, args ...) do {\ - cluster_local_t *__local = frame->local; \ - int __i = (long)cookie; \ - args_##fop##_cbk_store (&__local->replies[__i], args); \ - __local->replies[__i].valid = 1; \ - syncbarrier_wake (&__local->barrier); \ - } while (0) - -int32_t -cluster_fop_success_fill (default_args_cbk_t *replies, int numsubvols, - unsigned char *success) -{ - int i = 0; - int count = 0; - - for (i = 0; i < numsubvols; i++) { - if (replies[i].valid && replies[i].op_ret >= 0) { - success[i] = 1; - count++; - } else { - success[i] = 0; - } +#define FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fop, \ + args...) \ + do { \ + int __i = 0; \ + int __count = 0; \ + cluster_local_t __local = { \ + 0, \ + }; \ + void *__old_local = frame->local; \ + \ + __local.replies = replies; \ + memset(output, 0, numsubvols); \ + cluster_replies_wipe(replies, numsubvols); \ + for (__i = 0; __i < numsubvols; __i++) \ + INIT_LIST_HEAD(&replies[__i].entries.list); \ + if (syncbarrier_init(&__local.barrier)) \ + break; \ + frame->local = &__local; \ + for (__i = 0; __i < numsubvols; __i++) { \ + if (on[__i]) { \ + __count++; \ + } \ + } \ + __local.barrier.waitfor = __count; \ + for (__i = 0; __i < numsubvols; __i++) { \ + if (!on[__i]) \ + continue; \ + STACK_WIND_COOKIE(frame, cluster_##fop##_cbk, (void *)(long)__i, \ + subvols[__i], subvols[__i]->fops->fop, args); \ + } \ + syncbarrier_wait(&__local.barrier, __count); \ + syncbarrier_destroy(&__local.barrier); \ + frame->local = __old_local; \ + STACK_RESET(frame->root); \ + } while (0) + +#define FOP_SEQ(subvols, on, numsubvols, replies, output, frame, fop, args...) \ + do { \ + int __i = 0; \ + \ + cluster_local_t __local = { \ + 0, \ + }; \ + void *__old_local = frame->local; \ + __local.replies = replies; \ + memset(output, 0, numsubvols); \ + cluster_replies_wipe(replies, numsubvols); \ + for (__i = 0; __i < numsubvols; __i++) \ + INIT_LIST_HEAD(&replies[__i].entries.list); \ + if (syncbarrier_init(&__local.barrier)) \ + break; \ + frame->local = &__local; \ + for (__i = 0; __i < numsubvols; __i++) { \ + if (!on[__i]) \ + continue; \ + STACK_WIND_COOKIE(frame, cluster_##fop##_cbk, (void *)(long)__i, \ + subvols[__i], subvols[__i]->fops->fop, args); \ + syncbarrier_wait(&__local.barrier, 1); \ + } \ + syncbarrier_destroy(&__local.barrier); \ + frame->local = __old_local; \ + STACK_RESET(frame->root); \ + } while (0) + +#define FOP_CBK(fop, frame, cookie, args...) \ + do { \ + cluster_local_t *__local = frame->local; \ + int __i = (long)cookie; \ + args_##fop##_cbk_store(&__local->replies[__i], args); \ + __local->replies[__i].valid = 1; \ + syncbarrier_wake(&__local->barrier); \ + } while (0) + +int32_t +cluster_fop_success_fill(default_args_cbk_t *replies, int numsubvols, + unsigned char *success) +{ + int i = 0; + int count = 0; + + for (i = 0; i < numsubvols; i++) { + if (replies[i].valid && replies[i].op_ret >= 0) { + success[i] = 1; + count++; + } else { + success[i] = 0; } + } - return count; + return count; } void -cluster_replies_wipe (default_args_cbk_t *replies, int numsubvols) +cluster_replies_wipe(default_args_cbk_t *replies, int numsubvols) { - int i = 0; + int i = 0; - if (!replies) - return; + if (!replies) + return; - for (i = 0; i < numsubvols; i++) - args_cbk_wipe (&replies[i]); - memset (replies, 0, numsubvols * sizeof (*replies)); + for (i = 0; i < numsubvols; i++) + args_cbk_wipe(&replies[i]); + memset(replies, 0, numsubvols * sizeof(*replies)); } int32_t -cluster_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, dict_t *xdata, struct iatt *postparent) +cluster_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, dict_t *xdata, struct iatt *postparent) { - FOP_CBK (lookup, frame, cookie, op_ret, op_errno, inode, buf, - xdata, postparent); - return 0; + FOP_CBK(lookup, frame, cookie, op_ret, op_errno, inode, buf, xdata, + postparent); + return 0; } int32_t -cluster_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - dict_t *xdata) +cluster_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + dict_t *xdata) { - FOP_CBK (stat, frame, cookie, op_ret, op_errno, buf, xdata); - return 0; + FOP_CBK(stat, frame, cookie, op_ret, op_errno, buf, xdata); + return 0; } +int32_t +cluster_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + FOP_CBK(truncate, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata); + return 0; +} int32_t -cluster_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, +cluster_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, - dict_t *xdata) + struct iatt *postbuf, dict_t *xdata) { - FOP_CBK (truncate, frame, cookie, op_ret, op_errno, prebuf, - postbuf, xdata); - return 0; + FOP_CBK(ftruncate, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata); + return 0; } int32_t -cluster_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, - dict_t *xdata) +cluster_access_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (ftruncate, frame, cookie, op_ret, op_errno, prebuf, - postbuf, xdata); - return 0; + FOP_CBK(access, frame, cookie, op_ret, op_errno, xdata); + return 0; } int32_t -cluster_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_readlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, const char *path, + struct iatt *buf, dict_t *xdata) { - FOP_CBK (access, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(readlink, frame, cookie, op_ret, op_errno, path, buf, xdata); + return 0; } int32_t -cluster_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, const char *path, - struct iatt *buf, dict_t *xdata) +cluster_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (readlink, frame, cookie, op_ret, op_errno, path, buf, - xdata); - return 0; + FOP_CBK(mknod, frame, cookie, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); + return 0; } - int32_t -cluster_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +cluster_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (mknod, frame, cookie, op_ret, op_errno, inode, - buf, preparent, postparent, xdata); - return 0; + FOP_CBK(mkdir, frame, cookie, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); + return 0; } int32_t -cluster_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, +cluster_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, struct iatt *postparent, dict_t *xdata) { - FOP_CBK (mkdir, frame, cookie, op_ret, op_errno, inode, - buf, preparent, postparent, xdata); - return 0; + FOP_CBK(unlink, frame, cookie, op_ret, op_errno, preparent, postparent, + xdata); + return 0; } int32_t -cluster_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +cluster_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (unlink, frame, cookie, op_ret, op_errno, preparent, - postparent, xdata); - return 0; + FOP_CBK(rmdir, frame, cookie, op_ret, op_errno, preparent, postparent, + xdata); + return 0; } int32_t -cluster_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *preparent, - struct iatt *postparent, - dict_t *xdata) +cluster_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (rmdir, frame, cookie, op_ret, op_errno, preparent, - postparent, xdata); - return 0; + FOP_CBK(symlink, frame, cookie, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); + return 0; } int32_t -cluster_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +cluster_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) { - FOP_CBK (symlink, frame, cookie, op_ret, op_errno, inode, buf, - preparent, postparent, xdata); - return 0; + FOP_CBK(rename, frame, cookie, op_ret, op_errno, buf, preoldparent, + postoldparent, prenewparent, postnewparent, xdata); + return 0; } int32_t -cluster_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent, - dict_t *xdata) +cluster_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (rename, frame, cookie, op_ret, op_errno, buf, preoldparent, - postoldparent, prenewparent, postnewparent, xdata); - return 0; + FOP_CBK(link, frame, cookie, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); + return 0; } - int32_t -cluster_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, - dict_t *xdata) +cluster_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (link, frame, cookie, op_ret, op_errno, inode, buf, - preparent, postparent, xdata); - return 0; + FOP_CBK(create, frame, cookie, op_ret, op_errno, fd, inode, buf, preparent, + postparent, xdata); + return 0; } - int32_t -cluster_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, - dict_t *xdata) +cluster_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - FOP_CBK (create, frame, cookie, op_ret, op_errno, fd, inode, buf, - preparent, postparent, xdata); - return 0; + FOP_CBK(open, frame, cookie, op_ret, op_errno, fd, xdata); + return 0; } int32_t -cluster_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, +cluster_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iovec *vector, + int32_t count, struct iatt *stbuf, struct iobref *iobref, dict_t *xdata) { - FOP_CBK (open, frame, cookie, op_ret, op_errno, fd, xdata); - return 0; + FOP_CBK(readv, frame, cookie, op_ret, op_errno, vector, count, stbuf, + iobref, xdata); + return 0; } int32_t -cluster_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *stbuf, struct iobref *iobref, - dict_t *xdata) +cluster_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - FOP_CBK (readv, frame, cookie, op_ret, op_errno, vector, count, - stbuf, iobref, xdata); - return 0; + FOP_CBK(writev, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata); + return 0; } - int32_t -cluster_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, - dict_t *xdata) +cluster_put_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - FOP_CBK (writev, frame, cookie, op_ret, op_errno, prebuf, postbuf, - xdata); - return 0; + FOP_CBK(put, frame, cookie, op_ret, op_errno, inode, buf, preparent, + postparent, xdata); + return 0; } - int32_t -cluster_put_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +cluster_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (put, frame, cookie, op_ret, op_errno, inode, buf, preparent, - postparent, xdata); - return 0; + FOP_CBK(flush, frame, cookie, op_ret, op_errno, xdata); + return 0; } - int32_t -cluster_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - FOP_CBK (flush, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(fsync, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata); + return 0; } - - int32_t -cluster_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, - dict_t *xdata) +cluster_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + dict_t *xdata) { - FOP_CBK (fsync, frame, cookie, op_ret, op_errno, prebuf, postbuf, - xdata); - return 0; + FOP_CBK(fstat, frame, cookie, op_ret, op_errno, buf, xdata); + return 0; } int32_t -cluster_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - dict_t *xdata) +cluster_opendir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - FOP_CBK (fstat, frame, cookie, op_ret, op_errno, buf, xdata); - return 0; + FOP_CBK(opendir, frame, cookie, op_ret, op_errno, fd, xdata); + return 0; } int32_t -cluster_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, - dict_t *xdata) +cluster_fsyncdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (opendir, frame, cookie, op_ret, op_errno, fd, xdata); - return 0; + FOP_CBK(fsyncdir, frame, cookie, op_ret, op_errno, xdata); + return 0; } int32_t -cluster_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct statvfs *buf, + dict_t *xdata) { - FOP_CBK (fsyncdir, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(statfs, frame, cookie, op_ret, op_errno, buf, xdata); + return 0; } int32_t -cluster_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct statvfs *buf, - dict_t *xdata) +cluster_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (statfs, frame, cookie, op_ret, op_errno, buf, xdata); - return 0; + FOP_CBK(setxattr, frame, cookie, op_ret, op_errno, xdata); + return 0; } - int32_t -cluster_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (setxattr, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(fsetxattr, frame, cookie, op_ret, op_errno, xdata); + return 0; } - int32_t -cluster_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_fgetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { - FOP_CBK (fsetxattr, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(fgetxattr, frame, cookie, op_ret, op_errno, dict, xdata); + return 0; } - - int32_t -cluster_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict, - dict_t *xdata) +cluster_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { - FOP_CBK (fgetxattr, frame, cookie, op_ret, op_errno, dict, xdata); - return 0; + FOP_CBK(getxattr, frame, cookie, op_ret, op_errno, dict, xdata); + return 0; } - int32_t -cluster_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict, - dict_t *xdata) +cluster_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { - FOP_CBK (getxattr, frame, cookie, op_ret, op_errno, dict, xdata); - return 0; + FOP_CBK(xattrop, frame, cookie, op_ret, op_errno, dict, xdata); + return 0; } int32_t -cluster_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, +cluster_fxattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, dict_t *dict, dict_t *xdata) { - FOP_CBK (xattrop, frame, cookie, op_ret, op_errno, dict, xdata); - return 0; + FOP_CBK(fxattrop, frame, cookie, op_ret, op_errno, dict, xdata); + return 0; } int32_t -cluster_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict, - dict_t *xdata) +cluster_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (fxattrop, frame, cookie, op_ret, op_errno, dict, xdata); - return 0; + FOP_CBK(removexattr, frame, cookie, op_ret, op_errno, xdata); + return 0; } - int32_t -cluster_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (removexattr, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(fremovexattr, frame, cookie, op_ret, op_errno, xdata); + return 0; } - int32_t -cluster_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_lk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct gf_flock *lock, + dict_t *xdata) { - FOP_CBK (fremovexattr, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(lk, frame, cookie, op_ret, op_errno, lock, xdata); + return 0; } int32_t -cluster_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct gf_flock *lock, - dict_t *xdata) +cluster_inodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (lk, frame, cookie, op_ret, op_errno, lock, xdata); - return 0; + FOP_CBK(inodelk, frame, cookie, op_ret, op_errno, xdata); + return 0; } int32_t -cluster_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_finodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (inodelk, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(finodelk, frame, cookie, op_ret, op_errno, xdata); + return 0; } - int32_t -cluster_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_entrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (finodelk, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(entrylk, frame, cookie, op_ret, op_errno, xdata); + return 0; } int32_t -cluster_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_fentrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (entrylk, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(fentrylk, frame, cookie, op_ret, op_errno, xdata); + return 0; } int32_t -cluster_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - dict_t *xdata) +cluster_rchecksum_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, uint32_t weak_checksum, + uint8_t *strong_checksum, dict_t *xdata) { - FOP_CBK (fentrylk, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(rchecksum, frame, cookie, op_ret, op_errno, weak_checksum, + strong_checksum, xdata); + return 0; } - int32_t -cluster_rchecksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, uint32_t weak_checksum, - uint8_t *strong_checksum, - dict_t *xdata) +cluster_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) { - FOP_CBK (rchecksum, frame, cookie, op_ret, op_errno, weak_checksum, - strong_checksum, xdata); - return 0; + FOP_CBK(readdir, frame, cookie, op_ret, op_errno, entries, xdata); + return 0; } - int32_t -cluster_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, +cluster_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, dict_t *xdata) { - FOP_CBK (readdir, frame, cookie, op_ret, op_errno, entries, xdata); - return 0; + FOP_CBK(readdirp, frame, cookie, op_ret, op_errno, entries, xdata); + return 0; } - int32_t -cluster_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, - dict_t *xdata) +cluster_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - FOP_CBK (readdirp, frame, cookie, op_ret, op_errno, entries, xdata); - return 0; + FOP_CBK(setattr, frame, cookie, op_ret, op_errno, statpre, statpost, xdata); + return 0; } int32_t -cluster_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, +cluster_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct iatt *statpre, - struct iatt *statpost, - dict_t *xdata) + struct iatt *statpost, dict_t *xdata) { - FOP_CBK (setattr, frame, cookie, op_ret, op_errno, statpre, - statpost, xdata); - return 0; -} - -int32_t -cluster_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *statpre, - struct iatt *statpost, - dict_t *xdata) -{ - FOP_CBK (fsetattr, frame, cookie, op_ret, op_errno, statpre, - statpost, xdata); - return 0; + FOP_CBK(fsetattr, frame, cookie, op_ret, op_errno, statpre, statpost, + xdata); + return 0; } int32_t @@ -557,8 +514,8 @@ cluster_fallocate_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) { - FOP_CBK (fallocate, frame, cookie, op_ret, op_errno, pre, post, xdata); - return 0; + FOP_CBK(fallocate, frame, cookie, op_ret, op_errno, pre, post, xdata); + return 0; } int32_t @@ -566,752 +523,733 @@ cluster_discard_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) { - FOP_CBK (discard, frame, cookie, op_ret, op_errno, pre, post, xdata); - return 0; + FOP_CBK(discard, frame, cookie, op_ret, op_errno, pre, post, xdata); + return 0; } int32_t cluster_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 op_ret, int32_t op_errno, struct iatt *pre, + struct iatt *post, dict_t *xdata) { - FOP_CBK (zerofill, frame, cookie, op_ret, op_errno, pre, - post, xdata); - return 0; + FOP_CBK(zerofill, frame, cookie, op_ret, op_errno, pre, post, xdata); + return 0; } - int32_t -cluster_ipc_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +cluster_ipc_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - FOP_CBK (ipc, frame, cookie, op_ret, op_errno, xdata); - return 0; + FOP_CBK(ipc, frame, cookie, op_ret, op_errno, xdata); + return 0; } int32_t -cluster_fgetxattr (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name, dict_t *xdata) -{ - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fgetxattr, fd, - name, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); -} - -int32_t -cluster_fsetxattr (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict, - int32_t flags, dict_t *xdata) +cluster_fgetxattr(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fsetxattr, fd, - dict, flags, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fgetxattr, fd, + name, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_setxattr (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_fsetxattr(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, + call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict, int32_t flags, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, setxattr, loc, - dict, flags, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsetxattr, fd, + dict, flags, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_statfs (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) +cluster_setxattr(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, + int32_t flags, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, statfs, loc, - xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, setxattr, loc, + dict, flags, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fsyncdir (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, - dict_t *xdata) +cluster_statfs(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fsyncdir, fd, - flags, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, statfs, loc, + xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_opendir (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_fsyncdir(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, + call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, opendir, loc, - fd, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsyncdir, fd, + flags, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fstat (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) +cluster_opendir(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fstat, fd, - xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, opendir, loc, + fd, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fsync (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, - dict_t *xdata) +cluster_fstat(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fsync, fd, - flags, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fstat, fd, + xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_flush (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) +cluster_fsync(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, flush, fd, - xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsync, fd, + flags, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_writev (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iovec *vector, int32_t count, off_t off, uint32_t flags, - struct iobref *iobref, dict_t *xdata) +cluster_flush(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, writev, fd, - vector, count, off, flags, iobref, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, flush, fd, + xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_put (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode, mode_t umask, uint32_t flags, struct iovec *vector, - int32_t count, off_t offset, struct iobref *iobref, dict_t *xattr, - dict_t *xdata) +cluster_writev(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iovec *vector, int32_t count, off_t off, uint32_t flags, + struct iobref *iobref, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, put, loc, - mode, umask, flags, vector, count, offset, iobref, xattr, - xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, writev, fd, + vector, count, off, flags, iobref, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_readv (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset, uint32_t flags, dict_t *xdata) +cluster_put(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + mode_t umask, uint32_t flags, struct iovec *vector, int32_t count, + off_t offset, struct iobref *iobref, dict_t *xattr, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, readv, fd, size, - offset, flags, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, put, loc, mode, + umask, flags, vector, count, offset, iobref, xattr, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int32_t -cluster_open (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_readv(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - fd_t *fd, dict_t *xdata) + call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, + off_t offset, uint32_t flags, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, open, loc, - flags, fd, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readv, fd, size, + offset, flags, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_create (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, - mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) +cluster_open(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, + fd_t *fd, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, create, loc, - flags, mode, umask, fd, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, open, loc, + flags, fd, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_link (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, - dict_t *xdata) +cluster_create(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, + mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, link, oldloc, - newloc, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, create, loc, + flags, mode, umask, fd, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_rename (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *oldloc, - loc_t *newloc, dict_t *xdata) +cluster_link(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, rename, oldloc, - newloc, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, link, oldloc, + newloc, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } +int32_t +cluster_rename(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) +{ + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, rename, oldloc, + newloc, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); +} int -cluster_symlink (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, const char *linkpath, - loc_t *loc, mode_t umask, dict_t *xdata) +cluster_symlink(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, const char *linkpath, + loc_t *loc, mode_t umask, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, symlink, - linkpath, loc, umask, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, symlink, + linkpath, loc, umask, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_rmdir (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, - dict_t *xdata) +cluster_rmdir(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, rmdir, loc, - flags, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, rmdir, loc, + flags, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_unlink (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, - dict_t *xdata) +cluster_unlink(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, unlink, loc, - xflag, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, unlink, loc, + xflag, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int -cluster_mkdir (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - mode_t umask, dict_t *xdata) +cluster_mkdir(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + mode_t umask, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, mkdir, loc, - mode, umask, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, mkdir, loc, + mode, umask, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int -cluster_mknod (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dev_t rdev, mode_t umask, dict_t *xdata) +cluster_mknod(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, + dev_t rdev, mode_t umask, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, mknod, loc, - mode, rdev, umask, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, mknod, loc, + mode, rdev, umask, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_readlink (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, - dict_t *xdata) +cluster_readlink(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, readlink, loc, - size, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readlink, loc, + size, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int32_t -cluster_access (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask, - dict_t *xdata) +cluster_access(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, access, loc, - mask, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, access, loc, + mask, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_ftruncate (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - dict_t *xdata) +cluster_ftruncate(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, ftruncate, fd, - offset, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, ftruncate, fd, + offset, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_getxattr (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name, dict_t *xdata) +cluster_getxattr(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, getxattr, loc, - name, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, getxattr, loc, + name, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } +int32_t +cluster_xattrop(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) +{ + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, xattrop, loc, + flags, dict, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); +} int32_t -cluster_xattrop (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_fxattrop(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, + call_frame_t *frame, xlator_t *this, fd_t *fd, gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, xattrop, loc, - flags, dict, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fxattrop, fd, + flags, dict, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fxattrop (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) +cluster_removexattr(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, + const char *name, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fxattrop, fd, - flags, dict, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, removexattr, + loc, name, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_removexattr (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_fremovexattr(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, + call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, removexattr, - loc, name, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fremovexattr, + fd, name, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fremovexattr (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name, dict_t *xdata) +cluster_lk(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, + struct gf_flock *lock, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fremovexattr, - fd, name, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, lk, fd, cmd, + lock, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_lk (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - int32_t cmd, struct gf_flock *lock, dict_t *xdata) +cluster_rchecksum(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + int32_t len, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, lk, fd, cmd, - lock, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, rchecksum, fd, + offset, len, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int32_t -cluster_rchecksum (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - int32_t len, dict_t *xdata) +cluster_readdir(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, + off_t off, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, rchecksum, fd, - offset, len, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readdir, fd, + size, off, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int32_t -cluster_readdir (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_readdirp(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off, dict_t *xdata) + call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, + off_t off, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, readdir, fd, - size, off, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readdirp, fd, + size, off, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int32_t -cluster_readdirp (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off, dict_t *xdata) +cluster_setattr(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, readdirp, fd, - size, off, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, setattr, loc, + stbuf, valid, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_setattr (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_truncate(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid, dict_t *xdata) + call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, + dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, setattr, loc, - stbuf, valid, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, truncate, loc, + offset, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_truncate (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, - dict_t *xdata) +cluster_stat(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, truncate, loc, - offset, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, stat, loc, + xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_stat (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) +cluster_lookup(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, stat, loc, - xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, lookup, loc, + xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_lookup (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) +cluster_fsetattr(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, + struct iatt *stbuf, int32_t valid, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, lookup, loc, - xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsetattr, fd, + stbuf, valid, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fsetattr (xlator_t **subvols, unsigned char *on, int numsubvols, +cluster_fallocate(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid, dict_t *xdata) + int32_t keep_size, off_t offset, size_t len, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, fsetattr, fd, - stbuf, valid, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fallocate, fd, + keep_size, offset, len, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t -cluster_fallocate (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - int32_t keep_size, off_t offset, size_t len, dict_t *xdata) -{ - FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fallocate, fd, - keep_size, offset, len, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); -} - -int32_t -cluster_discard (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - off_t offset, size_t len, dict_t *xdata) +cluster_discard(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) { - FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, discard, fd, - offset, len, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, discard, fd, + offset, len, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int32_t cluster_zerofill(xlator_t **subvols, unsigned char *on, int numsubvols, default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, fd_t *fd, - off_t offset, off_t len, dict_t *xdata) + call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + off_t len, dict_t *xdata) { - FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, zerofill, fd, - offset, len, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, zerofill, fd, + offset, len, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } - int32_t -cluster_ipc (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata) +cluster_ipc(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata) { - FOP_ONLIST (subvols, on, numsubvols, replies, output, frame, ipc, op, xdata); - return cluster_fop_success_fill (replies, numsubvols, output); + FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, ipc, op, xdata); + return cluster_fop_success_fill(replies, numsubvols, output); } int -cluster_uninodelk (xlator_t **subvols, unsigned char *locked_on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, char *dom, - inode_t *inode, off_t off, size_t size) +cluster_uninodelk(xlator_t **subvols, unsigned char *locked_on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, char *dom, + inode_t *inode, off_t off, size_t size) { - loc_t loc = {0,}; - struct gf_flock flock = {0, }; - + loc_t loc = { + 0, + }; + struct gf_flock flock = { + 0, + }; - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); - flock.l_type = F_UNLCK; - flock.l_start = off; - flock.l_len = size; + flock.l_type = F_UNLCK; + flock.l_start = off; + flock.l_len = size; - FOP_ONLIST (subvols, locked_on, numsubvols, replies, output, frame, inodelk, - dom, &loc, F_SETLK, &flock, NULL); + FOP_ONLIST(subvols, locked_on, numsubvols, replies, output, frame, inodelk, + dom, &loc, F_SETLK, &flock, NULL); - loc_wipe (&loc); + loc_wipe(&loc); - return cluster_fop_success_fill (replies, numsubvols, output); + return cluster_fop_success_fill(replies, numsubvols, output); } int -cluster_tryinodelk (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *locked_on, - call_frame_t *frame, xlator_t *this, char *dom, - inode_t *inode, off_t off, size_t size) +cluster_tryinodelk(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *locked_on, + call_frame_t *frame, xlator_t *this, char *dom, + inode_t *inode, off_t off, size_t size) { - struct gf_flock flock = {0, }; - loc_t loc = {0}; + struct gf_flock flock = { + 0, + }; + loc_t loc = {0}; - flock.l_type = F_WRLCK; - flock.l_start = off; - flock.l_len = size; + flock.l_type = F_WRLCK; + flock.l_start = off; + flock.l_len = size; - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - FOP_ONLIST (subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom, - &loc, F_SETLK, &flock, NULL); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom, + &loc, F_SETLK, &flock, NULL); - loc_wipe (&loc); - return cluster_fop_success_fill (replies, numsubvols, locked_on); + loc_wipe(&loc); + return cluster_fop_success_fill(replies, numsubvols, locked_on); } int -cluster_inodelk (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *locked_on, - call_frame_t *frame, xlator_t *this, char *dom, - inode_t *inode, off_t off, size_t size) -{ - struct gf_flock flock = {0, }; - int i = 0; - loc_t loc = {0}; - unsigned char *output = NULL; - - flock.l_type = F_WRLCK; - flock.l_start = off; - flock.l_len = size; - - output = alloca(numsubvols); - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - FOP_ONLIST (subvols, on, numsubvols, replies, locked_on, frame, - inodelk, dom, &loc, F_SETLK, &flock, NULL); - - for (i = 0; i < numsubvols; i++) { - if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { - cluster_fop_success_fill (replies, numsubvols, - locked_on); - cluster_uninodelk (subvols, locked_on, numsubvols, - replies, output, frame, this, dom, inode, off, size); - - FOP_SEQ (subvols, on, numsubvols, replies, locked_on, - frame, inodelk, dom, &loc, F_SETLKW, &flock, - NULL); - break; - } +cluster_inodelk(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *locked_on, + call_frame_t *frame, xlator_t *this, char *dom, inode_t *inode, + off_t off, size_t size) +{ + struct gf_flock flock = { + 0, + }; + int i = 0; + loc_t loc = {0}; + unsigned char *output = NULL; + + flock.l_type = F_WRLCK; + flock.l_start = off; + flock.l_len = size; + + output = alloca(numsubvols); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom, + &loc, F_SETLK, &flock, NULL); + + for (i = 0; i < numsubvols; i++) { + if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { + cluster_fop_success_fill(replies, numsubvols, locked_on); + cluster_uninodelk(subvols, locked_on, numsubvols, replies, output, + frame, this, dom, inode, off, size); + + FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame, inodelk, + dom, &loc, F_SETLKW, &flock, NULL); + break; } + } - loc_wipe (&loc); - return cluster_fop_success_fill (replies, numsubvols, locked_on); + loc_wipe(&loc); + return cluster_fop_success_fill(replies, numsubvols, locked_on); } - int -cluster_unentrylk (xlator_t **subvols, unsigned char *locked_on, int numsubvols, - default_args_cbk_t *replies, unsigned char *output, - call_frame_t *frame, xlator_t *this, char *dom, - inode_t *inode, const char *name) +cluster_unentrylk(xlator_t **subvols, unsigned char *locked_on, int numsubvols, + default_args_cbk_t *replies, unsigned char *output, + call_frame_t *frame, xlator_t *this, char *dom, + inode_t *inode, const char *name) { - loc_t loc = {0,}; - + loc_t loc = { + 0, + }; - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); - FOP_ONLIST (subvols, locked_on, numsubvols, replies, output, frame, - entrylk, dom, &loc, name, ENTRYLK_UNLOCK, ENTRYLK_WRLCK, - NULL); + FOP_ONLIST(subvols, locked_on, numsubvols, replies, output, frame, entrylk, + dom, &loc, name, ENTRYLK_UNLOCK, ENTRYLK_WRLCK, NULL); - loc_wipe (&loc); + loc_wipe(&loc); - return cluster_fop_success_fill (replies, numsubvols, output); + return cluster_fop_success_fill(replies, numsubvols, output); } int -cluster_tryentrylk (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *locked_on, - call_frame_t *frame, xlator_t *this, char *dom, - inode_t *inode, const char *name) +cluster_tryentrylk(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *locked_on, + call_frame_t *frame, xlator_t *this, char *dom, + inode_t *inode, const char *name) { - loc_t loc = {0}; + loc_t loc = {0}; - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - FOP_ONLIST (subvols, on, numsubvols, replies, locked_on, frame, - entrylk, dom, &loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, - NULL); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, entrylk, dom, + &loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, NULL); - loc_wipe (&loc); - return cluster_fop_success_fill (replies, numsubvols, locked_on); + loc_wipe(&loc); + return cluster_fop_success_fill(replies, numsubvols, locked_on); } int -cluster_entrylk (xlator_t **subvols, unsigned char *on, int numsubvols, - default_args_cbk_t *replies, unsigned char *locked_on, - call_frame_t *frame, xlator_t *this, char *dom, - inode_t *inode, const char *name) -{ - int i = 0; - loc_t loc = {0}; - unsigned char *output = NULL; - - output = alloca(numsubvols); - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - FOP_ONLIST (subvols, on, numsubvols, replies, locked_on, frame, - entrylk, dom, &loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, - NULL); - - for (i = 0; i < numsubvols; i++) { - if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { - cluster_fop_success_fill (replies, numsubvols, - locked_on); - cluster_unentrylk (subvols, locked_on, numsubvols, - replies, output, frame, this, dom, - inode, name); - FOP_SEQ (subvols, on, numsubvols, replies, - locked_on, frame, entrylk, dom, &loc, name, - ENTRYLK_LOCK, ENTRYLK_WRLCK, NULL); - break; - } +cluster_entrylk(xlator_t **subvols, unsigned char *on, int numsubvols, + default_args_cbk_t *replies, unsigned char *locked_on, + call_frame_t *frame, xlator_t *this, char *dom, inode_t *inode, + const char *name) +{ + int i = 0; + loc_t loc = {0}; + unsigned char *output = NULL; + + output = alloca(numsubvols); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, entrylk, dom, + &loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, NULL); + + for (i = 0; i < numsubvols; i++) { + if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { + cluster_fop_success_fill(replies, numsubvols, locked_on); + cluster_unentrylk(subvols, locked_on, numsubvols, replies, output, + frame, this, dom, inode, name); + FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame, entrylk, + dom, &loc, name, ENTRYLK_LOCK, ENTRYLK_WRLCK, NULL); + break; } + } - loc_wipe (&loc); - return cluster_fop_success_fill (replies, numsubvols, locked_on); + loc_wipe(&loc); + return cluster_fop_success_fill(replies, numsubvols, locked_on); } int -cluster_tiebreaker_inodelk (xlator_t **subvols, unsigned char *on, - int numsubvols, default_args_cbk_t *replies, - unsigned char *locked_on, call_frame_t *frame, - xlator_t *this, char *dom, inode_t *inode, - off_t off, size_t size) -{ - struct gf_flock flock = {0, }; - int i = 0; - int num_success = 0; - loc_t loc = {0}; - unsigned char *output = NULL; - - flock.l_type = F_WRLCK; - flock.l_start = off; - flock.l_len = size; - - output = alloca(numsubvols); - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - FOP_ONLIST (subvols, on, numsubvols, replies, locked_on, frame, - inodelk, dom, &loc, F_SETLK, &flock, NULL); - - for (i = 0; i < numsubvols; i++) { - if (replies[i].valid && replies[i].op_ret == 0) { - num_success++; - continue; - } - - /* TODO: If earlier subvols fail with an error other - * than EAGAIN, we could still have 2 clients competing - * for the lock*/ - if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { - cluster_fop_success_fill (replies, numsubvols, - locked_on); - cluster_uninodelk (subvols, locked_on, numsubvols, - replies, output, frame, this, dom, - inode, off, size); - - if (num_success) { - FOP_SEQ (subvols, on, numsubvols, replies, - locked_on, frame, inodelk, dom, &loc, - F_SETLKW, &flock, NULL); - } - break; - } +cluster_tiebreaker_inodelk(xlator_t **subvols, unsigned char *on, + int numsubvols, default_args_cbk_t *replies, + unsigned char *locked_on, call_frame_t *frame, + xlator_t *this, char *dom, inode_t *inode, off_t off, + size_t size) +{ + struct gf_flock flock = { + 0, + }; + int i = 0; + int num_success = 0; + loc_t loc = {0}; + unsigned char *output = NULL; + + flock.l_type = F_WRLCK; + flock.l_start = off; + flock.l_len = size; + + output = alloca(numsubvols); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom, + &loc, F_SETLK, &flock, NULL); + + for (i = 0; i < numsubvols; i++) { + if (replies[i].valid && replies[i].op_ret == 0) { + num_success++; + continue; } - loc_wipe (&loc); - return cluster_fop_success_fill (replies, numsubvols, locked_on); + /* TODO: If earlier subvols fail with an error other + * than EAGAIN, we could still have 2 clients competing + * for the lock*/ + if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { + cluster_fop_success_fill(replies, numsubvols, locked_on); + cluster_uninodelk(subvols, locked_on, numsubvols, replies, output, + frame, this, dom, inode, off, size); + + if (num_success) { + FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame, + inodelk, dom, &loc, F_SETLKW, &flock, NULL); + } + break; + } + } + + loc_wipe(&loc); + return cluster_fop_success_fill(replies, numsubvols, locked_on); } int -cluster_tiebreaker_entrylk (xlator_t **subvols, unsigned char *on, - int numsubvols, default_args_cbk_t *replies, - unsigned char *locked_on, call_frame_t *frame, - xlator_t *this, char *dom, inode_t *inode, - const char *name) -{ - int i = 0; - loc_t loc = {0}; - unsigned char *output = NULL; - int num_success = 0; - - output = alloca(numsubvols); - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - FOP_ONLIST (subvols, on, numsubvols, replies, locked_on, frame, - entrylk, dom, &loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, - NULL); - - for (i = 0; i < numsubvols; i++) { - if (replies[i].valid && replies[i].op_ret == 0) { - num_success++; - continue; - } - if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { - cluster_fop_success_fill (replies, numsubvols, - locked_on); - cluster_unentrylk (subvols, locked_on, numsubvols, - replies, output, frame, this, dom, - inode, name); - if (num_success) { - FOP_SEQ (subvols, on, numsubvols, replies, - locked_on, frame, entrylk, dom, &loc, - name, ENTRYLK_LOCK, ENTRYLK_WRLCK, - NULL); - } else { - memset (locked_on, 0, numsubvols); - } - break; - } +cluster_tiebreaker_entrylk(xlator_t **subvols, unsigned char *on, + int numsubvols, default_args_cbk_t *replies, + unsigned char *locked_on, call_frame_t *frame, + xlator_t *this, char *dom, inode_t *inode, + const char *name) +{ + int i = 0; + loc_t loc = {0}; + unsigned char *output = NULL; + int num_success = 0; + + output = alloca(numsubvols); + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, entrylk, dom, + &loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, NULL); + + for (i = 0; i < numsubvols; i++) { + if (replies[i].valid && replies[i].op_ret == 0) { + num_success++; + continue; + } + if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) { + cluster_fop_success_fill(replies, numsubvols, locked_on); + cluster_unentrylk(subvols, locked_on, numsubvols, replies, output, + frame, this, dom, inode, name); + if (num_success) { + FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame, + entrylk, dom, &loc, name, ENTRYLK_LOCK, ENTRYLK_WRLCK, + NULL); + } else { + memset(locked_on, 0, numsubvols); + } + break; } + } - loc_wipe (&loc); - return cluster_fop_success_fill (replies, numsubvols, locked_on); + loc_wipe(&loc); + return cluster_fop_success_fill(replies, numsubvols, locked_on); } diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 748772bb21b..aae9858fe22 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -63,36 +63,41 @@ #define AI_ADDRCONFIG 0 #endif /* AI_ADDRCONFIG */ -char *vol_type_str[] = {"Distribute", - "Stripe", - "Replicate", - "Striped-Replicate", - "Disperse", - "Tier", - "Distributed-Stripe", - "Distributed-Replicate", - "Distributed-Striped-Replicate", - "Distributed-Disperse", - }; +char *vol_type_str[] = { + "Distribute", + "Stripe", + "Replicate", + "Striped-Replicate", + "Disperse", + "Tier", + "Distributed-Stripe", + "Distributed-Replicate", + "Distributed-Striped-Replicate", + "Distributed-Disperse", +}; typedef int32_t (*rw_op_t)(int32_t fd, char *buf, int32_t size); typedef int32_t (*rwv_op_t)(int32_t fd, const struct iovec *buf, int32_t size); void -gf_xxh64_wrapper(const unsigned char *data, size_t const len, unsigned long long const seed, - char *xxh64) +gf_xxh64_wrapper(const unsigned char *data, size_t const len, + unsigned long long const seed, char *xxh64) { - unsigned short i = 0; - const unsigned short lim = GF_XXH64_DIGEST_LENGTH*2+1; - XXH64_hash_t hash = 0; - XXH64_canonical_t c_hash = {{0,},}; - const uint8_t *p = (const uint8_t *) &c_hash; + unsigned short i = 0; + const unsigned short lim = GF_XXH64_DIGEST_LENGTH * 2 + 1; + XXH64_hash_t hash = 0; + XXH64_canonical_t c_hash = { + { + 0, + }, + }; + const uint8_t *p = (const uint8_t *)&c_hash; - hash = XXH64(data, len, seed); - XXH64_canonicalFromHash(&c_hash, hash); + hash = XXH64(data, len, seed); + XXH64_canonicalFromHash(&c_hash, hash); - for (i = 0; i < GF_XXH64_DIGEST_LENGTH; i++) - snprintf(xxh64 + i * 2, lim-i*2, "%02x", p[i]); + for (i = 0; i < GF_XXH64_DIGEST_LENGTH; i++) + snprintf(xxh64 + i * 2, lim - i * 2, "%02x", p[i]); } /** @@ -133,34 +138,35 @@ gf_xxh64_wrapper(const unsigned char *data, size_t const len, unsigned long long * tmp[15] = (hash_1) & 0xff; **/ static int -gf_gfid_from_xxh64 (xlator_t *this, uuid_t gfid, XXH64_hash_t hash, - unsigned short index) -{ - int ret = -1; - int i = -1; - - if ((index != 0) && (index != 8)) { - gf_msg_callingfn ("gfid-from-xxh64", GF_LOG_WARNING, 0, - LG_MSG_INDEX_NOT_FOUND, - "index can only be either 0 or 8, as this" - "function's purpose is to encode a 8 byte " - "hash inside the gfid (index: %d)", index); - goto out; - } - - for (i = 0; i < sizeof (hash); i++) { - /* - * As of now the below statement is equivalent of this. - * gfid[index+i] = (hash >> (64 - (8 * (i+1)))) & 0xff; - */ - gfid[index+i] = (hash >> ((sizeof (hash) * 8) - (8 * (i+1)))) - & (0xff); - } +gf_gfid_from_xxh64(xlator_t *this, uuid_t gfid, XXH64_hash_t hash, + unsigned short index) +{ + int ret = -1; + int i = -1; + + if ((index != 0) && (index != 8)) { + gf_msg_callingfn("gfid-from-xxh64", GF_LOG_WARNING, 0, + LG_MSG_INDEX_NOT_FOUND, + "index can only be either 0 or 8, as this" + "function's purpose is to encode a 8 byte " + "hash inside the gfid (index: %d)", + index); + goto out; + } + + for (i = 0; i < sizeof(hash); i++) { + /* + * As of now the below statement is equivalent of this. + * gfid[index+i] = (hash >> (64 - (8 * (i+1)))) & 0xff; + */ + gfid[index + i] = (hash >> ((sizeof(hash) * 8) - (8 * (i + 1)))) & + (0xff); + } - ret = 0; + ret = 0; out: - return ret; + return ret; } /** @@ -177,22 +183,26 @@ out: * of the hash). **/ XXH64_hash_t -gf_xxh64_hash_wrapper (const unsigned char *data, size_t const len, - unsigned long long const seed, char *xxh64) +gf_xxh64_hash_wrapper(const unsigned char *data, size_t const len, + unsigned long long const seed, char *xxh64) { - unsigned short i = 0; - const unsigned short lim = GF_XXH64_DIGEST_LENGTH*2+1; - XXH64_hash_t hash = 0; - XXH64_canonical_t c_hash = {{0,},}; - const uint8_t *p = (const uint8_t *)&c_hash; + unsigned short i = 0; + const unsigned short lim = GF_XXH64_DIGEST_LENGTH * 2 + 1; + XXH64_hash_t hash = 0; + XXH64_canonical_t c_hash = { + { + 0, + }, + }; + const uint8_t *p = (const uint8_t *)&c_hash; - hash = XXH64(data, len, seed); - XXH64_canonicalFromHash (&c_hash, hash); + hash = XXH64(data, len, seed); + XXH64_canonicalFromHash(&c_hash, hash); - for (i = 0; i < GF_XXH64_DIGEST_LENGTH; i++) - snprintf (xxh64 + i * 2, lim-i*2, "%02x", p[i]); + for (i = 0; i < GF_XXH64_DIGEST_LENGTH; i++) + snprintf(xxh64 + i * 2, lim - i * 2, "%02x", p[i]); - return hash; + return hash; } /** @@ -220,152 +230,165 @@ gf_xxh64_hash_wrapper (const unsigned char *data, size_t const len, * one 16 byte entity. **/ int -gf_gfid_generate_from_xxh64 (uuid_t gfid, char *key) -{ - char xxh64_1[GF_XXH64_DIGEST_LENGTH*2+1] = {0, }; - char xxh64_2[GF_XXH64_DIGEST_LENGTH*2+1] = {0, }; - XXH64_hash_t hash_1 = 0; - XXH64_hash_t hash_2 = 0; - int ret = -1; - xlator_t *this = THIS; - - hash_1 = gf_xxh64_hash_wrapper((unsigned char *)key, - strlen (key), GF_XXHSUM64_DEFAULT_SEED, - xxh64_1); - - hash_2 = gf_xxh64_hash_wrapper((unsigned char *)xxh64_1, - strlen (xxh64_1), - GF_XXHSUM64_DEFAULT_SEED, xxh64_2); - - /* hash_2 is saved in 1st 8 elements of uuid_t char array */ - if (gf_gfid_from_xxh64 (this, gfid, hash_2, 0)) { - gf_msg_callingfn (this->name, GF_LOG_WARNING, 0, - LG_MSG_XXH64_TO_GFID_FAILED, - "failed to encode the hash %llx into the 1st" - "half of gfid", hash_2); - goto out; - } - - /* hash_1 is saved in the remaining 8 elements of uuid_t */ - if (gf_gfid_from_xxh64 (this, gfid, hash_1, 8)) { - gf_msg_callingfn (this->name, GF_LOG_WARNING, 0, - LG_MSG_XXH64_TO_GFID_FAILED, - "failed to encode the hash %llx into the 2nd" - "half of gfid", hash_1); - goto out; - } - - gf_msg_debug (this->name, 0, "gfid generated is %s (hash1: %llx) " - "hash2: %llx, xxh64_1: %s xxh64_2: %s", uuid_utoa (gfid), - hash_1, hash_2, xxh64_1, xxh64_2); - - ret = 0; +gf_gfid_generate_from_xxh64(uuid_t gfid, char *key) +{ + char xxh64_1[GF_XXH64_DIGEST_LENGTH * 2 + 1] = { + 0, + }; + char xxh64_2[GF_XXH64_DIGEST_LENGTH * 2 + 1] = { + 0, + }; + XXH64_hash_t hash_1 = 0; + XXH64_hash_t hash_2 = 0; + int ret = -1; + xlator_t *this = THIS; + + hash_1 = gf_xxh64_hash_wrapper((unsigned char *)key, strlen(key), + GF_XXHSUM64_DEFAULT_SEED, xxh64_1); + + hash_2 = gf_xxh64_hash_wrapper((unsigned char *)xxh64_1, strlen(xxh64_1), + GF_XXHSUM64_DEFAULT_SEED, xxh64_2); + + /* hash_2 is saved in 1st 8 elements of uuid_t char array */ + if (gf_gfid_from_xxh64(this, gfid, hash_2, 0)) { + gf_msg_callingfn(this->name, GF_LOG_WARNING, 0, + LG_MSG_XXH64_TO_GFID_FAILED, + "failed to encode the hash %llx into the 1st" + "half of gfid", + hash_2); + goto out; + } + + /* hash_1 is saved in the remaining 8 elements of uuid_t */ + if (gf_gfid_from_xxh64(this, gfid, hash_1, 8)) { + gf_msg_callingfn(this->name, GF_LOG_WARNING, 0, + LG_MSG_XXH64_TO_GFID_FAILED, + "failed to encode the hash %llx into the 2nd" + "half of gfid", + hash_1); + goto out; + } + + gf_msg_debug(this->name, 0, + "gfid generated is %s (hash1: %llx) " + "hash2: %llx, xxh64_1: %s xxh64_2: %s", + uuid_utoa(gfid), hash_1, hash_2, xxh64_1, xxh64_2); + + ret = 0; out: - return ret; + return ret; } /* works similar to mkdir(1) -p. */ int -mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks) -{ - int i = 0; - int ret = -1; - char dir[PATH_MAX] = {0,}; - struct stat stbuf = {0,}; - - const int path_len = min(strlen(path), PATH_MAX -1); - - snprintf(dir, path_len + 1, "%s", path); - - i = (dir[0] == '/')? 1: 0; - do { - if (path[i] != '/' && path[i] != '\0') - continue; - - dir[i] = '\0'; - ret = sys_mkdir (dir, mode); - if (ret && errno != EEXIST) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, - "Failed due to reason"); - goto out; - } - - if (ret && errno == EEXIST && !allow_symlinks) { - ret = sys_lstat (dir, &stbuf); - if (ret) - goto out; - - if (S_ISLNK (stbuf.st_mode)) { - ret = -1; - gf_msg ("", GF_LOG_ERROR, 0, - LG_MSG_DIR_IS_SYMLINK, "%s is a " - "symlink", dir); - goto out; - } - } - dir[i] = '/'; - - } while (path[i++] != '\0'); - - ret = sys_stat (dir, &stbuf); - if (ret || !S_ISDIR (stbuf.st_mode)) { - if (ret == 0) - errno = 0; +mkdir_p(char *path, mode_t mode, gf_boolean_t allow_symlinks) +{ + int i = 0; + int ret = -1; + char dir[PATH_MAX] = { + 0, + }; + struct stat stbuf = { + 0, + }; + + const int path_len = min(strlen(path), PATH_MAX - 1); + + snprintf(dir, path_len + 1, "%s", path); + + i = (dir[0] == '/') ? 1 : 0; + do { + if (path[i] != '/' && path[i] != '\0') + continue; + + dir[i] = '\0'; + ret = sys_mkdir(dir, mode); + if (ret && errno != EEXIST) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "Failed due to reason"); + goto out; + } + + if (ret && errno == EEXIST && !allow_symlinks) { + ret = sys_lstat(dir, &stbuf); + if (ret) + goto out; + + if (S_ISLNK(stbuf.st_mode)) { ret = -1; - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "Failed" - " to create directory, possibly some of the components" - " were not directories"); + gf_msg("", GF_LOG_ERROR, 0, LG_MSG_DIR_IS_SYMLINK, + "%s is a " + "symlink", + dir); goto out; + } } + dir[i] = '/'; - ret = 0; + } while (path[i++] != '\0'); + + ret = sys_stat(dir, &stbuf); + if (ret || !S_ISDIR(stbuf.st_mode)) { + if (ret == 0) + errno = 0; + ret = -1; + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "Failed" + " to create directory, possibly some of the components" + " were not directories"); + goto out; + } + + ret = 0; out: - return ret; + return ret; } int -gf_lstat_dir (const char *path, struct stat *stbuf_in) +gf_lstat_dir(const char *path, struct stat *stbuf_in) { - int ret = -1; - struct stat stbuf = {0,}; + int ret = -1; + struct stat stbuf = { + 0, + }; - if (path == NULL) { - errno = EINVAL; - goto out; - } + if (path == NULL) { + errno = EINVAL; + goto out; + } - ret = sys_lstat (path, &stbuf); - if (ret) - goto out; + ret = sys_lstat(path, &stbuf); + if (ret) + goto out; - if (!S_ISDIR (stbuf.st_mode)) { - errno = ENOTDIR; - ret = -1; - goto out; - } - ret = 0; + if (!S_ISDIR(stbuf.st_mode)) { + errno = ENOTDIR; + ret = -1; + goto out; + } + ret = 0; out: - if (!ret && stbuf_in) - *stbuf_in = stbuf; + if (!ret && stbuf_in) + *stbuf_in = stbuf; - return ret; + return ret; } int -log_base2 (unsigned long x) +log_base2(unsigned long x) { - int val = 0; + int val = 0; - while (x > 1) { - x /= 2; - val++; - } + while (x > 1) { + x /= 2; + val++; + } - return val; + return val; } /** @@ -377,22 +400,23 @@ log_base2 (unsigned long x) * failure: NULL */ char * -gf_rev_dns_lookup (const char *ip) +gf_rev_dns_lookup(const char *ip) { - char *fqdn = NULL; - int ret = 0; + char *fqdn = NULL; + int ret = 0; - GF_VALIDATE_OR_GOTO ("resolver", ip, out); + GF_VALIDATE_OR_GOTO("resolver", ip, out); - /* Get the FQDN */ - ret = gf_get_hostname_from_ip ((char *)ip, &fqdn); - if (ret != 0) { - gf_msg ("resolver", GF_LOG_INFO, errno, - LG_MSG_RESOLVE_HOSTNAME_FAILED, "could not resolve " - "hostname for %s", ip); - } + /* Get the FQDN */ + ret = gf_get_hostname_from_ip((char *)ip, &fqdn); + if (ret != 0) { + gf_msg("resolver", GF_LOG_INFO, errno, LG_MSG_RESOLVE_HOSTNAME_FAILED, + "could not resolve " + "hostname for %s", + ip); + } out: - return fqdn; + return fqdn; } /** @@ -402,144 +426,145 @@ out: * @return: The parent path if found, NULL otherwise */ char * -gf_resolve_path_parent (const char *path) +gf_resolve_path_parent(const char *path) { - char *parent = NULL; - char *tmp = NULL; - char *pathc = NULL; + char *parent = NULL; + char *tmp = NULL; + char *pathc = NULL; - GF_VALIDATE_OR_GOTO (THIS->name, path, out); + GF_VALIDATE_OR_GOTO(THIS->name, path, out); - if (strlen (path) <= 0) { - gf_msg_callingfn (THIS->name, GF_LOG_DEBUG, 0, - LG_MSG_INVALID_STRING, - "invalid string for 'path'"); - goto out; - } + if (strlen(path) <= 0) { + gf_msg_callingfn(THIS->name, GF_LOG_DEBUG, 0, LG_MSG_INVALID_STRING, + "invalid string for 'path'"); + goto out; + } - /* dup the parameter, we don't want to modify it */ - pathc = strdupa (path); - if (!pathc) { - goto out; - } + /* dup the parameter, we don't want to modify it */ + pathc = strdupa(path); + if (!pathc) { + goto out; + } - /* Get the parent directory */ - tmp = dirname (pathc); - if (strcmp (tmp, "/") == 0) - goto out; + /* Get the parent directory */ + tmp = dirname(pathc); + if (strcmp(tmp, "/") == 0) + goto out; - parent = gf_strdup (tmp); + parent = gf_strdup(tmp); out: - return parent; + return parent; } int32_t -gf_resolve_ip6 (const char *hostname, - uint16_t port, - int family, - void **dnscache, - struct addrinfo **addr_info) -{ - int32_t ret = 0; - struct addrinfo hints; - struct dnscache6 *cache = NULL; - char service[NI_MAXSERV], host[NI_MAXHOST]; - - if (!hostname) { - gf_msg_callingfn ("resolver", GF_LOG_WARNING, 0, - LG_MSG_HOSTNAME_NULL, "hostname is NULL"); - return -1; - } +gf_resolve_ip6(const char *hostname, uint16_t port, int family, void **dnscache, + struct addrinfo **addr_info) +{ + int32_t ret = 0; + struct addrinfo hints; + struct dnscache6 *cache = NULL; + char service[NI_MAXSERV], host[NI_MAXHOST]; - if (!*dnscache) { - *dnscache = GF_CALLOC (1, sizeof (struct dnscache6), - gf_common_mt_dnscache6); - if (!*dnscache) - return -1; - } + if (!hostname) { + gf_msg_callingfn("resolver", GF_LOG_WARNING, 0, LG_MSG_HOSTNAME_NULL, + "hostname is NULL"); + return -1; + } + + if (!*dnscache) { + *dnscache = GF_CALLOC(1, sizeof(struct dnscache6), + gf_common_mt_dnscache6); + if (!*dnscache) + return -1; + } + + cache = *dnscache; + if (cache->first && !cache->next) { + freeaddrinfo(cache->first); + cache->first = cache->next = NULL; + gf_msg_trace("resolver", 0, "flushing DNS cache"); + } - cache = *dnscache; - if (cache->first && !cache->next) { - freeaddrinfo(cache->first); - cache->first = cache->next = NULL; - gf_msg_trace ("resolver", 0, "flushing DNS cache"); - } + if (!cache->first) { + char *port_str = NULL; + gf_msg_trace("resolver", 0, + "DNS cache not present, freshly " + "probing hostname: %s", + hostname); + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = family; + hints.ai_socktype = SOCK_STREAM; - if (!cache->first) { - char *port_str = NULL; - gf_msg_trace ("resolver", 0, "DNS cache not present, freshly " - "probing hostname: %s", hostname); - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = family; - hints.ai_socktype = SOCK_STREAM; - - ret = gf_asprintf (&port_str, "%d", port); - if (-1 == ret) { - return -1; - } - if ((ret = getaddrinfo(hostname, port_str, &hints, &cache->first)) != 0) { - gf_msg ("resolver", GF_LOG_ERROR, 0, - LG_MSG_GETADDRINFO_FAILED, "getaddrinfo failed" - " (%s)", gai_strerror (ret)); - - GF_FREE (*dnscache); - *dnscache = NULL; - GF_FREE (port_str); - return -1; - } - GF_FREE (port_str); - - cache->next = cache->first; + ret = gf_asprintf(&port_str, "%d", port); + if (-1 == ret) { + return -1; } + if ((ret = getaddrinfo(hostname, port_str, &hints, &cache->first)) != + 0) { + gf_msg("resolver", GF_LOG_ERROR, 0, LG_MSG_GETADDRINFO_FAILED, + "getaddrinfo failed" + " (%s)", + gai_strerror(ret)); - if (cache->next) { - ret = getnameinfo((struct sockaddr *)cache->next->ai_addr, - cache->next->ai_addrlen, - host, sizeof (host), - service, sizeof (service), - NI_NUMERICHOST); - if (ret != 0) { - gf_msg ("resolver", GF_LOG_ERROR, 0, - LG_MSG_GETNAMEINFO_FAILED, "getnameinfo failed" - " (%s)", gai_strerror (ret)); - goto err; - } - - gf_msg_debug ("resolver", 0, "returning ip-%s (port-%s) for " - "hostname: %s and port: %d", host, service, - hostname, port); - - *addr_info = cache->next; + GF_FREE(*dnscache); + *dnscache = NULL; + GF_FREE(port_str); + return -1; } + GF_FREE(port_str); + + cache->next = cache->first; + } - if (cache->next) - cache->next = cache->next->ai_next; - if (cache->next) { - ret = getnameinfo((struct sockaddr *)cache->next->ai_addr, - cache->next->ai_addrlen, - host, sizeof (host), - service, sizeof (service), - NI_NUMERICHOST); - if (ret != 0) { - gf_msg ("resolver", GF_LOG_ERROR, 0, - LG_MSG_GETNAMEINFO_FAILED, "getnameinfo failed" - " (%s)", gai_strerror (ret)); - goto err; - } - - gf_msg_debug ("resolver", 0, "next DNS query will return: " - "ip-%s port-%s", host, service); + if (cache->next) { + ret = getnameinfo((struct sockaddr *)cache->next->ai_addr, + cache->next->ai_addrlen, host, sizeof(host), service, + sizeof(service), NI_NUMERICHOST); + if (ret != 0) { + gf_msg("resolver", GF_LOG_ERROR, 0, LG_MSG_GETNAMEINFO_FAILED, + "getnameinfo failed" + " (%s)", + gai_strerror(ret)); + goto err; + } + + gf_msg_debug("resolver", 0, + "returning ip-%s (port-%s) for " + "hostname: %s and port: %d", + host, service, hostname, port); + + *addr_info = cache->next; + } + + if (cache->next) + cache->next = cache->next->ai_next; + if (cache->next) { + ret = getnameinfo((struct sockaddr *)cache->next->ai_addr, + cache->next->ai_addrlen, host, sizeof(host), service, + sizeof(service), NI_NUMERICHOST); + if (ret != 0) { + gf_msg("resolver", GF_LOG_ERROR, 0, LG_MSG_GETNAMEINFO_FAILED, + "getnameinfo failed" + " (%s)", + gai_strerror(ret)); + goto err; } - return 0; + gf_msg_debug("resolver", 0, + "next DNS query will return: " + "ip-%s port-%s", + host, service); + } + + return 0; err: - freeaddrinfo (cache->first); - cache->first = cache->next = NULL; - GF_FREE (cache); - *dnscache = NULL; - return -1; + freeaddrinfo(cache->first); + cache->first = cache->next = NULL; + GF_FREE(cache); + *dnscache = NULL; + return -1; } /** @@ -551,16 +576,15 @@ err: * FAILURE: NULL */ struct dnscache * -gf_dnscache_init (time_t ttl) +gf_dnscache_init(time_t ttl) { - struct dnscache *cache = GF_MALLOC (sizeof (*cache), - gf_common_mt_dnscache); - if (cache) { - cache->cache_dict = NULL; - cache->ttl = ttl; - } + struct dnscache *cache = GF_MALLOC(sizeof(*cache), gf_common_mt_dnscache); + if (cache) { + cache->cache_dict = NULL; + cache->ttl = ttl; + } - return cache; + return cache; } /** @@ -570,11 +594,11 @@ gf_dnscache_init (time_t ttl) * FAILURE: NULL */ struct dnscache_entry * -gf_dnscache_entry_init () +gf_dnscache_entry_init() { - struct dnscache_entry *entry = GF_CALLOC (1, sizeof (*entry), - gf_common_mt_dnscache_entry); - return entry; + struct dnscache_entry *entry = GF_CALLOC(1, sizeof(*entry), + gf_common_mt_dnscache_entry); + return entry; } /** @@ -583,11 +607,11 @@ gf_dnscache_entry_init () * @entry: Pointer to deallocate */ void -gf_dnscache_entry_deinit (struct dnscache_entry *entry) +gf_dnscache_entry_deinit(struct dnscache_entry *entry) { - GF_FREE (entry->ip); - GF_FREE (entry->fqdn); - GF_FREE (entry); + GF_FREE(entry->ip); + GF_FREE(entry->fqdn); + GF_FREE(entry); } /** @@ -599,1466 +623,1448 @@ gf_dnscache_entry_deinit (struct dnscache_entry *entry) * failure: NULL */ char * -gf_rev_dns_lookup_cached (const char *ip, struct dnscache *dnscache) +gf_rev_dns_lookup_cached(const char *ip, struct dnscache *dnscache) { - char *fqdn = NULL; - int ret = 0; - dict_t *cache = NULL; - data_t *entrydata = NULL; - struct dnscache_entry *dnsentry = NULL; - gf_boolean_t from_cache = _gf_false; + char *fqdn = NULL; + int ret = 0; + dict_t *cache = NULL; + data_t *entrydata = NULL; + struct dnscache_entry *dnsentry = NULL; + gf_boolean_t from_cache = _gf_false; - if (!dnscache) - goto out; + if (!dnscache) + goto out; + if (!dnscache->cache_dict) { + dnscache->cache_dict = dict_new(); if (!dnscache->cache_dict) { - dnscache->cache_dict = dict_new (); - if (!dnscache->cache_dict) { - goto out; - } - } - cache = dnscache->cache_dict; - - /* Quick cache lookup to see if we already hold it */ - entrydata = dict_get (cache, (char *)ip); - if (entrydata) { - dnsentry = (struct dnscache_entry *)entrydata->data; - /* First check the TTL & timestamp */ - if (time (NULL) - dnsentry->timestamp > dnscache->ttl) { - gf_dnscache_entry_deinit (dnsentry); - entrydata->data = NULL; /* Mark this as 'null' so - * dict_del () doesn't try free - * this after we've already - * freed it. - */ - - dict_del (cache, (char *)ip); /* Remove this entry */ - } else { - /* Cache entry is valid, get the FQDN and return */ - fqdn = dnsentry->fqdn; - from_cache = _gf_true; /* Mark this as from cache */ - goto out; - } + goto out; + } + } + cache = dnscache->cache_dict; + + /* Quick cache lookup to see if we already hold it */ + entrydata = dict_get(cache, (char *)ip); + if (entrydata) { + dnsentry = (struct dnscache_entry *)entrydata->data; + /* First check the TTL & timestamp */ + if (time(NULL) - dnsentry->timestamp > dnscache->ttl) { + gf_dnscache_entry_deinit(dnsentry); + entrydata->data = NULL; /* Mark this as 'null' so + * dict_del () doesn't try free + * this after we've already + * freed it. + */ + + dict_del(cache, (char *)ip); /* Remove this entry */ + } else { + /* Cache entry is valid, get the FQDN and return */ + fqdn = dnsentry->fqdn; + from_cache = _gf_true; /* Mark this as from cache */ + goto out; } + } - /* Get the FQDN */ - ret = gf_get_hostname_from_ip ((char *)ip, &fqdn); - if (ret != 0) - goto out; + /* Get the FQDN */ + ret = gf_get_hostname_from_ip((char *)ip, &fqdn); + if (ret != 0) + goto out; - if (!fqdn) { - gf_log_callingfn ("resolver", GF_LOG_CRITICAL, - "Allocation failed for the host address"); - goto out; - } + if (!fqdn) { + gf_log_callingfn("resolver", GF_LOG_CRITICAL, + "Allocation failed for the host address"); + goto out; + } - from_cache = _gf_false; + from_cache = _gf_false; out: - /* Insert into the cache */ - if (fqdn && !from_cache) { - struct dnscache_entry *entry = gf_dnscache_entry_init (); - - if (!entry) { - goto out; - } - entry->fqdn = fqdn; - if (!ip) { - gf_dnscache_entry_deinit (entry); - goto out; - } - - entry->ip = gf_strdup (ip); - entry->timestamp = time (NULL); - - entrydata = bin_to_data (entry, sizeof (*entry)); - dict_set (cache, (char *)ip, entrydata); + /* Insert into the cache */ + if (fqdn && !from_cache) { + struct dnscache_entry *entry = gf_dnscache_entry_init(); + + if (!entry) { + goto out; } - return fqdn; + entry->fqdn = fqdn; + if (!ip) { + gf_dnscache_entry_deinit(entry); + goto out; + } + + entry->ip = gf_strdup(ip); + entry->timestamp = time(NULL); + + entrydata = bin_to_data(entry, sizeof(*entry)); + dict_set(cache, (char *)ip, entrydata); + } + return fqdn; } struct xldump { - int lineno; + int lineno; }; /* to catch any format discrepencies that may arise in code */ -static int nprintf (struct xldump *dump, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); static int -nprintf (struct xldump *dump, const char *fmt, ...) +nprintf(struct xldump *dump, const char *fmt, ...) + __attribute__((__format__(__printf__, 2, 3))); +static int +nprintf(struct xldump *dump, const char *fmt, ...) { - va_list ap; - char *msg = NULL; - char header[32]; - int ret = 0; + va_list ap; + char *msg = NULL; + char header[32]; + int ret = 0; - ret = snprintf (header, 32, "%3d:", ++dump->lineno); - if (ret < 0) - goto out; + ret = snprintf(header, 32, "%3d:", ++dump->lineno); + if (ret < 0) + goto out; - va_start (ap, fmt); - ret = vasprintf (&msg, fmt, ap); - va_end (ap); - if (-1 == ret) - goto out; + va_start(ap, fmt); + ret = vasprintf(&msg, fmt, ap); + va_end(ap); + if (-1 == ret) + goto out; - /* NOTE: No ret value from gf_msg_plain, so unable to compute printed - * characters. The return value from nprintf is not used, so for now - * living with it */ - gf_msg_plain (GF_LOG_WARNING, "%s %s", header, msg); + /* NOTE: No ret value from gf_msg_plain, so unable to compute printed + * characters. The return value from nprintf is not used, so for now + * living with it */ + gf_msg_plain(GF_LOG_WARNING, "%s %s", header, msg); out: - FREE (msg); - return 0; + FREE(msg); + return 0; } - static int -xldump_options (dict_t *this, char *key, data_t *value, void *d) +xldump_options(dict_t *this, char *key, data_t *value, void *d) { - nprintf (d, " option %s %s", key, value->data); - return 0; + nprintf(d, " option %s %s", key, value->data); + return 0; } - static void -xldump_subvolumes (xlator_t *this, void *d) +xldump_subvolumes(xlator_t *this, void *d) { - xlator_list_t *subv = NULL; - int len = 0; - char *subvstr = NULL; + xlator_list_t *subv = NULL; + int len = 0; + char *subvstr = NULL; - subv = this->children; - if (!this->children) - return; + subv = this->children; + if (!this->children) + return; - for (subv = this->children; subv; subv = subv->next) - len += (strlen (subv->xlator->name) + 1); + for (subv = this->children; subv; subv = subv->next) + len += (strlen(subv->xlator->name) + 1); - subvstr = GF_MALLOC (len, gf_common_mt_strdup); + subvstr = GF_MALLOC(len, gf_common_mt_strdup); - len = 0; - for (subv = this->children; subv; subv= subv->next) - len += sprintf (subvstr + len, "%s%s", subv->xlator->name, - subv->next ? " " : ""); + len = 0; + for (subv = this->children; subv; subv = subv->next) + len += sprintf(subvstr + len, "%s%s", subv->xlator->name, + subv->next ? " " : ""); - nprintf (d, " subvolumes %s", subvstr); + nprintf(d, " subvolumes %s", subvstr); - GF_FREE (subvstr); + GF_FREE(subvstr); } - static void -xldump (xlator_t *each, void *d) +xldump(xlator_t *each, void *d) { - nprintf (d, "volume %s", each->name); - nprintf (d, " type %s", each->type); - dict_foreach (each->options, xldump_options, d); + nprintf(d, "volume %s", each->name); + nprintf(d, " type %s", each->type); + dict_foreach(each->options, xldump_options, d); - xldump_subvolumes (each, d); + xldump_subvolumes(each, d); - nprintf (d, "end-volume"); - nprintf (d, " "); + nprintf(d, "end-volume"); + nprintf(d, " "); } - void -gf_log_dump_graph (FILE *specfp, glusterfs_graph_t *graph) +gf_log_dump_graph(FILE *specfp, glusterfs_graph_t *graph) { - struct xldump xld = {0, }; + struct xldump xld = { + 0, + }; - gf_msg_plain (GF_LOG_WARNING, "Final graph:"); - gf_msg_plain (GF_LOG_WARNING, - "+---------------------------------------" - "---------------------------------------+"); + gf_msg_plain(GF_LOG_WARNING, "Final graph:"); + gf_msg_plain(GF_LOG_WARNING, + "+---------------------------------------" + "---------------------------------------+"); - xlator_foreach_depth_first (graph->top, xldump, &xld); + xlator_foreach_depth_first(graph->top, xldump, &xld); - gf_msg_plain (GF_LOG_WARNING, - "+---------------------------------------" - "---------------------------------------+"); + gf_msg_plain(GF_LOG_WARNING, + "+---------------------------------------" + "---------------------------------------+"); } static void -gf_dump_config_flags () +gf_dump_config_flags() { - gf_msg_plain_nomem (GF_LOG_ALERT, "configuration details:"); + gf_msg_plain_nomem(GF_LOG_ALERT, "configuration details:"); /* have argp */ #ifdef HAVE_ARGP - gf_msg_plain_nomem (GF_LOG_ALERT, "argp 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "argp 1"); #endif /* ifdef if found backtrace */ #ifdef HAVE_BACKTRACE - gf_msg_plain_nomem (GF_LOG_ALERT, "backtrace 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "backtrace 1"); #endif /* Berkeley-DB version has cursor->get() */ #ifdef HAVE_BDB_CURSOR_GET - gf_msg_plain_nomem (GF_LOG_ALERT, "bdb->cursor->get 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "bdb->cursor->get 1"); #endif /* Define to 1 if you have the <db.h> header file. */ #ifdef HAVE_DB_H - gf_msg_plain_nomem (GF_LOG_ALERT, "db.h 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "db.h 1"); #endif /* Define to 1 if you have the <dlfcn.h> header file. */ #ifdef HAVE_DLFCN_H - gf_msg_plain_nomem (GF_LOG_ALERT, "dlfcn 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "dlfcn 1"); #endif /* define if fdatasync exists */ #ifdef HAVE_FDATASYNC - gf_msg_plain_nomem (GF_LOG_ALERT, "fdatasync 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "fdatasync 1"); #endif /* Define to 1 if you have the `pthread' library (-lpthread). */ #ifdef HAVE_LIBPTHREAD - gf_msg_plain_nomem (GF_LOG_ALERT, "libpthread 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "libpthread 1"); #endif /* define if llistxattr exists */ #ifdef HAVE_LLISTXATTR - gf_msg_plain_nomem (GF_LOG_ALERT, "llistxattr 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "llistxattr 1"); #endif /* define if found setfsuid setfsgid */ #ifdef HAVE_SET_FSID - gf_msg_plain_nomem (GF_LOG_ALERT, "setfsid 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "setfsid 1"); #endif /* define if found spinlock */ #ifdef HAVE_SPINLOCK - gf_msg_plain_nomem (GF_LOG_ALERT, "spinlock 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "spinlock 1"); #endif /* Define to 1 if you have the <sys/epoll.h> header file. */ #ifdef HAVE_SYS_EPOLL_H - gf_msg_plain_nomem (GF_LOG_ALERT, "epoll.h 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "epoll.h 1"); #endif /* Define to 1 if you have the <sys/extattr.h> header file. */ #ifdef HAVE_SYS_EXTATTR_H - gf_msg_plain_nomem (GF_LOG_ALERT, "extattr.h 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "extattr.h 1"); #endif /* Define to 1 if you have the <sys/xattr.h> header file. */ #ifdef HAVE_SYS_XATTR_H - gf_msg_plain_nomem (GF_LOG_ALERT, "xattr.h 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "xattr.h 1"); #endif /* define if found st_atim.tv_nsec */ #ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC - gf_msg_plain_nomem (GF_LOG_ALERT, "st_atim.tv_nsec 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "st_atim.tv_nsec 1"); #endif /* define if found st_atimespec.tv_nsec */ #ifdef HAVE_STRUCT_STAT_ST_ATIMESPEC_TV_NSEC - gf_msg_plain_nomem (GF_LOG_ALERT, "st_atimespec.tv_nsec 1"); + gf_msg_plain_nomem(GF_LOG_ALERT, "st_atimespec.tv_nsec 1"); #endif /* Define to the full name and version of this package. */ #ifdef PACKAGE_STRING - { - char *msg = NULL; - int ret = -1; - - ret = gf_asprintf (&msg, "package-string: %s", PACKAGE_STRING); - if (ret >= 0) { - gf_msg_plain_nomem (GF_LOG_ALERT, msg); - GF_FREE (msg); - } + { + char *msg = NULL; + int ret = -1; + + ret = gf_asprintf(&msg, "package-string: %s", PACKAGE_STRING); + if (ret >= 0) { + gf_msg_plain_nomem(GF_LOG_ALERT, msg); + GF_FREE(msg); } + } #endif - return; + return; } /* Obtain a backtrace and print it to the log */ void -gf_print_trace (int32_t signum, glusterfs_ctx_t *ctx) -{ - char msg[1024] = {0,}; - char timestr[64] = {0,}; - call_stack_t *stack = NULL; - - /* Now every gf_log call will just write to a buffer and when the - * buffer becomes full, its written to the log-file. Suppose the process - * crashes and prints the backtrace in the log-file, then the previous - * log information will still be in the buffer itself. So flush the - * contents of the buffer to the log file before printing the backtrace - * which helps in debugging. - */ - gf_log_flush(); - - gf_log_disable_suppression_before_exit (ctx); - - /* Pending frames, (if any), list them in order */ - gf_msg_plain_nomem (GF_LOG_ALERT, "pending frames:"); +gf_print_trace(int32_t signum, glusterfs_ctx_t *ctx) +{ + char msg[1024] = { + 0, + }; + char timestr[64] = { + 0, + }; + call_stack_t *stack = NULL; + + /* Now every gf_log call will just write to a buffer and when the + * buffer becomes full, its written to the log-file. Suppose the process + * crashes and prints the backtrace in the log-file, then the previous + * log information will still be in the buffer itself. So flush the + * contents of the buffer to the log file before printing the backtrace + * which helps in debugging. + */ + gf_log_flush(); + + gf_log_disable_suppression_before_exit(ctx); + + /* Pending frames, (if any), list them in order */ + gf_msg_plain_nomem(GF_LOG_ALERT, "pending frames:"); + { + /* FIXME: traversing stacks outside pool->lock */ + list_for_each_entry(stack, &ctx->pool->all_frames, all_frames) { - /* FIXME: traversing stacks outside pool->lock */ - list_for_each_entry (stack, &ctx->pool->all_frames, - all_frames) { - if (stack->type == GF_OP_TYPE_FOP) - sprintf (msg,"frame : type(%d) op(%s)", - stack->type, - gf_fop_list[stack->op]); - else - sprintf (msg,"frame : type(%d) op(%d)", - stack->type, - stack->op); - - gf_msg_plain_nomem (GF_LOG_ALERT, msg); - } + if (stack->type == GF_OP_TYPE_FOP) + sprintf(msg, "frame : type(%d) op(%s)", stack->type, + gf_fop_list[stack->op]); + else + sprintf(msg, "frame : type(%d) op(%d)", stack->type, stack->op); + + gf_msg_plain_nomem(GF_LOG_ALERT, msg); } + } - sprintf (msg, "patchset: %s", GLUSTERFS_REPOSITORY_REVISION); - gf_msg_plain_nomem (GF_LOG_ALERT, msg); + sprintf(msg, "patchset: %s", GLUSTERFS_REPOSITORY_REVISION); + gf_msg_plain_nomem(GF_LOG_ALERT, msg); - sprintf (msg, "signal received: %d", signum); - gf_msg_plain_nomem (GF_LOG_ALERT, msg); - { - /* Dump the timestamp of the crash too, so the previous logs - can be related */ - gf_time_fmt (timestr, sizeof timestr, time (NULL), - gf_timefmt_FT); - gf_msg_plain_nomem (GF_LOG_ALERT, "time of crash: "); - gf_msg_plain_nomem (GF_LOG_ALERT, timestr); - } + sprintf(msg, "signal received: %d", signum); + gf_msg_plain_nomem(GF_LOG_ALERT, msg); + { + /* Dump the timestamp of the crash too, so the previous logs + can be related */ + gf_time_fmt(timestr, sizeof timestr, time(NULL), gf_timefmt_FT); + gf_msg_plain_nomem(GF_LOG_ALERT, "time of crash: "); + gf_msg_plain_nomem(GF_LOG_ALERT, timestr); + } - gf_dump_config_flags (); - gf_msg_backtrace_nomem (GF_LOG_ALERT, 200); - sprintf (msg, "---------"); - gf_msg_plain_nomem (GF_LOG_ALERT, msg); + gf_dump_config_flags(); + gf_msg_backtrace_nomem(GF_LOG_ALERT, 200); + sprintf(msg, "---------"); + gf_msg_plain_nomem(GF_LOG_ALERT, msg); - /* Send a signal to terminate the process */ - signal (signum, SIG_DFL); - raise (signum); + /* Send a signal to terminate the process */ + signal(signum, SIG_DFL); + raise(signum); } void -trap (void) +trap(void) { - } char * -gf_trim (char *string) +gf_trim(char *string) { - register char *s, *t; + register char *s, *t; - if (string == NULL) { - return NULL; - } + if (string == NULL) { + return NULL; + } - for (s = string; isspace (*s); s++) - ; + for (s = string; isspace(*s); s++) + ; - if (*s == 0) - return s; + if (*s == 0) + return s; - t = s + strlen (s) - 1; - while (t > s && isspace (*t)) - t--; - *++t = '\0'; + t = s + strlen(s) - 1; + while (t > s && isspace(*t)) + t--; + *++t = '\0'; - return s; + return s; } int -gf_strstr (const char *str, const char *delim, const char *match) +gf_strstr(const char *str, const char *delim, const char *match) { - char *tmp = NULL; - char *save_ptr = NULL; - char *tmp_str = NULL; + char *tmp = NULL; + char *save_ptr = NULL; + char *tmp_str = NULL; - int ret = 0; + int ret = 0; - tmp_str = strdup (str); + tmp_str = strdup(str); - if (str == NULL || delim == NULL || match == NULL || tmp_str == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - ret = -1; - goto out; - } + if (str == NULL || delim == NULL || match == NULL || tmp_str == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + ret = -1; + goto out; + } + tmp = strtok_r(tmp_str, delim, &save_ptr); - tmp = strtok_r (tmp_str, delim, &save_ptr); + while (tmp) { + ret = strcmp(tmp, match); - while (tmp) { - ret = strcmp (tmp, match); + if (ret == 0) + break; - if (ret == 0) - break; - - tmp = strtok_r (NULL, delim, &save_ptr); - } + tmp = strtok_r(NULL, delim, &save_ptr); + } out: - free (tmp_str); - - return ret; + free(tmp_str); + return ret; } int -gf_volume_name_validate (const char *volume_name) +gf_volume_name_validate(const char *volume_name) { - const char *vname = NULL; + const char *vname = NULL; - if (volume_name == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - return -1; - } + if (volume_name == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + return -1; + } - if (!isalpha (volume_name[0])) - return 1; + if (!isalpha(volume_name[0])) + return 1; - for (vname = &volume_name[1]; *vname != '\0'; vname++) { - if (!(isalnum (*vname) || *vname == '_')) - return 1; - } + for (vname = &volume_name[1]; *vname != '\0'; vname++) { + if (!(isalnum(*vname) || *vname == '_')) + return 1; + } - return 0; + return 0; } - int -gf_string2time (const char *str, uint32_t *n) -{ - unsigned long value = 0; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } - - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } - - old_errno = errno; - errno = 0; - value = strtol (str, &tail, 0); - if (str == tail) - errno = EINVAL; - - if (errno == ERANGE || errno == EINVAL) - return -1; - - if (errno == 0) - errno = old_errno; - - if (((tail[0] == '\0') || - ((tail[0] == 's') && (tail[1] == '\0')) || - ((tail[0] == 's') && (tail[1] == 'e') && - (tail[2] == 'c') && (tail[3] == '\0')))) - goto out; - - else if (((tail[0] == 'm') && (tail[1] == '\0')) || - ((tail[0] == 'm') && (tail[1] == 'i') && - (tail[2] == 'n') && (tail[3] == '\0'))) { - value = value * GF_MINUTE_IN_SECONDS; - goto out; - } - - else if (((tail[0] == 'h') && (tail[1] == '\0')) || - ((tail[0] == 'h') && (tail[1] == 'r') && - (tail[2] == '\0'))) { - value = value * GF_HOUR_IN_SECONDS; - goto out; - } +gf_string2time(const char *str, uint32_t *n) +{ + unsigned long value = 0; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; - else if (((tail[0] == 'd') && (tail[1] == '\0')) || - ((tail[0] == 'd') && (tail[1] == 'a') && - (tail[2] == 'y') && (tail[3] == 's') && - (tail[4] == '\0'))) { - value = value * GF_DAY_IN_SECONDS; - goto out; - } + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } + + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } + + old_errno = errno; + errno = 0; + value = strtol(str, &tail, 0); + if (str == tail) + errno = EINVAL; + + if (errno == ERANGE || errno == EINVAL) + return -1; - else if (((tail[0] == 'w') && (tail[1] == '\0')) || - ((tail[0] == 'w') && (tail[1] == 'k') && - (tail[2] == '\0'))) { - value = value * GF_WEEK_IN_SECONDS; - goto out; - } else { - return -1; - } + if (errno == 0) + errno = old_errno; + + if (((tail[0] == '\0') || ((tail[0] == 's') && (tail[1] == '\0')) || + ((tail[0] == 's') && (tail[1] == 'e') && (tail[2] == 'c') && + (tail[3] == '\0')))) + goto out; + + else if (((tail[0] == 'm') && (tail[1] == '\0')) || + ((tail[0] == 'm') && (tail[1] == 'i') && (tail[2] == 'n') && + (tail[3] == '\0'))) { + value = value * GF_MINUTE_IN_SECONDS; + goto out; + } + + else if (((tail[0] == 'h') && (tail[1] == '\0')) || + ((tail[0] == 'h') && (tail[1] == 'r') && (tail[2] == '\0'))) { + value = value * GF_HOUR_IN_SECONDS; + goto out; + } + + else if (((tail[0] == 'd') && (tail[1] == '\0')) || + ((tail[0] == 'd') && (tail[1] == 'a') && (tail[2] == 'y') && + (tail[3] == 's') && (tail[4] == '\0'))) { + value = value * GF_DAY_IN_SECONDS; + goto out; + } + + else if (((tail[0] == 'w') && (tail[1] == '\0')) || + ((tail[0] == 'w') && (tail[1] == 'k') && (tail[2] == '\0'))) { + value = value * GF_WEEK_IN_SECONDS; + goto out; + } else { + return -1; + } out: - *n = value; + *n = value; - return 0; + return 0; } int -gf_string2percent (const char *str, double *n) -{ - double value = 0; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } - - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } - - old_errno = errno; - errno = 0; - value = strtod (str, &tail); - if (str == tail) - errno = EINVAL; +gf_string2percent(const char *str, double *n) +{ + double value = 0; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } + + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } + + old_errno = errno; + errno = 0; + value = strtod(str, &tail); + if (str == tail) + errno = EINVAL; + + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (!((tail[0] == '\0') || - ((tail[0] == '%') && (tail[1] == '\0')))) - return -1; + if (!((tail[0] == '\0') || ((tail[0] == '%') && (tail[1] == '\0')))) + return -1; - *n = value; + *n = value; - return 0; + return 0; } - static int -_gf_string2long (const char *str, long *n, int base) +_gf_string2long(const char *str, long *n, int base) { - long value = 0; - char *tail = NULL; - int old_errno = 0; + long value = 0; + char *tail = NULL; + int old_errno = 0; - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } - old_errno = errno; - errno = 0; - value = strtol (str, &tail, base); - if (str == tail) - errno = EINVAL; + old_errno = errno; + errno = 0; + value = strtol(str, &tail, base); + if (str == tail) + errno = EINVAL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - return -1; + if (tail[0] != '\0') + return -1; - *n = value; + *n = value; - return 0; + return 0; } static int -_gf_string2ulong (const char *str, unsigned long *n, int base) -{ - unsigned long value = 0; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } - - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } - - old_errno = errno; - errno = 0; - value = strtoul (str, &tail, base); - if (str == tail) - errno = EINVAL; +_gf_string2ulong(const char *str, unsigned long *n, int base) +{ + unsigned long value = 0; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } + + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } + + old_errno = errno; + errno = 0; + value = strtoul(str, &tail, base); + if (str == tail) + errno = EINVAL; + + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - return -1; + if (tail[0] != '\0') + return -1; - *n = value; + *n = value; - return 0; + return 0; } static int -_gf_string2uint (const char *str, unsigned int *n, int base) -{ - unsigned long value = 0; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } - - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } - - old_errno = errno; - errno = 0; - value = strtoul (str, &tail, base); - if (str == tail) - errno = EINVAL; +_gf_string2uint(const char *str, unsigned int *n, int base) +{ + unsigned long value = 0; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } + + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } + + old_errno = errno; + errno = 0; + value = strtoul(str, &tail, base); + if (str == tail) + errno = EINVAL; + + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - return -1; + if (tail[0] != '\0') + return -1; - *n = (unsigned int)value; + *n = (unsigned int)value; - return 0; + return 0; } static int -_gf_string2double (const char *str, double *n) +_gf_string2double(const char *str, double *n) { - double value = 0.0; - char *tail = NULL; - int old_errno = 0; + double value = 0.0; + char *tail = NULL; + int old_errno = 0; - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } - old_errno = errno; - errno = 0; - value = strtod (str, &tail); - if (str == tail) - errno = EINVAL; + old_errno = errno; + errno = 0; + value = strtod(str, &tail); + if (str == tail) + errno = EINVAL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - return -1; + if (tail[0] != '\0') + return -1; - *n = value; + *n = value; - return 0; + return 0; } static int -_gf_string2longlong (const char *str, long long *n, int base) +_gf_string2longlong(const char *str, long long *n, int base) { - long long value = 0; - char *tail = NULL; - int old_errno = 0; + long long value = 0; + char *tail = NULL; + int old_errno = 0; - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } - old_errno = errno; - errno = 0; - value = strtoll (str, &tail, base); - if (str == tail) - errno = EINVAL; + old_errno = errno; + errno = 0; + value = strtoll(str, &tail, base); + if (str == tail) + errno = EINVAL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - return -1; + if (tail[0] != '\0') + return -1; - *n = value; + *n = value; - return 0; + return 0; } static int -_gf_string2ulonglong (const char *str, unsigned long long *n, int base) -{ - unsigned long long value = 0; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } - - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } - - old_errno = errno; - errno = 0; - value = strtoull (str, &tail, base); - if (str == tail) - errno = EINVAL; +_gf_string2ulonglong(const char *str, unsigned long long *n, int base) +{ + unsigned long long value = 0; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } + + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } + + old_errno = errno; + errno = 0; + value = strtoull(str, &tail, base); + if (str == tail) + errno = EINVAL; + + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - return -1; + if (tail[0] != '\0') + return -1; - *n = value; + *n = value; - return 0; + return 0; } int -gf_string2long (const char *str, long *n) +gf_string2long(const char *str, long *n) { - return _gf_string2long (str, n, 0); + return _gf_string2long(str, n, 0); } int -gf_string2ulong (const char *str, unsigned long *n) +gf_string2ulong(const char *str, unsigned long *n) { - return _gf_string2ulong (str, n, 0); + return _gf_string2ulong(str, n, 0); } int -gf_string2int (const char *str, int *n) +gf_string2int(const char *str, int *n) { - long l = 0; - int ret = 0; + long l = 0; + int ret = 0; - ret = _gf_string2long (str, &l, 0); + ret = _gf_string2long(str, &l, 0); - *n = l; - return ret; + *n = l; + return ret; } int -gf_string2uint (const char *str, unsigned int *n) +gf_string2uint(const char *str, unsigned int *n) { - return _gf_string2uint (str, n, 0); + return _gf_string2uint(str, n, 0); } int -gf_string2double (const char *str, double *n) +gf_string2double(const char *str, double *n) { - return _gf_string2double (str, n); + return _gf_string2double(str, n); } int -gf_string2longlong (const char *str, long long *n) +gf_string2longlong(const char *str, long long *n) { - return _gf_string2longlong (str, n, 0); + return _gf_string2longlong(str, n, 0); } int -gf_string2ulonglong (const char *str, unsigned long long *n) +gf_string2ulonglong(const char *str, unsigned long long *n) { - return _gf_string2ulonglong (str, n, 0); + return _gf_string2ulonglong(str, n, 0); } int -gf_string2int8 (const char *str, int8_t *n) +gf_string2int8(const char *str, int8_t *n) { - long l = 0L; - int rv = 0; + long l = 0L; + int rv = 0; - rv = _gf_string2long (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2long(str, &l, 0); + if (rv != 0) + return rv; - if ((l >= INT8_MIN) && (l <= INT8_MAX)) { - *n = (int8_t) l; - return 0; - } + if ((l >= INT8_MIN) && (l <= INT8_MAX)) { + *n = (int8_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2int16 (const char *str, int16_t *n) +gf_string2int16(const char *str, int16_t *n) { - long l = 0L; - int rv = 0; + long l = 0L; + int rv = 0; - rv = _gf_string2long (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2long(str, &l, 0); + if (rv != 0) + return rv; - if ((l >= INT16_MIN) && (l <= INT16_MAX)) { - *n = (int16_t) l; - return 0; - } + if ((l >= INT16_MIN) && (l <= INT16_MAX)) { + *n = (int16_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2int32 (const char *str, int32_t *n) +gf_string2int32(const char *str, int32_t *n) { - long l = 0L; - int rv = 0; + long l = 0L; + int rv = 0; - rv = _gf_string2long (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2long(str, &l, 0); + if (rv != 0) + return rv; - if ((l >= INT32_MIN) && (l <= INT32_MAX)) { - *n = (int32_t) l; - return 0; - } + if ((l >= INT32_MIN) && (l <= INT32_MAX)) { + *n = (int32_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2int64 (const char *str, int64_t *n) +gf_string2int64(const char *str, int64_t *n) { - long long l = 0LL; - int rv = 0; + long long l = 0LL; + int rv = 0; - rv = _gf_string2longlong (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2longlong(str, &l, 0); + if (rv != 0) + return rv; - *n = (int64_t) l; - return 0; + *n = (int64_t)l; + return 0; } int -gf_string2uint8 (const char *str, uint8_t *n) +gf_string2uint8(const char *str, uint8_t *n) { - unsigned long l = 0L; - int rv = 0; + unsigned long l = 0L; + int rv = 0; - rv = _gf_string2ulong (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2ulong(str, &l, 0); + if (rv != 0) + return rv; - if (l <= UINT8_MAX) { - *n = (uint8_t) l; - return 0; - } + if (l <= UINT8_MAX) { + *n = (uint8_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2uint16 (const char *str, uint16_t *n) +gf_string2uint16(const char *str, uint16_t *n) { - unsigned long l = 0L; - int rv = 0; + unsigned long l = 0L; + int rv = 0; - rv = _gf_string2ulong (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2ulong(str, &l, 0); + if (rv != 0) + return rv; - if (l <= UINT16_MAX) { - *n = (uint16_t) l; - return 0; - } + if (l <= UINT16_MAX) { + *n = (uint16_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2uint32 (const char *str, uint32_t *n) +gf_string2uint32(const char *str, uint32_t *n) { - unsigned long l = 0L; - int rv = 0; + unsigned long l = 0L; + int rv = 0; - rv = _gf_string2ulong (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2ulong(str, &l, 0); + if (rv != 0) + return rv; - if (l <= UINT32_MAX) { - *n = (uint32_t) l; - return 0; - } + if (l <= UINT32_MAX) { + *n = (uint32_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2uint64 (const char *str, uint64_t *n) +gf_string2uint64(const char *str, uint64_t *n) { - unsigned long long l = 0ULL; - int rv = 0; + unsigned long long l = 0ULL; + int rv = 0; - rv = _gf_string2ulonglong (str, &l, 0); - if (rv != 0) - return rv; + rv = _gf_string2ulonglong(str, &l, 0); + if (rv != 0) + return rv; - if (l <= UINT64_MAX) { - *n = (uint64_t) l; - return 0; - } + if (l <= UINT64_MAX) { + *n = (uint64_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2ulong_base10 (const char *str, unsigned long *n) +gf_string2ulong_base10(const char *str, unsigned long *n) { - return _gf_string2ulong (str, n, 10); + return _gf_string2ulong(str, n, 10); } int -gf_string2uint_base10 (const char *str, unsigned int *n) +gf_string2uint_base10(const char *str, unsigned int *n) { - return _gf_string2uint (str, n, 10); + return _gf_string2uint(str, n, 10); } int -gf_string2uint8_base10 (const char *str, uint8_t *n) +gf_string2uint8_base10(const char *str, uint8_t *n) { - unsigned long l = 0L; - int rv = 0; + unsigned long l = 0L; + int rv = 0; - rv = _gf_string2ulong (str, &l, 10); - if (rv != 0) - return rv; + rv = _gf_string2ulong(str, &l, 10); + if (rv != 0) + return rv; - if (l <= UINT8_MAX) { - *n = (uint8_t) l; - return 0; - } + if (l <= UINT8_MAX) { + *n = (uint8_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2uint16_base10 (const char *str, uint16_t *n) +gf_string2uint16_base10(const char *str, uint16_t *n) { - unsigned long l = 0L; - int rv = 0; + unsigned long l = 0L; + int rv = 0; - rv = _gf_string2ulong (str, &l, 10); - if (rv != 0) - return rv; + rv = _gf_string2ulong(str, &l, 10); + if (rv != 0) + return rv; - if (l <= UINT16_MAX) { - *n = (uint16_t) l; - return 0; - } + if (l <= UINT16_MAX) { + *n = (uint16_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2uint32_base10 (const char *str, uint32_t *n) +gf_string2uint32_base10(const char *str, uint32_t *n) { - unsigned long l = 0L; - int rv = 0; + unsigned long l = 0L; + int rv = 0; - rv = _gf_string2ulong (str, &l, 10); - if (rv != 0) - return rv; + rv = _gf_string2ulong(str, &l, 10); + if (rv != 0) + return rv; - if (l <= UINT32_MAX) { - *n = (uint32_t) l; - return 0; - } + if (l <= UINT32_MAX) { + *n = (uint32_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } int -gf_string2uint64_base10 (const char *str, uint64_t *n) +gf_string2uint64_base10(const char *str, uint64_t *n) { - unsigned long long l = 0ULL; - int rv = 0; + unsigned long long l = 0ULL; + int rv = 0; - rv = _gf_string2ulonglong (str, &l, 10); - if (rv != 0) - return rv; + rv = _gf_string2ulonglong(str, &l, 10); + if (rv != 0) + return rv; - if (l <= UINT64_MAX) { - *n = (uint64_t) l; - return 0; - } + if (l <= UINT64_MAX) { + *n = (uint64_t)l; + return 0; + } - errno = ERANGE; - return -1; + errno = ERANGE; + return -1; } char * -gf_uint64_2human_readable (uint64_t n) -{ - int ret = 0; - char *str = NULL; - - if (n >= GF_UNIT_PB) { - ret = gf_asprintf (&str, "%.1lfPB", ((double) n)/GF_UNIT_PB); - if (ret < 0) - goto err; - } else if (n >= GF_UNIT_TB) { - ret = gf_asprintf (&str, "%.1lfTB", ((double) n)/GF_UNIT_TB); - if (ret < 0) - goto err; - } else if (n >= GF_UNIT_GB) { - ret = gf_asprintf (&str, "%.1lfGB", ((double) n)/GF_UNIT_GB); - if (ret < 0) - goto err; - } else if (n >= GF_UNIT_MB) { - ret = gf_asprintf (&str, "%.1lfMB", ((double) n)/GF_UNIT_MB); - if (ret < 0) - goto err; - } else if (n >= GF_UNIT_KB) { - ret = gf_asprintf (&str, "%.1lfKB", ((double) n)/GF_UNIT_KB); - if (ret < 0) - goto err; - } else { - ret = gf_asprintf (&str, "%luBytes", n); - if (ret < 0) - goto err; - } - return str; +gf_uint64_2human_readable(uint64_t n) +{ + int ret = 0; + char *str = NULL; + + if (n >= GF_UNIT_PB) { + ret = gf_asprintf(&str, "%.1lfPB", ((double)n) / GF_UNIT_PB); + if (ret < 0) + goto err; + } else if (n >= GF_UNIT_TB) { + ret = gf_asprintf(&str, "%.1lfTB", ((double)n) / GF_UNIT_TB); + if (ret < 0) + goto err; + } else if (n >= GF_UNIT_GB) { + ret = gf_asprintf(&str, "%.1lfGB", ((double)n) / GF_UNIT_GB); + if (ret < 0) + goto err; + } else if (n >= GF_UNIT_MB) { + ret = gf_asprintf(&str, "%.1lfMB", ((double)n) / GF_UNIT_MB); + if (ret < 0) + goto err; + } else if (n >= GF_UNIT_KB) { + ret = gf_asprintf(&str, "%.1lfKB", ((double)n) / GF_UNIT_KB); + if (ret < 0) + goto err; + } else { + ret = gf_asprintf(&str, "%luBytes", n); + if (ret < 0) + goto err; + } + return str; err: - return NULL; + return NULL; } int -gf_string2bytesize_range (const char *str, uint64_t *n, uint64_t umax) -{ - double value = 0.0; - int64_t int_value = 0; - uint64_t unit = 0; - int64_t max = 0; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - gf_boolean_t fraction = _gf_false; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } +gf_string2bytesize_range(const char *str, uint64_t *n, uint64_t umax) +{ + double value = 0.0; + int64_t int_value = 0; + uint64_t unit = 0; + int64_t max = 0; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; + gf_boolean_t fraction = _gf_false; + + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } - max = umax & 0x7fffffffffffffffLL; + max = umax & 0x7fffffffffffffffLL; - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } - if (strrchr (str, '.')) - fraction = _gf_true; + if (strrchr(str, '.')) + fraction = _gf_true; - old_errno = errno; - errno = 0; - if (fraction) - value = strtod (str, &tail); - else - int_value = strtoll (str, &tail, 10); + old_errno = errno; + errno = 0; + if (fraction) + value = strtod(str, &tail); + else + int_value = strtoll(str, &tail, 10); - if (str == tail) - errno = EINVAL; + if (str == tail) + errno = EINVAL; - if (errno == ERANGE || errno == EINVAL) - return -1; + if (errno == ERANGE || errno == EINVAL) + return -1; - if (errno == 0) - errno = old_errno; + if (errno == 0) + errno = old_errno; - if (tail[0] != '\0') - { - if (strcasecmp (tail, GF_UNIT_KB_STRING) == 0) - unit = GF_UNIT_KB; - else if (strcasecmp (tail, GF_UNIT_MB_STRING) == 0) - unit = GF_UNIT_MB; - else if (strcasecmp (tail, GF_UNIT_GB_STRING) == 0) - unit = GF_UNIT_GB; - else if (strcasecmp (tail, GF_UNIT_TB_STRING) == 0) - unit = GF_UNIT_TB; - else if (strcasecmp (tail, GF_UNIT_PB_STRING) == 0) - unit = GF_UNIT_PB; - else if (strcasecmp (tail, GF_UNIT_B_STRING) != 0) - return -1; - - if (unit > 0) { - if (fraction) - value *= unit; - else - int_value *= unit; - } + if (tail[0] != '\0') { + if (strcasecmp(tail, GF_UNIT_KB_STRING) == 0) + unit = GF_UNIT_KB; + else if (strcasecmp(tail, GF_UNIT_MB_STRING) == 0) + unit = GF_UNIT_MB; + else if (strcasecmp(tail, GF_UNIT_GB_STRING) == 0) + unit = GF_UNIT_GB; + else if (strcasecmp(tail, GF_UNIT_TB_STRING) == 0) + unit = GF_UNIT_TB; + else if (strcasecmp(tail, GF_UNIT_PB_STRING) == 0) + unit = GF_UNIT_PB; + else if (strcasecmp(tail, GF_UNIT_B_STRING) != 0) + return -1; + + if (unit > 0) { + if (fraction) + value *= unit; + else + int_value *= unit; } + } - if (fraction) { - if ((max - value) < 0) { - errno = ERANGE; - return -1; - } - *n = (uint64_t) value; - } else { - if ((max - int_value) < 0) { - errno = ERANGE; - return -1; - } - *n = int_value; + if (fraction) { + if ((max - value) < 0) { + errno = ERANGE; + return -1; + } + *n = (uint64_t)value; + } else { + if ((max - int_value) < 0) { + errno = ERANGE; + return -1; } + *n = int_value; + } - return 0; + return 0; } int -gf_string2bytesize_size (const char *str, size_t *n) +gf_string2bytesize_size(const char *str, size_t *n) { - uint64_t u64; - size_t max = (size_t) - 1; - int val = gf_string2bytesize_range (str, &u64, max); - *n = (size_t) u64; - return val; + uint64_t u64; + size_t max = (size_t)-1; + int val = gf_string2bytesize_range(str, &u64, max); + *n = (size_t)u64; + return val; } int -gf_string2bytesize (const char *str, uint64_t *n) +gf_string2bytesize(const char *str, uint64_t *n) { - return gf_string2bytesize_range(str, n, UINT64_MAX); + return gf_string2bytesize_range(str, n, UINT64_MAX); } int -gf_string2bytesize_uint64 (const char *str, uint64_t *n) +gf_string2bytesize_uint64(const char *str, uint64_t *n) { - return gf_string2bytesize_range(str, n, UINT64_MAX); + return gf_string2bytesize_range(str, n, UINT64_MAX); } int -gf_string2bytesize_int64 (const char *str, int64_t *n) +gf_string2bytesize_int64(const char *str, int64_t *n) { - uint64_t u64 = 0; - int ret = 0; + uint64_t u64 = 0; + int ret = 0; - ret = gf_string2bytesize_range(str, &u64, INT64_MAX); - *n = (int64_t) u64; - return ret; + ret = gf_string2bytesize_range(str, &u64, INT64_MAX); + *n = (int64_t)u64; + return ret; } int -gf_string2percent_or_bytesize (const char *str, double *n, - gf_boolean_t *is_percent) -{ - double value = 0ULL; - char *tail = NULL; - int old_errno = 0; - const char *s = NULL; - - if (str == NULL || n == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - errno = EINVAL; - return -1; - } - - for (s = str; *s != '\0'; s++) { - if (isspace (*s)) - continue; - if (*s == '-') - return -1; - break; - } +gf_string2percent_or_bytesize(const char *str, double *n, + gf_boolean_t *is_percent) +{ + double value = 0ULL; + char *tail = NULL; + int old_errno = 0; + const char *s = NULL; + + if (str == NULL || n == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + errno = EINVAL; + return -1; + } + + for (s = str; *s != '\0'; s++) { + if (isspace(*s)) + continue; + if (*s == '-') + return -1; + break; + } + + old_errno = errno; + errno = 0; + value = strtod(str, &tail); + if (str == tail) + errno = EINVAL; + + if (errno == ERANGE || errno == EINVAL) + return -1; - old_errno = errno; - errno = 0; - value = strtod (str, &tail); - if (str == tail) - errno = EINVAL; - - if (errno == ERANGE || errno == EINVAL) - return -1; - - if (errno == 0) - errno = old_errno; - - /*Maximum accepted value for 64 bit OS will be (2^14 -1)PB*/ - if (tail[0] != '\0') { - if (strcasecmp (tail, GF_UNIT_KB_STRING) == 0) - value *= GF_UNIT_KB; - else if (strcasecmp (tail, GF_UNIT_MB_STRING) == 0) - value *= GF_UNIT_MB; - else if (strcasecmp (tail, GF_UNIT_GB_STRING) == 0) - value *= GF_UNIT_GB; - else if (strcasecmp (tail, GF_UNIT_TB_STRING) == 0) - value *= GF_UNIT_TB; - else if (strcasecmp (tail, GF_UNIT_PB_STRING) == 0) - value *= GF_UNIT_PB; - else if (strcasecmp (tail, GF_UNIT_PERCENT_STRING) == 0) - *is_percent = _gf_true; - else - return -1; - } + if (errno == 0) + errno = old_errno; + + /*Maximum accepted value for 64 bit OS will be (2^14 -1)PB*/ + if (tail[0] != '\0') { + if (strcasecmp(tail, GF_UNIT_KB_STRING) == 0) + value *= GF_UNIT_KB; + else if (strcasecmp(tail, GF_UNIT_MB_STRING) == 0) + value *= GF_UNIT_MB; + else if (strcasecmp(tail, GF_UNIT_GB_STRING) == 0) + value *= GF_UNIT_GB; + else if (strcasecmp(tail, GF_UNIT_TB_STRING) == 0) + value *= GF_UNIT_TB; + else if (strcasecmp(tail, GF_UNIT_PB_STRING) == 0) + value *= GF_UNIT_PB; + else if (strcasecmp(tail, GF_UNIT_PERCENT_STRING) == 0) + *is_percent = _gf_true; + else + return -1; + } - /* Error out if we cannot store the value in uint64 */ - if ((UINT64_MAX - value) < 0) { - errno = ERANGE; - return -1; - } + /* Error out if we cannot store the value in uint64 */ + if ((UINT64_MAX - value) < 0) { + errno = ERANGE; + return -1; + } - *n = value; + *n = value; - return 0; + return 0; } int64_t -gf_str_to_long_long (const char *number) -{ - int64_t unit = 1; - int64_t ret = 0; - char *endptr = NULL ; - if (!number) - return 0; - - ret = strtoll (number, &endptr, 0); - - if (endptr) { - switch (*endptr) { - case 'G': - case 'g': - if ((* (endptr + 1) == 'B') ||(* (endptr + 1) == 'b')) - unit = 1024 * 1024 * 1024; - break; - case 'M': - case 'm': - if ((* (endptr + 1) == 'B') ||(* (endptr + 1) == 'b')) - unit = 1024 * 1024; - break; - case 'K': - case 'k': - if ((* (endptr + 1) == 'B') ||(* (endptr + 1) == 'b')) - unit = 1024; - break; - case '%': - unit = 1; - break; - default: - unit = 1; - break; - } +gf_str_to_long_long(const char *number) +{ + int64_t unit = 1; + int64_t ret = 0; + char *endptr = NULL; + if (!number) + return 0; + + ret = strtoll(number, &endptr, 0); + + if (endptr) { + switch (*endptr) { + case 'G': + case 'g': + if ((*(endptr + 1) == 'B') || (*(endptr + 1) == 'b')) + unit = 1024 * 1024 * 1024; + break; + case 'M': + case 'm': + if ((*(endptr + 1) == 'B') || (*(endptr + 1) == 'b')) + unit = 1024 * 1024; + break; + case 'K': + case 'k': + if ((*(endptr + 1) == 'B') || (*(endptr + 1) == 'b')) + unit = 1024; + break; + case '%': + unit = 1; + break; + default: + unit = 1; + break; } - return ret * unit; + } + return ret * unit; } int -gf_string2boolean (const char *str, gf_boolean_t *b) +gf_string2boolean(const char *str, gf_boolean_t *b) { - if (str == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - return -1; - } + if (str == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + return -1; + } - if ((strcasecmp (str, "1") == 0) || - (strcasecmp (str, "on") == 0) || - (strcasecmp (str, "yes") == 0) || - (strcasecmp (str, "true") == 0) || - (strcasecmp (str, "enable") == 0)) { - *b = _gf_true; - return 0; - } + if ((strcasecmp(str, "1") == 0) || (strcasecmp(str, "on") == 0) || + (strcasecmp(str, "yes") == 0) || (strcasecmp(str, "true") == 0) || + (strcasecmp(str, "enable") == 0)) { + *b = _gf_true; + return 0; + } - if ((strcasecmp (str, "0") == 0) || - (strcasecmp (str, "off") == 0) || - (strcasecmp (str, "no") == 0) || - (strcasecmp (str, "false") == 0) || - (strcasecmp (str, "disable") == 0)) { - *b = _gf_false; - return 0; - } + if ((strcasecmp(str, "0") == 0) || (strcasecmp(str, "off") == 0) || + (strcasecmp(str, "no") == 0) || (strcasecmp(str, "false") == 0) || + (strcasecmp(str, "disable") == 0)) { + *b = _gf_false; + return 0; + } - return -1; + return -1; } - int -gf_lockfd (int fd) +gf_lockfd(int fd) { - struct gf_flock fl; + struct gf_flock fl; - fl.l_type = F_WRLCK; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; - return fcntl (fd, F_SETLK, &fl); + return fcntl(fd, F_SETLK, &fl); } - int -gf_unlockfd (int fd) +gf_unlockfd(int fd) { - struct gf_flock fl; + struct gf_flock fl; - fl.l_type = F_UNLCK; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 0; + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; - return fcntl (fd, F_SETLK, &fl); + return fcntl(fd, F_SETLK, &fl); } static void -compute_checksum (char *buf, size_t size, uint32_t *checksum) +compute_checksum(char *buf, size_t size, uint32_t *checksum) { - int ret = -1; - char *checksum_buf = NULL; + int ret = -1; + char *checksum_buf = NULL; - checksum_buf = (char *)(checksum); + checksum_buf = (char *)(checksum); - if (!(*checksum)) { - checksum_buf [0] = 0xba; - checksum_buf [1] = 0xbe; - checksum_buf [2] = 0xb0; - checksum_buf [3] = 0x0b; - } + if (!(*checksum)) { + checksum_buf[0] = 0xba; + checksum_buf[1] = 0xbe; + checksum_buf[2] = 0xb0; + checksum_buf[3] = 0x0b; + } - for (ret = 0; ret < (size - 4); ret += 4) { - checksum_buf[0] ^= (buf[ret]); - checksum_buf[1] ^= (buf[ret + 1] << 1) ; - checksum_buf[2] ^= (buf[ret + 2] << 2); - checksum_buf[3] ^= (buf[ret + 3] << 3); - } + for (ret = 0; ret < (size - 4); ret += 4) { + checksum_buf[0] ^= (buf[ret]); + checksum_buf[1] ^= (buf[ret + 1] << 1); + checksum_buf[2] ^= (buf[ret + 2] << 2); + checksum_buf[3] ^= (buf[ret + 3] << 3); + } - for (ret = 0; ret <= (size % 4); ret++) { - checksum_buf[ret] ^= (buf[(size - 4) + ret] << ret); - } + for (ret = 0; ret <= (size % 4); ret++) { + checksum_buf[ret] ^= (buf[(size - 4) + ret] << ret); + } - return; + return; } #define GF_CHECKSUM_BUF_SIZE 1024 int -get_checksum_for_file (int fd, uint32_t *checksum) +get_checksum_for_file(int fd, uint32_t *checksum) { - int ret = -1; - char buf[GF_CHECKSUM_BUF_SIZE] = {0,}; + int ret = -1; + char buf[GF_CHECKSUM_BUF_SIZE] = { + 0, + }; - /* goto first place */ - sys_lseek (fd, 0L, SEEK_SET); - do { - ret = sys_read (fd, &buf, GF_CHECKSUM_BUF_SIZE); - if (ret > 0) - compute_checksum (buf, GF_CHECKSUM_BUF_SIZE, - checksum); - } while (ret > 0); + /* goto first place */ + sys_lseek(fd, 0L, SEEK_SET); + do { + ret = sys_read(fd, &buf, GF_CHECKSUM_BUF_SIZE); + if (ret > 0) + compute_checksum(buf, GF_CHECKSUM_BUF_SIZE, checksum); + } while (ret > 0); - /* set it back */ - sys_lseek (fd, 0L, SEEK_SET); + /* set it back */ + sys_lseek(fd, 0L, SEEK_SET); - return ret; + return ret; } - int -get_checksum_for_path (char *path, uint32_t *checksum) +get_checksum_for_path(char *path, uint32_t *checksum) { - int ret = -1; - int fd = -1; + int ret = -1; + int fd = -1; - GF_ASSERT (path); - GF_ASSERT (checksum); + GF_ASSERT(path); + GF_ASSERT(checksum); - fd = open (path, O_RDWR); + fd = open(path, O_RDWR); - if (fd == -1) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_PATH_ERROR, - "Unable to open %s", path); - goto out; - } + if (fd == -1) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_PATH_ERROR, + "Unable to open %s", path); + goto out; + } - ret = get_checksum_for_file (fd, checksum); + ret = get_checksum_for_file(fd, checksum); out: - if (fd != -1) - sys_close (fd); + if (fd != -1) + sys_close(fd); - return ret; + return ret; } /** @@ -2071,26 +2077,25 @@ out: * errors : Errors returned by the stat () call */ int -get_file_mtime (const char *path, time_t *stamp) +get_file_mtime(const char *path, time_t *stamp) { - struct stat f_stat = {0}; - int ret = -EINVAL; + struct stat f_stat = {0}; + int ret = -EINVAL; - GF_VALIDATE_OR_GOTO (THIS->name, path, out); - GF_VALIDATE_OR_GOTO (THIS->name, stamp, out); + GF_VALIDATE_OR_GOTO(THIS->name, path, out); + GF_VALIDATE_OR_GOTO(THIS->name, stamp, out); - ret = sys_stat (path, &f_stat); - if (ret < 0) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - LG_MSG_FILE_STAT_FAILED, "failed to stat %s", - path); - goto out; - } + ret = sys_stat(path, &f_stat); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_STAT_FAILED, + "failed to stat %s", path); + goto out; + } - /* Set the mtime */ - *stamp = f_stat.st_mtime; + /* Set the mtime */ + *stamp = f_stat.st_mtime; out: - return ret; + return ret; } /** @@ -2106,117 +2111,117 @@ out: * failure: -EINVAL for bad args, retval of inet_pton otherwise */ gf_boolean_t -gf_is_ip_in_net (const char *network, const char *ip_str) -{ - unsigned long ip_buf = 0; - unsigned long net_ip_buf = 0; - unsigned long subnet_mask = 0; - int ret = -EINVAL; - char *slash = NULL; - char *net_ip = NULL; - char *subnet = NULL; - char *net_str = NULL; - int family = AF_INET; - gf_boolean_t result = _gf_false; - - GF_ASSERT (network); - GF_ASSERT (ip_str); - - if (strchr (network, ':')) - family = AF_INET6; - else if (strchr (network, '.')) - family = AF_INET; - else { - family = -1; - goto out; - } - - net_str = strdupa (network); - slash = strchr (net_str, '/'); - if (!slash) - goto out; - *slash = '\0'; - - subnet = slash + 1; - net_ip = net_str; - - /* Convert IP address to a long */ - ret = inet_pton (family, ip_str, &ip_buf); - if (ret < 0) - gf_msg ("common-utils", GF_LOG_ERROR, errno, - LG_MSG_INET_PTON_FAILED, "inet_pton() failed"); - - /* Convert network IP address to a long */ - ret = inet_pton (family, net_ip, &net_ip_buf); - if (ret < 0) { - gf_msg ("common-utils", GF_LOG_ERROR, errno, - LG_MSG_INET_PTON_FAILED, "inet_pton() failed"); - goto out; - } - - /* Converts /x into a mask */ - subnet_mask = (1 << atoi (subnet)) - 1; - - result = ((ip_buf & subnet_mask) == (net_ip_buf & subnet_mask)); +gf_is_ip_in_net(const char *network, const char *ip_str) +{ + unsigned long ip_buf = 0; + unsigned long net_ip_buf = 0; + unsigned long subnet_mask = 0; + int ret = -EINVAL; + char *slash = NULL; + char *net_ip = NULL; + char *subnet = NULL; + char *net_str = NULL; + int family = AF_INET; + gf_boolean_t result = _gf_false; + + GF_ASSERT(network); + GF_ASSERT(ip_str); + + if (strchr(network, ':')) + family = AF_INET6; + else if (strchr(network, '.')) + family = AF_INET; + else { + family = -1; + goto out; + } + + net_str = strdupa(network); + slash = strchr(net_str, '/'); + if (!slash) + goto out; + *slash = '\0'; + + subnet = slash + 1; + net_ip = net_str; + + /* Convert IP address to a long */ + ret = inet_pton(family, ip_str, &ip_buf); + if (ret < 0) + gf_msg("common-utils", GF_LOG_ERROR, errno, LG_MSG_INET_PTON_FAILED, + "inet_pton() failed"); + + /* Convert network IP address to a long */ + ret = inet_pton(family, net_ip, &net_ip_buf); + if (ret < 0) { + gf_msg("common-utils", GF_LOG_ERROR, errno, LG_MSG_INET_PTON_FAILED, + "inet_pton() failed"); + goto out; + } + + /* Converts /x into a mask */ + subnet_mask = (1 << atoi(subnet)) - 1; + + result = ((ip_buf & subnet_mask) == (net_ip_buf & subnet_mask)); out: - return result; + return result; } char * -strtail (char *str, const char *pattern) +strtail(char *str, const char *pattern) { - int i = 0; + int i = 0; - for (i = 0; str[i] == pattern[i] && str[i]; i++); + for (i = 0; str[i] == pattern[i] && str[i]; i++) + ; - if (pattern[i] == '\0') - return str + i; + if (pattern[i] == '\0') + return str + i; - return NULL; + return NULL; } void -skipwhite (char **s) +skipwhite(char **s) { - while (isspace (**s)) - (*s)++; + while (isspace(**s)) + (*s)++; } void -gf_strTrim (char **s) +gf_strTrim(char **s) { - char *end = NULL; + char *end = NULL; - end = *s + strlen(*s) - 1; - while (end > *s && isspace ((unsigned char)*end)) - end--; + end = *s + strlen(*s) - 1; + while (end > *s && isspace((unsigned char)*end)) + end--; - *(end+1) = '\0'; + *(end + 1) = '\0'; - while (isspace (**s)) - (*s)++; + while (isspace(**s)) + (*s)++; - return; + return; } char * -nwstrtail (char *str, char *pattern) +nwstrtail(char *str, char *pattern) { - for (;;) { - skipwhite (&str); - skipwhite (&pattern); + for (;;) { + skipwhite(&str); + skipwhite(&pattern); - if (*str != *pattern || !*str) - break; + if (*str != *pattern || !*str) + break; - str++; - pattern++; - } + str++; + pattern++; + } - return *pattern ? NULL : str; + return *pattern ? NULL : str; } - /** * token_iter_init -- initialize tokenization * @@ -2231,12 +2236,12 @@ nwstrtail (char *str, char *pattern) * next_token(). */ char * -token_iter_init (char *str, char sep, token_iter_t *tit) +token_iter_init(char *str, char sep, token_iter_t *tit) { - tit->end = str + strlen (str); - tit->sep = sep; + tit->end = str + strlen(str); + tit->sep = sep; - return str; + return str; } /** @@ -2256,30 +2261,32 @@ token_iter_init (char *str, char sep, token_iter_t *tit) * apart from dropped tokens (see drop_token()). */ gf_boolean_t -next_token (char **tokenp, token_iter_t *tit) -{ - char *cursor = NULL; - gf_boolean_t is_last = _gf_false; - - for (cursor = *tokenp; *cursor; cursor++); - if (cursor < tit->end) { - /* - * We detect that in between current token and end a zero - * marker has already been inserted. This means that the - * token has already been returned. We restore the - * separator and move ahead. - */ - *cursor = tit->sep; - *tokenp = cursor + 1; - } +next_token(char **tokenp, token_iter_t *tit) +{ + char *cursor = NULL; + gf_boolean_t is_last = _gf_false; - for (cursor = *tokenp; *cursor && *cursor != tit->sep; cursor++); - /* If the cursor ended up on a zero byte, then it's the last token. */ - is_last = !*cursor; - /* Zero-terminate the token. */ - *cursor = 0; + for (cursor = *tokenp; *cursor; cursor++) + ; + if (cursor < tit->end) { + /* + * We detect that in between current token and end a zero + * marker has already been inserted. This means that the + * token has already been returned. We restore the + * separator and move ahead. + */ + *cursor = tit->sep; + *tokenp = cursor + 1; + } - return is_last; + for (cursor = *tokenp; *cursor && *cursor != tit->sep; cursor++) + ; + /* If the cursor ended up on a zero byte, then it's the last token. */ + is_last = !*cursor; + /* Zero-terminate the token. */ + *cursor = 0; + + return is_last; } /* @@ -2330,142 +2337,143 @@ next_token (char **tokenp, token_iter_t *tit) * } */ void -drop_token (char *token, token_iter_t *tit) -{ - char *cursor = NULL; - - for (cursor = token; *cursor; cursor++); - if (cursor < tit->end) { - /* - * We detect a zero inserted by next_token(). - * Step the cursor and copy what comes after - * to token. - */ - for (cursor++; cursor < tit->end; *token++ = *cursor++); - } +drop_token(char *token, token_iter_t *tit) +{ + char *cursor = NULL; + for (cursor = token; *cursor; cursor++) + ; + if (cursor < tit->end) { /* - * Zero out the remainder of the buffer. - * It would be enough to insert just a single zero, - * but we continue 'till the end to have cleaner - * memory content. + * We detect a zero inserted by next_token(). + * Step the cursor and copy what comes after + * to token. */ - for (cursor = token; cursor < tit->end; *cursor++ = 0); + for (cursor++; cursor < tit->end; *token++ = *cursor++) + ; + } - /* Adjust the end to point to the new terminating zero. */ - tit->end = token; + /* + * Zero out the remainder of the buffer. + * It would be enough to insert just a single zero, + * but we continue 'till the end to have cleaner + * memory content. + */ + for (cursor = token; cursor < tit->end; *cursor++ = 0) + ; + + /* Adjust the end to point to the new terminating zero. */ + tit->end = token; } /* Syntax formed according to RFC 1912 (RFC 1123 & 952 are more restrictive) * <hname> ::= <gen-name>*["."<gen-name>] * <gen-name> ::= <let-or-digit> <[*[<let-or-digit-or-hyphen>]<let-or-digit>] */ char -valid_host_name (char *address, int length) +valid_host_name(char *address, int length) { - int i = 0; - int str_len = 0; - char ret = 1; - char *dup_addr = NULL; - char *temp_str = NULL; - char *save_ptr = NULL; + int i = 0; + int str_len = 0; + char ret = 1; + char *dup_addr = NULL; + char *temp_str = NULL; + char *save_ptr = NULL; - if ((length > _POSIX_HOST_NAME_MAX) || (length < 1)) { - ret = 0; - goto out; - } + if ((length > _POSIX_HOST_NAME_MAX) || (length < 1)) { + ret = 0; + goto out; + } - dup_addr = gf_strdup (address); - if (!dup_addr) { - ret = 0; - goto out; - } + dup_addr = gf_strdup(address); + if (!dup_addr) { + ret = 0; + goto out; + } - if (!isalnum (dup_addr[length - 1]) && (dup_addr[length - 1] != '*')) { - ret = 0; - goto out; - } + if (!isalnum(dup_addr[length - 1]) && (dup_addr[length - 1] != '*')) { + ret = 0; + goto out; + } - /* Check for consecutive dots, which is invalid in a hostname and is - * ignored by strtok() - */ - if (strstr (dup_addr, "..")) { + /* Check for consecutive dots, which is invalid in a hostname and is + * ignored by strtok() + */ + if (strstr(dup_addr, "..")) { + ret = 0; + goto out; + } + + /* gen-name */ + temp_str = strtok_r(dup_addr, ".", &save_ptr); + do { + str_len = strlen(temp_str); + + if (!isalnum(temp_str[0]) || !isalnum(temp_str[str_len - 1])) { + ret = 0; + goto out; + } + for (i = 1; i < str_len; i++) { + if (!isalnum(temp_str[i]) && (temp_str[i] != '-')) { ret = 0; goto out; + } } - - /* gen-name */ - temp_str = strtok_r (dup_addr, ".", &save_ptr); - do { - str_len = strlen (temp_str); - - if (!isalnum (temp_str[0]) || - !isalnum (temp_str[str_len-1])) { - ret = 0; - goto out; - } - for (i = 1; i < str_len; i++) { - if (!isalnum (temp_str[i]) && (temp_str[i] != '-')) { - ret = 0; - goto out; - } - } - } while ((temp_str = strtok_r (NULL, ".", &save_ptr))); + } while ((temp_str = strtok_r(NULL, ".", &save_ptr))); out: - GF_FREE (dup_addr); - return ret; + GF_FREE(dup_addr); + return ret; } /* Matches all ipv4 address, if wildcard_acc is true '*' wildcard pattern for* - subnets is considered as valid strings as well */ + subnets is considered as valid strings as well */ char -valid_ipv4_address (char *address, int length, gf_boolean_t wildcard_acc) -{ - int octets = 0; - int value = 0; - char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL; - char ret = 1; - int is_wildcard = 0; +valid_ipv4_address(char *address, int length, gf_boolean_t wildcard_acc) +{ + int octets = 0; + int value = 0; + char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL; + char ret = 1; + int is_wildcard = 0; + + tmp = gf_strdup(address); + + /* + * To prevent cases where last character is '.' and which have + * consecutive dots like ".." as strtok ignore consecutive + * delimiters. + */ + if (length <= 0 || (strstr(address, "..")) || + (!isdigit(tmp[length - 1]) && (tmp[length - 1] != '*'))) { + ret = 0; + goto out; + } - tmp = gf_strdup (address); + prev = tmp; + prev = strtok_r(tmp, ".", &ptr); - /* - * To prevent cases where last character is '.' and which have - * consecutive dots like ".." as strtok ignore consecutive - * delimiters. - */ - if (length <= 0 || - (strstr (address, "..")) || - (!isdigit (tmp[length - 1]) && (tmp[length - 1] != '*'))) { + while (prev != NULL) { + octets++; + if (wildcard_acc && !strcmp(prev, "*")) { + is_wildcard = 1; + } else { + value = strtol(prev, &endptr, 10); + if ((value > 255) || (value < 0) || + (endptr != NULL && *endptr != '\0')) { ret = 0; goto out; + } } + prev = strtok_r(NULL, ".", &ptr); + } - prev = tmp; - prev = strtok_r (tmp, ".", &ptr); - - while (prev != NULL) { - octets++; - if (wildcard_acc && !strcmp (prev, "*")) { - is_wildcard = 1; - } else { - value = strtol (prev, &endptr, 10); - if ((value > 255) || (value < 0) || - (endptr != NULL && *endptr != '\0')) { - ret = 0; - goto out; - } - } - prev = strtok_r (NULL, ".", &ptr); - } - - if ((octets > 4) || (octets < 4 && !is_wildcard)) { - ret = 0; - } + if ((octets > 4) || (octets < 4 && !is_wildcard)) { + ret = 0; + } out: - GF_FREE (tmp); - return ret; + GF_FREE(tmp); + return ret; } /** @@ -2479,152 +2487,153 @@ out: * _gf_false otherwise. */ gf_boolean_t -valid_ipv4_subnetwork (const char *address) +valid_ipv4_subnetwork(const char *address) { - char *slash = NULL; - char *paddr = NULL; - char *endptr = NULL; - long prefixlen = -1; - gf_boolean_t retv = _gf_true; + char *slash = NULL; + char *paddr = NULL; + char *endptr = NULL; + long prefixlen = -1; + gf_boolean_t retv = _gf_true; - if (address == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - return _gf_false; - } - - paddr = gf_strdup (address); - if (paddr == NULL) /* ENOMEM */ - return _gf_false; - - /* - * INVALID: If '/' is not present OR - * Nothing specified after '/' - */ - slash = strchr(paddr, '/'); - if ((slash == NULL) || (slash[1] == '\0')) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_IPV4_FORMAT, "Invalid IPv4 " - "subnetwork format"); - retv = _gf_false; - goto out; - } + if (address == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + return _gf_false; + } - *slash = '\0'; - retv = valid_ipv4_address (paddr, strlen(paddr), _gf_false); - if (retv == _gf_false) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_IPV4_FORMAT, - "Invalid IPv4 subnetwork address"); - goto out; - } - /* - * Reset errno before checking it - */ - errno = 0; - prefixlen = strtol (slash + 1, &endptr, 10); - if ((errno != 0) || (*endptr != '\0') || - (prefixlen < 0) || (prefixlen > IPv4_ADDR_SIZE)) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_IPV4_FORMAT, - "Invalid IPv4 subnetwork mask"); - retv = _gf_false; - goto out; - } + paddr = gf_strdup(address); + if (paddr == NULL) /* ENOMEM */ + return _gf_false; - retv = _gf_true; + /* + * INVALID: If '/' is not present OR + * Nothing specified after '/' + */ + slash = strchr(paddr, '/'); + if ((slash == NULL) || (slash[1] == '\0')) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INVALID_IPV4_FORMAT, + "Invalid IPv4 " + "subnetwork format"); + retv = _gf_false; + goto out; + } + + *slash = '\0'; + retv = valid_ipv4_address(paddr, strlen(paddr), _gf_false); + if (retv == _gf_false) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INVALID_IPV4_FORMAT, + "Invalid IPv4 subnetwork address"); + goto out; + } + /* + * Reset errno before checking it + */ + errno = 0; + prefixlen = strtol(slash + 1, &endptr, 10); + if ((errno != 0) || (*endptr != '\0') || (prefixlen < 0) || + (prefixlen > IPv4_ADDR_SIZE)) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INVALID_IPV4_FORMAT, + "Invalid IPv4 subnetwork mask"); + retv = _gf_false; + goto out; + } + + retv = _gf_true; out: - GF_FREE (paddr); - return retv; + GF_FREE(paddr); + return retv; } char -valid_ipv6_address (char *address, int length, gf_boolean_t wildcard_acc) -{ - int hex_numbers = 0; - int value = 0; - int i = 0; - char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL; - char ret = 1; - int is_wildcard = 0; - int is_compressed = 0; - - tmp = gf_strdup (address); - - /* Check for '%' for link local addresses */ - endptr = strchr(tmp, '%'); - if (endptr) { - *endptr = '\0'; - length = strlen(tmp); - endptr = NULL; - } - - /* Check for compressed form */ - if (length <= 0 || tmp[length - 1] == ':') { +valid_ipv6_address(char *address, int length, gf_boolean_t wildcard_acc) +{ + int hex_numbers = 0; + int value = 0; + int i = 0; + char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL; + char ret = 1; + int is_wildcard = 0; + int is_compressed = 0; + + tmp = gf_strdup(address); + + /* Check for '%' for link local addresses */ + endptr = strchr(tmp, '%'); + if (endptr) { + *endptr = '\0'; + length = strlen(tmp); + endptr = NULL; + } + + /* Check for compressed form */ + if (length <= 0 || tmp[length - 1] == ':') { + ret = 0; + goto out; + } + for (i = 0; i < (length - 1); i++) { + if (tmp[i] == ':' && tmp[i + 1] == ':') { + if (is_compressed == 0) + is_compressed = 1; + else { ret = 0; goto out; + } } - for (i = 0; i < (length - 1) ; i++) { - if (tmp[i] == ':' && tmp[i + 1] == ':') { - if (is_compressed == 0) - is_compressed = 1; - else { - ret = 0; - goto out; - } - } - } + } - prev = strtok_r (tmp, ":", &ptr); - - while (prev != NULL) { - hex_numbers++; - if (wildcard_acc && !strcmp (prev, "*")) { - is_wildcard = 1; - } else { - value = strtol (prev, &endptr, 16); - if ((value > 0xffff) || (value < 0) - || (endptr != NULL && *endptr != '\0')) { - ret = 0; - goto out; - } - } - prev = strtok_r (NULL, ":", &ptr); - } + prev = strtok_r(tmp, ":", &ptr); - if ((hex_numbers > 8) || (hex_numbers < 8 && !is_wildcard - && !is_compressed)) { + while (prev != NULL) { + hex_numbers++; + if (wildcard_acc && !strcmp(prev, "*")) { + is_wildcard = 1; + } else { + value = strtol(prev, &endptr, 16); + if ((value > 0xffff) || (value < 0) || + (endptr != NULL && *endptr != '\0')) { ret = 0; + goto out; + } } + prev = strtok_r(NULL, ":", &ptr); + } + + if ((hex_numbers > 8) || + (hex_numbers < 8 && !is_wildcard && !is_compressed)) { + ret = 0; + } out: - GF_FREE (tmp); - return ret; + GF_FREE(tmp); + return ret; } char -valid_internet_address (char *address, gf_boolean_t wildcard_acc) +valid_internet_address(char *address, gf_boolean_t wildcard_acc) { - char ret = 0; - int length = 0; + char ret = 0; + int length = 0; - if (address == NULL) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - goto out; - } + if (address == NULL) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + goto out; + } - length = strlen (address); - if (length == 0) - goto out; + length = strlen(address); + if (length == 0) + goto out; - if (valid_ipv4_address (address, length, wildcard_acc) - || valid_ipv6_address (address, length, wildcard_acc) - || valid_host_name (address, length)) - ret = 1; + if (valid_ipv4_address(address, length, wildcard_acc) || + valid_ipv6_address(address, length, wildcard_acc) || + valid_host_name(address, length)) + ret = 1; out: - return ret; + return ret; } /** @@ -2634,56 +2643,56 @@ out: * * @return _gf_true if "address" is "*" (anonymous) 'OR' * if "address" is valid FQDN or valid IPv4/6 address 'OR' - * if "address" contains wildcard chars e.g. "'*' or '?' or '['" - * if "address" is valid ipv4 subnet pattern (xx.xx.xx.xx/n) - * _gf_false otherwise + * if "address" contains wildcard chars e.g. "'*' or '?' or + * '['" if "address" is valid ipv4 subnet pattern (xx.xx.xx.xx/n) _gf_false + * otherwise * * * NB: If the user/admin set for wildcard pattern, then it does not have * to be validated. Make it similar to the way exportfs (kNFS) works. */ gf_boolean_t -valid_mount_auth_address (char *address) +valid_mount_auth_address(char *address) { - int length = 0; - char *cp = NULL; + int length = 0; + char *cp = NULL; - /* 1. Check for "NULL and empty string */ - if ((address == NULL) || (address[0] == '\0')){ - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "argument invalid"); - return _gf_false; - } + /* 1. Check for "NULL and empty string */ + if ((address == NULL) || (address[0] == '\0')) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "argument invalid"); + return _gf_false; + } - /* 2. Check for Anonymous */ - if (strcmp(address, "*") == 0) - return _gf_true; + /* 2. Check for Anonymous */ + if (strcmp(address, "*") == 0) + return _gf_true; - for (cp = address; *cp; cp++) { - /* 3. Check for wildcard pattern */ - if (*cp == '*' || *cp == '?' || *cp == '[') { - return _gf_true; - } - - /* - * 4. check for IPv4 subnetwork i.e. xx.xx.xx.xx/n - * TODO: check for IPv6 subnetwork - * NB: Wildcard must not be mixed with subnetwork. - */ - if (*cp == '/') { - return valid_ipv4_subnetwork (address); - } + for (cp = address; *cp; cp++) { + /* 3. Check for wildcard pattern */ + if (*cp == '*' || *cp == '?' || *cp == '[') { + return _gf_true; } - /* 5. Check for v4/v6 IP addr and FQDN/hostname */ - length = strlen (address); - if ((valid_ipv4_address (address, length, _gf_false)) || - (valid_ipv6_address (address, length, _gf_false)) || - (valid_host_name (address, length))) { - return _gf_true; + /* + * 4. check for IPv4 subnetwork i.e. xx.xx.xx.xx/n + * TODO: check for IPv6 subnetwork + * NB: Wildcard must not be mixed with subnetwork. + */ + if (*cp == '/') { + return valid_ipv4_subnetwork(address); } + } - return _gf_false; + /* 5. Check for v4/v6 IP addr and FQDN/hostname */ + length = strlen(address); + if ((valid_ipv4_address(address, length, _gf_false)) || + (valid_ipv6_address(address, length, _gf_false)) || + (valid_host_name(address, length))) { + return _gf_true; + } + + return _gf_false; } /** @@ -2694,40 +2703,39 @@ valid_mount_auth_address (char *address) * @return _gf_true if a and b have same ipv{4,6} addr, _gf_false otherwise */ gf_boolean_t -gf_sock_union_equal_addr (union gf_sock_union *a, - union gf_sock_union *b) +gf_sock_union_equal_addr(union gf_sock_union *a, union gf_sock_union *b) { - if (!a || !b) { - gf_msg ("common-utils", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, - "Invalid arguments to gf_sock_union_equal_addr"); - return _gf_false; - } + if (!a || !b) { + gf_msg("common-utils", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Invalid arguments to gf_sock_union_equal_addr"); + return _gf_false; + } - if (a->storage.ss_family != b->storage.ss_family) - return _gf_false; + if (a->storage.ss_family != b->storage.ss_family) + return _gf_false; - switch (a->storage.ss_family) { + switch (a->storage.ss_family) { case AF_INET: - if (a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr) - return _gf_true; - else - return _gf_false; + if (a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr) + return _gf_true; + else + return _gf_false; case AF_INET6: - if (memcmp ((void *)(&a->sin6.sin6_addr), - (void *)(&b->sin6.sin6_addr), - sizeof (a->sin6.sin6_addr))) - return _gf_false; - else - return _gf_true; + if (memcmp((void *)(&a->sin6.sin6_addr), + (void *)(&b->sin6.sin6_addr), sizeof(a->sin6.sin6_addr))) + return _gf_false; + else + return _gf_true; default: - gf_msg_debug ("common-utils", 0, "Unsupported/invalid address " - "family"); - break; - } + gf_msg_debug("common-utils", 0, + "Unsupported/invalid address " + "family"); + break; + } - return _gf_false; + return _gf_false; } /* @@ -2743,62 +2751,61 @@ gf_sock_union_equal_addr (union gf_sock_union *a, gf_boolean_t mask_match(const uint32_t a, const uint32_t b, const uint32_t m) { - return (((a ^ b) & m) == 0); + return (((a ^ b) & m) == 0); } - /*Thread safe conversion function*/ char * -uuid_utoa (uuid_t uuid) +uuid_utoa(uuid_t uuid) { - char *uuid_buffer = glusterfs_uuid_buf_get (); - gf_uuid_unparse (uuid, uuid_buffer); - return uuid_buffer; + char *uuid_buffer = glusterfs_uuid_buf_get(); + gf_uuid_unparse(uuid, uuid_buffer); + return uuid_buffer; } /*Re-entrant conversion function*/ char * -uuid_utoa_r (uuid_t uuid, char *dst) +uuid_utoa_r(uuid_t uuid, char *dst) { - if(!dst) - return NULL; - gf_uuid_unparse (uuid, dst); - return dst; + if (!dst) + return NULL; + gf_uuid_unparse(uuid, dst); + return dst; } /*Thread safe conversion function*/ char * -lkowner_utoa (gf_lkowner_t *lkowner) +lkowner_utoa(gf_lkowner_t *lkowner) { - char *lkowner_buffer = glusterfs_lkowner_buf_get (); - lkowner_unparse (lkowner, lkowner_buffer, GF_LKOWNER_BUF_SIZE); - return lkowner_buffer; + char *lkowner_buffer = glusterfs_lkowner_buf_get(); + lkowner_unparse(lkowner, lkowner_buffer, GF_LKOWNER_BUF_SIZE); + return lkowner_buffer; } /*Re-entrant conversion function*/ char * -lkowner_utoa_r (gf_lkowner_t *lkowner, char *dst, int len) +lkowner_utoa_r(gf_lkowner_t *lkowner, char *dst, int len) { - if(!dst) - return NULL; - lkowner_unparse (lkowner, dst, len); - return dst; + if (!dst) + return NULL; + lkowner_unparse(lkowner, dst, len); + return dst; } gf_boolean_t -is_valid_lease_id (const char *lease_id) +is_valid_lease_id(const char *lease_id) { - int i = 0; - gf_boolean_t valid = _gf_false; + int i = 0; + gf_boolean_t valid = _gf_false; - for (i = 0; i < LEASE_ID_SIZE; i++) { - if (lease_id[i] != 0) { - valid = _gf_true; - goto out; - } + for (i = 0; i < LEASE_ID_SIZE; i++) { + if (lease_id[i] != 0) { + valid = _gf_true; + goto out; } + } out: - return valid; + return valid; } /* Lease_id can be a either in printable or non printable binary @@ -2815,108 +2822,107 @@ out: * subsequent call to this function will override the same buffer. */ char * -leaseid_utoa (const char *lease_id) -{ - char *buf = NULL; - int i = 0; - int j = 0; - - buf = glusterfs_leaseid_buf_get (); - if (!buf) - goto out; - - for (i = 0; i < LEASE_ID_SIZE; i++) { - if (i && !(i % 2)) { - buf[j] = '-'; - j++; - } - sprintf (&buf[j], "%02hhx", lease_id[i]); - j += 2; - if (j == GF_LEASE_ID_BUF_SIZE) - break; - } - buf[GF_LEASE_ID_BUF_SIZE - 1] = '\0'; +leaseid_utoa(const char *lease_id) +{ + char *buf = NULL; + int i = 0; + int j = 0; + + buf = glusterfs_leaseid_buf_get(); + if (!buf) + goto out; + + for (i = 0; i < LEASE_ID_SIZE; i++) { + if (i && !(i % 2)) { + buf[j] = '-'; + j++; + } + sprintf(&buf[j], "%02hhx", lease_id[i]); + j += 2; + if (j == GF_LEASE_ID_BUF_SIZE) + break; + } + buf[GF_LEASE_ID_BUF_SIZE - 1] = '\0'; out: - return buf; + return buf; } char * -gf_leaseid_get () +gf_leaseid_get() { - return glusterfs_leaseid_buf_get (); + return glusterfs_leaseid_buf_get(); } char * -gf_existing_leaseid () +gf_existing_leaseid() { - return glusterfs_leaseid_exist (); + return glusterfs_leaseid_exist(); } -void* gf_array_elem (void *a, int index, size_t elem_size) +void * +gf_array_elem(void *a, int index, size_t elem_size) { - uint8_t* ptr = a; - return (void*)(ptr + index * elem_size); + uint8_t *ptr = a; + return (void *)(ptr + index * elem_size); } void -gf_elem_swap (void *x, void *y, size_t l) { - uint8_t *a = x, *b = y, c; - while(l--) { - c = *a; - *a++ = *b; - *b++ = c; - } +gf_elem_swap(void *x, void *y, size_t l) +{ + uint8_t *a = x, *b = y, c; + while (l--) { + c = *a; + *a++ = *b; + *b++ = c; + } } void -gf_array_insertionsort (void *A, int l, int r, size_t elem_size, - gf_cmp cmp) -{ - int i = l; - int N = r+1; - void *Temp = NULL; - int j = 0; - - for(i = l; i < N; i++) { - Temp = gf_array_elem (A, i, elem_size); - j = i - 1; - while (j >= 0 && (cmp (Temp, gf_array_elem (A, j, elem_size)) - < 0)) { - gf_elem_swap (Temp, gf_array_elem (A, j, elem_size), - elem_size); - Temp = gf_array_elem (A, j, elem_size); - j = j-1; - } +gf_array_insertionsort(void *A, int l, int r, size_t elem_size, gf_cmp cmp) +{ + int i = l; + int N = r + 1; + void *Temp = NULL; + int j = 0; + + for (i = l; i < N; i++) { + Temp = gf_array_elem(A, i, elem_size); + j = i - 1; + while (j >= 0 && (cmp(Temp, gf_array_elem(A, j, elem_size)) < 0)) { + gf_elem_swap(Temp, gf_array_elem(A, j, elem_size), elem_size); + Temp = gf_array_elem(A, j, elem_size); + j = j - 1; } + } } int -gf_is_str_int (const char *value) +gf_is_str_int(const char *value) { - int flag = 0; - char *str = NULL; - char *fptr = NULL; + int flag = 0; + char *str = NULL; + char *fptr = NULL; - GF_VALIDATE_OR_GOTO (THIS->name, value, out); + GF_VALIDATE_OR_GOTO(THIS->name, value, out); - str = gf_strdup (value); - if (!str) - goto out; + str = gf_strdup(value); + if (!str) + goto out; - fptr = str; + fptr = str; - while (*str) { - if (!isdigit(*str)) { - flag = 1; - goto out; - } - str++; + while (*str) { + if (!isdigit(*str)) { + flag = 1; + goto out; } + str++; + } out: - GF_FREE (fptr); + GF_FREE(fptr); - return flag; + return flag; } /* * rounds up nr to power of two. If nr is already a power of two, just returns @@ -2924,22 +2930,22 @@ out: */ int32_t -gf_roundup_power_of_two (int32_t nr) +gf_roundup_power_of_two(int32_t nr) { - int32_t result = 1; + int32_t result = 1; - if (nr < 0) { - gf_msg ("common-utils", GF_LOG_WARNING, 0, - LG_MSG_NEGATIVE_NUM_PASSED, "negative number passed"); - result = -1; - goto out; - } + if (nr < 0) { + gf_msg("common-utils", GF_LOG_WARNING, 0, LG_MSG_NEGATIVE_NUM_PASSED, + "negative number passed"); + result = -1; + goto out; + } - while (result < nr) - result *= 2; + while (result < nr) + result *= 2; out: - return result; + return result; } /* @@ -2948,392 +2954,384 @@ out: */ int32_t -gf_roundup_next_power_of_two (int32_t nr) +gf_roundup_next_power_of_two(int32_t nr) { - int32_t result = 1; + int32_t result = 1; - if (nr < 0) { - gf_msg ("common-utils", GF_LOG_WARNING, 0, - LG_MSG_NEGATIVE_NUM_PASSED, "negative number passed"); - result = -1; - goto out; - } + if (nr < 0) { + gf_msg("common-utils", GF_LOG_WARNING, 0, LG_MSG_NEGATIVE_NUM_PASSED, + "negative number passed"); + result = -1; + goto out; + } - while (result <= nr) - result *= 2; + while (result <= nr) + result *= 2; out: - return result; + return result; } int -get_vol_type (int type, int dist_count, int brick_count) +get_vol_type(int type, int dist_count, int brick_count) { - if ((type != GF_CLUSTER_TYPE_TIER) && (type > 0) && - (dist_count < brick_count)) - type = type + GF_CLUSTER_TYPE_MAX - 1; + if ((type != GF_CLUSTER_TYPE_TIER) && (type > 0) && + (dist_count < brick_count)) + type = type + GF_CLUSTER_TYPE_MAX - 1; - return type; + return type; } int -validate_brick_name (char *brick) +validate_brick_name(char *brick) { - char *delimiter = NULL; - int ret = 0; - delimiter = strrchr (brick, ':'); - if (!delimiter || delimiter == brick - || *(delimiter+1) != '/') - ret = -1; + char *delimiter = NULL; + int ret = 0; + delimiter = strrchr(brick, ':'); + if (!delimiter || delimiter == brick || *(delimiter + 1) != '/') + ret = -1; - return ret; + return ret; } char * -get_host_name (char *word, char **host) +get_host_name(char *word, char **host) { - char *delimiter = NULL; - delimiter = strrchr (word, ':'); - if (delimiter) - *delimiter = '\0'; - else - return NULL; - *host = word; - return *host; + char *delimiter = NULL; + delimiter = strrchr(word, ':'); + if (delimiter) + *delimiter = '\0'; + else + return NULL; + *host = word; + return *host; } - char * -get_path_name (char *word, char **path) +get_path_name(char *word, char **path) { - char *delimiter = NULL; - delimiter = strchr (word, '/'); - if (!delimiter) - return NULL; - *path = delimiter; - return *path; + char *delimiter = NULL; + delimiter = strchr(word, '/'); + if (!delimiter) + return NULL; + *path = delimiter; + return *path; } void -gf_path_strip_trailing_slashes (char *path) +gf_path_strip_trailing_slashes(char *path) { - int i = 0; - int len = 0; + int i = 0; + int len = 0; - if (!path) - return; + if (!path) + return; - len = strlen (path); - for (i = len - 1; i > 0; i--) { - if (path[i] != '/') - break; - } + len = strlen(path); + for (i = len - 1; i > 0; i--) { + if (path[i] != '/') + break; + } - if (i < (len -1)) - path [i+1] = '\0'; + if (i < (len - 1)) + path[i + 1] = '\0'; - return; + return; } uint64_t -get_mem_size () +get_mem_size() { - uint64_t memsize = -1; + uint64_t memsize = -1; #if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS - uint64_t page_size = 0; - uint64_t num_pages = 0; + uint64_t page_size = 0; + uint64_t num_pages = 0; - page_size = sysconf (_SC_PAGESIZE); - num_pages = sysconf (_SC_PHYS_PAGES); + page_size = sysconf(_SC_PAGESIZE); + num_pages = sysconf(_SC_PHYS_PAGES); - memsize = page_size * num_pages; + memsize = page_size * num_pages; #endif #if defined GF_DARWIN_HOST_OS - size_t len = sizeof(memsize); - int name [] = { CTL_HW, HW_PHYSMEM }; + size_t len = sizeof(memsize); + int name[] = {CTL_HW, HW_PHYSMEM}; - sysctl (name, 2, &memsize, &len, NULL, 0); + sysctl(name, 2, &memsize, &len, NULL, 0); #endif #if defined __NetBSD__ - size_t len = sizeof(memsize); - int name64 [] = { CTL_HW, HW_PHYSMEM64 }; + size_t len = sizeof(memsize); + int name64[] = {CTL_HW, HW_PHYSMEM64}; - sysctl (name64, 2, &memsize, &len, NULL, 0); - if (memsize == -1) - sysctl (name64, 2, &memsize, &len, NULL, 0); + sysctl(name64, 2, &memsize, &len, NULL, 0); + if (memsize == -1) + sysctl(name64, 2, &memsize, &len, NULL, 0); #endif - return memsize; + return memsize; } /* Strips all whitespace characters in a string and returns length of new string * on success */ int -gf_strip_whitespace (char *str, int len) +gf_strip_whitespace(char *str, int len) { - int i = 0; - int new_len = 0; - char *new_str = NULL; + int i = 0; + int new_len = 0; + char *new_str = NULL; - GF_ASSERT (str); + GF_ASSERT(str); - new_str = GF_MALLOC (len + 1, gf_common_mt_char); - if (new_str == NULL) - return -1; + new_str = GF_MALLOC(len + 1, gf_common_mt_char); + if (new_str == NULL) + return -1; - for (i = 0; i < len; i++) { - if (!isspace (str[i])) - new_str[new_len++] = str[i]; - } - new_str[new_len] = '\0'; + for (i = 0; i < len; i++) { + if (!isspace(str[i])) + new_str[new_len++] = str[i]; + } + new_str[new_len] = '\0'; - if (new_len != len) { - snprintf(str, new_len + 1, "%s", new_str); - } + if (new_len != len) { + snprintf(str, new_len + 1, "%s", new_str); + } - GF_FREE (new_str); - return new_len; + GF_FREE(new_str); + return new_len; } int -gf_canonicalize_path (char *path) +gf_canonicalize_path(char *path) { - int ret = -1; - int path_len = 0; - int dir_path_len = 0; - char *tmppath = NULL; - char *dir = NULL; - char *tmpstr = NULL; + int ret = -1; + int path_len = 0; + int dir_path_len = 0; + char *tmppath = NULL; + char *dir = NULL; + char *tmpstr = NULL; - if (!path || *path != '/') - goto out; + if (!path || *path != '/') + goto out; + + if (!strcmp(path, "/")) + return 0; - if (!strcmp (path, "/")) - return 0; + tmppath = gf_strdup(path); + if (!tmppath) + goto out; - tmppath = gf_strdup (path); - if (!tmppath) - goto out; + /* Strip the extra slashes and return */ + bzero(path, strlen(path)); + path[0] = '/'; + dir = strtok_r(tmppath, "/", &tmpstr); - /* Strip the extra slashes and return */ - bzero (path, strlen(path)); - path[0] = '/'; - dir = strtok_r(tmppath, "/", &tmpstr); - - while (dir) { - dir_path_len = strlen(dir); - strncpy ((path + path_len + 1), dir, dir_path_len); - path_len += dir_path_len + 1; - dir = strtok_r (NULL, "/", &tmpstr); - if (dir) { - path[path_len] = '/'; - } + while (dir) { + dir_path_len = strlen(dir); + strncpy((path + path_len + 1), dir, dir_path_len); + path_len += dir_path_len + 1; + dir = strtok_r(NULL, "/", &tmpstr); + if (dir) { + path[path_len] = '/'; } - path[path_len] = '\0'; - ret = 0; + } + path[path_len] = '\0'; + ret = 0; - out: - if (ret) - gf_msg ("common-utils", GF_LOG_ERROR, 0, LG_MSG_PATH_ERROR, - "Path manipulation failed"); +out: + if (ret) + gf_msg("common-utils", GF_LOG_ERROR, 0, LG_MSG_PATH_ERROR, + "Path manipulation failed"); - GF_FREE(tmppath); + GF_FREE(tmppath); - return ret; + return ret; } static const char *__gf_timefmts[] = { - "%F %T", - "%Y/%m/%d-%T", - "%b %d %T", - "%F %H%M%S", - "%Y-%m-%d-%T", - "%s", + "%F %T", "%Y/%m/%d-%T", "%b %d %T", "%F %H%M%S", "%Y-%m-%d-%T", "%s", }; static const char *__gf_zerotimes[] = { - "0000-00-00 00:00:00", - "0000/00/00-00:00:00", - "xxx 00 00:00:00", - "0000-00-00 000000", - "0000-00-00-00:00:00", - "0", + "0000-00-00 00:00:00", "0000/00/00-00:00:00", "xxx 00 00:00:00", + "0000-00-00 000000", "0000-00-00-00:00:00", "0", }; void -_gf_timestuff (const char ***fmts, const char ***zeros) +_gf_timestuff(const char ***fmts, const char ***zeros) { - *fmts = __gf_timefmts; - *zeros = __gf_zerotimes; + *fmts = __gf_timefmts; + *zeros = __gf_zerotimes; } - char * -generate_glusterfs_ctx_id (void) +generate_glusterfs_ctx_id(void) { - uuid_t ctxid; - char *tmp = NULL; + uuid_t ctxid; + char *tmp = NULL; - gf_uuid_generate (ctxid); - tmp = uuid_utoa (ctxid); + gf_uuid_generate(ctxid); + tmp = uuid_utoa(ctxid); - return gf_strdup (tmp); + return gf_strdup(tmp); } char * -gf_get_reserved_ports () +gf_get_reserved_ports() { - char *ports_info = NULL; + char *ports_info = NULL; #if defined GF_LINUX_HOST_OS - int proc_fd = -1; - char *proc_file = "/proc/sys/net/ipv4/ip_local_reserved_ports"; - char buffer[4096] = {0,}; - int32_t ret = -1; - - proc_fd = open (proc_file, O_RDONLY); - if (proc_fd == -1) { - /* What should be done in this case? error out from here - * and thus stop the glusterfs process from starting or - * continue with older method of using any of the available - * port? For now 2nd option is considered. - */ - gf_msg ("glusterfs", GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "could not open the file " - "/proc/sys/net/ipv4/ip_local_reserved_ports for " - "getting reserved ports info"); - goto out; - } - - ret = sys_read (proc_fd, buffer, sizeof (buffer)-1); - if (ret < 0) { - gf_msg ("glusterfs", GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "could not read the file %s for" - " getting reserved ports info", proc_file); - goto out; - } - - buffer[ret] = '\0'; - ports_info = gf_strdup (buffer); + int proc_fd = -1; + char *proc_file = "/proc/sys/net/ipv4/ip_local_reserved_ports"; + char buffer[4096] = { + 0, + }; + int32_t ret = -1; + + proc_fd = open(proc_file, O_RDONLY); + if (proc_fd == -1) { + /* What should be done in this case? error out from here + * and thus stop the glusterfs process from starting or + * continue with older method of using any of the available + * port? For now 2nd option is considered. + */ + gf_msg("glusterfs", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "could not open the file " + "/proc/sys/net/ipv4/ip_local_reserved_ports for " + "getting reserved ports info"); + goto out; + } + + ret = sys_read(proc_fd, buffer, sizeof(buffer) - 1); + if (ret < 0) { + gf_msg("glusterfs", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "could not read the file %s for" + " getting reserved ports info", + proc_file); + goto out; + } + + buffer[ret] = '\0'; + ports_info = gf_strdup(buffer); out: - if (proc_fd != -1) - sys_close (proc_fd); + if (proc_fd != -1) + sys_close(proc_fd); #endif /* GF_LINUX_HOST_OS */ - return ports_info; + return ports_info; } int -gf_process_reserved_ports (unsigned char *ports, uint32_t ceiling) +gf_process_reserved_ports(unsigned char *ports, uint32_t ceiling) { - int ret = -1; + int ret = -1; - memset (ports, 0, GF_PORT_ARRAY_SIZE); + memset(ports, 0, GF_PORT_ARRAY_SIZE); #if defined GF_LINUX_HOST_OS - char *ports_info = NULL; - char *tmp = NULL; - char *blocked_port = NULL; - - ports_info = gf_get_reserved_ports (); - if (!ports_info) { - gf_msg ("glusterfs", GF_LOG_WARNING, 0, - LG_MSG_RESERVED_PORTS_ERROR, "Not able to get reserved" - " ports, hence there is a possibility that glusterfs " - "may consume reserved port"); - goto out; - } + char *ports_info = NULL; + char *tmp = NULL; + char *blocked_port = NULL; - blocked_port = strtok_r (ports_info, ",\n",&tmp); + ports_info = gf_get_reserved_ports(); + if (!ports_info) { + gf_msg("glusterfs", GF_LOG_WARNING, 0, LG_MSG_RESERVED_PORTS_ERROR, + "Not able to get reserved" + " ports, hence there is a possibility that glusterfs " + "may consume reserved port"); + goto out; + } - while (blocked_port) { - gf_ports_reserved (blocked_port, ports, ceiling); - blocked_port = strtok_r (NULL, ",\n", &tmp); - } + blocked_port = strtok_r(ports_info, ",\n", &tmp); - ret = 0; + while (blocked_port) { + gf_ports_reserved(blocked_port, ports, ceiling); + blocked_port = strtok_r(NULL, ",\n", &tmp); + } + + ret = 0; out: - GF_FREE (ports_info); + GF_FREE(ports_info); #else /* FIXME: Non Linux Host */ - ret = 0; + ret = 0; #endif /* GF_LINUX_HOST_OS */ - return ret; + return ret; } gf_boolean_t -gf_ports_reserved (char *blocked_port, unsigned char *ports, uint32_t ceiling) -{ - gf_boolean_t result = _gf_false; - char *range_port = NULL; - int32_t tmp_port1 = -1; - int32_t tmp_port2 = -1; - - if (strstr (blocked_port, "-") == NULL) { - /* get rid of the new line character*/ - if (blocked_port[strlen(blocked_port) -1] == '\n') - blocked_port[strlen(blocked_port) -1] = '\0'; - if (gf_string2int32 (blocked_port, &tmp_port1) == 0) { - if (tmp_port1 > ceiling - || tmp_port1 < 0) { - gf_msg ("glusterfs-socket", GF_LOG_WARNING, 0, - LG_MSG_INVALID_PORT, "invalid port %d", - tmp_port1); - result = _gf_true; - goto out; - } else { - gf_msg_debug ("glusterfs", 0, "blocking port " - "%d", tmp_port1); - BIT_SET (ports, tmp_port1); - } - } else { - gf_msg ("glusterfs-socket", GF_LOG_WARNING, 0, - LG_MSG_INVALID_PORT, "%s is not a valid port " - "identifier", blocked_port); - result = _gf_true; - goto out; - } +gf_ports_reserved(char *blocked_port, unsigned char *ports, uint32_t ceiling) +{ + gf_boolean_t result = _gf_false; + char *range_port = NULL; + int32_t tmp_port1 = -1; + int32_t tmp_port2 = -1; + + if (strstr(blocked_port, "-") == NULL) { + /* get rid of the new line character*/ + if (blocked_port[strlen(blocked_port) - 1] == '\n') + blocked_port[strlen(blocked_port) - 1] = '\0'; + if (gf_string2int32(blocked_port, &tmp_port1) == 0) { + if (tmp_port1 > ceiling || tmp_port1 < 0) { + gf_msg("glusterfs-socket", GF_LOG_WARNING, 0, + LG_MSG_INVALID_PORT, "invalid port %d", tmp_port1); + result = _gf_true; + goto out; + } else { + gf_msg_debug("glusterfs", 0, + "blocking port " + "%d", + tmp_port1); + BIT_SET(ports, tmp_port1); + } } else { - range_port = strtok (blocked_port, "-"); - if (!range_port){ - result = _gf_true; - goto out; - } - if (gf_string2int32 (range_port, &tmp_port1) == 0) { - if (tmp_port1 > ceiling) - tmp_port1 = ceiling; - if (tmp_port1 < 0) - tmp_port1 = 0; - } - range_port = strtok (NULL, "-"); - if (!range_port) { - result = _gf_true; - goto out; - } - /* get rid of the new line character*/ - if (range_port[strlen(range_port) -1] == '\n') - range_port[strlen(range_port) - 1] = '\0'; - if (gf_string2int32 (range_port, &tmp_port2) == 0) { - if (tmp_port2 > ceiling) - tmp_port2 = ceiling; - if (tmp_port2 < 0) - tmp_port2 = 0; - } - gf_msg_debug ("glusterfs", 0, "lower: %d, higher: %d", - tmp_port1, tmp_port2); - for (; tmp_port1 <= tmp_port2; tmp_port1++) - BIT_SET (ports, tmp_port1); - } + gf_msg("glusterfs-socket", GF_LOG_WARNING, 0, LG_MSG_INVALID_PORT, + "%s is not a valid port " + "identifier", + blocked_port); + result = _gf_true; + goto out; + } + } else { + range_port = strtok(blocked_port, "-"); + if (!range_port) { + result = _gf_true; + goto out; + } + if (gf_string2int32(range_port, &tmp_port1) == 0) { + if (tmp_port1 > ceiling) + tmp_port1 = ceiling; + if (tmp_port1 < 0) + tmp_port1 = 0; + } + range_port = strtok(NULL, "-"); + if (!range_port) { + result = _gf_true; + goto out; + } + /* get rid of the new line character*/ + if (range_port[strlen(range_port) - 1] == '\n') + range_port[strlen(range_port) - 1] = '\0'; + if (gf_string2int32(range_port, &tmp_port2) == 0) { + if (tmp_port2 > ceiling) + tmp_port2 = ceiling; + if (tmp_port2 < 0) + tmp_port2 = 0; + } + gf_msg_debug("glusterfs", 0, "lower: %d, higher: %d", tmp_port1, + tmp_port2); + for (; tmp_port1 <= tmp_port2; tmp_port1++) + BIT_SET(ports, tmp_port1); + } out: - return result; + return result; } /* Takes in client ip{v4,v6} and returns associated hostname, if any @@ -3341,331 +3339,326 @@ out: * Returns: 0 for success, -1 for failure */ int -gf_get_hostname_from_ip (char *client_ip, char **hostname) -{ - int ret = -1; - struct sockaddr *client_sockaddr = NULL; - struct sockaddr_in client_sock_in = {0}; - struct sockaddr_in6 client_sock_in6 = {0}; - char client_hostname[NI_MAXHOST] = {0}; - char *client_ip_copy = NULL; - char *tmp = NULL; - char *ip = NULL; - size_t addr_sz = 0; - - /* if ipv4, reverse lookup the hostname to - * allow FQDN based rpc authentication - */ - if (!valid_ipv6_address (client_ip, strlen (client_ip), 0) && - !valid_ipv4_address (client_ip, strlen (client_ip), 0)) { - /* most times, we get a.b.c.d:port form, so check that */ - client_ip_copy = gf_strdup (client_ip); - if (!client_ip_copy) - goto out; - - ip = strtok_r (client_ip_copy, ":", &tmp); - } else { - ip = client_ip; - } - - if (valid_ipv4_address (ip, strlen (ip), 0) == _gf_true) { - client_sockaddr = (struct sockaddr *)&client_sock_in; - addr_sz = sizeof (client_sock_in); - client_sock_in.sin_family = AF_INET; - ret = inet_pton (AF_INET, ip, - (void *)&client_sock_in.sin_addr.s_addr); - - } else if (valid_ipv6_address (ip, strlen (ip), 0) == _gf_true) { - client_sockaddr = (struct sockaddr *) &client_sock_in6; - addr_sz = sizeof (client_sock_in6); +gf_get_hostname_from_ip(char *client_ip, char **hostname) +{ + int ret = -1; + struct sockaddr *client_sockaddr = NULL; + struct sockaddr_in client_sock_in = {0}; + struct sockaddr_in6 client_sock_in6 = {0}; + char client_hostname[NI_MAXHOST] = {0}; + char *client_ip_copy = NULL; + char *tmp = NULL; + char *ip = NULL; + size_t addr_sz = 0; + + /* if ipv4, reverse lookup the hostname to + * allow FQDN based rpc authentication + */ + if (!valid_ipv6_address(client_ip, strlen(client_ip), 0) && + !valid_ipv4_address(client_ip, strlen(client_ip), 0)) { + /* most times, we get a.b.c.d:port form, so check that */ + client_ip_copy = gf_strdup(client_ip); + if (!client_ip_copy) + goto out; + + ip = strtok_r(client_ip_copy, ":", &tmp); + } else { + ip = client_ip; + } + + if (valid_ipv4_address(ip, strlen(ip), 0) == _gf_true) { + client_sockaddr = (struct sockaddr *)&client_sock_in; + addr_sz = sizeof(client_sock_in); + client_sock_in.sin_family = AF_INET; + ret = inet_pton(AF_INET, ip, (void *)&client_sock_in.sin_addr.s_addr); + + } else if (valid_ipv6_address(ip, strlen(ip), 0) == _gf_true) { + client_sockaddr = (struct sockaddr *)&client_sock_in6; + addr_sz = sizeof(client_sock_in6); + + client_sock_in6.sin6_family = AF_INET6; + ret = inet_pton(AF_INET6, ip, (void *)&client_sock_in6.sin6_addr); + } else { + goto out; + } + + if (ret != 1) { + ret = -1; + goto out; + } + + /* You cannot just use sizeof (*client_sockaddr), as per the man page + * the (getnameinfo) size must be the size of the underlying sockaddr + * struct e.g. sockaddr_in6 or sockaddr_in. Failure to do so will + * break IPv6 hostname resolution (IPv4 will work only because + * the sockaddr_in struct happens to be of the correct size). + */ + ret = getnameinfo(client_sockaddr, addr_sz, client_hostname, + sizeof(client_hostname), NULL, 0, 0); + if (ret) { + gf_msg("common-utils", GF_LOG_ERROR, 0, LG_MSG_GETNAMEINFO_FAILED, + "Could not lookup hostname " + "of %s : %s", + client_ip, gai_strerror(ret)); + ret = -1; + goto out; + } + + *hostname = gf_strdup((char *)client_hostname); +out: + if (client_ip_copy) + GF_FREE(client_ip_copy); - client_sock_in6.sin6_family = AF_INET6; - ret = inet_pton (AF_INET6, ip, - (void *)&client_sock_in6.sin6_addr); - } else { - goto out; - } + return ret; +} - if (ret != 1) { - ret = -1; - goto out; - } +gf_boolean_t +gf_interface_search(char *ip) +{ + int32_t ret = -1; + gf_boolean_t found = _gf_false; + struct ifaddrs *ifaddr, *ifa; + int family; + char host[NI_MAXHOST]; + xlator_t *this = NULL; + char *pct = NULL; - /* You cannot just use sizeof (*client_sockaddr), as per the man page - * the (getnameinfo) size must be the size of the underlying sockaddr - * struct e.g. sockaddr_in6 or sockaddr_in. Failure to do so will - * break IPv6 hostname resolution (IPv4 will work only because - * the sockaddr_in struct happens to be of the correct size). - */ - ret = getnameinfo (client_sockaddr, - addr_sz, - client_hostname, sizeof (client_hostname), - NULL, 0, 0); - if (ret) { - gf_msg ("common-utils", GF_LOG_ERROR, 0, - LG_MSG_GETNAMEINFO_FAILED, "Could not lookup hostname " - "of %s : %s", client_ip, gai_strerror (ret)); - ret = -1; - goto out; - } + this = THIS; - *hostname = gf_strdup ((char *)client_hostname); - out: - if (client_ip_copy) - GF_FREE (client_ip_copy); + ret = getifaddrs(&ifaddr); - return ret; -} + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, LG_MSG_GETIFADDRS_FAILED, + "getifaddrs() failed: %s\n", gai_strerror(ret)); + goto out; + } -gf_boolean_t -gf_interface_search (char *ip) -{ - int32_t ret = -1; - gf_boolean_t found = _gf_false; - struct ifaddrs *ifaddr, *ifa; - int family; - char host[NI_MAXHOST]; - xlator_t *this = NULL; - char *pct = NULL; + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (!ifa->ifa_addr) { + /* + * This seemingly happens if an interface hasn't + * been bound to a particular protocol (seen with + * TUN devices). + */ + continue; + } + family = ifa->ifa_addr->sa_family; - this = THIS; + if (family != AF_INET && family != AF_INET6) + continue; - ret = getifaddrs (&ifaddr); + ret = getnameinfo(ifa->ifa_addr, + (family == AF_INET) ? sizeof(struct sockaddr_in) + : sizeof(struct sockaddr_in6), + host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, LG_MSG_GETIFADDRS_FAILED, - "getifaddrs() failed: %s\n", gai_strerror(ret)); - goto out; + gf_msg(this->name, GF_LOG_ERROR, 0, LG_MSG_GETNAMEINFO_FAILED, + "getnameinfo() " + "failed: %s\n", + gai_strerror(ret)); + goto out; + } + + /* + * Sometimes the address comes back as addr%eth0 or + * similar. Since % is an invalid character, we can + * strip it out with confidence that doing so won't + * harm anything. + */ + pct = index(host, '%'); + if (pct) { + *pct = '\0'; } - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (!ifa->ifa_addr) { - /* - * This seemingly happens if an interface hasn't - * been bound to a particular protocol (seen with - * TUN devices). - */ - continue; - } - family = ifa->ifa_addr->sa_family; - - if (family != AF_INET && family != AF_INET6) - continue; - - ret = getnameinfo (ifa->ifa_addr, - (family == AF_INET) ? sizeof(struct sockaddr_in) : - sizeof(struct sockaddr_in6), - host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); - - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, - LG_MSG_GETNAMEINFO_FAILED, "getnameinfo() " - "failed: %s\n", gai_strerror(ret)); - goto out; - } - - /* - * Sometimes the address comes back as addr%eth0 or - * similar. Since % is an invalid character, we can - * strip it out with confidence that doing so won't - * harm anything. - */ - pct = index(host,'%'); - if (pct) { - *pct = '\0'; - } - - if (strncmp (ip, host, NI_MAXHOST) == 0) { - gf_msg_debug (this->name, 0, "%s is local address at " - "interface %s", ip, ifa->ifa_name); - found = _gf_true; - goto out; - } + if (strncmp(ip, host, NI_MAXHOST) == 0) { + gf_msg_debug(this->name, 0, + "%s is local address at " + "interface %s", + ip, ifa->ifa_name); + found = _gf_true; + goto out; } + } out: - if(ifaddr) - freeifaddrs (ifaddr); - return found; + if (ifaddr) + freeifaddrs(ifaddr); + return found; } char * -get_ip_from_addrinfo (struct addrinfo *addr, char **ip) +get_ip_from_addrinfo(struct addrinfo *addr, char **ip) { - char buf[64]; - void *in_addr = NULL; - struct sockaddr_in *s4 = NULL; - struct sockaddr_in6 *s6 = NULL; + char buf[64]; + void *in_addr = NULL; + struct sockaddr_in *s4 = NULL; + struct sockaddr_in6 *s6 = NULL; - switch (addr->ai_family) - { - case AF_INET: - s4 = (struct sockaddr_in *)addr->ai_addr; - in_addr = &s4->sin_addr; - break; - - case AF_INET6: - s6 = (struct sockaddr_in6 *)addr->ai_addr; - in_addr = &s6->sin6_addr; - break; - - default: - gf_msg ("glusterd", GF_LOG_ERROR, 0, - LG_MSG_INVALID_FAMILY, "Invalid family"); - return NULL; - } + switch (addr->ai_family) { + case AF_INET: + s4 = (struct sockaddr_in *)addr->ai_addr; + in_addr = &s4->sin_addr; + break; - if (!inet_ntop(addr->ai_family, in_addr, buf, sizeof(buf))) { - gf_msg ("glusterd", GF_LOG_ERROR, 0, LG_MSG_CONVERSION_FAILED, - "String conversion failed"); - return NULL; - } + case AF_INET6: + s6 = (struct sockaddr_in6 *)addr->ai_addr; + in_addr = &s6->sin6_addr; + break; + + default: + gf_msg("glusterd", GF_LOG_ERROR, 0, LG_MSG_INVALID_FAMILY, + "Invalid family"); + return NULL; + } + + if (!inet_ntop(addr->ai_family, in_addr, buf, sizeof(buf))) { + gf_msg("glusterd", GF_LOG_ERROR, 0, LG_MSG_CONVERSION_FAILED, + "String conversion failed"); + return NULL; + } - *ip = gf_strdup (buf); - return *ip; + *ip = gf_strdup(buf); + return *ip; } gf_boolean_t -gf_is_loopback_localhost (const struct sockaddr *sa, char *hostname) -{ - GF_ASSERT (sa); - - gf_boolean_t is_local = _gf_false; - const struct in_addr *addr4 = NULL; - const struct in6_addr *addr6 = NULL; - uint8_t *ap = NULL; - struct in6_addr loopbackaddr6 = IN6ADDR_LOOPBACK_INIT; - - switch (sa->sa_family) { - case AF_INET: - addr4 = &(((struct sockaddr_in *)sa)->sin_addr); - ap = (uint8_t*)&addr4->s_addr; - if (ap[0] == 127) - is_local = _gf_true; - break; - - case AF_INET6: - addr6 = &(((struct sockaddr_in6 *)sa)->sin6_addr); - if (memcmp (addr6, &loopbackaddr6, - sizeof (loopbackaddr6)) == 0) - is_local = _gf_true; - break; - - default: - if (hostname) - gf_msg ("glusterd", GF_LOG_ERROR, 0, - LG_MSG_INVALID_FAMILY, "unknown " - "address family %d for %s", - sa->sa_family, hostname); - break; - } +gf_is_loopback_localhost(const struct sockaddr *sa, char *hostname) +{ + GF_ASSERT(sa); + + gf_boolean_t is_local = _gf_false; + const struct in_addr *addr4 = NULL; + const struct in6_addr *addr6 = NULL; + uint8_t *ap = NULL; + struct in6_addr loopbackaddr6 = IN6ADDR_LOOPBACK_INIT; + + switch (sa->sa_family) { + case AF_INET: + addr4 = &(((struct sockaddr_in *)sa)->sin_addr); + ap = (uint8_t *)&addr4->s_addr; + if (ap[0] == 127) + is_local = _gf_true; + break; + + case AF_INET6: + addr6 = &(((struct sockaddr_in6 *)sa)->sin6_addr); + if (memcmp(addr6, &loopbackaddr6, sizeof(loopbackaddr6)) == 0) + is_local = _gf_true; + break; + + default: + if (hostname) + gf_msg("glusterd", GF_LOG_ERROR, 0, LG_MSG_INVALID_FAMILY, + "unknown " + "address family %d for %s", + sa->sa_family, hostname); + break; + } - return is_local; + return is_local; } gf_boolean_t -gf_is_local_addr (char *hostname) +gf_is_local_addr(char *hostname) { - int32_t ret = -1; - struct addrinfo *result = NULL; - struct addrinfo *res = NULL; - gf_boolean_t found = _gf_false; - char *ip = NULL; - xlator_t *this = NULL; - struct addrinfo hints; + int32_t ret = -1; + struct addrinfo *result = NULL; + struct addrinfo *res = NULL; + gf_boolean_t found = _gf_false; + char *ip = NULL; + xlator_t *this = NULL; + struct addrinfo hints; - this = THIS; + this = THIS; - memset (&hints, 0, sizeof (hints)); - /* - * Removing AI_ADDRCONFIG from default_hints - * for being able to use link local ipv6 addresses - */ - hints.ai_family = AF_UNSPEC; + memset(&hints, 0, sizeof(hints)); + /* + * Removing AI_ADDRCONFIG from default_hints + * for being able to use link local ipv6 addresses + */ + hints.ai_family = AF_UNSPEC; - ret = getaddrinfo (hostname, NULL, &hints, &result); + ret = getaddrinfo(hostname, NULL, &hints, &result); - if (ret != 0) { - gf_msg (this->name, GF_LOG_ERROR, 0, LG_MSG_GETADDRINFO_FAILED, - "error in getaddrinfo: %s\n", gai_strerror(ret)); - goto out; - } + if (ret != 0) { + gf_msg(this->name, GF_LOG_ERROR, 0, LG_MSG_GETADDRINFO_FAILED, + "error in getaddrinfo: %s\n", gai_strerror(ret)); + goto out; + } + + for (res = result; res != NULL; res = res->ai_next) { + gf_msg_debug(this->name, 0, "%s ", get_ip_from_addrinfo(res, &ip)); - for (res = result; res != NULL; res = res->ai_next) { - gf_msg_debug (this->name, 0, "%s ", - get_ip_from_addrinfo (res, &ip)); - - if (ip) { - found = gf_is_loopback_localhost - (res->ai_addr, hostname) || - gf_interface_search (ip); - } - if (found) { - GF_FREE (ip); - goto out; - } - GF_FREE (ip); + if (ip) { + found = gf_is_loopback_localhost(res->ai_addr, hostname) || + gf_interface_search(ip); + } + if (found) { + GF_FREE(ip); + goto out; } + GF_FREE(ip); + } out: - if (result) - freeaddrinfo (result); + if (result) + freeaddrinfo(result); - if (!found) - gf_msg_debug (this->name, 0, "%s is not local", hostname); + if (!found) + gf_msg_debug(this->name, 0, "%s is not local", hostname); - return found; + return found; } gf_boolean_t -gf_is_same_address (char *name1, char *name2) -{ - struct addrinfo *addr1 = NULL; - struct addrinfo *addr2 = NULL; - struct addrinfo *p = NULL; - struct addrinfo *q = NULL; - gf_boolean_t ret = _gf_false; - int gai_err = 0; - struct addrinfo hints; - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = AF_UNSPEC; - - gai_err = getaddrinfo(name1, NULL, &hints, &addr1); - if (gai_err != 0) { - gf_msg (name1, GF_LOG_WARNING, 0, LG_MSG_GETADDRINFO_FAILED, - "error in getaddrinfo: %s\n", gai_strerror(gai_err)); - goto out; - } - - gai_err = getaddrinfo(name2, NULL, &hints, &addr2); - if (gai_err != 0) { - gf_msg (name2, GF_LOG_WARNING, 0, LG_MSG_GETADDRINFO_FAILED, - "error in getaddrinfo: %s\n", gai_strerror(gai_err)); - goto out; - } - - for (p = addr1; p; p = p->ai_next) { - for (q = addr2; q; q = q->ai_next) { - if (p->ai_addrlen != q->ai_addrlen) { - continue; - } - if (memcmp(p->ai_addr,q->ai_addr,p->ai_addrlen)) { - continue; - } - ret = _gf_true; - goto out; - } - } +gf_is_same_address(char *name1, char *name2) +{ + struct addrinfo *addr1 = NULL; + struct addrinfo *addr2 = NULL; + struct addrinfo *p = NULL; + struct addrinfo *q = NULL; + gf_boolean_t ret = _gf_false; + int gai_err = 0; + struct addrinfo hints; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + + gai_err = getaddrinfo(name1, NULL, &hints, &addr1); + if (gai_err != 0) { + gf_msg(name1, GF_LOG_WARNING, 0, LG_MSG_GETADDRINFO_FAILED, + "error in getaddrinfo: %s\n", gai_strerror(gai_err)); + goto out; + } + + gai_err = getaddrinfo(name2, NULL, &hints, &addr2); + if (gai_err != 0) { + gf_msg(name2, GF_LOG_WARNING, 0, LG_MSG_GETADDRINFO_FAILED, + "error in getaddrinfo: %s\n", gai_strerror(gai_err)); + goto out; + } + + for (p = addr1; p; p = p->ai_next) { + for (q = addr2; q; q = q->ai_next) { + if (p->ai_addrlen != q->ai_addrlen) { + continue; + } + if (memcmp(p->ai_addr, q->ai_addr, p->ai_addrlen)) { + continue; + } + ret = _gf_true; + goto out; + } + } out: - if (addr1) { - freeaddrinfo(addr1); - } - if (addr2) { - freeaddrinfo(addr2); - } - return ret; - + if (addr1) { + freeaddrinfo(addr1); + } + if (addr2) { + freeaddrinfo(addr2); + } + return ret; } /* @@ -3673,511 +3666,503 @@ out: * Format: <host1>:<port1> <host2>:<port2>... */ int -gf_process_getspec_servers_list(cmd_args_t *cmd_args, - const char *servers_list) { - char *tmp = NULL; - char *address = NULL; - char *host = NULL; - char *last_colon = NULL; - char *save_ptr = NULL; - int port = 0; - int ret = -1; - - tmp = gf_strdup (servers_list); - if (!tmp) { - errno = ENOMEM; - goto out; - } - - address = strtok_r (tmp, " ", &save_ptr); +gf_process_getspec_servers_list(cmd_args_t *cmd_args, const char *servers_list) +{ + char *tmp = NULL; + char *address = NULL; + char *host = NULL; + char *last_colon = NULL; + char *save_ptr = NULL; + int port = 0; + int ret = -1; + + tmp = gf_strdup(servers_list); + if (!tmp) { + errno = ENOMEM; + goto out; + } + + address = strtok_r(tmp, " ", &save_ptr); + if (!address) { + errno = EINVAL; + goto out; + } + + while (1) { + last_colon = strrchr(address, ':'); + if (!last_colon) { + errno = EINVAL; + ret = -1; + break; + } + *last_colon = '\0'; + host = address; + port = atoi(last_colon + 1); + if (port <= 0) { + errno = EINVAL; + ret = -1; + break; + } + ret = gf_set_volfile_server_common(cmd_args, host, + GF_DEFAULT_VOLFILE_TRANSPORT, port); + if (ret && errno != EEXIST) { + break; + } + address = strtok_r(NULL, " ", &save_ptr); if (!address) { - errno = EINVAL; - goto out; - } - - while (1) { - last_colon = strrchr (address, ':'); - if (!last_colon) { - errno = EINVAL; - ret = -1; - break; - } - *last_colon = '\0'; - host = address; - port = atoi (last_colon + 1); - if (port <= 0) { - errno = EINVAL; - ret = -1; - break; - } - ret = gf_set_volfile_server_common ( - cmd_args, host, GF_DEFAULT_VOLFILE_TRANSPORT, port); - if (ret && errno != EEXIST) { - break; - } - address = strtok_r (NULL, " ", &save_ptr); - if (!address) { - errno = 0; - ret = 0; - break; - } + errno = 0; + ret = 0; + break; } + } out: - if (tmp) { - GF_FREE (tmp); - } + if (tmp) { + GF_FREE(tmp); + } - return ret; + return ret; } int -gf_set_volfile_server_common (cmd_args_t *cmd_args, const char *host, - const char *transport, int port) -{ - server_cmdline_t *server = NULL; - server_cmdline_t *tmp = NULL; - int ret = -1; - - GF_VALIDATE_OR_GOTO (THIS->name, cmd_args, out); - GF_VALIDATE_OR_GOTO (THIS->name, host, out); - GF_VALIDATE_OR_GOTO (THIS->name, transport, out); - - server = GF_CALLOC (1, sizeof (server_cmdline_t), - gf_common_mt_server_cmdline_t); - if (!server) { - errno = ENOMEM; - goto out; - } - - INIT_LIST_HEAD (&server->list); - - server->volfile_server = gf_strdup (host); - if (!server->volfile_server) { - errno = ENOMEM; - goto out; - } - - server->transport = gf_strdup (transport); - if (!server->transport) { - errno = ENOMEM; - goto out; - } - - server->port = port; - - if (!cmd_args->volfile_server) { - cmd_args->volfile_server = server->volfile_server; - cmd_args->volfile_server_transport = server->transport; - cmd_args->volfile_server_port = server->port; - cmd_args->curr_server = server; - } - - list_for_each_entry(tmp, &cmd_args->volfile_servers, list) { - if ((!strcmp(tmp->volfile_server, server->volfile_server) && - !strcmp(tmp->transport, server->transport) && - (tmp->port == server->port))) { - errno = EEXIST; - ret = -1; - goto out; - } - } - - list_add_tail (&server->list, &cmd_args->volfile_servers); - - ret = 0; +gf_set_volfile_server_common(cmd_args_t *cmd_args, const char *host, + const char *transport, int port) +{ + server_cmdline_t *server = NULL; + server_cmdline_t *tmp = NULL; + int ret = -1; + + GF_VALIDATE_OR_GOTO(THIS->name, cmd_args, out); + GF_VALIDATE_OR_GOTO(THIS->name, host, out); + GF_VALIDATE_OR_GOTO(THIS->name, transport, out); + + server = GF_CALLOC(1, sizeof(server_cmdline_t), + gf_common_mt_server_cmdline_t); + if (!server) { + errno = ENOMEM; + goto out; + } + + INIT_LIST_HEAD(&server->list); + + server->volfile_server = gf_strdup(host); + if (!server->volfile_server) { + errno = ENOMEM; + goto out; + } + + server->transport = gf_strdup(transport); + if (!server->transport) { + errno = ENOMEM; + goto out; + } + + server->port = port; + + if (!cmd_args->volfile_server) { + cmd_args->volfile_server = server->volfile_server; + cmd_args->volfile_server_transport = server->transport; + cmd_args->volfile_server_port = server->port; + cmd_args->curr_server = server; + } + + list_for_each_entry(tmp, &cmd_args->volfile_servers, list) + { + if ((!strcmp(tmp->volfile_server, server->volfile_server) && + !strcmp(tmp->transport, server->transport) && + (tmp->port == server->port))) { + errno = EEXIST; + ret = -1; + goto out; + } + } + + list_add_tail(&server->list, &cmd_args->volfile_servers); + + ret = 0; out: - if (-1 == ret) { - if (server) { - GF_FREE (server->volfile_server); - GF_FREE (server->transport); - GF_FREE (server); - } + if (-1 == ret) { + if (server) { + GF_FREE(server->volfile_server); + GF_FREE(server->transport); + GF_FREE(server); } + } - return ret; + return ret; } /* Sets log file path from user provided arguments */ int -gf_set_log_file_path (cmd_args_t *cmd_args, glusterfs_ctx_t *ctx) -{ - int i = 0; - int j = 0; - int ret = 0; - int tmp_len = 0; - char tmp_str[1024] = {0,}; - - if (!cmd_args) - goto done; - - if (cmd_args->mount_point) { - j = 0; - i = 0; - if (cmd_args->mount_point[0] == '/') - i = 1; - for (; i < strlen (cmd_args->mount_point); i++,j++) { - tmp_str[j] = cmd_args->mount_point[i]; - if (cmd_args->mount_point[i] == '/') - tmp_str[j] = '-'; - } - - ret = gf_asprintf (&cmd_args->log_file, - DEFAULT_LOG_FILE_DIRECTORY "/%s.log", - tmp_str); - if (ret > 0) - ret = 0; - goto done; - } +gf_set_log_file_path(cmd_args_t *cmd_args, glusterfs_ctx_t *ctx) +{ + int i = 0; + int j = 0; + int ret = 0; + int tmp_len = 0; + char tmp_str[1024] = { + 0, + }; - if (ctx && GF_GLUSTERD_PROCESS == ctx->process_mode) { - ret = gf_asprintf (&cmd_args->log_file, - DEFAULT_LOG_FILE_DIRECTORY "/%s.log", - GLUSTERD_NAME); - if (ret > 0) - ret = 0; + if (!cmd_args) + goto done; - goto done; + if (cmd_args->mount_point) { + j = 0; + i = 0; + if (cmd_args->mount_point[0] == '/') + i = 1; + for (; i < strlen(cmd_args->mount_point); i++, j++) { + tmp_str[j] = cmd_args->mount_point[i]; + if (cmd_args->mount_point[i] == '/') + tmp_str[j] = '-'; } - if (cmd_args->volfile) { - j = 0; - i = 0; - if (cmd_args->volfile[0] == '/') - i = 1; - for (; i < strlen (cmd_args->volfile); i++,j++) { - tmp_str[j] = cmd_args->volfile[i]; - if (cmd_args->volfile[i] == '/') - tmp_str[j] = '-'; - } - ret = gf_asprintf (&cmd_args->log_file, - DEFAULT_LOG_FILE_DIRECTORY "/%s.log", - tmp_str); - if (ret > 0) - ret = 0; - goto done; - } + ret = gf_asprintf(&cmd_args->log_file, + DEFAULT_LOG_FILE_DIRECTORY "/%s.log", tmp_str); + if (ret > 0) + ret = 0; + goto done; + } + + if (ctx && GF_GLUSTERD_PROCESS == ctx->process_mode) { + ret = gf_asprintf(&cmd_args->log_file, + DEFAULT_LOG_FILE_DIRECTORY "/%s.log", GLUSTERD_NAME); + if (ret > 0) + ret = 0; + + goto done; + } - if (cmd_args->volfile_server) { - if (strncmp (cmd_args->volfile_server_transport, - "unix", 4) == 0) { - if (cmd_args->volfile_server[0] == '/') - i = 1; - tmp_len = strlen (cmd_args->volfile_server); - for (j = 0; i < tmp_len; i++, j++) { - tmp_str[j] = cmd_args->volfile_server[i]; - if (cmd_args->volfile_server[i] == '/') - tmp_str[j] = '-'; - } - ret = gf_asprintf (&cmd_args->log_file, - "%s/%s-%s-%d.log", - DEFAULT_LOG_FILE_DIRECTORY, - tmp_str, - cmd_args->volfile_id, getpid()); - } else { - ret = gf_asprintf (&cmd_args->log_file, - "%s/%s-%s-%d.log", - DEFAULT_LOG_FILE_DIRECTORY, - cmd_args->volfile_server, - cmd_args->volfile_id, getpid()); - } - if (ret > 0) - ret = 0; + if (cmd_args->volfile) { + j = 0; + i = 0; + if (cmd_args->volfile[0] == '/') + i = 1; + for (; i < strlen(cmd_args->volfile); i++, j++) { + tmp_str[j] = cmd_args->volfile[i]; + if (cmd_args->volfile[i] == '/') + tmp_str[j] = '-'; + } + ret = gf_asprintf(&cmd_args->log_file, + DEFAULT_LOG_FILE_DIRECTORY "/%s.log", tmp_str); + if (ret > 0) + ret = 0; + goto done; + } + + if (cmd_args->volfile_server) { + if (strncmp(cmd_args->volfile_server_transport, "unix", 4) == 0) { + if (cmd_args->volfile_server[0] == '/') + i = 1; + tmp_len = strlen(cmd_args->volfile_server); + for (j = 0; i < tmp_len; i++, j++) { + tmp_str[j] = cmd_args->volfile_server[i]; + if (cmd_args->volfile_server[i] == '/') + tmp_str[j] = '-'; + } + ret = gf_asprintf(&cmd_args->log_file, "%s/%s-%s-%d.log", + DEFAULT_LOG_FILE_DIRECTORY, tmp_str, + cmd_args->volfile_id, getpid()); + } else { + ret = gf_asprintf(&cmd_args->log_file, "%s/%s-%s-%d.log", + DEFAULT_LOG_FILE_DIRECTORY, + cmd_args->volfile_server, cmd_args->volfile_id, + getpid()); } + if (ret > 0) + ret = 0; + } done: - return ret; + return ret; } int -gf_set_log_ident (cmd_args_t *cmd_args) +gf_set_log_ident(cmd_args_t *cmd_args) { - int ret = 0; - char *ptr = NULL; - - if (cmd_args->log_file == NULL) { - /* no ident source */ - return 0; - } + int ret = 0; + char *ptr = NULL; - /* TODO: Some idents would look like, etc-glusterfs-glusterd.vol, which - * seems ugly and can be bettered? */ - /* just get the filename as the ident */ - if (NULL != (ptr = strrchr (cmd_args->log_file, '/'))) { - ret = gf_asprintf (&cmd_args->log_ident, "%s", ptr + 1); - } else { - ret = gf_asprintf (&cmd_args->log_ident, "%s", - cmd_args->log_file); - } - - if (ret > 0) - ret = 0; - else - return ret; + if (cmd_args->log_file == NULL) { + /* no ident source */ + return 0; + } + + /* TODO: Some idents would look like, etc-glusterfs-glusterd.vol, which + * seems ugly and can be bettered? */ + /* just get the filename as the ident */ + if (NULL != (ptr = strrchr(cmd_args->log_file, '/'))) { + ret = gf_asprintf(&cmd_args->log_ident, "%s", ptr + 1); + } else { + ret = gf_asprintf(&cmd_args->log_ident, "%s", cmd_args->log_file); + } + + if (ret > 0) + ret = 0; + else + return ret; - /* remove .log suffix */ - if (NULL != (ptr = strrchr (cmd_args->log_ident, '.'))) { - if (strcmp (ptr, ".log") == 0) { - ptr[0] = '\0'; - } + /* remove .log suffix */ + if (NULL != (ptr = strrchr(cmd_args->log_ident, '.'))) { + if (strcmp(ptr, ".log") == 0) { + ptr[0] = '\0'; } + } - return ret; + return ret; } int -gf_thread_cleanup_xint (pthread_t thread) +gf_thread_cleanup_xint(pthread_t thread) { - int ret = 0; - void *res = NULL; + int ret = 0; + void *res = NULL; - ret = pthread_cancel (thread); - if (ret != 0) - goto error_return; + ret = pthread_cancel(thread); + if (ret != 0) + goto error_return; - ret = pthread_join (thread, &res); - if (ret != 0) - goto error_return; + ret = pthread_join(thread, &res); + if (ret != 0) + goto error_return; - if (res != PTHREAD_CANCELED) - goto error_return; + if (res != PTHREAD_CANCELED) + goto error_return; - ret = 0; + ret = 0; - error_return: - return ret; +error_return: + return ret; } int -gf_thread_create (pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void *), void *arg, const char *name) -{ - sigset_t set, old; - int ret; - char thread_name[GF_THREAD_NAMEMAX+GF_THREAD_NAME_PREFIX_LEN] = {0,}; - /* Max name on Linux is 16 and on NetBSD is 32 - * All Gluster threads have a set prefix of gluster and hence the limit - * of 9 on GF_THREAD_NAMEMAX including the null character. - */ - - sigemptyset (&old); - sigfillset (&set); - sigdelset (&set, SIGSEGV); - sigdelset (&set, SIGBUS); - sigdelset (&set, SIGILL); - sigdelset (&set, SIGSYS); - sigdelset (&set, SIGFPE); - sigdelset (&set, SIGABRT); - - pthread_sigmask (SIG_BLOCK, &set, &old); - - ret = pthread_create (thread, attr, start_routine, arg); - snprintf (thread_name, sizeof(thread_name), "%s%s", - GF_THREAD_NAME_PREFIX, name); - - if (0 == ret && name) { - #ifdef GF_LINUX_HOST_OS - pthread_setname_np(*thread, thread_name); - #elif defined(__NetBSD__) - pthread_setname_np(*thread, thread_name, NULL); - #elif defined(__FreeBSD__) - pthread_set_name_np(*thread, thread_name); - #else - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_PTHREAD_NAMING_FAILED, - "Could not set thread name: %s", - thread_name); - #endif - } +gf_thread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*start_routine)(void *), void *arg, const char *name) +{ + sigset_t set, old; + int ret; + char thread_name[GF_THREAD_NAMEMAX + GF_THREAD_NAME_PREFIX_LEN] = { + 0, + }; + /* Max name on Linux is 16 and on NetBSD is 32 + * All Gluster threads have a set prefix of gluster and hence the limit + * of 9 on GF_THREAD_NAMEMAX including the null character. + */ + + sigemptyset(&old); + sigfillset(&set); + sigdelset(&set, SIGSEGV); + sigdelset(&set, SIGBUS); + sigdelset(&set, SIGILL); + sigdelset(&set, SIGSYS); + sigdelset(&set, SIGFPE); + sigdelset(&set, SIGABRT); + + pthread_sigmask(SIG_BLOCK, &set, &old); + + ret = pthread_create(thread, attr, start_routine, arg); + snprintf(thread_name, sizeof(thread_name), "%s%s", GF_THREAD_NAME_PREFIX, + name); + + if (0 == ret && name) { +#ifdef GF_LINUX_HOST_OS + pthread_setname_np(*thread, thread_name); +#elif defined(__NetBSD__) + pthread_setname_np(*thread, thread_name, NULL); +#elif defined(__FreeBSD__) + pthread_set_name_np(*thread, thread_name); +#else + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_PTHREAD_NAMING_FAILED, + "Could not set thread name: %s", thread_name); +#endif + } - pthread_sigmask (SIG_SETMASK, &old, NULL); + pthread_sigmask(SIG_SETMASK, &old, NULL); - return ret; + return ret; } int -gf_thread_create_detached (pthread_t *thread, - void *(*start_routine)(void *), void *arg, - const char *name) +gf_thread_create_detached(pthread_t *thread, void *(*start_routine)(void *), + void *arg, const char *name) { - pthread_attr_t attr; - int ret = -1; + pthread_attr_t attr; + int ret = -1; - ret = pthread_attr_init (&attr); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, ret, - LG_MSG_PTHREAD_ATTR_INIT_FAILED, - "Thread attribute initialization failed"); - return -1; - } + ret = pthread_attr_init(&attr); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, ret, LG_MSG_PTHREAD_ATTR_INIT_FAILED, + "Thread attribute initialization failed"); + return -1; + } - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - ret = gf_thread_create (thread, &attr, start_routine, arg, name); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, ret, - LG_MSG_PTHREAD_FAILED, - "Thread creation failed"); - ret = -1; - } + ret = gf_thread_create(thread, &attr, start_routine, arg, name); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, ret, LG_MSG_PTHREAD_FAILED, + "Thread creation failed"); + ret = -1; + } - pthread_attr_destroy (&attr); + pthread_attr_destroy(&attr); - return ret; + return ret; } int -gf_skip_header_section (int fd, int header_len) +gf_skip_header_section(int fd, int header_len) { - int ret = -1; + int ret = -1; - ret = sys_lseek (fd, header_len, SEEK_SET); - if (ret == (off_t) -1) { - gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_SKIP_HEADER_FAILED, - "Failed to skip header section"); - } else { - ret = 0; - } + ret = sys_lseek(fd, header_len, SEEK_SET); + if (ret == (off_t)-1) { + gf_msg("", GF_LOG_ERROR, 0, LG_MSG_SKIP_HEADER_FAILED, + "Failed to skip header section"); + } else { + ret = 0; + } - return ret; + return ret; } /* Below function is use to check at runtime if pid is running */ gf_boolean_t -gf_is_pid_running (int pid) +gf_is_pid_running(int pid) { - char fname[32] = {0,}; + char fname[32] = { + 0, + }; - snprintf(fname, sizeof(fname), "/proc/%d/cmdline", pid); - - if (sys_access (fname , R_OK) != 0) { - return _gf_false; - } + snprintf(fname, sizeof(fname), "/proc/%d/cmdline", pid); - return _gf_true; + if (sys_access(fname, R_OK) != 0) { + return _gf_false; + } + return _gf_true; } - gf_boolean_t -gf_is_service_running (char *pidfile, int *pid) -{ - FILE *file = NULL; - gf_boolean_t running = _gf_false; - int ret = 0; - int fno = 0; - - file = fopen (pidfile, "r+"); - if (!file) { - goto out; - } - - fno = fileno (file); - ret = lockf (fno, F_TEST, 0); - if (ret == -1) { - running = _gf_true; - goto out; - } - - ret = fscanf (file, "%d", pid); - if (ret <= 0) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Unable to read pidfile: %s", pidfile); - *pid = -1; - } - - running = gf_is_pid_running (*pid); +gf_is_service_running(char *pidfile, int *pid) +{ + FILE *file = NULL; + gf_boolean_t running = _gf_false; + int ret = 0; + int fno = 0; + + file = fopen(pidfile, "r+"); + if (!file) { + goto out; + } + + fno = fileno(file); + ret = lockf(fno, F_TEST, 0); + if (ret == -1) { + running = _gf_true; + goto out; + } + + ret = fscanf(file, "%d", pid); + if (ret <= 0) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Unable to read pidfile: %s", pidfile); + *pid = -1; + } + + running = gf_is_pid_running(*pid); out: - if (file) - fclose (file); - return running; + if (file) + fclose(file); + return running; } /* Check if the pid is > 0 */ gf_boolean_t -gf_valid_pid (const char *pid, int length) +gf_valid_pid(const char *pid, int length) { - gf_boolean_t ret = _gf_true; - pid_t value = 0; - char *end_ptr = NULL; + gf_boolean_t ret = _gf_true; + pid_t value = 0; + char *end_ptr = NULL; - if (length <= 0) { - ret = _gf_false; - goto out; - } + if (length <= 0) { + ret = _gf_false; + goto out; + } - value = strtol (pid, &end_ptr, 10); - if (value <= 0) { - ret = _gf_false; - } + value = strtol(pid, &end_ptr, 10); + if (value <= 0) { + ret = _gf_false; + } out: - return ret; + return ret; } static int -dht_is_linkfile_key (dict_t *this, char *key, data_t *value, void *data) +dht_is_linkfile_key(dict_t *this, char *key, data_t *value, void *data) { - gf_boolean_t *linkfile_key_found = NULL; + gf_boolean_t *linkfile_key_found = NULL; - if (!data) - goto out; + if (!data) + goto out; - linkfile_key_found = data; + linkfile_key_found = data; - *linkfile_key_found = _gf_true; + *linkfile_key_found = _gf_true; out: - return 0; + return 0; } - gf_boolean_t -dht_is_linkfile (struct iatt *buf, dict_t *dict) +dht_is_linkfile(struct iatt *buf, dict_t *dict) { - gf_boolean_t linkfile_key_found = _gf_false; + gf_boolean_t linkfile_key_found = _gf_false; - if (!IS_DHT_LINKFILE_MODE (buf)) - return _gf_false; + if (!IS_DHT_LINKFILE_MODE(buf)) + return _gf_false; - dict_foreach_fnmatch (dict, "*."DHT_LINKFILE_STR, dht_is_linkfile_key, - &linkfile_key_found); + dict_foreach_fnmatch(dict, "*." DHT_LINKFILE_STR, dht_is_linkfile_key, + &linkfile_key_found); - return linkfile_key_found; + return linkfile_key_found; } int -gf_check_log_format (const char *value) +gf_check_log_format(const char *value) { - int log_format = -1; + int log_format = -1; - if (!strcasecmp (value, GF_LOG_FORMAT_NO_MSG_ID)) - log_format = gf_logformat_traditional; - else if (!strcasecmp (value, GF_LOG_FORMAT_WITH_MSG_ID)) - log_format = gf_logformat_withmsgid; + if (!strcasecmp(value, GF_LOG_FORMAT_NO_MSG_ID)) + log_format = gf_logformat_traditional; + else if (!strcasecmp(value, GF_LOG_FORMAT_WITH_MSG_ID)) + log_format = gf_logformat_withmsgid; - if (log_format == -1) - gf_msg (THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_LOG, - "Invalid log-format. possible values are " - GF_LOG_FORMAT_NO_MSG_ID "|" GF_LOG_FORMAT_WITH_MSG_ID); + if (log_format == -1) + gf_msg( + THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_LOG, + "Invalid log-format. possible values are " GF_LOG_FORMAT_NO_MSG_ID + "|" GF_LOG_FORMAT_WITH_MSG_ID); - return log_format; + return log_format; } int -gf_check_logger (const char *value) +gf_check_logger(const char *value) { - int logger = -1; + int logger = -1; - if (!strcasecmp (value, GF_LOGGER_GLUSTER_LOG)) - logger = gf_logger_glusterlog; - else if (!strcasecmp (value, GF_LOGGER_SYSLOG)) - logger = gf_logger_syslog; + if (!strcasecmp(value, GF_LOGGER_GLUSTER_LOG)) + logger = gf_logger_glusterlog; + else if (!strcasecmp(value, GF_LOGGER_SYSLOG)) + logger = gf_logger_syslog; - if (logger == -1) - gf_msg (THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_LOG, - "Invalid logger. possible values are " - GF_LOGGER_GLUSTER_LOG "|" GF_LOGGER_SYSLOG); + if (logger == -1) + gf_msg(THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_LOG, + "Invalid logger. possible values are " GF_LOGGER_GLUSTER_LOG + "|" GF_LOGGER_SYSLOG); - return logger; + return logger; } /* gf_compare_sockaddr compares the given addresses @addr1 and @addr2 for @@ -4187,30 +4172,28 @@ gf_check_logger (const char *value) * https://www.opensource.apple.com/source/postfix/postfix-197/postfix/src/util/sock_addr.c */ gf_boolean_t -gf_compare_sockaddr (const struct sockaddr *addr1, - const struct sockaddr *addr2) +gf_compare_sockaddr(const struct sockaddr *addr1, const struct sockaddr *addr2) { - GF_ASSERT (addr1 != NULL); - GF_ASSERT (addr2 != NULL); - - /* Obviously, the addresses don't match if their families are different - */ - if (addr1->sa_family != addr2->sa_family) - return _gf_false; + GF_ASSERT(addr1 != NULL); + GF_ASSERT(addr2 != NULL); + /* Obviously, the addresses don't match if their families are different + */ + if (addr1->sa_family != addr2->sa_family) + return _gf_false; - if (AF_INET == addr1->sa_family) { - if (((struct sockaddr_in *)addr1)->sin_addr.s_addr == - ((struct sockaddr_in *)addr2)->sin_addr.s_addr) - return _gf_true; + if (AF_INET == addr1->sa_family) { + if (((struct sockaddr_in *)addr1)->sin_addr.s_addr == + ((struct sockaddr_in *)addr2)->sin_addr.s_addr) + return _gf_true; - } else if (AF_INET6 == addr1->sa_family) { - if (memcmp ((char *)&((struct sockaddr_in6 *)addr1)->sin6_addr, - (char *)&((struct sockaddr_in6 *)addr2)->sin6_addr, - sizeof (struct in6_addr)) == 0) - return _gf_true; - } - return _gf_false; + } else if (AF_INET6 == addr1->sa_family) { + if (memcmp((char *)&((struct sockaddr_in6 *)addr1)->sin6_addr, + (char *)&((struct sockaddr_in6 *)addr2)->sin6_addr, + sizeof(struct in6_addr)) == 0) + return _gf_true; + } + return _gf_false; } /* @@ -4219,155 +4202,168 @@ gf_compare_sockaddr (const struct sockaddr *addr1, */ int -gf_set_timestamp (const char *src, const char* dest) +gf_set_timestamp(const char *src, const char *dest) { - struct stat sb = {0, }; + struct stat sb = { + 0, + }; #if defined(HAVE_UTIMENSAT) - struct timespec new_time[2] = { {0, }, {0, } }; + struct timespec new_time[2] = {{ + 0, + }, + { + 0, + }}; #else - struct timeval new_time[2] = { {0, }, {0, } }; + struct timeval new_time[2] = {{ + 0, + }, + { + 0, + }}; #endif - int ret = 0; - xlator_t *this = NULL; - - this = THIS; - GF_ASSERT (this); - GF_ASSERT (src); - GF_ASSERT (dest); - - ret = sys_stat (src, &sb); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, - LG_MSG_FILE_STAT_FAILED, "stat on %s", src); - goto out; - } - /* The granularity is nano seconds if `utimensat()` is available, - * and micro seconds otherwise. - */ + int ret = 0; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT(this); + GF_ASSERT(src); + GF_ASSERT(dest); + + ret = sys_stat(src, &sb); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, LG_MSG_FILE_STAT_FAILED, + "stat on %s", src); + goto out; + } + /* The granularity is nano seconds if `utimensat()` is available, + * and micro seconds otherwise. + */ #if defined(HAVE_UTIMENSAT) - new_time[0].tv_sec = sb.st_atime; - new_time[0].tv_nsec = ST_ATIM_NSEC (&sb); - - new_time[1].tv_sec = sb.st_mtime; - new_time[1].tv_nsec = ST_MTIM_NSEC (&sb); - - /* dirfd = 0 is ignored because `dest` is an absolute path. */ - ret = sys_utimensat (AT_FDCWD, dest, new_time, AT_SYMLINK_NOFOLLOW); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, - LG_MSG_UTIMENSAT_FAILED, "utimensat on %s", dest); - } + new_time[0].tv_sec = sb.st_atime; + new_time[0].tv_nsec = ST_ATIM_NSEC(&sb); + + new_time[1].tv_sec = sb.st_mtime; + new_time[1].tv_nsec = ST_MTIM_NSEC(&sb); + + /* dirfd = 0 is ignored because `dest` is an absolute path. */ + ret = sys_utimensat(AT_FDCWD, dest, new_time, AT_SYMLINK_NOFOLLOW); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, LG_MSG_UTIMENSAT_FAILED, + "utimensat on %s", dest); + } #else - new_time[0].tv_sec = sb.st_atime; - new_time[0].tv_usec = ST_ATIM_NSEC (&sb)/1000; + new_time[0].tv_sec = sb.st_atime; + new_time[0].tv_usec = ST_ATIM_NSEC(&sb) / 1000; - new_time[1].tv_sec = sb.st_mtime; - new_time[1].tv_usec = ST_MTIM_NSEC (&sb)/1000; + new_time[1].tv_sec = sb.st_mtime; + new_time[1].tv_usec = ST_MTIM_NSEC(&sb) / 1000; - ret = sys_utimes (dest, new_time); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_UTIMES_FAILED, - "utimes on %s", dest); - } + ret = sys_utimes(dest, new_time); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, LG_MSG_UTIMES_FAILED, + "utimes on %s", dest); + } #endif out: - return ret; + return ret; } static void -gf_backtrace_end (char *buf, size_t frames) +gf_backtrace_end(char *buf, size_t frames) { - size_t pos = 0; + size_t pos = 0; - if (!buf) - return; + if (!buf) + return; - pos = strlen (buf); + pos = strlen(buf); - frames = min(frames, GF_BACKTRACE_LEN - pos -1); + frames = min(frames, GF_BACKTRACE_LEN - pos - 1); - if (frames <= 0) - return; + if (frames <= 0) + return; - memset (buf+pos, ')', frames); - buf[pos+frames] = '\0'; + memset(buf + pos, ')', frames); + buf[pos + frames] = '\0'; } /*Returns bytes written*/ static int -gf_backtrace_append (char *buf, size_t pos, char *framestr) +gf_backtrace_append(char *buf, size_t pos, char *framestr) { - if (pos >= GF_BACKTRACE_LEN) - return -1; - return snprintf (buf+pos, GF_BACKTRACE_LEN-pos, "(--> %s ", framestr); + if (pos >= GF_BACKTRACE_LEN) + return -1; + return snprintf(buf + pos, GF_BACKTRACE_LEN - pos, "(--> %s ", framestr); } static int -gf_backtrace_fillframes (char *buf) -{ - void *array[GF_BACKTRACE_FRAME_COUNT]; - size_t frames = 0; - FILE *fp = NULL; - char callingfn[GF_BACKTRACE_FRAME_COUNT-2][1024] = {{0},}; - int ret = -1; - int fd = -1; - size_t idx = 0; - size_t pos = 0; - size_t inc = 0; - char tmpl[] = "/tmp/glfs-bt-XXXXXX"; - - frames = backtrace (array, GF_BACKTRACE_FRAME_COUNT); - if (!frames) - return -1; - - /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ - fd = mkstemp (tmpl); - if (fd == -1) - return -1; - - /* Calling unlink so that when the file is closed or program - * terminates the temporary file is deleted. - */ - ret = sys_unlink (tmpl); - if (ret < 0) { - gf_msg (THIS->name, GF_LOG_INFO, 0, LG_MSG_FILE_OP_FAILED, - "Unable to delete temporary file: %s", tmpl); - } - - /*The most recent two frames are the calling function and - * gf_backtrace_save, which we can infer.*/ - - backtrace_symbols_fd (&array[2], frames-2, fd); - - fp = fdopen (fd, "r"); - if (!fp) { - sys_close (fd); - ret = -1; - goto out; - } +gf_backtrace_fillframes(char *buf) +{ + void *array[GF_BACKTRACE_FRAME_COUNT]; + size_t frames = 0; + FILE *fp = NULL; + char callingfn[GF_BACKTRACE_FRAME_COUNT - 2][1024] = { + {0}, + }; + int ret = -1; + int fd = -1; + size_t idx = 0; + size_t pos = 0; + size_t inc = 0; + char tmpl[] = "/tmp/glfs-bt-XXXXXX"; + + frames = backtrace(array, GF_BACKTRACE_FRAME_COUNT); + if (!frames) + return -1; - ret = fseek (fp, 0L, SEEK_SET); - if (ret) - goto out; + /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ + fd = mkstemp(tmpl); + if (fd == -1) + return -1; - pos = 0; - for (idx = 0; idx < frames - 2; idx++) { - ret = fscanf (fp, "%s", callingfn[idx]); - if (ret == EOF) - break; - inc = gf_backtrace_append (buf, pos, callingfn[idx]); - if (inc == -1) - break; - pos += inc; - } - gf_backtrace_end (buf, idx); + /* Calling unlink so that when the file is closed or program + * terminates the temporary file is deleted. + */ + ret = sys_unlink(tmpl); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_INFO, 0, LG_MSG_FILE_OP_FAILED, + "Unable to delete temporary file: %s", tmpl); + } + + /*The most recent two frames are the calling function and + * gf_backtrace_save, which we can infer.*/ + + backtrace_symbols_fd(&array[2], frames - 2, fd); + + fp = fdopen(fd, "r"); + if (!fp) { + sys_close(fd); + ret = -1; + goto out; + } + + ret = fseek(fp, 0L, SEEK_SET); + if (ret) + goto out; + + pos = 0; + for (idx = 0; idx < frames - 2; idx++) { + ret = fscanf(fp, "%s", callingfn[idx]); + if (ret == EOF) + break; + inc = gf_backtrace_append(buf, pos, callingfn[idx]); + if (inc == -1) + break; + pos += inc; + } + gf_backtrace_end(buf, idx); out: - if (fp) - fclose (fp); - - return (idx > 0)? 0: -1; + if (fp) + fclose(fp); + return (idx > 0) ? 0 : -1; } /* Optionally takes @buf to save backtrace. If @buf is NULL, uses the @@ -4378,72 +4374,66 @@ out: * when there is a real-use for that.*/ char * -gf_backtrace_save (char *buf) +gf_backtrace_save(char *buf) { - char *bt = NULL; - - if (!buf) { - bt = THIS->ctx->btbuf; - GF_ASSERT (bt); + char *bt = NULL; - } else { - bt = buf; + if (!buf) { + bt = THIS->ctx->btbuf; + GF_ASSERT(bt); - } + } else { + bt = buf; + } - if ((0 == gf_backtrace_fillframes (bt))) - return bt; + if ((0 == gf_backtrace_fillframes(bt))) + return bt; - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_BACKTRACE_SAVE_FAILED, - "Failed to save the backtrace."); - return NULL; + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_BACKTRACE_SAVE_FAILED, + "Failed to save the backtrace."); + return NULL; } gf_loglevel_t -fop_log_level (glusterfs_fop_t fop, int op_errno) -{ - /* if gfid doesn't exist ESTALE comes */ - if (op_errno == ENOENT || op_errno == ESTALE) - return GF_LOG_DEBUG; - - if ((fop == GF_FOP_ENTRYLK) || - (fop == GF_FOP_FENTRYLK) || - (fop == GF_FOP_FINODELK) || - (fop == GF_FOP_INODELK) || - (fop == GF_FOP_LK)) { - /* - * if non-blocking lock fails EAGAIN comes - * if locks xlator is not loaded ENOSYS comes - */ - if (op_errno == EAGAIN || op_errno == ENOSYS) - return GF_LOG_DEBUG; - } +fop_log_level(glusterfs_fop_t fop, int op_errno) +{ + /* if gfid doesn't exist ESTALE comes */ + if (op_errno == ENOENT || op_errno == ESTALE) + return GF_LOG_DEBUG; - if ((fop == GF_FOP_GETXATTR) || - (fop == GF_FOP_FGETXATTR)) { - if (op_errno == ENOTSUP || op_errno == ENODATA) - return GF_LOG_DEBUG; - } + if ((fop == GF_FOP_ENTRYLK) || (fop == GF_FOP_FENTRYLK) || + (fop == GF_FOP_FINODELK) || (fop == GF_FOP_INODELK) || + (fop == GF_FOP_LK)) { + /* + * if non-blocking lock fails EAGAIN comes + * if locks xlator is not loaded ENOSYS comes + */ + if (op_errno == EAGAIN || op_errno == ENOSYS) + return GF_LOG_DEBUG; + } - if ((fop == GF_FOP_SETXATTR) || - (fop == GF_FOP_FSETXATTR) || - (fop == GF_FOP_REMOVEXATTR) || - (fop == GF_FOP_FREMOVEXATTR)) { - if (op_errno == ENOTSUP) - return GF_LOG_DEBUG; - } + if ((fop == GF_FOP_GETXATTR) || (fop == GF_FOP_FGETXATTR)) { + if (op_errno == ENOTSUP || op_errno == ENODATA) + return GF_LOG_DEBUG; + } + + if ((fop == GF_FOP_SETXATTR) || (fop == GF_FOP_FSETXATTR) || + (fop == GF_FOP_REMOVEXATTR) || (fop == GF_FOP_FREMOVEXATTR)) { + if (op_errno == ENOTSUP) + return GF_LOG_DEBUG; + } - if (fop == GF_FOP_MKNOD || fop == GF_FOP_MKDIR) - if (op_errno == EEXIST) - return GF_LOG_DEBUG; + if (fop == GF_FOP_MKNOD || fop == GF_FOP_MKDIR) + if (op_errno == EEXIST) + return GF_LOG_DEBUG; - if (fop == GF_FOP_SEEK) { - if (op_errno == ENXIO) { - return GF_LOG_DEBUG; - } + if (fop == GF_FOP_SEEK) { + if (op_errno == ENXIO) { + return GF_LOG_DEBUG; } + } - return GF_LOG_ERROR; + return GF_LOG_ERROR; } /* This function will build absolute path of file/directory from the @@ -4461,116 +4451,115 @@ fop_log_level (glusterfs_fop_t fop, int op_errno) */ int32_t -gf_build_absolute_path (char *current_path, char *relative_path, char **path) -{ - char *absolute_path = NULL; - char *token = NULL; - char *component = NULL; - char *saveptr = NULL; - char *end = NULL; - int ret = 0; - size_t relativepath_len = 0; - size_t currentpath_len = 0; - size_t max_absolutepath_len = 0; - - GF_ASSERT (current_path); - GF_ASSERT (relative_path); - GF_ASSERT (path); - - if (!path || !current_path || !relative_path) { - ret = -EFAULT; - goto err; - } - /* Check for current and relative path - * current path should be absolute one and start from '/' - * relative path should not start from '/' - */ - currentpath_len = strlen (current_path); - if (current_path[0] != '/' || (currentpath_len > PATH_MAX)) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, - "Wrong value for current path %s", current_path); - ret = -EINVAL; - goto err; - } - - relativepath_len = strlen (relative_path); - if (relative_path[0] == '/' || (relativepath_len > PATH_MAX)) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, - "Wrong value for relative path %s", relative_path); - ret = -EINVAL; +gf_build_absolute_path(char *current_path, char *relative_path, char **path) +{ + char *absolute_path = NULL; + char *token = NULL; + char *component = NULL; + char *saveptr = NULL; + char *end = NULL; + int ret = 0; + size_t relativepath_len = 0; + size_t currentpath_len = 0; + size_t max_absolutepath_len = 0; + + GF_ASSERT(current_path); + GF_ASSERT(relative_path); + GF_ASSERT(path); + + if (!path || !current_path || !relative_path) { + ret = -EFAULT; + goto err; + } + /* Check for current and relative path + * current path should be absolute one and start from '/' + * relative path should not start from '/' + */ + currentpath_len = strlen(current_path); + if (current_path[0] != '/' || (currentpath_len > PATH_MAX)) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Wrong value for current path %s", current_path); + ret = -EINVAL; + goto err; + } + + relativepath_len = strlen(relative_path); + if (relative_path[0] == '/' || (relativepath_len > PATH_MAX)) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Wrong value for relative path %s", relative_path); + ret = -EINVAL; + goto err; + } + + /* It is maximum possible value for absolute path */ + max_absolutepath_len = currentpath_len + relativepath_len + 2; + + absolute_path = GF_CALLOC(1, max_absolutepath_len, gf_common_mt_char); + if (!absolute_path) { + ret = -ENOMEM; + goto err; + } + absolute_path[0] = '\0'; + + /* If current path is root i.e contains only "/", we do not + * need to copy it + */ + if (strcmp(current_path, "/") != 0) { + strcpy(absolute_path, current_path); + + /* We trim '/' at the end for easier string manipulation */ + gf_path_strip_trailing_slashes(absolute_path); + } + + /* Used to spilt relative path based on '/' */ + component = gf_strdup(relative_path); + if (!component) { + ret = -ENOMEM; + goto err; + } + + /* In the relative path, we want to consider ".." and "." + * if token is ".." , we just need to reduce one level hierarchy + * if token is "." , we just ignore it + * if token is NULL , end of relative path + * if absolute path becomes '\0' and still "..", then it is a bad + * relative path, it points to out of boundary area and stop + * building the absolute path + * All other cases we just concatenate token to the absolute path + */ + for (token = strtok_r(component, "/", &saveptr), + end = strchr(absolute_path, '\0'); + token; token = strtok_r(NULL, "/", &saveptr)) { + if (strcmp(token, ".") == 0) + continue; + + else if (strcmp(token, "..") == 0) { + if (absolute_path[0] == '\0') { + ret = -EACCES; goto err; - } - - /* It is maximum possible value for absolute path */ - max_absolutepath_len = currentpath_len + relativepath_len + 2; - - absolute_path = GF_CALLOC (1, max_absolutepath_len, gf_common_mt_char); - if (!absolute_path) { - ret = -ENOMEM; - goto err; - } - absolute_path[0] = '\0'; - - /* If current path is root i.e contains only "/", we do not - * need to copy it - */ - if (strcmp (current_path, "/") != 0) { - strcpy (absolute_path, current_path); - - /* We trim '/' at the end for easier string manipulation */ - gf_path_strip_trailing_slashes (absolute_path); - } - - /* Used to spilt relative path based on '/' */ - component = gf_strdup (relative_path); - if (!component) { - ret = -ENOMEM; - goto err; - } + } - /* In the relative path, we want to consider ".." and "." - * if token is ".." , we just need to reduce one level hierarchy - * if token is "." , we just ignore it - * if token is NULL , end of relative path - * if absolute path becomes '\0' and still "..", then it is a bad - * relative path, it points to out of boundary area and stop - * building the absolute path - * All other cases we just concatenate token to the absolute path - */ - for (token = strtok_r (component, "/", &saveptr), - end = strchr (absolute_path, '\0'); token; - token = strtok_r (NULL, "/", &saveptr)) { - if (strcmp (token, ".") == 0) - continue; - - else if (strcmp (token, "..") == 0) { - - if (absolute_path[0] == '\0') { - ret = -EACCES; - goto err; - } - - end = strrchr (absolute_path, '/'); - *end = '\0'; - } else { - ret = snprintf (end, max_absolutepath_len - - strlen (absolute_path), "/%s", token); - end = strchr (absolute_path , '\0'); - } + end = strrchr(absolute_path, '/'); + *end = '\0'; + } else { + ret = snprintf(end, max_absolutepath_len - strlen(absolute_path), + "/%s", token); + end = strchr(absolute_path, '\0'); } + } - if (strlen (absolute_path) > PATH_MAX) { - ret = -EINVAL; - goto err; - } - *path = gf_strdup (absolute_path); + if (strlen(absolute_path) > PATH_MAX) { + ret = -EINVAL; + goto err; + } + *path = gf_strdup(absolute_path); err: - if (component) - GF_FREE (component); - if (absolute_path) - GF_FREE (absolute_path); - return ret; + if (component) + GF_FREE(component); + if (absolute_path) + GF_FREE(absolute_path); + return ret; } /* This is an utility function which will recursively delete @@ -4581,69 +4570,85 @@ err: * @return 0 on success and -1 on failure. */ int -recursive_rmdir (const char *delete_path) -{ - int ret = -1; - char path[PATH_MAX] = {0,}; - struct stat st = {0,}; - DIR *dir = NULL; - struct dirent *entry = NULL; - struct dirent scratch[2] = {{0,},}; - xlator_t *this = NULL; - - this = THIS; - GF_ASSERT (this); - GF_VALIDATE_OR_GOTO (this->name, delete_path, out); - - dir = sys_opendir (delete_path); - if (!dir) { - gf_msg_debug (this->name, 0, "Failed to open directory %s. " - "Reason : %s", delete_path, strerror (errno)); - ret = 0; - goto out; - } +recursive_rmdir(const char *delete_path) +{ + int ret = -1; + char path[PATH_MAX] = { + 0, + }; + struct stat st = { + 0, + }; + DIR *dir = NULL; + struct dirent *entry = NULL; + struct dirent scratch[2] = { + { + 0, + }, + }; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT(this); + GF_VALIDATE_OR_GOTO(this->name, delete_path, out); + + dir = sys_opendir(delete_path); + if (!dir) { + gf_msg_debug(this->name, 0, + "Failed to open directory %s. " + "Reason : %s", + delete_path, strerror(errno)); + ret = 0; + goto out; + } - GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch); - while (entry) { - snprintf (path, PATH_MAX, "%s/%s", delete_path, entry->d_name); - ret = sys_lstat (path, &st); - if (ret == -1) { - gf_msg_debug (this->name, 0, "Failed to stat entry %s :" - " %s", path, strerror (errno)); - (void) sys_closedir (dir); - goto out; - } - - if (S_ISDIR (st.st_mode)) - ret = recursive_rmdir (path); - else - ret = sys_unlink (path); - - if (ret) { - gf_msg_debug (this->name, 0, " Failed to remove %s. " - "Reason : %s", path, strerror (errno)); - } - - gf_msg_debug (this->name, 0, "%s %s", ret ? - "Failed to remove" : "Removed", entry->d_name); - - GF_SKIP_IRRELEVANT_ENTRIES (entry, dir, scratch); + GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); + while (entry) { + snprintf(path, PATH_MAX, "%s/%s", delete_path, entry->d_name); + ret = sys_lstat(path, &st); + if (ret == -1) { + gf_msg_debug(this->name, 0, + "Failed to stat entry %s :" + " %s", + path, strerror(errno)); + (void)sys_closedir(dir); + goto out; } - ret = sys_closedir (dir); - if (ret) { - gf_msg_debug (this->name, 0, "Failed to close dir %s. Reason :" - " %s", delete_path, strerror (errno)); - } + if (S_ISDIR(st.st_mode)) + ret = recursive_rmdir(path); + else + ret = sys_unlink(path); - ret = sys_rmdir (delete_path); if (ret) { - gf_msg_debug (this->name, 0, "Failed to rmdir: %s,err: %s", - delete_path, strerror (errno)); + gf_msg_debug(this->name, 0, + " Failed to remove %s. " + "Reason : %s", + path, strerror(errno)); } + gf_msg_debug(this->name, 0, "%s %s", + ret ? "Failed to remove" : "Removed", entry->d_name); + + GF_SKIP_IRRELEVANT_ENTRIES(entry, dir, scratch); + } + + ret = sys_closedir(dir); + if (ret) { + gf_msg_debug(this->name, 0, + "Failed to close dir %s. Reason :" + " %s", + delete_path, strerror(errno)); + } + + ret = sys_rmdir(delete_path); + if (ret) { + gf_msg_debug(this->name, 0, "Failed to rmdir: %s,err: %s", delete_path, + strerror(errno)); + } + out: - return ret; + return ret; } /* * Input: Array of strings 'array' terminating in NULL @@ -4652,197 +4657,198 @@ out: * Output: Index of the element in the array if found, '-1' otherwise */ int -gf_get_index_by_elem (char **array, char *elem) +gf_get_index_by_elem(char **array, char *elem) { - int i = 0; + int i = 0; - for (i = 0; array[i]; i++) { - if (strcmp (elem, array[i]) == 0) - return i; - } + for (i = 0; array[i]; i++) { + if (strcmp(elem, array[i]) == 0) + return i; + } - return -1; + return -1; } static int -get_pathinfo_host (char *pathinfo, char *hostname, size_t size) +get_pathinfo_host(char *pathinfo, char *hostname, size_t size) { - char *start = NULL; - char *end = NULL; - int ret = -1; - int i = 0; + char *start = NULL; + char *end = NULL; + int ret = -1; + int i = 0; - if (!pathinfo) - goto out; + if (!pathinfo) + goto out; - start = strchr (pathinfo, ':'); - if (!start) - goto out; + start = strchr(pathinfo, ':'); + if (!start) + goto out; - end = strrchr (pathinfo, ':'); - if (start == end) - goto out; + end = strrchr(pathinfo, ':'); + if (start == end) + goto out; - memset (hostname, 0, size); - i = 0; - while (++start != end) - hostname[i++] = *start; - ret = 0; + memset(hostname, 0, size); + i = 0; + while (++start != end) + hostname[i++] = *start; + ret = 0; out: - return ret; + return ret; } /*Note: 'pathinfo' should be gathered only from one brick*/ int -glusterfs_is_local_pathinfo (char *pathinfo, gf_boolean_t *is_local) +glusterfs_is_local_pathinfo(char *pathinfo, gf_boolean_t *is_local) { - int ret = 0; - char pathinfohost[1024] = {0}; - char localhost[1024] = {0}; + int ret = 0; + char pathinfohost[1024] = {0}; + char localhost[1024] = {0}; - *is_local = _gf_false; - ret = get_pathinfo_host (pathinfo, pathinfohost, sizeof (pathinfohost)); - if (ret) - goto out; + *is_local = _gf_false; + ret = get_pathinfo_host(pathinfo, pathinfohost, sizeof(pathinfohost)); + if (ret) + goto out; - ret = gethostname (localhost, sizeof (localhost)); - if (ret) - goto out; + ret = gethostname(localhost, sizeof(localhost)); + if (ret) + goto out; - if (!strcmp (localhost, pathinfohost)) - *is_local = _gf_true; + if (!strcmp(localhost, pathinfohost)) + *is_local = _gf_true; out: - return ret; + return ret; } ssize_t -gf_nread (int fd, void *buf, size_t count) -{ - ssize_t ret = 0; - ssize_t read_bytes = 0; - - for (read_bytes = 0; read_bytes < count; read_bytes += ret) { - ret = sys_read (fd, buf + read_bytes, count - read_bytes); - if (ret == 0) { - break; - } else if (ret < 0) { - if (errno == EINTR) - ret = 0; - else - goto out; - } +gf_nread(int fd, void *buf, size_t count) +{ + ssize_t ret = 0; + ssize_t read_bytes = 0; + + for (read_bytes = 0; read_bytes < count; read_bytes += ret) { + ret = sys_read(fd, buf + read_bytes, count - read_bytes); + if (ret == 0) { + break; + } else if (ret < 0) { + if (errno == EINTR) + ret = 0; + else + goto out; } + } - ret = read_bytes; + ret = read_bytes; out: - return ret; + return ret; } ssize_t -gf_nwrite (int fd, const void *buf, size_t count) -{ - ssize_t ret = 0; - ssize_t written = 0; - - for (written = 0; written != count; written += ret) { - ret = sys_write (fd, buf + written, count - written); - if (ret < 0) { - if (errno == EINTR) - ret = 0; - else - goto out; - } +gf_nwrite(int fd, const void *buf, size_t count) +{ + ssize_t ret = 0; + ssize_t written = 0; + + for (written = 0; written != count; written += ret) { + ret = sys_write(fd, buf + written, count - written); + if (ret < 0) { + if (errno == EINTR) + ret = 0; + else + goto out; } + } - ret = written; + ret = written; out: - return ret; + return ret; } void -gf_free_mig_locks (lock_migration_info_t *locks) +gf_free_mig_locks(lock_migration_info_t *locks) { - lock_migration_info_t *current = NULL; - lock_migration_info_t *temp = NULL; + lock_migration_info_t *current = NULL; + lock_migration_info_t *temp = NULL; - if (!locks) - return; + if (!locks) + return; - if (list_empty (&locks->list)) - return; + if (list_empty(&locks->list)) + return; - list_for_each_entry_safe (current, temp, &locks->list, list) { - list_del_init (¤t->list); - GF_FREE (current->client_uid); - GF_FREE (current); - } + list_for_each_entry_safe(current, temp, &locks->list, list) + { + list_del_init(¤t->list); + GF_FREE(current->client_uid); + GF_FREE(current); + } } void -_mask_cancellation (void) +_mask_cancellation(void) { - (void) pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); + (void)pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); } void -_unmask_cancellation (void) +_unmask_cancellation(void) { - (void) pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); + (void)pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); } /* This is a wrapper function to add a pointer to a list, * which doesn't contain list member */ -struct list_node* -_list_node_add (void *ptr, struct list_head *list, +struct list_node * +_list_node_add(void *ptr, struct list_head *list, int (*compare)(struct list_head *, struct list_head *)) { - struct list_node *node = NULL; + struct list_node *node = NULL; - if (ptr == NULL || list == NULL) - goto out; + if (ptr == NULL || list == NULL) + goto out; - node = GF_CALLOC (1, sizeof (struct list_node), gf_common_list_node); + node = GF_CALLOC(1, sizeof(struct list_node), gf_common_list_node); - if (node == NULL) - goto out; + if (node == NULL) + goto out; - node->ptr = ptr; - if (compare) - list_add_order (&node->list, list, compare); - else - list_add_tail (&node->list, list); + node->ptr = ptr; + if (compare) + list_add_order(&node->list, list, compare); + else + list_add_tail(&node->list, list); out: - return node; + return node; } -struct list_node* -list_node_add (void *ptr, struct list_head *list) +struct list_node * +list_node_add(void *ptr, struct list_head *list) { - return _list_node_add (ptr, list, NULL); + return _list_node_add(ptr, list, NULL); } -struct list_node* -list_node_add_order (void *ptr, struct list_head *list, - int (*compare)(struct list_head *, struct list_head *)) +struct list_node * +list_node_add_order(void *ptr, struct list_head *list, + int (*compare)(struct list_head *, struct list_head *)) { - return _list_node_add (ptr, list, compare); + return _list_node_add(ptr, list, compare); } void -list_node_del (struct list_node *node) +list_node_del(struct list_node *node) { - if (node == NULL) - return; + if (node == NULL) + return; - list_del_init (&node->list); - GF_FREE (node); + list_del_init(&node->list); + GF_FREE(node); } const char * -fop_enum_to_pri_string (glusterfs_fop_t fop) +fop_enum_to_pri_string(glusterfs_fop_t fop) { - switch (fop) { + switch (fop) { case GF_FOP_OPEN: case GF_FOP_STAT: case GF_FOP_FSTAT: @@ -4857,7 +4863,7 @@ fop_enum_to_pri_string (glusterfs_fop_t fop) case GF_FOP_SETACTIVELK: case GF_FOP_ICREATE: case GF_FOP_NAMELINK: - return "HIGH"; + return "HIGH"; case GF_FOP_CREATE: case GF_FOP_FLUSH: @@ -4883,7 +4889,7 @@ fop_enum_to_pri_string (glusterfs_fop_t fop) case GF_FOP_FREMOVEXATTR: case GF_FOP_IPC: case GF_FOP_LEASE: - return "NORMAL"; + return "NORMAL"; case GF_FOP_READ: case GF_FOP_WRITE: @@ -4897,7 +4903,7 @@ fop_enum_to_pri_string (glusterfs_fop_t fop) case GF_FOP_ZEROFILL: case GF_FOP_FALLOCATE: case GF_FOP_SEEK: - return "LOW"; + return "LOW"; case GF_FOP_NULL: case GF_FOP_FORGET: @@ -4906,187 +4912,184 @@ fop_enum_to_pri_string (glusterfs_fop_t fop) case GF_FOP_GETSPEC: case GF_FOP_MAXVALUE: case GF_FOP_DISCARD: - return "LEAST"; + return "LEAST"; default: - return "UNKNOWN"; - } + return "UNKNOWN"; + } } const char * -gf_inode_type_to_str (ia_type_t type) +gf_inode_type_to_str(ia_type_t type) { - static const char *const str_ia_type[] = { - "UNKNOWN", - "REGULAR FILE", - "DIRECTORY", - "LINK", - "BLOCK DEVICE", - "CHARACTER DEVICE", - "PIPE", - "SOCKET"}; - return str_ia_type[type]; + static const char *const str_ia_type[] = { + "UNKNOWN", "REGULAR FILE", "DIRECTORY", "LINK", + "BLOCK DEVICE", "CHARACTER DEVICE", "PIPE", "SOCKET"}; + return str_ia_type[type]; } gf_boolean_t -gf_is_zero_filled_stat (struct iatt *buf) +gf_is_zero_filled_stat(struct iatt *buf) { - if (!buf) - return 1; + if (!buf) + return 1; - /* Do not use st_dev because it is transformed to store the xlator id - * in place of the device number. Do not use st_ino because by this time - * we've already mapped the root ino to 1 so it is not guaranteed to be - * 0. - */ - if ((buf->ia_nlink == 0) && (buf->ia_ctime == 0)) - return 1; + /* Do not use st_dev because it is transformed to store the xlator id + * in place of the device number. Do not use st_ino because by this time + * we've already mapped the root ino to 1 so it is not guaranteed to be + * 0. + */ + if ((buf->ia_nlink == 0) && (buf->ia_ctime == 0)) + return 1; - return 0; + return 0; } void -gf_zero_fill_stat (struct iatt *buf) +gf_zero_fill_stat(struct iatt *buf) { - buf->ia_nlink = 0; - buf->ia_ctime = 0; + buf->ia_nlink = 0; + buf->ia_ctime = 0; } gf_boolean_t -gf_is_valid_xattr_namespace (char *key) +gf_is_valid_xattr_namespace(char *key) { - static char *xattr_namespaces[] = {"trusted.", "security.", "system.", - "user.", NULL }; - int i = 0; + static char *xattr_namespaces[] = {"trusted.", "security.", "system.", + "user.", NULL}; + int i = 0; - for (i = 0; xattr_namespaces[i]; i++) { - if (strncmp (key, xattr_namespaces[i], - strlen (xattr_namespaces[i])) == 0) - return _gf_true; - } + for (i = 0; xattr_namespaces[i]; i++) { + if (strncmp(key, xattr_namespaces[i], strlen(xattr_namespaces[i])) == 0) + return _gf_true; + } - return _gf_false; + return _gf_false; } ino_t -gfid_to_ino (uuid_t gfid) +gfid_to_ino(uuid_t gfid) { - ino_t ino = 0; - int32_t i; + ino_t ino = 0; + int32_t i; - for (i = 8; i < 16; i++) { - ino <<= 8; - ino += (uint8_t)gfid[i]; - } + for (i = 8; i < 16; i++) { + ino <<= 8; + ino += (uint8_t)gfid[i]; + } - return ino; + return ino; } int -gf_bits_count (uint64_t n) +gf_bits_count(uint64_t n) { - int val = 0; + int val = 0; #if defined(__GNUC__) || defined(__clang__) - val = __builtin_popcountll (n); + val = __builtin_popcountll(n); #else - n -= (n >> 1) & 0x5555555555555555ULL; - n = ((n >> 2) & 0x3333333333333333ULL) + (n & 0x3333333333333333ULL); - n = (n + (n >> 4)) & 0x0F0F0F0F0F0F0F0FULL; - n += n >> 8; - n += n >> 16; - n += n >> 32; - val = n & 0xFF; + n -= (n >> 1) & 0x5555555555555555ULL; + n = ((n >> 2) & 0x3333333333333333ULL) + (n & 0x3333333333333333ULL); + n = (n + (n >> 4)) & 0x0F0F0F0F0F0F0F0FULL; + n += n >> 8; + n += n >> 16; + n += n >> 32; + val = n & 0xFF; #endif - return val; + return val; } int -gf_bits_index (uint64_t n) +gf_bits_index(uint64_t n) { #if defined(__GNUC__) || defined(__clang__) - return __builtin_ffsll (n) - 1; + return __builtin_ffsll(n) - 1; #else - return ffsll (n) - 1; + return ffsll(n) - 1; #endif } -const char* -gf_fop_string (glusterfs_fop_t fop) +const char * +gf_fop_string(glusterfs_fop_t fop) { - if ((fop > GF_FOP_NULL) && (fop < GF_FOP_MAXVALUE)) - return gf_fop_list[fop]; - return "INVALID"; + if ((fop > GF_FOP_NULL) && (fop < GF_FOP_MAXVALUE)) + return gf_fop_list[fop]; + return "INVALID"; } int -gf_fop_int (char *fop) +gf_fop_int(char *fop) { - int i = 0; + int i = 0; - for (i = GF_FOP_NULL + 1; i < GF_FOP_MAXVALUE; i++) { - if (strcasecmp (fop, gf_fop_list[i]) == 0) - return i; - } - return -1; + for (i = GF_FOP_NULL + 1; i < GF_FOP_MAXVALUE; i++) { + if (strcasecmp(fop, gf_fop_list[i]) == 0) + return i; + } + return -1; } int -close_fds_except (int *fdv, size_t count) +close_fds_except(int *fdv, size_t count) { - int i = 0; - size_t j = 0; - gf_boolean_t should_close = _gf_true; + int i = 0; + size_t j = 0; + gf_boolean_t should_close = _gf_true; #ifdef GF_LINUX_HOST_OS - DIR *d = NULL; - struct dirent *de = NULL; - struct dirent scratch[2] = {{0,},}; - char *e = NULL; - - d = sys_opendir ("/proc/self/fd"); - if (!d) - return -1; - - for (;;) { - should_close = _gf_true; - - errno = 0; - de = sys_readdir (d, scratch); - if (!de || errno != 0) - break; - i = strtoul (de->d_name, &e, 10); - if (*e != '\0' || i == dirfd (d)) - continue; - - for (j = 0; j < count; j++) { - if (i == fdv[j]) { - should_close = _gf_false; - break; - } - } - if (should_close) - sys_close (i); - } - sys_closedir (d); -#else /* !GF_LINUX_HOST_OS */ - struct rlimit rl; - int ret = -1; + DIR *d = NULL; + struct dirent *de = NULL; + struct dirent scratch[2] = { + { + 0, + }, + }; + char *e = NULL; + + d = sys_opendir("/proc/self/fd"); + if (!d) + return -1; + + for (;;) { + should_close = _gf_true; - ret = getrlimit (RLIMIT_NOFILE, &rl); - if (ret) - return ret; - - for (i = 0; i < rl.rlim_cur; i++) { - should_close = _gf_true; - for (j = 0; j < count; j++) { - if (i == fdv[j]) { - should_close = _gf_false; - break; - } - } - if (should_close) - sys_close (i); + errno = 0; + de = sys_readdir(d, scratch); + if (!de || errno != 0) + break; + i = strtoul(de->d_name, &e, 10); + if (*e != '\0' || i == dirfd(d)) + continue; + + for (j = 0; j < count; j++) { + if (i == fdv[j]) { + should_close = _gf_false; + break; + } + } + if (should_close) + sys_close(i); + } + sys_closedir(d); +#else /* !GF_LINUX_HOST_OS */ + struct rlimit rl; + int ret = -1; + + ret = getrlimit(RLIMIT_NOFILE, &rl); + if (ret) + return ret; + + for (i = 0; i < rl.rlim_cur; i++) { + should_close = _gf_true; + for (j = 0; j < count; j++) { + if (i == fdv[j]) { + should_close = _gf_false; + break; + } } + if (should_close) + sys_close(i); + } #endif /* !GF_LINUX_HOST_OS */ - return 0; + return 0; } /** @@ -5106,105 +5109,129 @@ close_fds_except (int *fdv, size_t count) * failure: -1 */ int -gf_getgrouplist (const char *user, gid_t group, gid_t **groups) +gf_getgrouplist(const char *user, gid_t group, gid_t **groups) { - int ret = -1; - int ngroups = SMALL_GROUP_COUNT; + int ret = -1; + int ngroups = SMALL_GROUP_COUNT; - *groups = GF_CALLOC (sizeof (gid_t), ngroups, gf_common_mt_groups_t); - if (!*groups) - return -1; + *groups = GF_CALLOC(sizeof(gid_t), ngroups, gf_common_mt_groups_t); + if (!*groups) + return -1; - /* - * We are running getgrouplist() in a loop until we succeed (or hit - * certain exit conditions, see the comments below). This is because - * the indicated number of auxiliary groups that we obtain in case of - * the failure of the first invocation is not guaranteed to keep its - * validity upon the next invocation with a gid buffer of that size. - */ - for (;;) { - int ngroups_old = ngroups; - ret = getgrouplist (user, group, *groups, &ngroups); - if (ret != -1) - break; - - if (ngroups >= GF_MAX_AUX_GROUPS) { - /* - * This should not happen as GF_MAX_AUX_GROUPS is set - * to the max value of number of supported auxiliary - * groups across all platforms supported by GlusterFS. - * However, if it still happened some way, we wouldn't - * care about the incompleteness of the result, we'd - * just go on with what we got. - */ - return GF_MAX_AUX_GROUPS; - } else if (ngroups <= ngroups_old) { - /* - * There is an edge case that getgrouplist() fails but - * ngroups remains the same. This is actually not - * specified in getgrouplist(3), but implementations - * can do this upon internal failure[1]. To avoid - * falling into an infinite loop when this happens, we - * break the loop if the getgrouplist call failed - * without an increase in the indicated group number. - * - * [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=grp/initgroups.c;hb=refs/heads/release/2.25/master#l168 - */ - GF_FREE (*groups); - return -1; - } - - *groups = GF_REALLOC (*groups, ngroups * sizeof (gid_t)); - if (!*groups) - return -1; - } - return ret; + /* + * We are running getgrouplist() in a loop until we succeed (or hit + * certain exit conditions, see the comments below). This is because + * the indicated number of auxiliary groups that we obtain in case of + * the failure of the first invocation is not guaranteed to keep its + * validity upon the next invocation with a gid buffer of that size. + */ + for (;;) { + int ngroups_old = ngroups; + ret = getgrouplist(user, group, *groups, &ngroups); + if (ret != -1) + break; + + if (ngroups >= GF_MAX_AUX_GROUPS) { + /* + * This should not happen as GF_MAX_AUX_GROUPS is set + * to the max value of number of supported auxiliary + * groups across all platforms supported by GlusterFS. + * However, if it still happened some way, we wouldn't + * care about the incompleteness of the result, we'd + * just go on with what we got. + */ + return GF_MAX_AUX_GROUPS; + } else if (ngroups <= ngroups_old) { + /* + * There is an edge case that getgrouplist() fails but + * ngroups remains the same. This is actually not + * specified in getgrouplist(3), but implementations + * can do this upon internal failure[1]. To avoid + * falling into an infinite loop when this happens, we + * break the loop if the getgrouplist call failed + * without an increase in the indicated group number. + * + * [1] + * https://sourceware.org/git/?p=glibc.git;a=blob;f=grp/initgroups.c;hb=refs/heads/release/2.25/master#l168 + */ + GF_FREE(*groups); + return -1; + } + + *groups = GF_REALLOC(*groups, ngroups * sizeof(gid_t)); + if (!*groups) + return -1; + } + return ret; } int -glusterfs_compute_sha256 (const unsigned char *content, size_t size, - char *sha256_hash) { - SHA256_CTX sha256; +glusterfs_compute_sha256(const unsigned char *content, size_t size, + char *sha256_hash) +{ + SHA256_CTX sha256; - SHA256_Init (&sha256); - SHA256_Update (&sha256, (const unsigned char *) (content), size); - SHA256_Final ((unsigned char *) sha256_hash, &sha256); + SHA256_Init(&sha256); + SHA256_Update(&sha256, (const unsigned char *)(content), size); + SHA256_Final((unsigned char *)sha256_hash, &sha256); - return 0; + return 0; } -char* -get_struct_variable (int mem_num, gf_gsync_status_t *sts_val) -{ - switch (mem_num) { - case 0: return (sts_val->node); - case 1: return (sts_val->master); - case 2: return (sts_val->brick); - case 3: return (sts_val->slave_user); - case 4: return (sts_val->slave); - case 5: return (sts_val->slave_node); - case 6: return (sts_val->worker_status); - case 7: return (sts_val->crawl_status); - case 8: return (sts_val->last_synced); - case 9: return (sts_val->entry); - case 10: return (sts_val->data); - case 11: return (sts_val->meta); - case 12: return (sts_val->failures); - case 13: return (sts_val->checkpoint_time); - case 14: return (sts_val->checkpoint_completed); - case 15: return (sts_val->checkpoint_completion_time); - case 16: return (sts_val->brick_host_uuid); - case 17: return (sts_val->last_synced_utc); - case 18: return (sts_val->checkpoint_time_utc); - case 19: return (sts_val->checkpoint_completion_time_utc); - case 20: return (sts_val->slavekey); - case 21: return (sts_val->session_slave); +char * +get_struct_variable(int mem_num, gf_gsync_status_t *sts_val) +{ + switch (mem_num) { + case 0: + return (sts_val->node); + case 1: + return (sts_val->master); + case 2: + return (sts_val->brick); + case 3: + return (sts_val->slave_user); + case 4: + return (sts_val->slave); + case 5: + return (sts_val->slave_node); + case 6: + return (sts_val->worker_status); + case 7: + return (sts_val->crawl_status); + case 8: + return (sts_val->last_synced); + case 9: + return (sts_val->entry); + case 10: + return (sts_val->data); + case 11: + return (sts_val->meta); + case 12: + return (sts_val->failures); + case 13: + return (sts_val->checkpoint_time); + case 14: + return (sts_val->checkpoint_completed); + case 15: + return (sts_val->checkpoint_completion_time); + case 16: + return (sts_val->brick_host_uuid); + case 17: + return (sts_val->last_synced_utc); + case 18: + return (sts_val->checkpoint_time_utc); + case 19: + return (sts_val->checkpoint_completion_time_utc); + case 20: + return (sts_val->slavekey); + case 21: + return (sts_val->session_slave); default: - goto out; - } + goto out; + } out: - return NULL; + return NULL; } /* * Safe wrapper function for strncpy. @@ -5214,73 +5241,73 @@ out: */ char * -gf_strncpy (char *dest, const char *src, const size_t dest_size) +gf_strncpy(char *dest, const char *src, const size_t dest_size) { - strncpy (dest, src, dest_size - 1); - dest[dest_size - 1] = '\0'; - return dest; + strncpy(dest, src, dest_size - 1); + dest[dest_size - 1] = '\0'; + return dest; } int -gf_replace_old_iatt_in_dict (dict_t *xdata) +gf_replace_old_iatt_in_dict(dict_t *xdata) { - int ret; - struct old_iatt *o_iatt; /* old iatt structure */ - struct iatt *c_iatt; /* current iatt */ + int ret; + struct old_iatt *o_iatt; /* old iatt structure */ + struct iatt *c_iatt; /* current iatt */ - if (!xdata) { - return 0; - } + if (!xdata) { + return 0; + } - ret = dict_get_bin (xdata, DHT_IATT_IN_XDATA_KEY, (void **)&c_iatt); - if (ret < 0) { - return 0; - } + ret = dict_get_bin(xdata, DHT_IATT_IN_XDATA_KEY, (void **)&c_iatt); + if (ret < 0) { + return 0; + } - o_iatt = GF_CALLOC (1, sizeof (struct old_iatt), gf_common_mt_char); - if (!o_iatt) { - return -1; - } + o_iatt = GF_CALLOC(1, sizeof(struct old_iatt), gf_common_mt_char); + if (!o_iatt) { + return -1; + } - oldiatt_from_iatt (o_iatt, c_iatt); + oldiatt_from_iatt(o_iatt, c_iatt); - ret = dict_set_bin (xdata, DHT_IATT_IN_XDATA_KEY, o_iatt, - sizeof (struct old_iatt)); - if (ret) { - GF_FREE (o_iatt); - } + ret = dict_set_bin(xdata, DHT_IATT_IN_XDATA_KEY, o_iatt, + sizeof(struct old_iatt)); + if (ret) { + GF_FREE(o_iatt); + } - return ret; + return ret; } int -gf_replace_new_iatt_in_dict (dict_t *xdata) +gf_replace_new_iatt_in_dict(dict_t *xdata) { - int ret; - struct old_iatt *o_iatt; /* old iatt structure */ - struct iatt *c_iatt; /* new iatt */ + int ret; + struct old_iatt *o_iatt; /* old iatt structure */ + struct iatt *c_iatt; /* new iatt */ - if (!xdata) { - return 0; - } + if (!xdata) { + return 0; + } - ret = dict_get_bin (xdata, DHT_IATT_IN_XDATA_KEY, (void **)&o_iatt); - if (ret < 0) { - return 0; - } + ret = dict_get_bin(xdata, DHT_IATT_IN_XDATA_KEY, (void **)&o_iatt); + if (ret < 0) { + return 0; + } - c_iatt = GF_CALLOC (1, sizeof (struct iatt), gf_common_mt_char); - if (!c_iatt) { - return -1; - } + c_iatt = GF_CALLOC(1, sizeof(struct iatt), gf_common_mt_char); + if (!c_iatt) { + return -1; + } - iatt_from_oldiatt (c_iatt, o_iatt); + iatt_from_oldiatt(c_iatt, o_iatt); - ret = dict_set_bin (xdata, DHT_IATT_IN_XDATA_KEY, c_iatt, - sizeof (struct iatt)); - if (ret) { - GF_FREE (c_iatt); - } + ret = dict_set_bin(xdata, DHT_IATT_IN_XDATA_KEY, c_iatt, + sizeof(struct iatt)); + if (ret) { + GF_FREE(c_iatt); + } - return ret; + return ret; } diff --git a/libglusterfs/src/compat-errno.c b/libglusterfs/src/compat-errno.c index 3674596ad71..5051b75c772 100644 --- a/libglusterfs/src/compat-errno.c +++ b/libglusterfs/src/compat-errno.c @@ -12,7 +12,6 @@ #include "compat-errno.h" - static int32_t gf_error_to_errno_array[1024]; static int32_t gf_errno_to_error_array[1024]; @@ -20,912 +19,937 @@ static int32_t gf_compat_errno_init_done; #ifdef GF_SOLARIS_HOST_OS static void -init_compat_errno_arrays () +init_compat_errno_arrays() { -/* ENOMSG 35 / * No message of desired type */ - gf_error_to_errno_array[GF_ERROR_CODE_NOMSG] = ENOMSG; - gf_errno_to_error_array[ENOMSG] = GF_ERROR_CODE_NOMSG; - -/* EIDRM 36 / * Identifier removed */ - gf_error_to_errno_array[GF_ERROR_CODE_IDRM] = EIDRM; - gf_errno_to_error_array[EIDRM] = GF_ERROR_CODE_IDRM; - -/* ECHRNG 37 / * Channel number out of range */ - gf_error_to_errno_array[GF_ERROR_CODE_CHRNG] = ECHRNG; - gf_errno_to_error_array[ECHRNG] = GF_ERROR_CODE_CHRNG; - -/* EL2NSYNC 38 / * Level 2 not synchronized */ - gf_error_to_errno_array[GF_ERROR_CODE_L2NSYNC] = EL2NSYNC; - gf_errno_to_error_array[EL2NSYNC] = GF_ERROR_CODE_L2NSYNC; - -/* EL3HLT 39 / * Level 3 halted */ - gf_error_to_errno_array[GF_ERROR_CODE_L3HLT] = EL3HLT; - gf_errno_to_error_array[EL3HLT] = GF_ERROR_CODE_L3HLT; - -/* EL3RST 40 / * Level 3 reset */ - gf_error_to_errno_array[GF_ERROR_CODE_L3RST] = EL3RST; - gf_errno_to_error_array[EL3RST] = GF_ERROR_CODE_L3RST; - -/* ELNRNG 41 / * Link number out of range */ - gf_error_to_errno_array[GF_ERROR_CODE_LNRNG] = ELNRNG; - gf_errno_to_error_array[ELNRNG] = GF_ERROR_CODE_LNRNG; - -/* EUNATCH 42 / * Protocol driver not attached */ - gf_error_to_errno_array[GF_ERROR_CODE_UNATCH] = EUNATCH; - gf_errno_to_error_array[EUNATCH] = GF_ERROR_CODE_UNATCH; - -/* ENOCSI 43 / * No CSI structure available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOCSI] = ENOCSI; - gf_errno_to_error_array[ENOCSI] = GF_ERROR_CODE_NOCSI; - -/* EL2HLT 44 / * Level 2 halted */ - gf_error_to_errno_array[GF_ERROR_CODE_L2HLT] = EL2HLT; - gf_errno_to_error_array[EL2HLT] = GF_ERROR_CODE_L2HLT; - -/* EDEADLK 45 / * Deadlock condition. */ - gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLK; - gf_errno_to_error_array[EDEADLK] = GF_ERROR_CODE_DEADLK; - -/* ENOLCK 46 / * No record locks available. */ - gf_error_to_errno_array[GF_ERROR_CODE_NOLCK] = ENOLCK; - gf_errno_to_error_array[ENOLCK] = GF_ERROR_CODE_NOLCK; - -/* ECANCELED 47 / * Operation canceled */ - gf_error_to_errno_array[GF_ERROR_CODE_CANCELED] = ECANCELED; - gf_errno_to_error_array[ECANCELED] = GF_ERROR_CODE_CANCELED; - -/* ENOTSUP 48 / * Operation not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTSUPP] = ENOTSUP; - gf_errno_to_error_array[ENOTSUP] = GF_ERROR_CODE_NOTSUPP; - -/* Filesystem Quotas */ -/* EDQUOT 49 / * Disc quota exceeded */ - gf_error_to_errno_array[GF_ERROR_CODE_DQUOT] = EDQUOT; - gf_errno_to_error_array[EDQUOT] = GF_ERROR_CODE_DQUOT; - -/* Convergent Error Returns */ -/* EBADE 50 / * invalid exchange */ - gf_error_to_errno_array[GF_ERROR_CODE_BADE] = EBADE; - gf_errno_to_error_array[EBADE] = GF_ERROR_CODE_BADE; -/* EBADR 51 / * invalid request descriptor */ - gf_error_to_errno_array[GF_ERROR_CODE_BADR] = EBADR; - gf_errno_to_error_array[EBADR] = GF_ERROR_CODE_BADR; -/* EXFULL 52 / * exchange full */ - gf_error_to_errno_array[GF_ERROR_CODE_XFULL] = EXFULL; - gf_errno_to_error_array[EXFULL] = GF_ERROR_CODE_XFULL; -/* ENOANO 53 / * no anode */ - gf_error_to_errno_array[GF_ERROR_CODE_NOANO] = ENOANO; - gf_errno_to_error_array[ENOANO] = GF_ERROR_CODE_NOANO; -/* EBADRQC 54 / * invalid request code */ - gf_error_to_errno_array[GF_ERROR_CODE_BADRQC] = EBADRQC; - gf_errno_to_error_array[EBADRQC] = GF_ERROR_CODE_BADRQC; -/* EBADSLT 55 / * invalid slot */ - gf_error_to_errno_array[GF_ERROR_CODE_BADSLT] = EBADSLT; - gf_errno_to_error_array[EBADSLT] = GF_ERROR_CODE_BADSLT; -/* EDEADLOCK 56 / * file locking deadlock error */ -/* This is same as EDEADLK on linux */ - gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLOCK; - gf_errno_to_error_array[EDEADLOCK] = GF_ERROR_CODE_DEADLK; - -/* EBFONT 57 / * bad font file fmt */ - gf_error_to_errno_array[GF_ERROR_CODE_BFONT] = EBFONT; - gf_errno_to_error_array[EBFONT] = GF_ERROR_CODE_BFONT; - -/* Interprocess Robust Locks */ -/* EOWNERDEAD 58 / * process died with the lock */ - gf_error_to_errno_array[GF_ERROR_CODE_OWNERDEAD] = EOWNERDEAD; - gf_errno_to_error_array[EOWNERDEAD] = GF_ERROR_CODE_OWNERDEAD; -/* ENOTRECOVERABLE 59 / * lock is not recoverable */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTRECOVERABLE] = ENOTRECOVERABLE; - gf_errno_to_error_array[ENOTRECOVERABLE] = GF_ERROR_CODE_NOTRECOVERABLE; - -/* stream problems */ -/* ENOSTR 60 / * Device not a stream */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSTR] = ENOSTR; - gf_errno_to_error_array[ENOSTR] = GF_ERROR_CODE_NOSTR; -/* ENODATA 61 / * no data (for no delay io) */ - gf_error_to_errno_array[GF_ERROR_CODE_NODATA] = ENODATA; - gf_errno_to_error_array[ENODATA] = GF_ERROR_CODE_NODATA; -/* ETIME 62 / * timer expired */ - gf_error_to_errno_array[GF_ERROR_CODE_TIME] = ETIME; - gf_errno_to_error_array[ETIME] = GF_ERROR_CODE_TIME; -/* ENOSR 63 / * out of streams resources */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSR] = ENOSR; - gf_errno_to_error_array[ENOSR] = GF_ERROR_CODE_NOSR; - -/* ENONET 64 / * Machine is not on the network */ - gf_error_to_errno_array[GF_ERROR_CODE_NONET] = ENONET; - gf_errno_to_error_array[ENONET] = GF_ERROR_CODE_NONET; -/* ENOPKG 65 / * Package not installed */ - gf_error_to_errno_array[GF_ERROR_CODE_NOPKG] = ENOPKG; - gf_errno_to_error_array[ENOPKG] = GF_ERROR_CODE_NOPKG; -/* EREMOTE 66 / * The object is remote */ - gf_error_to_errno_array[GF_ERROR_CODE_REMOTE] = EREMOTE; - gf_errno_to_error_array[EREMOTE] = GF_ERROR_CODE_REMOTE; -/* ENOLINK 67 / * the link has been severed */ - gf_error_to_errno_array[GF_ERROR_CODE_NOLINK] = ENOLINK; - gf_errno_to_error_array[ENOLINK] = GF_ERROR_CODE_NOLINK; -/* EADV 68 / * advertise error */ - gf_error_to_errno_array[GF_ERROR_CODE_ADV] = EADV; - gf_errno_to_error_array[EADV] = GF_ERROR_CODE_ADV; -/* ESRMNT 69 / * srmount error */ - gf_error_to_errno_array[GF_ERROR_CODE_SRMNT] = ESRMNT; - gf_errno_to_error_array[ESRMNT] = GF_ERROR_CODE_SRMNT; - -/* ECOMM 70 / * Communication error on send */ - gf_error_to_errno_array[GF_ERROR_CODE_COMM] = ECOMM; - gf_errno_to_error_array[ECOMM] = GF_ERROR_CODE_COMM; -/* EPROTO 71 / * Protocol error */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTO] = EPROTO; - gf_errno_to_error_array[EPROTO] = GF_ERROR_CODE_PROTO; - -/* Interprocess Robust Locks */ -/* ELOCKUNMAPPED 72 / * locked lock was unmapped */ - gf_error_to_errno_array[GF_ERROR_CODE_LOCKUNMAPPED] = ELOCKUNMAPPED; - gf_errno_to_error_array[ELOCKUNMAPPED] = GF_ERROR_CODE_LOCKUNMAPPED; - -/* ENOTACTIVE 73 / * Facility is not active */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTACTIVE] = ENOTACTIVE; - gf_errno_to_error_array[ENOTACTIVE] = GF_ERROR_CODE_NOTACTIVE; -/* EMULTIHOP 74 / * multihop attempted */ - gf_error_to_errno_array[GF_ERROR_CODE_MULTIHOP] = EMULTIHOP; - gf_errno_to_error_array[EMULTIHOP] = GF_ERROR_CODE_MULTIHOP; -/* EBADMSG 77 / * trying to read unreadable message */ - gf_error_to_errno_array[GF_ERROR_CODE_BADMSG] = EBADMSG; - gf_errno_to_error_array[EBADMSG] = GF_ERROR_CODE_BADMSG; -/* ENAMETOOLONG 78 / * path name is too long */ - gf_error_to_errno_array[GF_ERROR_CODE_NAMETOOLONG] = ENAMETOOLONG; - gf_errno_to_error_array[ENAMETOOLONG] = GF_ERROR_CODE_NAMETOOLONG; -/* EOVERFLOW 79 / * value too large to be stored in data type */ - gf_error_to_errno_array[GF_ERROR_CODE_OVERFLOW] = EOVERFLOW; - gf_errno_to_error_array[EOVERFLOW] = GF_ERROR_CODE_OVERFLOW; -/* ENOTUNIQ 80 / * given log. name not unique */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTUNIQ] = ENOTUNIQ; - gf_errno_to_error_array[ENOTUNIQ] = GF_ERROR_CODE_NOTUNIQ; -/* EBADFD 81 / * f.d. invalid for this operation */ - gf_error_to_errno_array[GF_ERROR_CODE_BADFD] = EBADFD; - gf_errno_to_error_array[EBADFD] = GF_ERROR_CODE_BADFD; -/* EREMCHG 82 / * Remote address changed */ - gf_error_to_errno_array[GF_ERROR_CODE_REMCHG] = EREMCHG; - gf_errno_to_error_array[EREMCHG] = GF_ERROR_CODE_REMCHG; - -/* shared library problems */ -/* ELIBACC 83 / * Can't access a needed shared lib. */ - gf_error_to_errno_array[GF_ERROR_CODE_LIBACC] = ELIBACC; - gf_errno_to_error_array[ELIBACC] = GF_ERROR_CODE_LIBACC; -/* ELIBBAD 84 / * Accessing a corrupted shared lib. */ - gf_error_to_errno_array[GF_ERROR_CODE_LIBBAD] = ELIBBAD; - gf_errno_to_error_array[ELIBBAD] = GF_ERROR_CODE_LIBBAD; -/* ELIBSCN 85 / * .lib section in a.out corrupted. */ - gf_error_to_errno_array[GF_ERROR_CODE_LIBSCN] = ELIBSCN; - gf_errno_to_error_array[ELIBSCN] = GF_ERROR_CODE_LIBSCN; -/* ELIBMAX 86 / * Attempting to link in too many libs. */ - gf_error_to_errno_array[GF_ERROR_CODE_LIBMAX] = ELIBMAX; - gf_errno_to_error_array[ELIBMAX] = GF_ERROR_CODE_LIBMAX; -/* ELIBEXEC 87 / * Attempting to exec a shared library. */ - gf_error_to_errno_array[GF_ERROR_CODE_LIBEXEC] = ELIBEXEC; - gf_errno_to_error_array[ELIBEXEC] = GF_ERROR_CODE_LIBEXEC; -/* EILSEQ 88 / * Illegal byte sequence. */ - gf_error_to_errno_array[GF_ERROR_CODE_ILSEQ] = EILSEQ; - gf_errno_to_error_array[EILSEQ] = GF_ERROR_CODE_ILSEQ; -/* ENOSYS 89 / * Unsupported file system operation */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSYS] = ENOSYS; - gf_errno_to_error_array[ENOSYS] = GF_ERROR_CODE_NOSYS; -/* ELOOP 90 / * Symbolic link loop */ - gf_error_to_errno_array[GF_ERROR_CODE_LOOP] = ELOOP; - gf_errno_to_error_array[ELOOP] = GF_ERROR_CODE_LOOP; -/* ERESTART 91 / * Restartable system call */ - gf_error_to_errno_array[GF_ERROR_CODE_RESTART] = ERESTART; - gf_errno_to_error_array[ERESTART] = GF_ERROR_CODE_RESTART; -/* ESTRPIPE 92 / * if pipe/FIFO, don't sleep in stream head */ - gf_error_to_errno_array[GF_ERROR_CODE_STRPIPE] = ESTRPIPE; - gf_errno_to_error_array[ESTRPIPE] = GF_ERROR_CODE_STRPIPE; -/* ENOTEMPTY 93 / * directory not empty */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTEMPTY] = ENOTEMPTY; - gf_errno_to_error_array[ENOTEMPTY] = GF_ERROR_CODE_NOTEMPTY; -/* EUSERS 94 / * Too many users (for UFS) */ - gf_error_to_errno_array[GF_ERROR_CODE_USERS] = EUSERS; - gf_errno_to_error_array[EUSERS] = GF_ERROR_CODE_USERS; - -/* BSD Networking Software */ - /* argument errors */ -/* ENOTSOCK 95 / * Socket operation on non-socket */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTSOCK] = ENOTSOCK; - gf_errno_to_error_array[ENOTSOCK] = GF_ERROR_CODE_NOTSOCK; -/* EDESTADDRREQ 96 / * Destination address required */ - gf_error_to_errno_array[GF_ERROR_CODE_DESTADDRREQ] = EDESTADDRREQ; - gf_errno_to_error_array[EDESTADDRREQ] = GF_ERROR_CODE_DESTADDRREQ; -/* EMSGSIZE 97 / * Message too long */ - gf_error_to_errno_array[GF_ERROR_CODE_MSGSIZE] = EMSGSIZE; - gf_errno_to_error_array[EMSGSIZE] = GF_ERROR_CODE_MSGSIZE; -/* EPROTOTYPE 98 / * Protocol wrong type for socket */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTOTYPE] = EPROTOTYPE; - gf_errno_to_error_array[EPROTOTYPE] = GF_ERROR_CODE_PROTOTYPE; -/* ENOPROTOOPT 99 / * Protocol not available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOPROTOOPT] = ENOPROTOOPT; - gf_errno_to_error_array[ENOPROTOOPT] = GF_ERROR_CODE_NOPROTOOPT; -/* EPROTONOSUPPORT 120 / * Protocol not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTONOSUPPORT] = EPROTONOSUPPORT; - gf_errno_to_error_array[EPROTONOSUPPORT] = GF_ERROR_CODE_PROTONOSUPPORT; -/* ESOCKTNOSUPPORT 121 / * Socket type not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_SOCKTNOSUPPORT] = ESOCKTNOSUPPORT; - gf_errno_to_error_array[ESOCKTNOSUPPORT] = GF_ERROR_CODE_SOCKTNOSUPPORT; - -/* EOPNOTSUPP 122 / * Operation not supported on socket */ - gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; - gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; -/* EPFNOSUPPORT 123 / * Protocol family not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_PFNOSUPPORT] = EPFNOSUPPORT; - gf_errno_to_error_array[EPFNOSUPPORT] = GF_ERROR_CODE_PFNOSUPPORT; -/* EAFNOSUPPORT 124 / * Address family not supported by */ - /* protocol family */ - gf_error_to_errno_array[GF_ERROR_CODE_AFNOSUPPORT] = EAFNOSUPPORT; - gf_errno_to_error_array[EAFNOSUPPORT] = GF_ERROR_CODE_AFNOSUPPORT; -/* EADDRINUSE 125 / * Address already in use */ - gf_error_to_errno_array[GF_ERROR_CODE_ADDRINUSE] = EADDRINUSE; - gf_errno_to_error_array[EADDRINUSE] = GF_ERROR_CODE_ADDRINUSE; -/* EADDRNOTAVAIL 126 / * Can't assign requested address */ - /* operational errors */ - gf_error_to_errno_array[GF_ERROR_CODE_ADDRNOTAVAIL] = EADDRNOTAVAIL; - gf_errno_to_error_array[EADDRNOTAVAIL] = GF_ERROR_CODE_ADDRNOTAVAIL; -/* ENETDOWN 127 / * Network is down */ - gf_error_to_errno_array[GF_ERROR_CODE_NETDOWN] = ENETDOWN; - gf_errno_to_error_array[ENETDOWN] = GF_ERROR_CODE_NETDOWN; -/* ENETUNREACH 128 / * Network is unreachable */ - gf_error_to_errno_array[GF_ERROR_CODE_NETUNREACH] = ENETUNREACH; - gf_errno_to_error_array[ENETUNREACH] = GF_ERROR_CODE_NETUNREACH; -/* ENETRESET 129 / * Network dropped connection because */ - /* of reset */ - gf_error_to_errno_array[GF_ERROR_CODE_NETRESET] = ENETRESET; - gf_errno_to_error_array[ENETRESET] = GF_ERROR_CODE_NETRESET; -/* ECONNABORTED 130 / * Software caused connection abort */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNABORTED] = ECONNABORTED; - gf_errno_to_error_array[ECONNABORTED] = GF_ERROR_CODE_CONNABORTED; -/* ECONNRESET 131 / * Connection reset by peer */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNRESET] = ECONNRESET; - gf_errno_to_error_array[ECONNRESET] = GF_ERROR_CODE_CONNRESET; -/* ENOBUFS 132 / * No buffer space available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOBUFS] = ENOBUFS; - gf_errno_to_error_array[ENOBUFS] = GF_ERROR_CODE_NOBUFS; -/* EISCONN 133 / * Socket is already connected */ - gf_error_to_errno_array[GF_ERROR_CODE_ISCONN] = EISCONN; - gf_errno_to_error_array[EISCONN] = GF_ERROR_CODE_ISCONN; -/* ENOTCONN 134 / * Socket is not connected */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTCONN] = ENOTCONN; - gf_errno_to_error_array[ENOTCONN] = GF_ERROR_CODE_NOTCONN; -/* XENIX has 135 - 142 */ -/* ESHUTDOWN 143 / * Can't send after socket shutdown */ - gf_error_to_errno_array[GF_ERROR_CODE_SHUTDOWN] = ESHUTDOWN; - gf_errno_to_error_array[ESHUTDOWN] = GF_ERROR_CODE_SHUTDOWN; -/* ETOOMANYREFS 144 / * Too many references: can't splice */ - gf_error_to_errno_array[GF_ERROR_CODE_TOOMANYREFS] = ETOOMANYREFS; - gf_errno_to_error_array[ETOOMANYREFS] = GF_ERROR_CODE_TOOMANYREFS; -/* ETIMEDOUT 145 / * Connection timed out */ - gf_error_to_errno_array[GF_ERROR_CODE_TIMEDOUT] = ETIMEDOUT; - gf_errno_to_error_array[ETIMEDOUT] = GF_ERROR_CODE_TIMEDOUT; - -/* ECONNREFUSED 146 / * Connection refused */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNREFUSED] = ECONNREFUSED; - gf_errno_to_error_array[ECONNREFUSED] = GF_ERROR_CODE_CONNREFUSED; -/* EHOSTDOWN 147 / * Host is down */ - gf_error_to_errno_array[GF_ERROR_CODE_HOSTDOWN] = EHOSTDOWN; - gf_errno_to_error_array[EHOSTDOWN] = GF_ERROR_CODE_HOSTDOWN; -/* EHOSTUNREACH 148 / * No route to host */ - gf_error_to_errno_array[GF_ERROR_CODE_HOSTUNREACH] = EHOSTUNREACH; - gf_errno_to_error_array[EHOSTUNREACH] = GF_ERROR_CODE_HOSTUNREACH; -/* EALREADY 149 / * operation already in progress */ - gf_error_to_errno_array[GF_ERROR_CODE_ALREADY] = EALREADY; - gf_errno_to_error_array[EALREADY] = GF_ERROR_CODE_ALREADY; -/* EINPROGRESS 150 / * operation now in progress */ - gf_error_to_errno_array[GF_ERROR_CODE_INPROGRESS] = EINPROGRESS; - gf_errno_to_error_array[EINPROGRESS] = GF_ERROR_CODE_INPROGRESS; - -/* SUN Network File System */ -/* ESTALE 151 / * Stale NFS file handle */ - gf_error_to_errno_array[GF_ERROR_CODE_STALE] = ESTALE; - gf_errno_to_error_array[ESTALE] = GF_ERROR_CODE_STALE; - - return ; + /* ENOMSG 35 / * No message of desired type */ + gf_error_to_errno_array[GF_ERROR_CODE_NOMSG] = ENOMSG; + gf_errno_to_error_array[ENOMSG] = GF_ERROR_CODE_NOMSG; + + /* EIDRM 36 / * Identifier removed */ + gf_error_to_errno_array[GF_ERROR_CODE_IDRM] = EIDRM; + gf_errno_to_error_array[EIDRM] = GF_ERROR_CODE_IDRM; + + /* ECHRNG 37 / * Channel number out of range */ + gf_error_to_errno_array[GF_ERROR_CODE_CHRNG] = ECHRNG; + gf_errno_to_error_array[ECHRNG] = GF_ERROR_CODE_CHRNG; + + /* EL2NSYNC 38 / * Level 2 not synchronized */ + gf_error_to_errno_array[GF_ERROR_CODE_L2NSYNC] = EL2NSYNC; + gf_errno_to_error_array[EL2NSYNC] = GF_ERROR_CODE_L2NSYNC; + + /* EL3HLT 39 / * Level 3 halted */ + gf_error_to_errno_array[GF_ERROR_CODE_L3HLT] = EL3HLT; + gf_errno_to_error_array[EL3HLT] = GF_ERROR_CODE_L3HLT; + + /* EL3RST 40 / * Level 3 reset */ + gf_error_to_errno_array[GF_ERROR_CODE_L3RST] = EL3RST; + gf_errno_to_error_array[EL3RST] = GF_ERROR_CODE_L3RST; + + /* ELNRNG 41 / * Link number out of range */ + gf_error_to_errno_array[GF_ERROR_CODE_LNRNG] = ELNRNG; + gf_errno_to_error_array[ELNRNG] = GF_ERROR_CODE_LNRNG; + + /* EUNATCH 42 / * Protocol driver not attached */ + gf_error_to_errno_array[GF_ERROR_CODE_UNATCH] = EUNATCH; + gf_errno_to_error_array[EUNATCH] = GF_ERROR_CODE_UNATCH; + + /* ENOCSI 43 / * No CSI structure available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOCSI] = ENOCSI; + gf_errno_to_error_array[ENOCSI] = GF_ERROR_CODE_NOCSI; + + /* EL2HLT 44 / * Level 2 halted */ + gf_error_to_errno_array[GF_ERROR_CODE_L2HLT] = EL2HLT; + gf_errno_to_error_array[EL2HLT] = GF_ERROR_CODE_L2HLT; + + /* EDEADLK 45 / * Deadlock condition. */ + gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLK; + gf_errno_to_error_array[EDEADLK] = GF_ERROR_CODE_DEADLK; + + /* ENOLCK 46 / * No record locks available. */ + gf_error_to_errno_array[GF_ERROR_CODE_NOLCK] = ENOLCK; + gf_errno_to_error_array[ENOLCK] = GF_ERROR_CODE_NOLCK; + + /* ECANCELED 47 / * Operation canceled */ + gf_error_to_errno_array[GF_ERROR_CODE_CANCELED] = ECANCELED; + gf_errno_to_error_array[ECANCELED] = GF_ERROR_CODE_CANCELED; + + /* ENOTSUP 48 / * Operation not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTSUPP] = ENOTSUP; + gf_errno_to_error_array[ENOTSUP] = GF_ERROR_CODE_NOTSUPP; + + /* Filesystem Quotas */ + /* EDQUOT 49 / * Disc quota exceeded */ + gf_error_to_errno_array[GF_ERROR_CODE_DQUOT] = EDQUOT; + gf_errno_to_error_array[EDQUOT] = GF_ERROR_CODE_DQUOT; + + /* Convergent Error Returns */ + /* EBADE 50 / * invalid exchange */ + gf_error_to_errno_array[GF_ERROR_CODE_BADE] = EBADE; + gf_errno_to_error_array[EBADE] = GF_ERROR_CODE_BADE; + /* EBADR 51 / * invalid request descriptor */ + gf_error_to_errno_array[GF_ERROR_CODE_BADR] = EBADR; + gf_errno_to_error_array[EBADR] = GF_ERROR_CODE_BADR; + /* EXFULL 52 / * exchange full */ + gf_error_to_errno_array[GF_ERROR_CODE_XFULL] = EXFULL; + gf_errno_to_error_array[EXFULL] = GF_ERROR_CODE_XFULL; + /* ENOANO 53 / * no anode */ + gf_error_to_errno_array[GF_ERROR_CODE_NOANO] = ENOANO; + gf_errno_to_error_array[ENOANO] = GF_ERROR_CODE_NOANO; + /* EBADRQC 54 / * invalid request code */ + gf_error_to_errno_array[GF_ERROR_CODE_BADRQC] = EBADRQC; + gf_errno_to_error_array[EBADRQC] = GF_ERROR_CODE_BADRQC; + /* EBADSLT 55 / * invalid slot */ + gf_error_to_errno_array[GF_ERROR_CODE_BADSLT] = EBADSLT; + gf_errno_to_error_array[EBADSLT] = GF_ERROR_CODE_BADSLT; + /* EDEADLOCK 56 / * file locking deadlock error */ + /* This is same as EDEADLK on linux */ + gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLOCK; + gf_errno_to_error_array[EDEADLOCK] = GF_ERROR_CODE_DEADLK; + + /* EBFONT 57 / * bad font file fmt */ + gf_error_to_errno_array[GF_ERROR_CODE_BFONT] = EBFONT; + gf_errno_to_error_array[EBFONT] = GF_ERROR_CODE_BFONT; + + /* Interprocess Robust Locks */ + /* EOWNERDEAD 58 / * process died with the lock */ + gf_error_to_errno_array[GF_ERROR_CODE_OWNERDEAD] = EOWNERDEAD; + gf_errno_to_error_array[EOWNERDEAD] = GF_ERROR_CODE_OWNERDEAD; + /* ENOTRECOVERABLE 59 / * lock is not recoverable */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTRECOVERABLE] = ENOTRECOVERABLE; + gf_errno_to_error_array[ENOTRECOVERABLE] = GF_ERROR_CODE_NOTRECOVERABLE; + + /* stream problems */ + /* ENOSTR 60 / * Device not a stream */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSTR] = ENOSTR; + gf_errno_to_error_array[ENOSTR] = GF_ERROR_CODE_NOSTR; + /* ENODATA 61 / * no data (for no delay io) */ + gf_error_to_errno_array[GF_ERROR_CODE_NODATA] = ENODATA; + gf_errno_to_error_array[ENODATA] = GF_ERROR_CODE_NODATA; + /* ETIME 62 / * timer expired */ + gf_error_to_errno_array[GF_ERROR_CODE_TIME] = ETIME; + gf_errno_to_error_array[ETIME] = GF_ERROR_CODE_TIME; + /* ENOSR 63 / * out of streams resources */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSR] = ENOSR; + gf_errno_to_error_array[ENOSR] = GF_ERROR_CODE_NOSR; + + /* ENONET 64 / * Machine is not on the network */ + gf_error_to_errno_array[GF_ERROR_CODE_NONET] = ENONET; + gf_errno_to_error_array[ENONET] = GF_ERROR_CODE_NONET; + /* ENOPKG 65 / * Package not installed */ + gf_error_to_errno_array[GF_ERROR_CODE_NOPKG] = ENOPKG; + gf_errno_to_error_array[ENOPKG] = GF_ERROR_CODE_NOPKG; + /* EREMOTE 66 / * The object is remote */ + gf_error_to_errno_array[GF_ERROR_CODE_REMOTE] = EREMOTE; + gf_errno_to_error_array[EREMOTE] = GF_ERROR_CODE_REMOTE; + /* ENOLINK 67 / * the link has been severed */ + gf_error_to_errno_array[GF_ERROR_CODE_NOLINK] = ENOLINK; + gf_errno_to_error_array[ENOLINK] = GF_ERROR_CODE_NOLINK; + /* EADV 68 / * advertise error */ + gf_error_to_errno_array[GF_ERROR_CODE_ADV] = EADV; + gf_errno_to_error_array[EADV] = GF_ERROR_CODE_ADV; + /* ESRMNT 69 / * srmount error */ + gf_error_to_errno_array[GF_ERROR_CODE_SRMNT] = ESRMNT; + gf_errno_to_error_array[ESRMNT] = GF_ERROR_CODE_SRMNT; + + /* ECOMM 70 / * Communication error on send */ + gf_error_to_errno_array[GF_ERROR_CODE_COMM] = ECOMM; + gf_errno_to_error_array[ECOMM] = GF_ERROR_CODE_COMM; + /* EPROTO 71 / * Protocol error */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTO] = EPROTO; + gf_errno_to_error_array[EPROTO] = GF_ERROR_CODE_PROTO; + + /* Interprocess Robust Locks */ + /* ELOCKUNMAPPED 72 / * locked lock was unmapped */ + gf_error_to_errno_array[GF_ERROR_CODE_LOCKUNMAPPED] = ELOCKUNMAPPED; + gf_errno_to_error_array[ELOCKUNMAPPED] = GF_ERROR_CODE_LOCKUNMAPPED; + + /* ENOTACTIVE 73 / * Facility is not active */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTACTIVE] = ENOTACTIVE; + gf_errno_to_error_array[ENOTACTIVE] = GF_ERROR_CODE_NOTACTIVE; + /* EMULTIHOP 74 / * multihop attempted */ + gf_error_to_errno_array[GF_ERROR_CODE_MULTIHOP] = EMULTIHOP; + gf_errno_to_error_array[EMULTIHOP] = GF_ERROR_CODE_MULTIHOP; + /* EBADMSG 77 / * trying to read unreadable message */ + gf_error_to_errno_array[GF_ERROR_CODE_BADMSG] = EBADMSG; + gf_errno_to_error_array[EBADMSG] = GF_ERROR_CODE_BADMSG; + /* ENAMETOOLONG 78 / * path name is too long */ + gf_error_to_errno_array[GF_ERROR_CODE_NAMETOOLONG] = ENAMETOOLONG; + gf_errno_to_error_array[ENAMETOOLONG] = GF_ERROR_CODE_NAMETOOLONG; + /* EOVERFLOW 79 / * value too large to be stored in data type */ + gf_error_to_errno_array[GF_ERROR_CODE_OVERFLOW] = EOVERFLOW; + gf_errno_to_error_array[EOVERFLOW] = GF_ERROR_CODE_OVERFLOW; + /* ENOTUNIQ 80 / * given log. name not unique */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTUNIQ] = ENOTUNIQ; + gf_errno_to_error_array[ENOTUNIQ] = GF_ERROR_CODE_NOTUNIQ; + /* EBADFD 81 / * f.d. invalid for this operation */ + gf_error_to_errno_array[GF_ERROR_CODE_BADFD] = EBADFD; + gf_errno_to_error_array[EBADFD] = GF_ERROR_CODE_BADFD; + /* EREMCHG 82 / * Remote address changed */ + gf_error_to_errno_array[GF_ERROR_CODE_REMCHG] = EREMCHG; + gf_errno_to_error_array[EREMCHG] = GF_ERROR_CODE_REMCHG; + + /* shared library problems */ + /* ELIBACC 83 / * Can't access a needed shared lib. */ + gf_error_to_errno_array[GF_ERROR_CODE_LIBACC] = ELIBACC; + gf_errno_to_error_array[ELIBACC] = GF_ERROR_CODE_LIBACC; + /* ELIBBAD 84 / * Accessing a corrupted shared lib. */ + gf_error_to_errno_array[GF_ERROR_CODE_LIBBAD] = ELIBBAD; + gf_errno_to_error_array[ELIBBAD] = GF_ERROR_CODE_LIBBAD; + /* ELIBSCN 85 / * .lib section in a.out corrupted. */ + gf_error_to_errno_array[GF_ERROR_CODE_LIBSCN] = ELIBSCN; + gf_errno_to_error_array[ELIBSCN] = GF_ERROR_CODE_LIBSCN; + /* ELIBMAX 86 / * Attempting to link in too many libs. */ + gf_error_to_errno_array[GF_ERROR_CODE_LIBMAX] = ELIBMAX; + gf_errno_to_error_array[ELIBMAX] = GF_ERROR_CODE_LIBMAX; + /* ELIBEXEC 87 / * Attempting to exec a shared library. */ + gf_error_to_errno_array[GF_ERROR_CODE_LIBEXEC] = ELIBEXEC; + gf_errno_to_error_array[ELIBEXEC] = GF_ERROR_CODE_LIBEXEC; + /* EILSEQ 88 / * Illegal byte sequence. */ + gf_error_to_errno_array[GF_ERROR_CODE_ILSEQ] = EILSEQ; + gf_errno_to_error_array[EILSEQ] = GF_ERROR_CODE_ILSEQ; + /* ENOSYS 89 / * Unsupported file system operation */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSYS] = ENOSYS; + gf_errno_to_error_array[ENOSYS] = GF_ERROR_CODE_NOSYS; + /* ELOOP 90 / * Symbolic link loop */ + gf_error_to_errno_array[GF_ERROR_CODE_LOOP] = ELOOP; + gf_errno_to_error_array[ELOOP] = GF_ERROR_CODE_LOOP; + /* ERESTART 91 / * Restartable system call */ + gf_error_to_errno_array[GF_ERROR_CODE_RESTART] = ERESTART; + gf_errno_to_error_array[ERESTART] = GF_ERROR_CODE_RESTART; + /* ESTRPIPE 92 / * if pipe/FIFO, don't sleep in stream head */ + gf_error_to_errno_array[GF_ERROR_CODE_STRPIPE] = ESTRPIPE; + gf_errno_to_error_array[ESTRPIPE] = GF_ERROR_CODE_STRPIPE; + /* ENOTEMPTY 93 / * directory not empty */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTEMPTY] = ENOTEMPTY; + gf_errno_to_error_array[ENOTEMPTY] = GF_ERROR_CODE_NOTEMPTY; + /* EUSERS 94 / * Too many users (for UFS) */ + gf_error_to_errno_array[GF_ERROR_CODE_USERS] = EUSERS; + gf_errno_to_error_array[EUSERS] = GF_ERROR_CODE_USERS; + + /* BSD Networking Software */ + /* argument errors */ + /* ENOTSOCK 95 / * Socket operation on non-socket */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTSOCK] = ENOTSOCK; + gf_errno_to_error_array[ENOTSOCK] = GF_ERROR_CODE_NOTSOCK; + /* EDESTADDRREQ 96 / * Destination address required */ + gf_error_to_errno_array[GF_ERROR_CODE_DESTADDRREQ] = EDESTADDRREQ; + gf_errno_to_error_array[EDESTADDRREQ] = GF_ERROR_CODE_DESTADDRREQ; + /* EMSGSIZE 97 / * Message too long */ + gf_error_to_errno_array[GF_ERROR_CODE_MSGSIZE] = EMSGSIZE; + gf_errno_to_error_array[EMSGSIZE] = GF_ERROR_CODE_MSGSIZE; + /* EPROTOTYPE 98 / * Protocol wrong type for socket */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTOTYPE] = EPROTOTYPE; + gf_errno_to_error_array[EPROTOTYPE] = GF_ERROR_CODE_PROTOTYPE; + /* ENOPROTOOPT 99 / * Protocol not available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOPROTOOPT] = ENOPROTOOPT; + gf_errno_to_error_array[ENOPROTOOPT] = GF_ERROR_CODE_NOPROTOOPT; + /* EPROTONOSUPPORT 120 / * Protocol not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTONOSUPPORT] = EPROTONOSUPPORT; + gf_errno_to_error_array[EPROTONOSUPPORT] = GF_ERROR_CODE_PROTONOSUPPORT; + /* ESOCKTNOSUPPORT 121 / * Socket type not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_SOCKTNOSUPPORT] = ESOCKTNOSUPPORT; + gf_errno_to_error_array[ESOCKTNOSUPPORT] = GF_ERROR_CODE_SOCKTNOSUPPORT; + + /* EOPNOTSUPP 122 / * Operation not supported on socket */ + gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; + gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; + /* EPFNOSUPPORT 123 / * Protocol family not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_PFNOSUPPORT] = EPFNOSUPPORT; + gf_errno_to_error_array[EPFNOSUPPORT] = GF_ERROR_CODE_PFNOSUPPORT; + /* EAFNOSUPPORT 124 / * Address family not supported by */ + /* protocol family */ + gf_error_to_errno_array[GF_ERROR_CODE_AFNOSUPPORT] = EAFNOSUPPORT; + gf_errno_to_error_array[EAFNOSUPPORT] = GF_ERROR_CODE_AFNOSUPPORT; + /* EADDRINUSE 125 / * Address already in use */ + gf_error_to_errno_array[GF_ERROR_CODE_ADDRINUSE] = EADDRINUSE; + gf_errno_to_error_array[EADDRINUSE] = GF_ERROR_CODE_ADDRINUSE; + /* EADDRNOTAVAIL 126 / * Can't assign requested address */ + /* operational errors */ + gf_error_to_errno_array[GF_ERROR_CODE_ADDRNOTAVAIL] = EADDRNOTAVAIL; + gf_errno_to_error_array[EADDRNOTAVAIL] = GF_ERROR_CODE_ADDRNOTAVAIL; + /* ENETDOWN 127 / * Network is down */ + gf_error_to_errno_array[GF_ERROR_CODE_NETDOWN] = ENETDOWN; + gf_errno_to_error_array[ENETDOWN] = GF_ERROR_CODE_NETDOWN; + /* ENETUNREACH 128 / * Network is unreachable */ + gf_error_to_errno_array[GF_ERROR_CODE_NETUNREACH] = ENETUNREACH; + gf_errno_to_error_array[ENETUNREACH] = GF_ERROR_CODE_NETUNREACH; + /* ENETRESET 129 / * Network dropped connection because */ + /* of reset */ + gf_error_to_errno_array[GF_ERROR_CODE_NETRESET] = ENETRESET; + gf_errno_to_error_array[ENETRESET] = GF_ERROR_CODE_NETRESET; + /* ECONNABORTED 130 / * Software caused connection abort */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNABORTED] = ECONNABORTED; + gf_errno_to_error_array[ECONNABORTED] = GF_ERROR_CODE_CONNABORTED; + /* ECONNRESET 131 / * Connection reset by peer */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNRESET] = ECONNRESET; + gf_errno_to_error_array[ECONNRESET] = GF_ERROR_CODE_CONNRESET; + /* ENOBUFS 132 / * No buffer space available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOBUFS] = ENOBUFS; + gf_errno_to_error_array[ENOBUFS] = GF_ERROR_CODE_NOBUFS; + /* EISCONN 133 / * Socket is already connected */ + gf_error_to_errno_array[GF_ERROR_CODE_ISCONN] = EISCONN; + gf_errno_to_error_array[EISCONN] = GF_ERROR_CODE_ISCONN; + /* ENOTCONN 134 / * Socket is not connected */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTCONN] = ENOTCONN; + gf_errno_to_error_array[ENOTCONN] = GF_ERROR_CODE_NOTCONN; + /* XENIX has 135 - 142 */ + /* ESHUTDOWN 143 / * Can't send after socket shutdown */ + gf_error_to_errno_array[GF_ERROR_CODE_SHUTDOWN] = ESHUTDOWN; + gf_errno_to_error_array[ESHUTDOWN] = GF_ERROR_CODE_SHUTDOWN; + /* ETOOMANYREFS 144 / * Too many references: can't splice */ + gf_error_to_errno_array[GF_ERROR_CODE_TOOMANYREFS] = ETOOMANYREFS; + gf_errno_to_error_array[ETOOMANYREFS] = GF_ERROR_CODE_TOOMANYREFS; + /* ETIMEDOUT 145 / * Connection timed out */ + gf_error_to_errno_array[GF_ERROR_CODE_TIMEDOUT] = ETIMEDOUT; + gf_errno_to_error_array[ETIMEDOUT] = GF_ERROR_CODE_TIMEDOUT; + + /* ECONNREFUSED 146 / * Connection refused */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNREFUSED] = ECONNREFUSED; + gf_errno_to_error_array[ECONNREFUSED] = GF_ERROR_CODE_CONNREFUSED; + /* EHOSTDOWN 147 / * Host is down */ + gf_error_to_errno_array[GF_ERROR_CODE_HOSTDOWN] = EHOSTDOWN; + gf_errno_to_error_array[EHOSTDOWN] = GF_ERROR_CODE_HOSTDOWN; + /* EHOSTUNREACH 148 / * No route to host */ + gf_error_to_errno_array[GF_ERROR_CODE_HOSTUNREACH] = EHOSTUNREACH; + gf_errno_to_error_array[EHOSTUNREACH] = GF_ERROR_CODE_HOSTUNREACH; + /* EALREADY 149 / * operation already in progress */ + gf_error_to_errno_array[GF_ERROR_CODE_ALREADY] = EALREADY; + gf_errno_to_error_array[EALREADY] = GF_ERROR_CODE_ALREADY; + /* EINPROGRESS 150 / * operation now in progress */ + gf_error_to_errno_array[GF_ERROR_CODE_INPROGRESS] = EINPROGRESS; + gf_errno_to_error_array[EINPROGRESS] = GF_ERROR_CODE_INPROGRESS; + + /* SUN Network File System */ + /* ESTALE 151 / * Stale NFS file handle */ + gf_error_to_errno_array[GF_ERROR_CODE_STALE] = ESTALE; + gf_errno_to_error_array[ESTALE] = GF_ERROR_CODE_STALE; + + return; } #endif /* GF_SOLARIS_HOST_OS */ #ifdef GF_DARWIN_HOST_OS static void -init_compat_errno_arrays () +init_compat_errno_arrays() { - /* EDEADLK 11 / * Resource deadlock would occur */ - gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLK; - gf_errno_to_error_array[EDEADLK] = GF_ERROR_CODE_DEADLK; - - /* EAGAIN 35 / * Try Again */ - gf_error_to_errno_array[GF_ERROR_CODE_AGAIN] = EAGAIN; - gf_errno_to_error_array[EAGAIN] = GF_ERROR_CODE_AGAIN; - - /* EINPROGRESS 36 / * Operation now in progress */ - gf_error_to_errno_array[GF_ERROR_CODE_INPROGRESS] = EINPROGRESS; - gf_errno_to_error_array[EINPROGRESS] = GF_ERROR_CODE_INPROGRESS; - - /* EALREADY 37 / * Operation already in progress */ - gf_error_to_errno_array[GF_ERROR_CODE_ALREADY] = EALREADY; - gf_errno_to_error_array[EALREADY] = GF_ERROR_CODE_ALREADY; - - /* ENOTSOCK 38 / * Socket operation on non-socket */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTSOCK] = ENOTSOCK; - gf_errno_to_error_array[ENOTSOCK] = GF_ERROR_CODE_NOTSOCK; - - /* EDESTADDRREQ 39 / * Destination address required */ - gf_error_to_errno_array[GF_ERROR_CODE_DESTADDRREQ] = EDESTADDRREQ; - gf_errno_to_error_array[EDESTADDRREQ] = GF_ERROR_CODE_DESTADDRREQ; - - /* EMSGSIZE 40 / * Message too long */ - gf_error_to_errno_array[GF_ERROR_CODE_MSGSIZE] = EMSGSIZE; - gf_errno_to_error_array[EMSGSIZE] = GF_ERROR_CODE_MSGSIZE; - - /* EPROTOTYPE 41 / * Protocol wrong type for socket */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTOTYPE] = EPROTOTYPE; - gf_errno_to_error_array[EPROTOTYPE] = GF_ERROR_CODE_PROTOTYPE; - - /* ENOPROTOOPT 42 / * Protocol not available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOPROTOOPT] = ENOPROTOOPT; - gf_errno_to_error_array[ENOPROTOOPT] = GF_ERROR_CODE_NOPROTOOPT; - - /* EPROTONOSUPPORT 43 / * Protocol not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTONOSUPPORT] = EPROTONOSUPPORT; - gf_errno_to_error_array[EPROTONOSUPPORT] = GF_ERROR_CODE_PROTONOSUPPORT; - - /* ESOCKTNOSUPPORT 44 / * Socket type not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_SOCKTNOSUPPORT] = ESOCKTNOSUPPORT; - gf_errno_to_error_array[ESOCKTNOSUPPORT] = GF_ERROR_CODE_SOCKTNOSUPPORT; - - /* EOPNOTSUPP 45 / * Operation not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; - gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; - - /* EPFNOSUPPORT 46 / * Protocol family not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_PFNOSUPPORT] = EPFNOSUPPORT; - gf_errno_to_error_array[EPFNOSUPPORT] = GF_ERROR_CODE_PFNOSUPPORT; - - /* EAFNOSUPPORT 47 / * Address family not supported by protocol family */ - gf_error_to_errno_array[GF_ERROR_CODE_AFNOSUPPORT] = EAFNOSUPPORT; - gf_errno_to_error_array[EAFNOSUPPORT] = GF_ERROR_CODE_AFNOSUPPORT; - - /* EADDRINUSE 48 / * Address already in use */ - gf_error_to_errno_array[GF_ERROR_CODE_ADDRINUSE] = EADDRINUSE; - gf_errno_to_error_array[EADDRINUSE] = GF_ERROR_CODE_ADDRINUSE; - - /* EADDRNOTAVAIL 49 / * Can't assign requested address */ - gf_error_to_errno_array[GF_ERROR_CODE_ADDRNOTAVAIL] = EADDRNOTAVAIL; - gf_errno_to_error_array[EADDRNOTAVAIL] = GF_ERROR_CODE_ADDRNOTAVAIL; - - /* ENETDOWN 50 / * Network is down */ - gf_error_to_errno_array[GF_ERROR_CODE_NETDOWN] = ENETDOWN; - gf_errno_to_error_array[ENETDOWN] = GF_ERROR_CODE_NETDOWN; - - /* ENETUNREACH 51 / * Network is unreachable */ - gf_error_to_errno_array[GF_ERROR_CODE_NETUNREACH] = ENETUNREACH; - gf_errno_to_error_array[ENETUNREACH] = GF_ERROR_CODE_NETUNREACH; - - /* ENETRESET 52 / * Network dropped connection on reset */ - gf_error_to_errno_array[GF_ERROR_CODE_NETRESET] = ENETRESET; - gf_errno_to_error_array[ENETRESET] = GF_ERROR_CODE_NETRESET; - - /* ECONNABORTED 53 / * Software caused connection abort */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNABORTED] = ECONNABORTED; - gf_errno_to_error_array[ECONNABORTED] = GF_ERROR_CODE_CONNABORTED; - - /* ECONNRESET 54 / * Connection reset by peer */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNRESET] = ECONNRESET; - gf_errno_to_error_array[ECONNRESET] = GF_ERROR_CODE_CONNRESET; - - /* ENOBUFS 55 / * No buffer space available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOBUFS] = ENOBUFS; - gf_errno_to_error_array[ENOBUFS] = GF_ERROR_CODE_NOBUFS; - - /* EISCONN 56 / * Socket is already connected */ - gf_error_to_errno_array[GF_ERROR_CODE_ISCONN] = EISCONN; - gf_errno_to_error_array[EISCONN] = GF_ERROR_CODE_ISCONN; - - /* ENOTCONN 57 / * Socket is not connected */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTCONN] = ENOTCONN; - gf_errno_to_error_array[ENOTCONN] = GF_ERROR_CODE_NOTCONN; - - /* ESHUTDOWN 58 / * Can't send after socket shutdown */ - gf_error_to_errno_array[GF_ERROR_CODE_SHUTDOWN] = ESHUTDOWN; - gf_errno_to_error_array[ESHUTDOWN] = GF_ERROR_CODE_SHUTDOWN; - - /* ETOOMANYREFS 59 / * Too many references: can't splice */ - gf_error_to_errno_array[GF_ERROR_CODE_TOOMANYREFS] = ETOOMANYREFS; - gf_errno_to_error_array[ETOOMANYREFS] = GF_ERROR_CODE_TOOMANYREFS; - - /* ETIMEDOUT 60 / * Operation timed out */ - gf_error_to_errno_array[GF_ERROR_CODE_TIMEDOUT] = ETIMEDOUT; - gf_errno_to_error_array[ETIMEDOUT] = GF_ERROR_CODE_TIMEDOUT; - - /* ECONNREFUSED 61 / * Connection refused */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNREFUSED] = ECONNREFUSED; - gf_errno_to_error_array[ECONNREFUSED] = GF_ERROR_CODE_CONNREFUSED; - - /* ELOOP 62 / * Too many levels of symbolic links */ - gf_error_to_errno_array[GF_ERROR_CODE_LOOP] = ELOOP; - gf_errno_to_error_array[ELOOP] = GF_ERROR_CODE_LOOP; - - /* ENAMETOOLONG 63 / * File name too long */ - gf_error_to_errno_array[GF_ERROR_CODE_NAMETOOLONG] = ENAMETOOLONG; - gf_errno_to_error_array[ENAMETOOLONG] = GF_ERROR_CODE_NAMETOOLONG; - - /* EHOSTDOWN 64 / * Host is down */ - gf_error_to_errno_array[GF_ERROR_CODE_HOSTDOWN] = EHOSTDOWN; - gf_errno_to_error_array[EHOSTDOWN] = GF_ERROR_CODE_HOSTDOWN; - - /* EHOSTUNREACH 65 / * No route to host */ - gf_error_to_errno_array[GF_ERROR_CODE_HOSTUNREACH] = EHOSTUNREACH; - gf_errno_to_error_array[EHOSTUNREACH] = GF_ERROR_CODE_HOSTUNREACH; - - /* ENOTEMPTY 66 / * Directory not empty */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTEMPTY] = ENOTEMPTY; - gf_errno_to_error_array[ENOTEMPTY] = GF_ERROR_CODE_NOTEMPTY; - - /* EPROCLIM 67 / * Too many processes */ - gf_error_to_errno_array[GF_ERROR_CODE_PROCLIM] = EPROCLIM; - gf_errno_to_error_array[EPROCLIM] = GF_ERROR_CODE_PROCLIM; - - /* EUSERS 68 / * Too many users */ - gf_error_to_errno_array[GF_ERROR_CODE_USERS] = EUSERS; - gf_errno_to_error_array[EUSERS] = GF_ERROR_CODE_USERS; - - /* EDQUOT 69 / * Disc quota exceeded */ - gf_error_to_errno_array[GF_ERROR_CODE_DQUOT] = EDQUOT; - gf_errno_to_error_array[EDQUOT] = GF_ERROR_CODE_DQUOT; - - /* ESTALE 70 / * Stale NFS file handle */ - gf_error_to_errno_array[GF_ERROR_CODE_STALE] = ESTALE; - gf_errno_to_error_array[ESTALE] = GF_ERROR_CODE_STALE; - - /* EREMOTE 71 / * Too many levels of remote in path */ - gf_error_to_errno_array[GF_ERROR_CODE_REMOTE] = EREMOTE; - gf_errno_to_error_array[EREMOTE] = GF_ERROR_CODE_REMOTE; - - /* EBADRPC 72 / * RPC struct is bad */ - gf_error_to_errno_array[GF_ERROR_CODE_BADRPC] = EBADRPC; - gf_errno_to_error_array[EBADRPC] = GF_ERROR_CODE_BADRPC; - - /* ERPCMISMATCH 73 / * RPC version wrong */ - gf_error_to_errno_array[GF_ERROR_CODE_RPCMISMATCH] = ERPCMISMATCH; - gf_errno_to_error_array[ERPCMISMATCH] = GF_ERROR_CODE_RPCMISMATCH; - - /* EPROGUNAVAIL 74 / * RPC prog. not avail */ - gf_error_to_errno_array[GF_ERROR_CODE_PROGUNAVAIL] = EPROGUNAVAIL; - gf_errno_to_error_array[EPROGUNAVAIL] = GF_ERROR_CODE_PROGUNAVAIL; - - /* EPROGMISMATCH 75 / * Program version wrong */ - gf_error_to_errno_array[GF_ERROR_CODE_PROGMISMATCH] = EPROGMISMATCH; - gf_errno_to_error_array[EPROGMISMATCH] = GF_ERROR_CODE_PROGMISMATCH; - - /* EPROCUNAVAIL 76 / * Bad procedure for program */ - gf_error_to_errno_array[GF_ERROR_CODE_PROCUNAVAIL] = EPROCUNAVAIL; - gf_errno_to_error_array[EPROCUNAVAIL] = GF_ERROR_CODE_PROCUNAVAIL; - - /* ENOLCK 77 / * No locks available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOLCK] = ENOLCK; - gf_errno_to_error_array[ENOLCK] = GF_ERROR_CODE_NOLCK; - - /* ENOSYS 78 / * Function not implemented */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSYS] = ENOSYS; - gf_errno_to_error_array[ENOSYS] = GF_ERROR_CODE_NOSYS; - - /* EFTYPE 79 / * Inappropriate file type or format */ - gf_error_to_errno_array[GF_ERROR_CODE_FTYPE] = EFTYPE; - gf_errno_to_error_array[EFTYPE] = GF_ERROR_CODE_FTYPE; - - /* EAUTH 80 / * Authentication error */ - gf_error_to_errno_array[GF_ERROR_CODE_AUTH] = EAUTH; - gf_errno_to_error_array[EAUTH] = GF_ERROR_CODE_AUTH; - - /* ENEEDAUTH 81 / * Need authenticator */ - gf_error_to_errno_array[GF_ERROR_CODE_NEEDAUTH] = ENEEDAUTH; - gf_errno_to_error_array[ENEEDAUTH] = GF_ERROR_CODE_NEEDAUTH; -/* Intelligent device errors */ -/* EPWROFF 82 / * Device power is off */ - gf_error_to_errno_array[GF_ERROR_CODE_PWROFF] = EPWROFF; - gf_errno_to_error_array[EPWROFF] = GF_ERROR_CODE_PWROFF; -/* EDEVERR 83 / * Device error, e.g. paper out */ - gf_error_to_errno_array[GF_ERROR_CODE_DEVERR] = EDEVERR; - gf_errno_to_error_array[EDEVERR] = GF_ERROR_CODE_DEVERR; - - /* EOVERFLOW 84 / * Value too large to be stored in data type */ - gf_error_to_errno_array[GF_ERROR_CODE_OVERFLOW] = EOVERFLOW; - gf_errno_to_error_array[EOVERFLOW] = GF_ERROR_CODE_OVERFLOW; - -/* Program loading errors */ -/* EBADEXEC 85 / * Bad executable */ - gf_error_to_errno_array[GF_ERROR_CODE_BADEXEC] = EBADEXEC; - gf_errno_to_error_array[EBADEXEC] = GF_ERROR_CODE_BADEXEC; - -/* EBADARCH 86 / * Bad CPU type in executable */ - gf_error_to_errno_array[GF_ERROR_CODE_BADARCH] = EBADARCH; - gf_errno_to_error_array[EBADARCH] = GF_ERROR_CODE_BADARCH; - -/* ESHLIBVERS 87 / * Shared library version mismatch */ - gf_error_to_errno_array[GF_ERROR_CODE_SHLIBVERS] = ESHLIBVERS; - gf_errno_to_error_array[ESHLIBVERS] = GF_ERROR_CODE_SHLIBVERS; - -/* EBADMACHO 88 / * Malformed Macho file */ - gf_error_to_errno_array[GF_ERROR_CODE_BADMACHO] = EBADMACHO; - gf_errno_to_error_array[EBADMACHO] = GF_ERROR_CODE_BADMACHO; + /* EDEADLK 11 / * Resource deadlock would occur */ + gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLK; + gf_errno_to_error_array[EDEADLK] = GF_ERROR_CODE_DEADLK; + + /* EAGAIN 35 / * Try Again */ + gf_error_to_errno_array[GF_ERROR_CODE_AGAIN] = EAGAIN; + gf_errno_to_error_array[EAGAIN] = GF_ERROR_CODE_AGAIN; + + /* EINPROGRESS 36 / * Operation now in progress */ + gf_error_to_errno_array[GF_ERROR_CODE_INPROGRESS] = EINPROGRESS; + gf_errno_to_error_array[EINPROGRESS] = GF_ERROR_CODE_INPROGRESS; + + /* EALREADY 37 / * Operation already in progress */ + gf_error_to_errno_array[GF_ERROR_CODE_ALREADY] = EALREADY; + gf_errno_to_error_array[EALREADY] = GF_ERROR_CODE_ALREADY; + + /* ENOTSOCK 38 / * Socket operation on non-socket + */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTSOCK] = ENOTSOCK; + gf_errno_to_error_array[ENOTSOCK] = GF_ERROR_CODE_NOTSOCK; + + /* EDESTADDRREQ 39 / * Destination address required */ + gf_error_to_errno_array[GF_ERROR_CODE_DESTADDRREQ] = EDESTADDRREQ; + gf_errno_to_error_array[EDESTADDRREQ] = GF_ERROR_CODE_DESTADDRREQ; + + /* EMSGSIZE 40 / * Message too long */ + gf_error_to_errno_array[GF_ERROR_CODE_MSGSIZE] = EMSGSIZE; + gf_errno_to_error_array[EMSGSIZE] = GF_ERROR_CODE_MSGSIZE; + + /* EPROTOTYPE 41 / * Protocol wrong type for socket + */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTOTYPE] = EPROTOTYPE; + gf_errno_to_error_array[EPROTOTYPE] = GF_ERROR_CODE_PROTOTYPE; + + /* ENOPROTOOPT 42 / * Protocol not available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOPROTOOPT] = ENOPROTOOPT; + gf_errno_to_error_array[ENOPROTOOPT] = GF_ERROR_CODE_NOPROTOOPT; + + /* EPROTONOSUPPORT 43 / * Protocol not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTONOSUPPORT] = EPROTONOSUPPORT; + gf_errno_to_error_array[EPROTONOSUPPORT] = GF_ERROR_CODE_PROTONOSUPPORT; + + /* ESOCKTNOSUPPORT 44 / * Socket type not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_SOCKTNOSUPPORT] = ESOCKTNOSUPPORT; + gf_errno_to_error_array[ESOCKTNOSUPPORT] = GF_ERROR_CODE_SOCKTNOSUPPORT; + + /* EOPNOTSUPP 45 / * Operation not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; + gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; + + /* EPFNOSUPPORT 46 / * Protocol family not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_PFNOSUPPORT] = EPFNOSUPPORT; + gf_errno_to_error_array[EPFNOSUPPORT] = GF_ERROR_CODE_PFNOSUPPORT; + + /* EAFNOSUPPORT 47 / * Address family not supported by + * protocol family */ + gf_error_to_errno_array[GF_ERROR_CODE_AFNOSUPPORT] = EAFNOSUPPORT; + gf_errno_to_error_array[EAFNOSUPPORT] = GF_ERROR_CODE_AFNOSUPPORT; + + /* EADDRINUSE 48 / * Address already in use */ + gf_error_to_errno_array[GF_ERROR_CODE_ADDRINUSE] = EADDRINUSE; + gf_errno_to_error_array[EADDRINUSE] = GF_ERROR_CODE_ADDRINUSE; + + /* EADDRNOTAVAIL 49 / * Can't assign requested address + */ + gf_error_to_errno_array[GF_ERROR_CODE_ADDRNOTAVAIL] = EADDRNOTAVAIL; + gf_errno_to_error_array[EADDRNOTAVAIL] = GF_ERROR_CODE_ADDRNOTAVAIL; + + /* ENETDOWN 50 / * Network is down */ + gf_error_to_errno_array[GF_ERROR_CODE_NETDOWN] = ENETDOWN; + gf_errno_to_error_array[ENETDOWN] = GF_ERROR_CODE_NETDOWN; + + /* ENETUNREACH 51 / * Network is unreachable */ + gf_error_to_errno_array[GF_ERROR_CODE_NETUNREACH] = ENETUNREACH; + gf_errno_to_error_array[ENETUNREACH] = GF_ERROR_CODE_NETUNREACH; + + /* ENETRESET 52 / * Network dropped connection on + * reset */ + gf_error_to_errno_array[GF_ERROR_CODE_NETRESET] = ENETRESET; + gf_errno_to_error_array[ENETRESET] = GF_ERROR_CODE_NETRESET; + + /* ECONNABORTED 53 / * Software caused connection abort + */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNABORTED] = ECONNABORTED; + gf_errno_to_error_array[ECONNABORTED] = GF_ERROR_CODE_CONNABORTED; + + /* ECONNRESET 54 / * Connection reset by peer */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNRESET] = ECONNRESET; + gf_errno_to_error_array[ECONNRESET] = GF_ERROR_CODE_CONNRESET; + + /* ENOBUFS 55 / * No buffer space available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOBUFS] = ENOBUFS; + gf_errno_to_error_array[ENOBUFS] = GF_ERROR_CODE_NOBUFS; + + /* EISCONN 56 / * Socket is already connected */ + gf_error_to_errno_array[GF_ERROR_CODE_ISCONN] = EISCONN; + gf_errno_to_error_array[EISCONN] = GF_ERROR_CODE_ISCONN; + + /* ENOTCONN 57 / * Socket is not connected */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTCONN] = ENOTCONN; + gf_errno_to_error_array[ENOTCONN] = GF_ERROR_CODE_NOTCONN; + + /* ESHUTDOWN 58 / * Can't send after socket shutdown + */ + gf_error_to_errno_array[GF_ERROR_CODE_SHUTDOWN] = ESHUTDOWN; + gf_errno_to_error_array[ESHUTDOWN] = GF_ERROR_CODE_SHUTDOWN; + + /* ETOOMANYREFS 59 / * Too many references: can't + * splice */ + gf_error_to_errno_array[GF_ERROR_CODE_TOOMANYREFS] = ETOOMANYREFS; + gf_errno_to_error_array[ETOOMANYREFS] = GF_ERROR_CODE_TOOMANYREFS; + + /* ETIMEDOUT 60 / * Operation timed out */ + gf_error_to_errno_array[GF_ERROR_CODE_TIMEDOUT] = ETIMEDOUT; + gf_errno_to_error_array[ETIMEDOUT] = GF_ERROR_CODE_TIMEDOUT; + + /* ECONNREFUSED 61 / * Connection refused */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNREFUSED] = ECONNREFUSED; + gf_errno_to_error_array[ECONNREFUSED] = GF_ERROR_CODE_CONNREFUSED; + + /* ELOOP 62 / * Too many levels of symbolic + * links */ + gf_error_to_errno_array[GF_ERROR_CODE_LOOP] = ELOOP; + gf_errno_to_error_array[ELOOP] = GF_ERROR_CODE_LOOP; + + /* ENAMETOOLONG 63 / * File name too long */ + gf_error_to_errno_array[GF_ERROR_CODE_NAMETOOLONG] = ENAMETOOLONG; + gf_errno_to_error_array[ENAMETOOLONG] = GF_ERROR_CODE_NAMETOOLONG; + + /* EHOSTDOWN 64 / * Host is down */ + gf_error_to_errno_array[GF_ERROR_CODE_HOSTDOWN] = EHOSTDOWN; + gf_errno_to_error_array[EHOSTDOWN] = GF_ERROR_CODE_HOSTDOWN; + + /* EHOSTUNREACH 65 / * No route to host */ + gf_error_to_errno_array[GF_ERROR_CODE_HOSTUNREACH] = EHOSTUNREACH; + gf_errno_to_error_array[EHOSTUNREACH] = GF_ERROR_CODE_HOSTUNREACH; + + /* ENOTEMPTY 66 / * Directory not empty */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTEMPTY] = ENOTEMPTY; + gf_errno_to_error_array[ENOTEMPTY] = GF_ERROR_CODE_NOTEMPTY; + + /* EPROCLIM 67 / * Too many processes */ + gf_error_to_errno_array[GF_ERROR_CODE_PROCLIM] = EPROCLIM; + gf_errno_to_error_array[EPROCLIM] = GF_ERROR_CODE_PROCLIM; + + /* EUSERS 68 / * Too many users */ + gf_error_to_errno_array[GF_ERROR_CODE_USERS] = EUSERS; + gf_errno_to_error_array[EUSERS] = GF_ERROR_CODE_USERS; + + /* EDQUOT 69 / * Disc quota exceeded */ + gf_error_to_errno_array[GF_ERROR_CODE_DQUOT] = EDQUOT; + gf_errno_to_error_array[EDQUOT] = GF_ERROR_CODE_DQUOT; + + /* ESTALE 70 / * Stale NFS file handle */ + gf_error_to_errno_array[GF_ERROR_CODE_STALE] = ESTALE; + gf_errno_to_error_array[ESTALE] = GF_ERROR_CODE_STALE; + + /* EREMOTE 71 / * Too many levels of remote in + * path */ + gf_error_to_errno_array[GF_ERROR_CODE_REMOTE] = EREMOTE; + gf_errno_to_error_array[EREMOTE] = GF_ERROR_CODE_REMOTE; + + /* EBADRPC 72 / * RPC struct is bad */ + gf_error_to_errno_array[GF_ERROR_CODE_BADRPC] = EBADRPC; + gf_errno_to_error_array[EBADRPC] = GF_ERROR_CODE_BADRPC; + + /* ERPCMISMATCH 73 / * RPC version wrong */ + gf_error_to_errno_array[GF_ERROR_CODE_RPCMISMATCH] = ERPCMISMATCH; + gf_errno_to_error_array[ERPCMISMATCH] = GF_ERROR_CODE_RPCMISMATCH; + + /* EPROGUNAVAIL 74 / * RPC prog. not avail */ + gf_error_to_errno_array[GF_ERROR_CODE_PROGUNAVAIL] = EPROGUNAVAIL; + gf_errno_to_error_array[EPROGUNAVAIL] = GF_ERROR_CODE_PROGUNAVAIL; + + /* EPROGMISMATCH 75 / * Program version wrong */ + gf_error_to_errno_array[GF_ERROR_CODE_PROGMISMATCH] = EPROGMISMATCH; + gf_errno_to_error_array[EPROGMISMATCH] = GF_ERROR_CODE_PROGMISMATCH; + + /* EPROCUNAVAIL 76 / * Bad procedure for program */ + gf_error_to_errno_array[GF_ERROR_CODE_PROCUNAVAIL] = EPROCUNAVAIL; + gf_errno_to_error_array[EPROCUNAVAIL] = GF_ERROR_CODE_PROCUNAVAIL; + + /* ENOLCK 77 / * No locks available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOLCK] = ENOLCK; + gf_errno_to_error_array[ENOLCK] = GF_ERROR_CODE_NOLCK; + + /* ENOSYS 78 / * Function not implemented */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSYS] = ENOSYS; + gf_errno_to_error_array[ENOSYS] = GF_ERROR_CODE_NOSYS; + + /* EFTYPE 79 / * Inappropriate file type or + * format */ + gf_error_to_errno_array[GF_ERROR_CODE_FTYPE] = EFTYPE; + gf_errno_to_error_array[EFTYPE] = GF_ERROR_CODE_FTYPE; + + /* EAUTH 80 / * Authentication error */ + gf_error_to_errno_array[GF_ERROR_CODE_AUTH] = EAUTH; + gf_errno_to_error_array[EAUTH] = GF_ERROR_CODE_AUTH; + + /* ENEEDAUTH 81 / * Need authenticator */ + gf_error_to_errno_array[GF_ERROR_CODE_NEEDAUTH] = ENEEDAUTH; + gf_errno_to_error_array[ENEEDAUTH] = GF_ERROR_CODE_NEEDAUTH; + /* Intelligent device errors */ + /* EPWROFF 82 / * Device power is off */ + gf_error_to_errno_array[GF_ERROR_CODE_PWROFF] = EPWROFF; + gf_errno_to_error_array[EPWROFF] = GF_ERROR_CODE_PWROFF; + /* EDEVERR 83 / * Device error, e.g. paper out */ + gf_error_to_errno_array[GF_ERROR_CODE_DEVERR] = EDEVERR; + gf_errno_to_error_array[EDEVERR] = GF_ERROR_CODE_DEVERR; + + /* EOVERFLOW 84 / * Value too large to be stored in + * data type */ + gf_error_to_errno_array[GF_ERROR_CODE_OVERFLOW] = EOVERFLOW; + gf_errno_to_error_array[EOVERFLOW] = GF_ERROR_CODE_OVERFLOW; + + /* Program loading errors */ + /* EBADEXEC 85 / * Bad executable */ + gf_error_to_errno_array[GF_ERROR_CODE_BADEXEC] = EBADEXEC; + gf_errno_to_error_array[EBADEXEC] = GF_ERROR_CODE_BADEXEC; + + /* EBADARCH 86 / * Bad CPU type in executable */ + gf_error_to_errno_array[GF_ERROR_CODE_BADARCH] = EBADARCH; + gf_errno_to_error_array[EBADARCH] = GF_ERROR_CODE_BADARCH; + + /* ESHLIBVERS 87 / * Shared library version mismatch */ + gf_error_to_errno_array[GF_ERROR_CODE_SHLIBVERS] = ESHLIBVERS; + gf_errno_to_error_array[ESHLIBVERS] = GF_ERROR_CODE_SHLIBVERS; + + /* EBADMACHO 88 / * Malformed Macho file */ + gf_error_to_errno_array[GF_ERROR_CODE_BADMACHO] = EBADMACHO; + gf_errno_to_error_array[EBADMACHO] = GF_ERROR_CODE_BADMACHO; #ifdef EDOOFUS - /* EDOOFUS 88 / * Programming error */ - gf_error_to_errno_array[GF_ERROR_CODE_DOOFUS] = EDOOFUS; - gf_errno_to_error_array[EDOOFUS] = GF_ERROR_CODE_DOOFUS; + /* EDOOFUS 88 / * Programming error */ + gf_error_to_errno_array[GF_ERROR_CODE_DOOFUS] = EDOOFUS; + gf_errno_to_error_array[EDOOFUS] = GF_ERROR_CODE_DOOFUS; #endif - /* ECANCELED 89 / * Operation canceled */ - gf_error_to_errno_array[GF_ERROR_CODE_CANCELED] = ECANCELED; - gf_errno_to_error_array[ECANCELED] = GF_ERROR_CODE_CANCELED; - - /* EIDRM 90 / * Identifier removed */ - gf_error_to_errno_array[GF_ERROR_CODE_IDRM] = EIDRM; - gf_errno_to_error_array[EIDRM] = GF_ERROR_CODE_IDRM; - /* ENOMSG 91 / * No message of desired type */ - gf_error_to_errno_array[GF_ERROR_CODE_NOMSG] = ENOMSG; - gf_errno_to_error_array[ENOMSG] = GF_ERROR_CODE_NOMSG; - - /* EILSEQ 92 / * Illegal byte sequence */ - gf_error_to_errno_array[GF_ERROR_CODE_ILSEQ] = EILSEQ; - gf_errno_to_error_array[EILSEQ] = GF_ERROR_CODE_ILSEQ; - - /* ENOATTR 93 / * Attribute not found */ - gf_error_to_errno_array[GF_ERROR_CODE_NOATTR] = ENOATTR; - gf_errno_to_error_array[ENOATTR] = GF_ERROR_CODE_NOATTR; - - /* EBADMSG 94 / * Bad message */ - gf_error_to_errno_array[GF_ERROR_CODE_BADMSG] = EBADMSG; - gf_errno_to_error_array[EBADMSG] = GF_ERROR_CODE_BADMSG; - - /* EMULTIHOP 95 / * Reserved */ - gf_error_to_errno_array[GF_ERROR_CODE_MULTIHOP] = EMULTIHOP; - gf_errno_to_error_array[EMULTIHOP] = GF_ERROR_CODE_MULTIHOP; - - /* ENODATA 96 / * No message available on STREAM */ - gf_error_to_errno_array[GF_ERROR_CODE_NEEDAUTH] = ENEEDAUTH; - gf_errno_to_error_array[ENEEDAUTH] = GF_ERROR_CODE_NEEDAUTH; - - /* ENOLINK 97 / * Reserved */ - gf_error_to_errno_array[GF_ERROR_CODE_NOLINK] = ENOLINK; - gf_errno_to_error_array[ENOLINK] = GF_ERROR_CODE_NOLINK; - - /* ENOSR 98 / * No STREAM resources */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSR] = ENOSR; - gf_errno_to_error_array[ENOSR] = GF_ERROR_CODE_NOSR; - - /* ENOSTR 99 / * Not a STREAM */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSTR] = ENOSTR; - gf_errno_to_error_array[ENOSTR] = GF_ERROR_CODE_NOSTR; - -/* EPROTO 100 / * Protocol error */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTO] = EPROTO; - gf_errno_to_error_array[EPROTO] = GF_ERROR_CODE_PROTO; -/* ETIME 101 / * STREAM ioctl timeout */ - gf_error_to_errno_array[GF_ERROR_CODE_TIME] = ETIME; - gf_errno_to_error_array[ETIME] = GF_ERROR_CODE_TIME; - -/* This value is only discrete when compiling __DARWIN_UNIX03, or KERNEL */ -/* EOPNOTSUPP 102 / * Operation not supported on socket */ - gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; - gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; - -/* ENOPOLICY 103 / * No such policy registered */ - gf_error_to_errno_array[GF_ERROR_CODE_NOPOLICY] = ENOPOLICY; - gf_errno_to_error_array[ENOPOLICY] = GF_ERROR_CODE_NOPOLICY; - - return ; + /* ECANCELED 89 / * Operation canceled */ + gf_error_to_errno_array[GF_ERROR_CODE_CANCELED] = ECANCELED; + gf_errno_to_error_array[ECANCELED] = GF_ERROR_CODE_CANCELED; + + /* EIDRM 90 / * Identifier removed */ + gf_error_to_errno_array[GF_ERROR_CODE_IDRM] = EIDRM; + gf_errno_to_error_array[EIDRM] = GF_ERROR_CODE_IDRM; + /* ENOMSG 91 / * No message of desired type */ + gf_error_to_errno_array[GF_ERROR_CODE_NOMSG] = ENOMSG; + gf_errno_to_error_array[ENOMSG] = GF_ERROR_CODE_NOMSG; + + /* EILSEQ 92 / * Illegal byte sequence */ + gf_error_to_errno_array[GF_ERROR_CODE_ILSEQ] = EILSEQ; + gf_errno_to_error_array[EILSEQ] = GF_ERROR_CODE_ILSEQ; + + /* ENOATTR 93 / * Attribute not found */ + gf_error_to_errno_array[GF_ERROR_CODE_NOATTR] = ENOATTR; + gf_errno_to_error_array[ENOATTR] = GF_ERROR_CODE_NOATTR; + + /* EBADMSG 94 / * Bad message */ + gf_error_to_errno_array[GF_ERROR_CODE_BADMSG] = EBADMSG; + gf_errno_to_error_array[EBADMSG] = GF_ERROR_CODE_BADMSG; + + /* EMULTIHOP 95 / * Reserved */ + gf_error_to_errno_array[GF_ERROR_CODE_MULTIHOP] = EMULTIHOP; + gf_errno_to_error_array[EMULTIHOP] = GF_ERROR_CODE_MULTIHOP; + + /* ENODATA 96 / * No message available on STREAM + */ + gf_error_to_errno_array[GF_ERROR_CODE_NEEDAUTH] = ENEEDAUTH; + gf_errno_to_error_array[ENEEDAUTH] = GF_ERROR_CODE_NEEDAUTH; + + /* ENOLINK 97 / * Reserved */ + gf_error_to_errno_array[GF_ERROR_CODE_NOLINK] = ENOLINK; + gf_errno_to_error_array[ENOLINK] = GF_ERROR_CODE_NOLINK; + + /* ENOSR 98 / * No STREAM resources */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSR] = ENOSR; + gf_errno_to_error_array[ENOSR] = GF_ERROR_CODE_NOSR; + + /* ENOSTR 99 / * Not a STREAM */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSTR] = ENOSTR; + gf_errno_to_error_array[ENOSTR] = GF_ERROR_CODE_NOSTR; + + /* EPROTO 100 / * Protocol error */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTO] = EPROTO; + gf_errno_to_error_array[EPROTO] = GF_ERROR_CODE_PROTO; + /* ETIME 101 / * STREAM ioctl timeout */ + gf_error_to_errno_array[GF_ERROR_CODE_TIME] = ETIME; + gf_errno_to_error_array[ETIME] = GF_ERROR_CODE_TIME; + + /* This value is only discrete when compiling __DARWIN_UNIX03, or KERNEL */ + /* EOPNOTSUPP 102 / * Operation not supported on + * socket */ + gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; + gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; + + /* ENOPOLICY 103 / * No such policy registered */ + gf_error_to_errno_array[GF_ERROR_CODE_NOPOLICY] = ENOPOLICY; + gf_errno_to_error_array[ENOPOLICY] = GF_ERROR_CODE_NOPOLICY; + + return; } #endif /* GF_DARWIN_HOST_OS */ #ifdef GF_BSD_HOST_OS static void -init_compat_errno_arrays () +init_compat_errno_arrays() { - /* Quite a bit of things changed in FreeBSD - current */ - - /* EAGAIN 35 / * Try Again */ - gf_error_to_errno_array[GF_ERROR_CODE_AGAIN] = EAGAIN; - gf_errno_to_error_array[EAGAIN] = GF_ERROR_CODE_AGAIN; - - /* EDEADLK 11 / * Resource deadlock would occur */ - gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLK; - gf_errno_to_error_array[EDEADLK] = GF_ERROR_CODE_DEADLK; - - /* EINPROGRESS 36 / * Operation now in progress */ - gf_error_to_errno_array[GF_ERROR_CODE_INPROGRESS] = EINPROGRESS; - gf_errno_to_error_array[EINPROGRESS] = GF_ERROR_CODE_INPROGRESS; - - /* EALREADY 37 / * Operation already in progress */ - gf_error_to_errno_array[GF_ERROR_CODE_ALREADY] = EALREADY; - gf_errno_to_error_array[EALREADY] = GF_ERROR_CODE_ALREADY; - - /* ENOTSOCK 38 / * Socket operation on non-socket */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTSOCK] = ENOTSOCK; - gf_errno_to_error_array[ENOTSOCK] = GF_ERROR_CODE_NOTSOCK; - - /* EDESTADDRREQ 39 / * Destination address required */ - gf_error_to_errno_array[GF_ERROR_CODE_DESTADDRREQ] = EDESTADDRREQ; - gf_errno_to_error_array[EDESTADDRREQ] = GF_ERROR_CODE_DESTADDRREQ; - - /* EMSGSIZE 40 / * Message too long */ - gf_error_to_errno_array[GF_ERROR_CODE_MSGSIZE] = EMSGSIZE; - gf_errno_to_error_array[EMSGSIZE] = GF_ERROR_CODE_MSGSIZE; - - /* EPROTOTYPE 41 / * Protocol wrong type for socket */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTOTYPE] = EPROTOTYPE; - gf_errno_to_error_array[EPROTOTYPE] = GF_ERROR_CODE_PROTOTYPE; - - /* ENOPROTOOPT 42 / * Protocol not available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOPROTOOPT] = ENOPROTOOPT; - gf_errno_to_error_array[ENOPROTOOPT] = GF_ERROR_CODE_NOPROTOOPT; - - /* EPROTONOSUPPORT 43 / * Protocol not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTONOSUPPORT] = EPROTONOSUPPORT; - gf_errno_to_error_array[EPROTONOSUPPORT] = GF_ERROR_CODE_PROTONOSUPPORT; - - /* ESOCKTNOSUPPORT 44 / * Socket type not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_SOCKTNOSUPPORT] = ESOCKTNOSUPPORT; - gf_errno_to_error_array[ESOCKTNOSUPPORT] = GF_ERROR_CODE_SOCKTNOSUPPORT; - - /* EOPNOTSUPP 45 / * Operation not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; - gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; - - /* EPFNOSUPPORT 46 / * Protocol family not supported */ - gf_error_to_errno_array[GF_ERROR_CODE_PFNOSUPPORT] = EPFNOSUPPORT; - gf_errno_to_error_array[EPFNOSUPPORT] = GF_ERROR_CODE_PFNOSUPPORT; - - /* EAFNOSUPPORT 47 / * Address family not supported by protocol family */ - gf_error_to_errno_array[GF_ERROR_CODE_AFNOSUPPORT] = EAFNOSUPPORT; - gf_errno_to_error_array[EAFNOSUPPORT] = GF_ERROR_CODE_AFNOSUPPORT; + /* Quite a bit of things changed in FreeBSD - current */ + + /* EAGAIN 35 / * Try Again */ + gf_error_to_errno_array[GF_ERROR_CODE_AGAIN] = EAGAIN; + gf_errno_to_error_array[EAGAIN] = GF_ERROR_CODE_AGAIN; + + /* EDEADLK 11 / * Resource deadlock would occur */ + gf_error_to_errno_array[GF_ERROR_CODE_DEADLK] = EDEADLK; + gf_errno_to_error_array[EDEADLK] = GF_ERROR_CODE_DEADLK; + + /* EINPROGRESS 36 / * Operation now in progress */ + gf_error_to_errno_array[GF_ERROR_CODE_INPROGRESS] = EINPROGRESS; + gf_errno_to_error_array[EINPROGRESS] = GF_ERROR_CODE_INPROGRESS; + + /* EALREADY 37 / * Operation already in progress */ + gf_error_to_errno_array[GF_ERROR_CODE_ALREADY] = EALREADY; + gf_errno_to_error_array[EALREADY] = GF_ERROR_CODE_ALREADY; + + /* ENOTSOCK 38 / * Socket operation on non-socket + */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTSOCK] = ENOTSOCK; + gf_errno_to_error_array[ENOTSOCK] = GF_ERROR_CODE_NOTSOCK; + + /* EDESTADDRREQ 39 / * Destination address required */ + gf_error_to_errno_array[GF_ERROR_CODE_DESTADDRREQ] = EDESTADDRREQ; + gf_errno_to_error_array[EDESTADDRREQ] = GF_ERROR_CODE_DESTADDRREQ; + + /* EMSGSIZE 40 / * Message too long */ + gf_error_to_errno_array[GF_ERROR_CODE_MSGSIZE] = EMSGSIZE; + gf_errno_to_error_array[EMSGSIZE] = GF_ERROR_CODE_MSGSIZE; + + /* EPROTOTYPE 41 / * Protocol wrong type for socket + */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTOTYPE] = EPROTOTYPE; + gf_errno_to_error_array[EPROTOTYPE] = GF_ERROR_CODE_PROTOTYPE; + + /* ENOPROTOOPT 42 / * Protocol not available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOPROTOOPT] = ENOPROTOOPT; + gf_errno_to_error_array[ENOPROTOOPT] = GF_ERROR_CODE_NOPROTOOPT; + + /* EPROTONOSUPPORT 43 / * Protocol not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTONOSUPPORT] = EPROTONOSUPPORT; + gf_errno_to_error_array[EPROTONOSUPPORT] = GF_ERROR_CODE_PROTONOSUPPORT; + + /* ESOCKTNOSUPPORT 44 / * Socket type not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_SOCKTNOSUPPORT] = ESOCKTNOSUPPORT; + gf_errno_to_error_array[ESOCKTNOSUPPORT] = GF_ERROR_CODE_SOCKTNOSUPPORT; + + /* EOPNOTSUPP 45 / * Operation not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_OPNOTSUPP] = EOPNOTSUPP; + gf_errno_to_error_array[EOPNOTSUPP] = GF_ERROR_CODE_OPNOTSUPP; + + /* EPFNOSUPPORT 46 / * Protocol family not supported */ + gf_error_to_errno_array[GF_ERROR_CODE_PFNOSUPPORT] = EPFNOSUPPORT; + gf_errno_to_error_array[EPFNOSUPPORT] = GF_ERROR_CODE_PFNOSUPPORT; + + /* EAFNOSUPPORT 47 / * Address family not supported by + * protocol family */ + gf_error_to_errno_array[GF_ERROR_CODE_AFNOSUPPORT] = EAFNOSUPPORT; + gf_errno_to_error_array[EAFNOSUPPORT] = GF_ERROR_CODE_AFNOSUPPORT; + + /* EADDRINUSE 48 / * Address already in use */ + gf_error_to_errno_array[GF_ERROR_CODE_ADDRINUSE] = EADDRINUSE; + gf_errno_to_error_array[EADDRINUSE] = GF_ERROR_CODE_ADDRINUSE; + + /* EADDRNOTAVAIL 49 / * Can't assign requested address + */ + gf_error_to_errno_array[GF_ERROR_CODE_ADDRNOTAVAIL] = EADDRNOTAVAIL; + gf_errno_to_error_array[EADDRNOTAVAIL] = GF_ERROR_CODE_ADDRNOTAVAIL; + + /* ENETDOWN 50 / * Network is down */ + gf_error_to_errno_array[GF_ERROR_CODE_NETDOWN] = ENETDOWN; + gf_errno_to_error_array[ENETDOWN] = GF_ERROR_CODE_NETDOWN; + + /* ENETUNREACH 51 / * Network is unreachable */ + gf_error_to_errno_array[GF_ERROR_CODE_NETUNREACH] = ENETUNREACH; + gf_errno_to_error_array[ENETUNREACH] = GF_ERROR_CODE_NETUNREACH; + + /* ENETRESET 52 / * Network dropped connection on + * reset */ + gf_error_to_errno_array[GF_ERROR_CODE_NETRESET] = ENETRESET; + gf_errno_to_error_array[ENETRESET] = GF_ERROR_CODE_NETRESET; + + /* ECONNABORTED 53 / * Software caused connection abort + */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNABORTED] = ECONNABORTED; + gf_errno_to_error_array[ECONNABORTED] = GF_ERROR_CODE_CONNABORTED; + + /* ECONNRESET 54 / * Connection reset by peer */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNRESET] = ECONNRESET; + gf_errno_to_error_array[ECONNRESET] = GF_ERROR_CODE_CONNRESET; + + /* ENOBUFS 55 / * No buffer space available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOBUFS] = ENOBUFS; + gf_errno_to_error_array[ENOBUFS] = GF_ERROR_CODE_NOBUFS; + + /* EISCONN 56 / * Socket is already connected */ + gf_error_to_errno_array[GF_ERROR_CODE_ISCONN] = EISCONN; + gf_errno_to_error_array[EISCONN] = GF_ERROR_CODE_ISCONN; + + /* ENOTCONN 57 / * Socket is not connected */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTCONN] = ENOTCONN; + gf_errno_to_error_array[ENOTCONN] = GF_ERROR_CODE_NOTCONN; + + /* ESHUTDOWN 58 / * Can't send after socket shutdown + */ + gf_error_to_errno_array[GF_ERROR_CODE_SHUTDOWN] = ESHUTDOWN; + gf_errno_to_error_array[ESHUTDOWN] = GF_ERROR_CODE_SHUTDOWN; + + /* ETOOMANYREFS 59 / * Too many references: can't + * splice */ + gf_error_to_errno_array[GF_ERROR_CODE_TOOMANYREFS] = ETOOMANYREFS; + gf_errno_to_error_array[ETOOMANYREFS] = GF_ERROR_CODE_TOOMANYREFS; + + /* ETIMEDOUT 60 / * Operation timed out */ + gf_error_to_errno_array[GF_ERROR_CODE_TIMEDOUT] = ETIMEDOUT; + gf_errno_to_error_array[ETIMEDOUT] = GF_ERROR_CODE_TIMEDOUT; + + /* ECONNREFUSED 61 / * Connection refused */ + gf_error_to_errno_array[GF_ERROR_CODE_CONNREFUSED] = ECONNREFUSED; + gf_errno_to_error_array[ECONNREFUSED] = GF_ERROR_CODE_CONNREFUSED; + + /* ELOOP 62 / * Too many levels of symbolic + * links */ + gf_error_to_errno_array[GF_ERROR_CODE_LOOP] = ELOOP; + gf_errno_to_error_array[ELOOP] = GF_ERROR_CODE_LOOP; + + /* ENAMETOOLONG 63 / * File name too long */ + gf_error_to_errno_array[GF_ERROR_CODE_NAMETOOLONG] = ENAMETOOLONG; + gf_errno_to_error_array[ENAMETOOLONG] = GF_ERROR_CODE_NAMETOOLONG; + + /* EHOSTDOWN 64 / * Host is down */ + gf_error_to_errno_array[GF_ERROR_CODE_HOSTDOWN] = EHOSTDOWN; + gf_errno_to_error_array[EHOSTDOWN] = GF_ERROR_CODE_HOSTDOWN; + + /* EHOSTUNREACH 65 / * No route to host */ + gf_error_to_errno_array[GF_ERROR_CODE_HOSTUNREACH] = EHOSTUNREACH; + gf_errno_to_error_array[EHOSTUNREACH] = GF_ERROR_CODE_HOSTUNREACH; + + /* ENOTEMPTY 66 / * Directory not empty */ + gf_error_to_errno_array[GF_ERROR_CODE_NOTEMPTY] = ENOTEMPTY; + gf_errno_to_error_array[ENOTEMPTY] = GF_ERROR_CODE_NOTEMPTY; + + /* EPROCLIM 67 / * Too many processes */ + gf_error_to_errno_array[GF_ERROR_CODE_PROCLIM] = EPROCLIM; + gf_errno_to_error_array[EPROCLIM] = GF_ERROR_CODE_PROCLIM; + + /* EUSERS 68 / * Too many users */ + gf_error_to_errno_array[GF_ERROR_CODE_USERS] = EUSERS; + gf_errno_to_error_array[EUSERS] = GF_ERROR_CODE_USERS; + + /* EDQUOT 69 / * Disc quota exceeded */ + gf_error_to_errno_array[GF_ERROR_CODE_DQUOT] = EDQUOT; + gf_errno_to_error_array[EDQUOT] = GF_ERROR_CODE_DQUOT; + + /* ESTALE 70 / * Stale NFS file handle */ + gf_error_to_errno_array[GF_ERROR_CODE_STALE] = ESTALE; + gf_errno_to_error_array[ESTALE] = GF_ERROR_CODE_STALE; + + /* EREMOTE 71 / * Too many levels of remote in + * path */ + gf_error_to_errno_array[GF_ERROR_CODE_REMOTE] = EREMOTE; + gf_errno_to_error_array[EREMOTE] = GF_ERROR_CODE_REMOTE; + + /* EBADRPC 72 / * RPC struct is bad */ + gf_error_to_errno_array[GF_ERROR_CODE_BADRPC] = EBADRPC; + gf_errno_to_error_array[EBADRPC] = GF_ERROR_CODE_BADRPC; + + /* ERPCMISMATCH 73 / * RPC version wrong */ + gf_error_to_errno_array[GF_ERROR_CODE_RPCMISMATCH] = ERPCMISMATCH; + gf_errno_to_error_array[ERPCMISMATCH] = GF_ERROR_CODE_RPCMISMATCH; + + /* EPROGUNAVAIL 74 / * RPC prog. not avail */ + gf_error_to_errno_array[GF_ERROR_CODE_PROGUNAVAIL] = EPROGUNAVAIL; + gf_errno_to_error_array[EPROGUNAVAIL] = GF_ERROR_CODE_PROGUNAVAIL; + + /* EPROGMISMATCH 75 / * Program version wrong */ + gf_error_to_errno_array[GF_ERROR_CODE_PROGMISMATCH] = EPROGMISMATCH; + gf_errno_to_error_array[EPROGMISMATCH] = GF_ERROR_CODE_PROGMISMATCH; + + /* EPROCUNAVAIL 76 / * Bad procedure for program */ + gf_error_to_errno_array[GF_ERROR_CODE_PROCUNAVAIL] = EPROCUNAVAIL; + gf_errno_to_error_array[EPROCUNAVAIL] = GF_ERROR_CODE_PROCUNAVAIL; + + /* ENOLCK 77 / * No locks available */ + gf_error_to_errno_array[GF_ERROR_CODE_NOLCK] = ENOLCK; + gf_errno_to_error_array[ENOLCK] = GF_ERROR_CODE_NOLCK; - /* EADDRINUSE 48 / * Address already in use */ - gf_error_to_errno_array[GF_ERROR_CODE_ADDRINUSE] = EADDRINUSE; - gf_errno_to_error_array[EADDRINUSE] = GF_ERROR_CODE_ADDRINUSE; + /* ENOSYS 78 / * Function not implemented */ + gf_error_to_errno_array[GF_ERROR_CODE_NOSYS] = ENOSYS; + gf_errno_to_error_array[ENOSYS] = GF_ERROR_CODE_NOSYS; - /* EADDRNOTAVAIL 49 / * Can't assign requested address */ - gf_error_to_errno_array[GF_ERROR_CODE_ADDRNOTAVAIL] = EADDRNOTAVAIL; - gf_errno_to_error_array[EADDRNOTAVAIL] = GF_ERROR_CODE_ADDRNOTAVAIL; + /* EFTYPE 79 / * Inappropriate file type or + * format */ + gf_error_to_errno_array[GF_ERROR_CODE_FTYPE] = EFTYPE; + gf_errno_to_error_array[EFTYPE] = GF_ERROR_CODE_FTYPE; + + /* EAUTH 80 / * Authentication error */ + gf_error_to_errno_array[GF_ERROR_CODE_AUTH] = EAUTH; + gf_errno_to_error_array[EAUTH] = GF_ERROR_CODE_AUTH; + + /* ENEEDAUTH 81 / * Need authenticator */ + gf_error_to_errno_array[GF_ERROR_CODE_NEEDAUTH] = ENEEDAUTH; + gf_errno_to_error_array[ENEEDAUTH] = GF_ERROR_CODE_NEEDAUTH; + + /* EIDRM 82 / * Identifier removed */ + gf_error_to_errno_array[GF_ERROR_CODE_IDRM] = EIDRM; + gf_errno_to_error_array[EIDRM] = GF_ERROR_CODE_IDRM; - /* ENETDOWN 50 / * Network is down */ - gf_error_to_errno_array[GF_ERROR_CODE_NETDOWN] = ENETDOWN; - gf_errno_to_error_array[ENETDOWN] = GF_ERROR_CODE_NETDOWN; + /* ENOMSG 83 / * No message of desired type */ + gf_error_to_errno_array[GF_ERROR_CODE_NOMSG] = ENOMSG; + gf_errno_to_error_array[ENOMSG] = GF_ERROR_CODE_NOMSG; - /* ENETUNREACH 51 / * Network is unreachable */ - gf_error_to_errno_array[GF_ERROR_CODE_NETUNREACH] = ENETUNREACH; - gf_errno_to_error_array[ENETUNREACH] = GF_ERROR_CODE_NETUNREACH; + /* EOVERFLOW 84 / * Value too large to be stored in + * data type */ + gf_error_to_errno_array[GF_ERROR_CODE_OVERFLOW] = EOVERFLOW; + gf_errno_to_error_array[EOVERFLOW] = GF_ERROR_CODE_OVERFLOW; - /* ENETRESET 52 / * Network dropped connection on reset */ - gf_error_to_errno_array[GF_ERROR_CODE_NETRESET] = ENETRESET; - gf_errno_to_error_array[ENETRESET] = GF_ERROR_CODE_NETRESET; + /* ECANCELED 85 / * Operation canceled */ + gf_error_to_errno_array[GF_ERROR_CODE_CANCELED] = ECANCELED; + gf_errno_to_error_array[ECANCELED] = GF_ERROR_CODE_CANCELED; - /* ECONNABORTED 53 / * Software caused connection abort */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNABORTED] = ECONNABORTED; - gf_errno_to_error_array[ECONNABORTED] = GF_ERROR_CODE_CONNABORTED; + /* EILSEQ 86 / * Illegal byte sequence */ + gf_error_to_errno_array[GF_ERROR_CODE_ILSEQ] = EILSEQ; + gf_errno_to_error_array[EILSEQ] = GF_ERROR_CODE_ILSEQ; - /* ECONNRESET 54 / * Connection reset by peer */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNRESET] = ECONNRESET; - gf_errno_to_error_array[ECONNRESET] = GF_ERROR_CODE_CONNRESET; - - /* ENOBUFS 55 / * No buffer space available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOBUFS] = ENOBUFS; - gf_errno_to_error_array[ENOBUFS] = GF_ERROR_CODE_NOBUFS; - - /* EISCONN 56 / * Socket is already connected */ - gf_error_to_errno_array[GF_ERROR_CODE_ISCONN] = EISCONN; - gf_errno_to_error_array[EISCONN] = GF_ERROR_CODE_ISCONN; - - /* ENOTCONN 57 / * Socket is not connected */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTCONN] = ENOTCONN; - gf_errno_to_error_array[ENOTCONN] = GF_ERROR_CODE_NOTCONN; - - /* ESHUTDOWN 58 / * Can't send after socket shutdown */ - gf_error_to_errno_array[GF_ERROR_CODE_SHUTDOWN] = ESHUTDOWN; - gf_errno_to_error_array[ESHUTDOWN] = GF_ERROR_CODE_SHUTDOWN; - - /* ETOOMANYREFS 59 / * Too many references: can't splice */ - gf_error_to_errno_array[GF_ERROR_CODE_TOOMANYREFS] = ETOOMANYREFS; - gf_errno_to_error_array[ETOOMANYREFS] = GF_ERROR_CODE_TOOMANYREFS; - - /* ETIMEDOUT 60 / * Operation timed out */ - gf_error_to_errno_array[GF_ERROR_CODE_TIMEDOUT] = ETIMEDOUT; - gf_errno_to_error_array[ETIMEDOUT] = GF_ERROR_CODE_TIMEDOUT; - - /* ECONNREFUSED 61 / * Connection refused */ - gf_error_to_errno_array[GF_ERROR_CODE_CONNREFUSED] = ECONNREFUSED; - gf_errno_to_error_array[ECONNREFUSED] = GF_ERROR_CODE_CONNREFUSED; - - /* ELOOP 62 / * Too many levels of symbolic links */ - gf_error_to_errno_array[GF_ERROR_CODE_LOOP] = ELOOP; - gf_errno_to_error_array[ELOOP] = GF_ERROR_CODE_LOOP; - - /* ENAMETOOLONG 63 / * File name too long */ - gf_error_to_errno_array[GF_ERROR_CODE_NAMETOOLONG] = ENAMETOOLONG; - gf_errno_to_error_array[ENAMETOOLONG] = GF_ERROR_CODE_NAMETOOLONG; - - /* EHOSTDOWN 64 / * Host is down */ - gf_error_to_errno_array[GF_ERROR_CODE_HOSTDOWN] = EHOSTDOWN; - gf_errno_to_error_array[EHOSTDOWN] = GF_ERROR_CODE_HOSTDOWN; - - /* EHOSTUNREACH 65 / * No route to host */ - gf_error_to_errno_array[GF_ERROR_CODE_HOSTUNREACH] = EHOSTUNREACH; - gf_errno_to_error_array[EHOSTUNREACH] = GF_ERROR_CODE_HOSTUNREACH; - - /* ENOTEMPTY 66 / * Directory not empty */ - gf_error_to_errno_array[GF_ERROR_CODE_NOTEMPTY] = ENOTEMPTY; - gf_errno_to_error_array[ENOTEMPTY] = GF_ERROR_CODE_NOTEMPTY; - - /* EPROCLIM 67 / * Too many processes */ - gf_error_to_errno_array[GF_ERROR_CODE_PROCLIM] = EPROCLIM; - gf_errno_to_error_array[EPROCLIM] = GF_ERROR_CODE_PROCLIM; - - /* EUSERS 68 / * Too many users */ - gf_error_to_errno_array[GF_ERROR_CODE_USERS] = EUSERS; - gf_errno_to_error_array[EUSERS] = GF_ERROR_CODE_USERS; - - /* EDQUOT 69 / * Disc quota exceeded */ - gf_error_to_errno_array[GF_ERROR_CODE_DQUOT] = EDQUOT; - gf_errno_to_error_array[EDQUOT] = GF_ERROR_CODE_DQUOT; - - /* ESTALE 70 / * Stale NFS file handle */ - gf_error_to_errno_array[GF_ERROR_CODE_STALE] = ESTALE; - gf_errno_to_error_array[ESTALE] = GF_ERROR_CODE_STALE; - - /* EREMOTE 71 / * Too many levels of remote in path */ - gf_error_to_errno_array[GF_ERROR_CODE_REMOTE] = EREMOTE; - gf_errno_to_error_array[EREMOTE] = GF_ERROR_CODE_REMOTE; - - /* EBADRPC 72 / * RPC struct is bad */ - gf_error_to_errno_array[GF_ERROR_CODE_BADRPC] = EBADRPC; - gf_errno_to_error_array[EBADRPC] = GF_ERROR_CODE_BADRPC; - - /* ERPCMISMATCH 73 / * RPC version wrong */ - gf_error_to_errno_array[GF_ERROR_CODE_RPCMISMATCH] = ERPCMISMATCH; - gf_errno_to_error_array[ERPCMISMATCH] = GF_ERROR_CODE_RPCMISMATCH; - - /* EPROGUNAVAIL 74 / * RPC prog. not avail */ - gf_error_to_errno_array[GF_ERROR_CODE_PROGUNAVAIL] = EPROGUNAVAIL; - gf_errno_to_error_array[EPROGUNAVAIL] = GF_ERROR_CODE_PROGUNAVAIL; - - /* EPROGMISMATCH 75 / * Program version wrong */ - gf_error_to_errno_array[GF_ERROR_CODE_PROGMISMATCH] = EPROGMISMATCH; - gf_errno_to_error_array[EPROGMISMATCH] = GF_ERROR_CODE_PROGMISMATCH; - - /* EPROCUNAVAIL 76 / * Bad procedure for program */ - gf_error_to_errno_array[GF_ERROR_CODE_PROCUNAVAIL] = EPROCUNAVAIL; - gf_errno_to_error_array[EPROCUNAVAIL] = GF_ERROR_CODE_PROCUNAVAIL; - - /* ENOLCK 77 / * No locks available */ - gf_error_to_errno_array[GF_ERROR_CODE_NOLCK] = ENOLCK; - gf_errno_to_error_array[ENOLCK] = GF_ERROR_CODE_NOLCK; - - /* ENOSYS 78 / * Function not implemented */ - gf_error_to_errno_array[GF_ERROR_CODE_NOSYS] = ENOSYS; - gf_errno_to_error_array[ENOSYS] = GF_ERROR_CODE_NOSYS; - - /* EFTYPE 79 / * Inappropriate file type or format */ - gf_error_to_errno_array[GF_ERROR_CODE_FTYPE] = EFTYPE; - gf_errno_to_error_array[EFTYPE] = GF_ERROR_CODE_FTYPE; - - /* EAUTH 80 / * Authentication error */ - gf_error_to_errno_array[GF_ERROR_CODE_AUTH] = EAUTH; - gf_errno_to_error_array[EAUTH] = GF_ERROR_CODE_AUTH; - - /* ENEEDAUTH 81 / * Need authenticator */ - gf_error_to_errno_array[GF_ERROR_CODE_NEEDAUTH] = ENEEDAUTH; - gf_errno_to_error_array[ENEEDAUTH] = GF_ERROR_CODE_NEEDAUTH; - - /* EIDRM 82 / * Identifier removed */ - gf_error_to_errno_array[GF_ERROR_CODE_IDRM] = EIDRM; - gf_errno_to_error_array[EIDRM] = GF_ERROR_CODE_IDRM; - - /* ENOMSG 83 / * No message of desired type */ - gf_error_to_errno_array[GF_ERROR_CODE_NOMSG] = ENOMSG; - gf_errno_to_error_array[ENOMSG] = GF_ERROR_CODE_NOMSG; - - /* EOVERFLOW 84 / * Value too large to be stored in data type */ - gf_error_to_errno_array[GF_ERROR_CODE_OVERFLOW] = EOVERFLOW; - gf_errno_to_error_array[EOVERFLOW] = GF_ERROR_CODE_OVERFLOW; - - /* ECANCELED 85 / * Operation canceled */ - gf_error_to_errno_array[GF_ERROR_CODE_CANCELED] = ECANCELED; - gf_errno_to_error_array[ECANCELED] = GF_ERROR_CODE_CANCELED; - - /* EILSEQ 86 / * Illegal byte sequence */ - gf_error_to_errno_array[GF_ERROR_CODE_ILSEQ] = EILSEQ; - gf_errno_to_error_array[EILSEQ] = GF_ERROR_CODE_ILSEQ; - - /* ENOATTR 87 / * Attribute not found */ - gf_error_to_errno_array[GF_ERROR_CODE_NOATTR] = ENOATTR; - gf_errno_to_error_array[ENOATTR] = GF_ERROR_CODE_NOATTR; + /* ENOATTR 87 / * Attribute not found */ + gf_error_to_errno_array[GF_ERROR_CODE_NOATTR] = ENOATTR; + gf_errno_to_error_array[ENOATTR] = GF_ERROR_CODE_NOATTR; #ifdef EDOOFUS - /* EDOOFUS 88 / * Programming error */ - gf_error_to_errno_array[GF_ERROR_CODE_DOOFUS] = EDOOFUS; - gf_errno_to_error_array[EDOOFUS] = GF_ERROR_CODE_DOOFUS; + /* EDOOFUS 88 / * Programming error */ + gf_error_to_errno_array[GF_ERROR_CODE_DOOFUS] = EDOOFUS; + gf_errno_to_error_array[EDOOFUS] = GF_ERROR_CODE_DOOFUS; #endif - /* EBADMSG 89 / * Bad message */ - gf_error_to_errno_array[GF_ERROR_CODE_BADMSG] = EBADMSG; - gf_errno_to_error_array[EBADMSG] = GF_ERROR_CODE_BADMSG; + /* EBADMSG 89 / * Bad message */ + gf_error_to_errno_array[GF_ERROR_CODE_BADMSG] = EBADMSG; + gf_errno_to_error_array[EBADMSG] = GF_ERROR_CODE_BADMSG; #ifdef __NetBSD__ - /* ENODATA 89 / * No message available */ - gf_error_to_errno_array[GF_ERROR_CODE_NODATA] = ENODATA; - gf_errno_to_error_array[ENODATA] = GF_ERROR_CODE_NODATA; + /* ENODATA 89 / * No message available */ + gf_error_to_errno_array[GF_ERROR_CODE_NODATA] = ENODATA; + gf_errno_to_error_array[ENODATA] = GF_ERROR_CODE_NODATA; #endif - /* EMULTIHOP 90 / * Multihop attempted */ - gf_error_to_errno_array[GF_ERROR_CODE_MULTIHOP] = EMULTIHOP; - gf_errno_to_error_array[EMULTIHOP] = GF_ERROR_CODE_MULTIHOP; - - /* ENOLINK 91 / * Link has been severed */ - gf_error_to_errno_array[GF_ERROR_CODE_NOLINK] = ENOLINK; - gf_errno_to_error_array[ENOLINK] = GF_ERROR_CODE_NOLINK; + /* EMULTIHOP 90 / * Multihop attempted */ + gf_error_to_errno_array[GF_ERROR_CODE_MULTIHOP] = EMULTIHOP; + gf_errno_to_error_array[EMULTIHOP] = GF_ERROR_CODE_MULTIHOP; - /* EPROTO 92 / * Protocol error */ - gf_error_to_errno_array[GF_ERROR_CODE_PROTO] = EPROTO; - gf_errno_to_error_array[EPROTO] = GF_ERROR_CODE_PROTO; + /* ENOLINK 91 / * Link has been severed */ + gf_error_to_errno_array[GF_ERROR_CODE_NOLINK] = ENOLINK; + gf_errno_to_error_array[ENOLINK] = GF_ERROR_CODE_NOLINK; + /* EPROTO 92 / * Protocol error */ + gf_error_to_errno_array[GF_ERROR_CODE_PROTO] = EPROTO; + gf_errno_to_error_array[EPROTO] = GF_ERROR_CODE_PROTO; - return ; + return; } #endif /* GF_BSD_HOST_OS */ #ifdef GF_LINUX_HOST_OS static void -init_compat_errno_arrays () +init_compat_errno_arrays() { - /* Things are fine. Everything should work seemlessly on GNU/Linux machines */ - return ; + /* Things are fine. Everything should work seemlessly on GNU/Linux machines + */ + return; } #endif /* GF_LINUX_HOST_OS */ - static void -init_errno_arrays () +init_errno_arrays() { - int i; - for (i=0; i < GF_ERROR_CODE_UNKNOWN; i++) { - gf_errno_to_error_array[i] = i; - gf_error_to_errno_array[i] = i; - } - /* Now change the order if it needs to be. */ - init_compat_errno_arrays(); - - return; + int i; + for (i = 0; i < GF_ERROR_CODE_UNKNOWN; i++) { + gf_errno_to_error_array[i] = i; + gf_error_to_errno_array[i] = i; + } + /* Now change the order if it needs to be. */ + init_compat_errno_arrays(); + + return; } int32_t -gf_errno_to_error (int32_t op_errno) +gf_errno_to_error(int32_t op_errno) { - if (!gf_compat_errno_init_done) { - init_errno_arrays (); - gf_compat_errno_init_done = 1; - } + if (!gf_compat_errno_init_done) { + init_errno_arrays(); + gf_compat_errno_init_done = 1; + } - if ((op_errno > GF_ERROR_CODE_SUCCESS) && (op_errno < GF_ERROR_CODE_UNKNOWN)) - return gf_errno_to_error_array[op_errno]; + if ((op_errno > GF_ERROR_CODE_SUCCESS) && + (op_errno < GF_ERROR_CODE_UNKNOWN)) + return gf_errno_to_error_array[op_errno]; - return op_errno; + return op_errno; } - int32_t -gf_error_to_errno (int32_t error) +gf_error_to_errno(int32_t error) { - if (!gf_compat_errno_init_done) { - init_errno_arrays (); - gf_compat_errno_init_done = 1; - } + if (!gf_compat_errno_init_done) { + init_errno_arrays(); + gf_compat_errno_init_done = 1; + } - if ((error > GF_ERROR_CODE_SUCCESS) && (error < GF_ERROR_CODE_UNKNOWN)) - return gf_error_to_errno_array[error]; + if ((error > GF_ERROR_CODE_SUCCESS) && (error < GF_ERROR_CODE_UNKNOWN)) + return gf_error_to_errno_array[error]; - return error; + return error; } diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index a27fe20ce64..137bdf45cab 100644 --- a/libglusterfs/src/compat.c +++ b/libglusterfs/src/compat.c @@ -30,507 +30,521 @@ #ifdef GF_SOLARIS_HOST_OS int -solaris_fsetxattr(int fd, const char* key, const char *value, size_t size, +solaris_fsetxattr(int fd, const char *key, const char *value, size_t size, int flags) { - int attrfd = -1; - int ret = 0; - - attrfd = openat (fd, key, flags|O_CREAT|O_WRONLY|O_XATTR, 0777); - if (attrfd >= 0) { - ftruncate (attrfd, 0); - ret = write (attrfd, value, size); - close (attrfd); - } else { - if (errno != ENOENT) - gf_msg ("libglusterfs", GF_LOG_ERROR, errno, - LG_MSG_SET_ATTRIBUTE_FAILED, "Couldn't set " - "extended attribute for %d", fd); - return -1; - } - - return 0; + int attrfd = -1; + int ret = 0; + + attrfd = openat(fd, key, flags | O_CREAT | O_WRONLY | O_XATTR, 0777); + if (attrfd >= 0) { + ftruncate(attrfd, 0); + ret = write(attrfd, value, size); + close(attrfd); + } else { + if (errno != ENOENT) + gf_msg("libglusterfs", GF_LOG_ERROR, errno, + LG_MSG_SET_ATTRIBUTE_FAILED, + "Couldn't set " + "extended attribute for %d", + fd); + return -1; + } + + return 0; } - int -solaris_fgetxattr(int fd, const char* key, char *value, size_t size) +solaris_fgetxattr(int fd, const char *key, char *value, size_t size) { - int attrfd = -1; - int ret = 0; - - attrfd = openat (fd, key, O_RDONLY|O_XATTR); - if (attrfd >= 0) { - if (size == 0) { - struct stat buf; - fstat (attrfd, &buf); - ret = buf.st_size; - } else { - ret = read (attrfd, value, size); - } - close (attrfd); + int attrfd = -1; + int ret = 0; + + attrfd = openat(fd, key, O_RDONLY | O_XATTR); + if (attrfd >= 0) { + if (size == 0) { + struct stat buf; + fstat(attrfd, &buf); + ret = buf.st_size; } else { - if (errno != ENOENT) - gf_msg ("libglusterfs", GF_LOG_INFO, errno, - LG_MSG_READ_ATTRIBUTE_FAILED, "Couldn't read " - "extended attribute for the file %d", fd); - if (errno == ENOENT) - errno = ENODATA; - return -1; + ret = read(attrfd, value, size); } - - return ret; + close(attrfd); + } else { + if (errno != ENOENT) + gf_msg("libglusterfs", GF_LOG_INFO, errno, + LG_MSG_READ_ATTRIBUTE_FAILED, + "Couldn't read " + "extended attribute for the file %d", + fd); + if (errno == ENOENT) + errno = ENODATA; + return -1; + } + + return ret; } /* Solaris does not support xattr for symlinks and dev files. Since gfid and other trusted attributes are stored as xattrs, we need to provide support for - them. A mapped regular file is stored in the /.glusterfs_xattr_inode of the export dir. - All xattr ops related to the special files are redirected to this map file. + them. A mapped regular file is stored in the /.glusterfs_xattr_inode of the + export dir. All xattr ops related to the special files are redirected to this + map file. */ int -make_export_path (const char *real_path, char **path) +make_export_path(const char *real_path, char **path) { - int ret = -1; - char *tmp = NULL; - char *export_path = NULL; - char *dup = NULL; - char *ptr = NULL; - char *freeptr = NULL; - uuid_t gfid = {0, }; - - export_path = GF_CALLOC (1, sizeof (char) * PATH_MAX, 0); - if (!export_path) - goto out; + int ret = -1; + char *tmp = NULL; + char *export_path = NULL; + char *dup = NULL; + char *ptr = NULL; + char *freeptr = NULL; + uuid_t gfid = { + 0, + }; + + export_path = GF_CALLOC(1, sizeof(char) * PATH_MAX, 0); + if (!export_path) + goto out; - dup = gf_strdup (real_path); - if (!dup) - goto out; + dup = gf_strdup(real_path); + if (!dup) + goto out; - freeptr = dup; - ret = solaris_getxattr ("/", GFID_XATTR_KEY, gfid, 16); - /* Return value of getxattr */ + freeptr = dup; + ret = solaris_getxattr("/", GFID_XATTR_KEY, gfid, 16); + /* Return value of getxattr */ + if (ret == 16) { + if (__is_root_gfid(gfid)) { + strcat(export_path, "/"); + ret = 0; + goto done; + } + } + + do { + ptr = strtok_r(dup, "/", &tmp); + if (!ptr) + break; + strcat(export_path, dup); + ret = solaris_getxattr(export_path, GFID_XATTR_KEY, gfid, 16); if (ret == 16) { - if (__is_root_gfid (gfid)){ - strcat (export_path, "/"); - ret = 0; - goto done; - } + if (__is_root_gfid(gfid)) { + ret = 0; + goto done; + } } + strcat(export_path, "/"); + dup = tmp; + } while (ptr); - do { - ptr = strtok_r (dup, "/", &tmp); - if (!ptr) - break; - strcat (export_path, dup); - ret = solaris_getxattr (export_path, GFID_XATTR_KEY, gfid, 16); - if (ret == 16) { - if (__is_root_gfid (gfid)) { - ret = 0; - goto done; - } - } - strcat (export_path, "/"); - dup = tmp; - } while (ptr); - - goto out; + goto out; done: - if (!ret) { - *path = export_path; - } + if (!ret) { + *path = export_path; + } out: - GF_FREE (freeptr); - if (ret && export_path) - GF_FREE (export_path); + GF_FREE(freeptr); + if (ret && export_path) + GF_FREE(export_path); - return ret; + return ret; } int -solaris_xattr_resolve_path (const char *real_path, char **path) +solaris_xattr_resolve_path(const char *real_path, char **path) { - int ret = -1; - char *export_path = NULL; - char xattr_path[PATH_MAX] = {0, }; - struct stat lstatbuf = {0, }; - struct iatt stbuf = {0, }; - struct stat statbuf = {0, }; - - ret = lstat (real_path, &lstatbuf); - if (ret != 0 ) - return ret; - iatt_from_stat (&stbuf, &lstatbuf); - if (IA_ISREG(stbuf.ia_type) || IA_ISDIR(stbuf.ia_type)) - return -1; - - ret = make_export_path (real_path, &export_path); - if (!ret && export_path) { - strcat (export_path, "/"GF_SOLARIS_XATTR_DIR); - if (lstat (export_path, &statbuf)) { - ret = mkdir (export_path, 0777); - if (ret && (errno != EEXIST)) { - gf_msg_debug (THIS->name, 0, "mkdir failed," - " errno: %d", errno); - goto out; - } - } + int ret = -1; + char *export_path = NULL; + char xattr_path[PATH_MAX] = { + 0, + }; + struct stat lstatbuf = { + 0, + }; + struct iatt stbuf = { + 0, + }; + struct stat statbuf = { + 0, + }; + + ret = lstat(real_path, &lstatbuf); + if (ret != 0) + return ret; + iatt_from_stat(&stbuf, &lstatbuf); + if (IA_ISREG(stbuf.ia_type) || IA_ISDIR(stbuf.ia_type)) + return -1; + + ret = make_export_path(real_path, &export_path); + if (!ret && export_path) { + strcat(export_path, "/" GF_SOLARIS_XATTR_DIR); + if (lstat(export_path, &statbuf)) { + ret = mkdir(export_path, 0777); + if (ret && (errno != EEXIST)) { + gf_msg_debug(THIS->name, 0, + "mkdir failed," + " errno: %d", + errno); + goto out; + } + } - snprintf(xattr_path, PATH_MAX, "%s%s%lu", export_path, - "/", stbuf.ia_ino); + snprintf(xattr_path, PATH_MAX, "%s%s%lu", export_path, "/", + stbuf.ia_ino); - ret = lstat (xattr_path, &statbuf); + ret = lstat(xattr_path, &statbuf); - if (ret) { - ret = mknod (xattr_path, S_IFREG|O_WRONLY, 0); - if (ret && (errno != EEXIST)) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "Failed to " - "create mapped file %s", xattr_path); - goto out; - } - } - *path = gf_strdup (xattr_path); + if (ret) { + ret = mknod(xattr_path, S_IFREG | O_WRONLY, 0); + if (ret && (errno != EEXIST)) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "Failed to " + "create mapped file %s", + xattr_path); + goto out; + } } + *path = gf_strdup(xattr_path); + } out: - GF_FREE (export_path); - if (*path) - return 0; - else - return -1; + GF_FREE(export_path); + if (*path) + return 0; + else + return -1; } int -solaris_setxattr(const char *path, const char* key, const char *value, +solaris_setxattr(const char *path, const char *key, const char *value, size_t size, int flags) { - int attrfd = -1; - int ret = 0; - char *mapped_path = NULL; - - ret = solaris_xattr_resolve_path (path, &mapped_path); - if (!ret) { - attrfd = attropen (mapped_path, key, flags|O_CREAT|O_WRONLY, - 0777); - } else { - attrfd = attropen (path, key, flags|O_CREAT|O_WRONLY, 0777); - } - if (attrfd >= 0) { - ftruncate (attrfd, 0); - ret = write (attrfd, value, size); - close (attrfd); - ret = 0; - } else { - if (errno != ENOENT) - gf_msg ("libglusterfs", GF_LOG_ERROR, errno, - LG_MSG_SET_ATTRIBUTE_FAILED, "Couldn't set " - "extended attribute for %s", path); - ret = -1; - } - GF_FREE (mapped_path); - return ret; + int attrfd = -1; + int ret = 0; + char *mapped_path = NULL; + + ret = solaris_xattr_resolve_path(path, &mapped_path); + if (!ret) { + attrfd = attropen(mapped_path, key, flags | O_CREAT | O_WRONLY, 0777); + } else { + attrfd = attropen(path, key, flags | O_CREAT | O_WRONLY, 0777); + } + if (attrfd >= 0) { + ftruncate(attrfd, 0); + ret = write(attrfd, value, size); + close(attrfd); + ret = 0; + } else { + if (errno != ENOENT) + gf_msg("libglusterfs", GF_LOG_ERROR, errno, + LG_MSG_SET_ATTRIBUTE_FAILED, + "Couldn't set " + "extended attribute for %s", + path); + ret = -1; + } + GF_FREE(mapped_path); + return ret; } - int solaris_listxattr(const char *path, char *list, size_t size) { - int attrdirfd = -1; - ssize_t len = 0; - DIR *dirptr = NULL; - struct dirent *dent = NULL; - int newfd = -1; - char *mapped_path = NULL; - int ret = -1; - - ret = solaris_xattr_resolve_path (path, &mapped_path); - if (!ret) { - attrdirfd = attropen (mapped_path, ".", O_RDONLY, 0); - } else { - attrdirfd = attropen (path, ".", O_RDONLY, 0); - } - if (attrdirfd >= 0) { - newfd = dup(attrdirfd); - dirptr = fdopendir(newfd); - if (dirptr) { - while ((dent = readdir(dirptr))) { - size_t listlen = strlen(dent->d_name); - if (!strcmp(dent->d_name, ".") || - !strcmp(dent->d_name, "..")) { - /* we don't want "." and ".." here */ - continue; - } - if (size == 0) { - /* return the current size of the list - of extended attribute names*/ - len += listlen + 1; - } else { - /* check size and copy entry + null - into list. */ - if ((len + listlen + 1) > size) { - errno = ERANGE; - len = -1; - break; - } else { - strncpy(list + len, dent->d_name, listlen); - len += listlen; - list[len] = '\0'; - ++len; - } - } - } - - if (closedir(dirptr) == -1) { - close (attrdirfd); - len = -1; - goto out; - } + int attrdirfd = -1; + ssize_t len = 0; + DIR *dirptr = NULL; + struct dirent *dent = NULL; + int newfd = -1; + char *mapped_path = NULL; + int ret = -1; + + ret = solaris_xattr_resolve_path(path, &mapped_path); + if (!ret) { + attrdirfd = attropen(mapped_path, ".", O_RDONLY, 0); + } else { + attrdirfd = attropen(path, ".", O_RDONLY, 0); + } + if (attrdirfd >= 0) { + newfd = dup(attrdirfd); + dirptr = fdopendir(newfd); + if (dirptr) { + while ((dent = readdir(dirptr))) { + size_t listlen = strlen(dent->d_name); + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) { + /* we don't want "." and ".." here */ + continue; + } + if (size == 0) { + /* return the current size of the list + of extended attribute names*/ + len += listlen + 1; } else { - close (attrdirfd); + /* check size and copy entry + null + into list. */ + if ((len + listlen + 1) > size) { + errno = ERANGE; len = -1; - goto out; + break; + } else { + strncpy(list + len, dent->d_name, listlen); + len += listlen; + list[len] = '\0'; + ++len; + } } - close (attrdirfd); + } + + if (closedir(dirptr) == -1) { + close(attrdirfd); + len = -1; + goto out; + } + } else { + close(attrdirfd); + len = -1; + goto out; } + close(attrdirfd); + } out: - GF_FREE (mapped_path); - return len; + GF_FREE(mapped_path); + return len; } - int solaris_flistxattr(int fd, char *list, size_t size) { - int attrdirfd = -1; - ssize_t len = 0; - DIR *dirptr = NULL; - struct dirent *dent = NULL; - int newfd = -1; - - attrdirfd = openat (fd, ".", O_RDONLY, 0); - if (attrdirfd >= 0) { - newfd = dup(attrdirfd); - dirptr = fdopendir(newfd); - if (dirptr) { - while ((dent = readdir(dirptr))) { - size_t listlen = strlen(dent->d_name); - if (!strcmp(dent->d_name, ".") || - !strcmp(dent->d_name, "..")) { - /* we don't want "." and ".." here */ - continue; - } - if (size == 0) { - /* return the current size of the list - of extended attribute names*/ - len += listlen + 1; - } else { - /* check size and copy entry + null - into list. */ - if ((len + listlen + 1) > size) { - errno = ERANGE; - len = -1; - break; - } else { - strncpy(list + len, dent->d_name, listlen); - len += listlen; - list[len] = '\0'; - ++len; - } - } - } - - if (closedir(dirptr) == -1) { - close (attrdirfd); - return -1; - } + int attrdirfd = -1; + ssize_t len = 0; + DIR *dirptr = NULL; + struct dirent *dent = NULL; + int newfd = -1; + + attrdirfd = openat(fd, ".", O_RDONLY, 0); + if (attrdirfd >= 0) { + newfd = dup(attrdirfd); + dirptr = fdopendir(newfd); + if (dirptr) { + while ((dent = readdir(dirptr))) { + size_t listlen = strlen(dent->d_name); + if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) { + /* we don't want "." and ".." here */ + continue; + } + if (size == 0) { + /* return the current size of the list + of extended attribute names*/ + len += listlen + 1; } else { - close (attrdirfd); - return -1; + /* check size and copy entry + null + into list. */ + if ((len + listlen + 1) > size) { + errno = ERANGE; + len = -1; + break; + } else { + strncpy(list + len, dent->d_name, listlen); + len += listlen; + list[len] = '\0'; + ++len; + } } - close (attrdirfd); + } + + if (closedir(dirptr) == -1) { + close(attrdirfd); + return -1; + } + } else { + close(attrdirfd); + return -1; } - return len; + close(attrdirfd); + } + return len; } - int -solaris_removexattr(const char *path, const char* key) +solaris_removexattr(const char *path, const char *key) { - int ret = -1; - int attrfd = -1; - char *mapped_path = NULL; - - ret = solaris_xattr_resolve_path (path, &mapped_path); - if (!ret) { - attrfd = attropen (mapped_path, ".", O_RDONLY, 0); - } else { - attrfd = attropen (path, ".", O_RDONLY, 0); - } - if (attrfd >= 0) { - ret = unlinkat (attrfd, key, 0); - close (attrfd); - } else { - if (errno == ENOENT) - errno = ENODATA; - ret = -1; - } - - GF_FREE (mapped_path); - - return ret; + int ret = -1; + int attrfd = -1; + char *mapped_path = NULL; + + ret = solaris_xattr_resolve_path(path, &mapped_path); + if (!ret) { + attrfd = attropen(mapped_path, ".", O_RDONLY, 0); + } else { + attrfd = attropen(path, ".", O_RDONLY, 0); + } + if (attrfd >= 0) { + ret = unlinkat(attrfd, key, 0); + close(attrfd); + } else { + if (errno == ENOENT) + errno = ENODATA; + ret = -1; + } + + GF_FREE(mapped_path); + + return ret; } int -solaris_getxattr(const char *path, - const char* key, - char *value, - size_t size) +solaris_getxattr(const char *path, const char *key, char *value, size_t size) { - int attrfd = -1; - int ret = 0; - char *mapped_path = NULL; - - ret = solaris_xattr_resolve_path (path, &mapped_path); - if (!ret) { - attrfd = attropen (mapped_path, key, O_RDONLY, 0); - } else { - attrfd = attropen (path, key, O_RDONLY, 0); - } - - if (attrfd >= 0) { - if (size == 0) { - struct stat buf; - fstat (attrfd, &buf); - ret = buf.st_size; - } else { - ret = read (attrfd, value, size); - } - close (attrfd); + int attrfd = -1; + int ret = 0; + char *mapped_path = NULL; + + ret = solaris_xattr_resolve_path(path, &mapped_path); + if (!ret) { + attrfd = attropen(mapped_path, key, O_RDONLY, 0); + } else { + attrfd = attropen(path, key, O_RDONLY, 0); + } + + if (attrfd >= 0) { + if (size == 0) { + struct stat buf; + fstat(attrfd, &buf); + ret = buf.st_size; } else { - if (errno != ENOENT) - gf_msg ("libglusterfs", GF_LOG_INFO, errno, - LG_MSG_READ_ATTRIBUTE_FAILED, "Couldn't read " - "extended attribute for the file %s", path); - if (errno == ENOENT) - errno = ENODATA; - ret = -1; + ret = read(attrfd, value, size); } - GF_FREE (mapped_path); - return ret; + close(attrfd); + } else { + if (errno != ENOENT) + gf_msg("libglusterfs", GF_LOG_INFO, errno, + LG_MSG_READ_ATTRIBUTE_FAILED, + "Couldn't read " + "extended attribute for the file %s", + path); + if (errno == ENOENT) + errno = ENODATA; + ret = -1; + } + GF_FREE(mapped_path); + return ret; } - -char* strsep(char** str, const char* delims) +char * +strsep(char **str, const char *delims) { - char* token; - - if (*str==NULL) { - /* No more tokens */ - return NULL; - } - - token=*str; - while (**str!='\0') { - if (strchr(delims,**str)!=NULL) { - **str='\0'; - (*str)++; - return token; - } - (*str)++; + char *token; + + if (*str == NULL) { + /* No more tokens */ + return NULL; + } + + token = *str; + while (**str != '\0') { + if (strchr(delims, **str) != NULL) { + **str = '\0'; + (*str)++; + return token; } - /* There is no other token */ - *str=NULL; - return token; + (*str)++; + } + /* There is no other token */ + *str = NULL; + return token; } /* Code comes from libiberty */ int -vasprintf (char **result, const char *format, va_list args) +vasprintf(char **result, const char *format, va_list args) { - return gf_vasprintf(result, format, args); + return gf_vasprintf(result, format, args); } int -asprintf (char **buf, const char *fmt, ...) +asprintf(char **buf, const char *fmt, ...) { - int status; - va_list ap; + int status; + va_list ap; - va_start (ap, fmt); - status = vasprintf (buf, fmt, ap); - va_end (ap); - return status; + va_start(ap, fmt); + status = vasprintf(buf, fmt, ap); + va_end(ap); + return status; } -int solaris_unlink (const char *path) +int +solaris_unlink(const char *path) { - char *mapped_path = NULL; - struct stat stbuf = {0, }; - int ret = -1; - - ret = solaris_xattr_resolve_path (path, &mapped_path); - - - if (!ret && mapped_path) { - if (lstat(path, &stbuf)) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "Stat failed on " - "mapped file %s", mapped_path); - goto out; - } - if (stbuf.st_nlink == 1) { - if(remove (mapped_path)) - gf_msg (THIS->name, GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "Failed to " - "remove mapped file %s", mapped_path); - } - + char *mapped_path = NULL; + struct stat stbuf = { + 0, + }; + int ret = -1; + + ret = solaris_xattr_resolve_path(path, &mapped_path); + + if (!ret && mapped_path) { + if (lstat(path, &stbuf)) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "Stat failed on " + "mapped file %s", + mapped_path); + goto out; + } + if (stbuf.st_nlink == 1) { + if (remove(mapped_path)) + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "Failed to " + "remove mapped file %s", + mapped_path); } + } out: - GF_FREE (mapped_path); + GF_FREE(mapped_path); - return unlink (path); + return unlink(path); } int -solaris_rename (const char *old_path, const char *new_path) +solaris_rename(const char *old_path, const char *new_path) { - char *mapped_path = NULL; - int ret = -1; - - ret = solaris_xattr_resolve_path (new_path, &mapped_path); + char *mapped_path = NULL; + int ret = -1; + ret = solaris_xattr_resolve_path(new_path, &mapped_path); - if (!ret && mapped_path) { - if (!remove (mapped_path)) - gf_msg (THIS->name, GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "Failed to remove " - "mapped file %s.", mapped_path); - GF_FREE (mapped_path); - } - - return rename(old_path, new_path); + if (!ret && mapped_path) { + if (!remove(mapped_path)) + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "Failed to remove " + "mapped file %s.", + mapped_path); + GF_FREE(mapped_path); + } + return rename(old_path, new_path); } char * -mkdtemp (char *tempstring) +mkdtemp(char *tempstring) { - char *new_string = NULL; - int ret = 0; + char *new_string = NULL; + int ret = 0; - new_string = mkstemp (tempstring); - if (!new_string) - goto out; + new_string = mkstemp(tempstring); + if (!new_string) + goto out; - ret = mkdir (new_string, 0700); - if (ret < 0) - new_string = NULL; + ret = mkdir(new_string, 0700); + if (ret < 0) + new_string = NULL; out: - return new_string; + return new_string; } #endif /* GF_SOLARIS_HOST_OS */ @@ -539,27 +553,27 @@ out: void gf_extattr_list_reshape(char *bsd_list, ssize_t size) { - /* - * the format of bsd_list is - * <attr_len>attr<attr_len>attr... - * we try to reformat it as Linux's - * attr<\0>attr<\0>... - * */ - if (NULL == bsd_list || size <= 0) - return; - - size_t i = 0, j; - - while (i < size) { - size_t attr_len = bsd_list[i]; - - for (j = i; j < i+attr_len; ++j) - bsd_list[j] = bsd_list[j+1]; - bsd_list[j] = '\0'; - - i += attr_len + 1; - gf_msg_debug ("syscall", 0, "syscall debug: %lu", attr_len); - } + /* + * the format of bsd_list is + * <attr_len>attr<attr_len>attr... + * we try to reformat it as Linux's + * attr<\0>attr<\0>... + * */ + if (NULL == bsd_list || size <= 0) + return; + + size_t i = 0, j; + + while (i < size) { + size_t attr_len = bsd_list[i]; + + for (j = i; j < i + attr_len; ++j) + bsd_list[j] = bsd_list[j + 1]; + bsd_list[j] = '\0'; + + i += attr_len + 1; + gf_msg_debug("syscall", 0, "syscall debug: %lu", attr_len); + } } #endif /* GF_BSD_HOST_OS */ @@ -567,44 +581,44 @@ gf_extattr_list_reshape(char *bsd_list, ssize_t size) size_t strnlen(const char *string, size_t maxlen) { - int len = 0; - while ((len < maxlen) && string[len]) - len++; - return len; + int len = 0; + while ((len < maxlen) && string[len]) + len++; + return len; } #endif /* STRNLEN */ int -gf_umount_lazy (char *xlname, char *path, int rmdir_flag) +gf_umount_lazy(char *xlname, char *path, int rmdir_flag) { - int ret = -1; - runner_t runner = {0,}; + int ret = -1; + runner_t runner = { + 0, + }; - runinit (&runner); + runinit(&runner); #ifdef GF_LINUX_HOST_OS - runner_add_args (&runner, _PATH_UMOUNT, "-l", path, NULL); + runner_add_args(&runner, _PATH_UMOUNT, "-l", path, NULL); #else - if (rmdir_flag) - runner_add_args (&runner, SBIN_DIR "/umountd", - "-r", path, NULL); - else - runner_add_args (&runner, SBIN_DIR "/umountd", - path, NULL); + if (rmdir_flag) + runner_add_args(&runner, SBIN_DIR "/umountd", "-r", path, NULL); + else + runner_add_args(&runner, SBIN_DIR "/umountd", path, NULL); #endif - ret = runner_run (&runner); - if (ret) { - gf_msg (xlname, GF_LOG_ERROR, errno, LG_MSG_UNMOUNT_FAILED, - "Lazy unmount of %s", path); - } + ret = runner_run(&runner); + if (ret) { + gf_msg(xlname, GF_LOG_ERROR, errno, LG_MSG_UNMOUNT_FAILED, + "Lazy unmount of %s", path); + } #ifdef GF_LINUX_HOST_OS - if (!ret && rmdir_flag) { - ret = sys_rmdir (path); - if (ret) - gf_msg (xlname, GF_LOG_WARNING, errno, - LG_MSG_DIR_OP_FAILED, "rmdir %s", path); - } + if (!ret && rmdir_flag) { + ret = sys_rmdir(path); + if (ret) + gf_msg(xlname, GF_LOG_WARNING, errno, LG_MSG_DIR_OP_FAILED, + "rmdir %s", path); + } #endif - return ret; + return ret; } diff --git a/libglusterfs/src/compound-fop-utils.c b/libglusterfs/src/compound-fop-utils.c index 03d7b5ba459..8bdb8e8fd5b 100644 --- a/libglusterfs/src/compound-fop-utils.c +++ b/libglusterfs/src/compound-fop-utils.c @@ -14,125 +14,125 @@ #include "dict.h" void -compound_args_cleanup (compound_args_t *args) +compound_args_cleanup(compound_args_t *args) { - int i; + int i; - if (!args) - return; + if (!args) + return; - if (args->xdata) - dict_unref (args->xdata); + if (args->xdata) + dict_unref(args->xdata); - if (args->req_list) { - for (i = 0; i < args->fop_length; i++) { - args_wipe (&args->req_list[i]); - } + if (args->req_list) { + for (i = 0; i < args->fop_length; i++) { + args_wipe(&args->req_list[i]); } + } - GF_FREE (args->enum_list); - GF_FREE (args->req_list); - GF_FREE (args); + GF_FREE(args->enum_list); + GF_FREE(args->req_list); + GF_FREE(args); } void -compound_args_cbk_cleanup (compound_args_cbk_t *args_cbk) +compound_args_cbk_cleanup(compound_args_cbk_t *args_cbk) { - int i; + int i; - if (!args_cbk) - return; + if (!args_cbk) + return; - if (args_cbk->xdata) - dict_unref (args_cbk->xdata); + if (args_cbk->xdata) + dict_unref(args_cbk->xdata); - if (args_cbk->rsp_list) { - for (i = 0; i < args_cbk->fop_length; i++) { - args_cbk_wipe (&args_cbk->rsp_list[i]); - } + if (args_cbk->rsp_list) { + for (i = 0; i < args_cbk->fop_length; i++) { + args_cbk_wipe(&args_cbk->rsp_list[i]); } + } - GF_FREE (args_cbk->rsp_list); - GF_FREE (args_cbk->enum_list); - GF_FREE (args_cbk); + GF_FREE(args_cbk->rsp_list); + GF_FREE(args_cbk->enum_list); + GF_FREE(args_cbk); } -compound_args_cbk_t* -compound_args_cbk_alloc (int length, dict_t *xdata) +compound_args_cbk_t * +compound_args_cbk_alloc(int length, dict_t *xdata) { - int i = 0; - compound_args_cbk_t *args_cbk = NULL; + int i = 0; + compound_args_cbk_t *args_cbk = NULL; - args_cbk = GF_CALLOC (1, sizeof (*args_cbk), gf_mt_compound_rsp_t); - if (!args_cbk) - return NULL; + args_cbk = GF_CALLOC(1, sizeof(*args_cbk), gf_mt_compound_rsp_t); + if (!args_cbk) + return NULL; - args_cbk->fop_length = length; + args_cbk->fop_length = length; - args_cbk->rsp_list = GF_CALLOC (length, sizeof (*args_cbk->rsp_list), - gf_mt_default_args_cbk_t); - if (!args_cbk->rsp_list) - goto out; + args_cbk->rsp_list = GF_CALLOC(length, sizeof(*args_cbk->rsp_list), + gf_mt_default_args_cbk_t); + if (!args_cbk->rsp_list) + goto out; - for (i = 0; i < length; i++) { - args_cbk_init (&args_cbk->rsp_list[i]); - } + for (i = 0; i < length; i++) { + args_cbk_init(&args_cbk->rsp_list[i]); + } - args_cbk->enum_list = GF_CALLOC (length, sizeof (*args_cbk->enum_list), - gf_common_mt_int); - if (!args_cbk->enum_list) - goto out; + args_cbk->enum_list = GF_CALLOC(length, sizeof(*args_cbk->enum_list), + gf_common_mt_int); + if (!args_cbk->enum_list) + goto out; - if (xdata) { - args_cbk->xdata = dict_copy_with_ref (xdata, NULL); - if (!args_cbk->xdata) - goto out; - } + if (xdata) { + args_cbk->xdata = dict_copy_with_ref(xdata, NULL); + if (!args_cbk->xdata) + goto out; + } - return args_cbk; + return args_cbk; out: - compound_args_cbk_cleanup (args_cbk); - return NULL; + compound_args_cbk_cleanup(args_cbk); + return NULL; } -compound_args_t* -compound_fop_alloc (int length, glusterfs_compound_fop_t fop, dict_t *xdata) +compound_args_t * +compound_fop_alloc(int length, glusterfs_compound_fop_t fop, dict_t *xdata) { - compound_args_t *args = NULL; + compound_args_t *args = NULL; - args = GF_CALLOC (1, sizeof (*args), gf_mt_compound_req_t); + args = GF_CALLOC(1, sizeof(*args), gf_mt_compound_req_t); - if (!args) - return NULL; + if (!args) + return NULL; - /* fop_enum can be used by xlators to see which fops are - * included as part of compound fop. This will help in checking - * for compatibility or support without going through the entire - * fop list packed. - */ - args->fop_enum = fop; - args->fop_length = length; + /* fop_enum can be used by xlators to see which fops are + * included as part of compound fop. This will help in checking + * for compatibility or support without going through the entire + * fop list packed. + */ + args->fop_enum = fop; + args->fop_length = length; - args->enum_list = GF_CALLOC (length, sizeof (*args->enum_list), - gf_common_mt_int); + args->enum_list = GF_CALLOC(length, sizeof(*args->enum_list), + gf_common_mt_int); - if (!args->enum_list) - goto out; + if (!args->enum_list) + goto out; - args->req_list = GF_CALLOC (length, sizeof (*args->req_list), - gf_mt_default_args_t); + args->req_list = GF_CALLOC(length, sizeof(*args->req_list), + gf_mt_default_args_t); - if (!args->req_list) - goto out; + if (!args->req_list) + goto out; - if (xdata) { - args->xdata = dict_copy_with_ref (xdata, args->xdata); - if (!args->xdata) - goto out; - } + if (xdata) { + args->xdata = dict_copy_with_ref(xdata, args->xdata); + if (!args->xdata) + goto out; + } - return args; + return args; out: - compound_args_cleanup (args); - return NULL; + compound_args_cleanup(args); + return NULL; } diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c index afd12cd22f8..1e4c341df05 100644 --- a/libglusterfs/src/ctx.c +++ b/libglusterfs/src/ctx.c @@ -15,82 +15,82 @@ #include "timer-wheel.h" glusterfs_ctx_t * -glusterfs_ctx_new () +glusterfs_ctx_new() { - int ret = 0; - glusterfs_ctx_t *ctx = NULL; - - /* no GF_CALLOC here, gf_acct_mem_set_enable is not - yet decided at this point */ - ctx = calloc (1, sizeof (*ctx)); - if (!ctx) { - ret = -1; - goto out; - } + int ret = 0; + glusterfs_ctx_t *ctx = NULL; + + /* no GF_CALLOC here, gf_acct_mem_set_enable is not + yet decided at this point */ + ctx = calloc(1, sizeof(*ctx)); + if (!ctx) { + ret = -1; + goto out; + } - ctx->mem_acct_enable = gf_global_mem_acct_enable_get(); + ctx->mem_acct_enable = gf_global_mem_acct_enable_get(); - INIT_LIST_HEAD (&ctx->graphs); - INIT_LIST_HEAD (&ctx->mempool_list); - INIT_LIST_HEAD (&ctx->volfile_list); + INIT_LIST_HEAD(&ctx->graphs); + INIT_LIST_HEAD(&ctx->mempool_list); + INIT_LIST_HEAD(&ctx->volfile_list); - ctx->daemon_pipe[0] = -1; - ctx->daemon_pipe[1] = -1; + ctx->daemon_pipe[0] = -1; + ctx->daemon_pipe[1] = -1; - ctx->log.loglevel = DEFAULT_LOG_LEVEL; + ctx->log.loglevel = DEFAULT_LOG_LEVEL; #ifdef RUN_WITH_VALGRIND - ctx->cmd_args.valgrind = _gf_true; + ctx->cmd_args.valgrind = _gf_true; #endif - /* lock is never destroyed! */ - ret = LOCK_INIT (&ctx->lock); - if (ret) { - free (ctx); - ctx = NULL; - goto out; - } - - GF_ATOMIC_INIT (ctx->stats.max_dict_pairs, 0); - GF_ATOMIC_INIT (ctx->stats.total_pairs_used, 0); - GF_ATOMIC_INIT (ctx->stats.total_dicts_used, 0); + /* lock is never destroyed! */ + ret = LOCK_INIT(&ctx->lock); + if (ret) { + free(ctx); + ctx = NULL; + goto out; + } + + GF_ATOMIC_INIT(ctx->stats.max_dict_pairs, 0); + GF_ATOMIC_INIT(ctx->stats.total_pairs_used, 0); + GF_ATOMIC_INIT(ctx->stats.total_dicts_used, 0); out: - return ctx; + return ctx; } static void -glusterfs_ctx_tw_destroy (struct gf_ctx_tw *ctx_tw) +glusterfs_ctx_tw_destroy(struct gf_ctx_tw *ctx_tw) { - if (ctx_tw->timer_wheel) - gf_tw_cleanup_timers (ctx_tw->timer_wheel); + if (ctx_tw->timer_wheel) + gf_tw_cleanup_timers(ctx_tw->timer_wheel); - GF_FREE (ctx_tw); + GF_FREE(ctx_tw); } -struct tvec_base* -glusterfs_ctx_tw_get (glusterfs_ctx_t *ctx) +struct tvec_base * +glusterfs_ctx_tw_get(glusterfs_ctx_t *ctx) { - struct gf_ctx_tw *ctx_tw = NULL; - - LOCK (&ctx->lock); - { - if (ctx->tw) { - ctx_tw = GF_REF_GET (ctx->tw); - } else { - ctx_tw = GF_CALLOC (1, sizeof (struct gf_ctx_tw), - gf_common_mt_tw_ctx); - ctx_tw->timer_wheel = gf_tw_init_timers(); - GF_REF_INIT (ctx_tw, glusterfs_ctx_tw_destroy); - ctx->tw = ctx_tw; - } + struct gf_ctx_tw *ctx_tw = NULL; + + LOCK(&ctx->lock); + { + if (ctx->tw) { + ctx_tw = GF_REF_GET(ctx->tw); + } else { + ctx_tw = GF_CALLOC(1, sizeof(struct gf_ctx_tw), + gf_common_mt_tw_ctx); + ctx_tw->timer_wheel = gf_tw_init_timers(); + GF_REF_INIT(ctx_tw, glusterfs_ctx_tw_destroy); + ctx->tw = ctx_tw; } - UNLOCK (&ctx->lock); + } + UNLOCK(&ctx->lock); - return ctx_tw->timer_wheel; + return ctx_tw->timer_wheel; } void -glusterfs_ctx_tw_put (glusterfs_ctx_t *ctx) +glusterfs_ctx_tw_put(glusterfs_ctx_t *ctx) { - GF_REF_PUT (ctx->tw); + GF_REF_PUT(ctx->tw); } diff --git a/libglusterfs/src/daemon.c b/libglusterfs/src/daemon.c index 348e3ad4083..f821f8f7ed0 100644 --- a/libglusterfs/src/daemon.c +++ b/libglusterfs/src/daemon.c @@ -14,53 +14,53 @@ #include "daemon.h" int -os_daemon_return (int nochdir, int noclose) +os_daemon_return(int nochdir, int noclose) { - pid_t pid = -1; - int ret = -1; - FILE *ptr = NULL; + pid_t pid = -1; + int ret = -1; + FILE *ptr = NULL; - ret = fork(); - if (ret) - return ret; + ret = fork(); + if (ret) + return ret; - pid = setsid(); + pid = setsid(); - if (pid == -1) { - ret = -1; - goto out; - } + if (pid == -1) { + ret = -1; + goto out; + } - if (!nochdir) - ret = chdir("/"); + if (!nochdir) + ret = chdir("/"); - if (!noclose) { - ptr = freopen (DEVNULLPATH, "r", stdin); - if (!ptr) - goto out; + if (!noclose) { + ptr = freopen(DEVNULLPATH, "r", stdin); + if (!ptr) + goto out; - ptr = freopen (DEVNULLPATH, "w", stdout); - if (!ptr) - goto out; + ptr = freopen(DEVNULLPATH, "w", stdout); + if (!ptr) + goto out; - ptr = freopen (DEVNULLPATH, "w", stderr); - if (!ptr) - goto out; - } + ptr = freopen(DEVNULLPATH, "w", stderr); + if (!ptr) + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } int -os_daemon (int nochdir, int noclose) +os_daemon(int nochdir, int noclose) { - int ret = -1; + int ret = -1; - ret = os_daemon_return (nochdir, noclose); - if (ret <= 0) - return ret; + ret = os_daemon_return(nochdir, noclose); + if (ret <= 0) + return ret; - _exit (0); + _exit(0); } diff --git a/libglusterfs/src/default-args.c b/libglusterfs/src/default-args.c index 2bc1ec28649..c92f3d46a86 100644 --- a/libglusterfs/src/default-args.c +++ b/libglusterfs/src/default-args.c @@ -17,1656 +17,1593 @@ #include "defaults.h" int -args_lookup_store (default_args_t *args, loc_t *loc, - dict_t *xdata) +args_lookup_store(default_args_t *args, loc_t *loc, dict_t *xdata) { - loc_copy (&args->loc, loc); - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_lookup_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, - dict_t *xdata, struct iatt *postparent) +args_lookup_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + dict_t *xdata, struct iatt *postparent) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_stat_store (default_args_t *args, loc_t *loc, dict_t *xdata) +args_stat_store(default_args_t *args, loc_t *loc, dict_t *xdata) { - loc_copy (&args->loc, loc); - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_stat_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *buf, dict_t *xdata) +args_stat_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + struct iatt *buf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret == 0) - args->stat = *buf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret == 0) + args->stat = *buf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fstat_store (default_args_t *args, fd_t *fd, dict_t *xdata) +args_fstat_store(default_args_t *args, fd_t *fd, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fstat_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *buf, dict_t *xdata) +args_fstat_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + struct iatt *buf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (buf) - args->stat = *buf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (buf) + args->stat = *buf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_truncate_store (default_args_t *args, loc_t *loc, off_t off, - dict_t *xdata) +args_truncate_store(default_args_t *args, loc_t *loc, off_t off, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->offset = off; - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + args->offset = off; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_truncate_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +args_truncate_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (prebuf) - args->prestat = *prebuf; - if (postbuf) - args->poststat = *postbuf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (prebuf) + args->prestat = *prebuf; + if (postbuf) + args->poststat = *postbuf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_ftruncate_store (default_args_t *args, fd_t *fd, off_t off, - dict_t *xdata) +args_ftruncate_store(default_args_t *args, fd_t *fd, off_t off, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - args->offset = off; - if (xdata) - args->xdata = dict_ref (xdata); + args->offset = off; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_ftruncate_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +args_ftruncate_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (prebuf) - args->prestat = *prebuf; - if (postbuf) - args->poststat = *postbuf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (prebuf) + args->prestat = *prebuf; + if (postbuf) + args->poststat = *postbuf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_access_store (default_args_t *args, loc_t *loc, int32_t mask, - dict_t *xdata) +args_access_store(default_args_t *args, loc_t *loc, int32_t mask, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->mask = mask; - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + args->mask = mask; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_access_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_access_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_readlink_store (default_args_t *args, loc_t *loc, size_t size, - dict_t *xdata) +args_readlink_store(default_args_t *args, loc_t *loc, size_t size, + dict_t *xdata) { - loc_copy (&args->loc, loc); - args->size = size; - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + args->size = size; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_readlink_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - const char *path, struct iatt *stbuf, dict_t *xdata) +args_readlink_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, const char *path, struct iatt *stbuf, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (path) - args->buf = gf_strdup (path); - if (stbuf) - args->stat = *stbuf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (path) + args->buf = gf_strdup(path); + if (stbuf) + args->stat = *stbuf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_mknod_store (default_args_t *args, loc_t *loc, mode_t mode, - dev_t rdev, mode_t umask, dict_t *xdata) +args_mknod_store(default_args_t *args, loc_t *loc, mode_t mode, dev_t rdev, + mode_t umask, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->mode = mode; - args->rdev = rdev; - args->umask = umask; - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + args->mode = mode; + args->rdev = rdev; + args->umask = umask; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_mknod_cbk_store (default_args_cbk_t *args, int op_ret, - int32_t op_errno, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +args_mknod_cbk_store(default_args_cbk_t *args, int op_ret, int32_t op_errno, + inode_t *inode, struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_mkdir_store (default_args_t *args, loc_t *loc, mode_t mode, - mode_t umask, dict_t *xdata) +args_mkdir_store(default_args_t *args, loc_t *loc, mode_t mode, mode_t umask, + dict_t *xdata) { - loc_copy (&args->loc, loc); - args->mode = mode; - args->umask = umask; + loc_copy(&args->loc, loc); + args->mode = mode; + args->umask = umask; - if (xdata) - args->xdata = dict_ref (xdata); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_mkdir_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +args_mkdir_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + inode_t *inode, struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_unlink_store (default_args_t *args, loc_t *loc, int xflag, dict_t *xdata) +args_unlink_store(default_args_t *args, loc_t *loc, int xflag, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->xflag = xflag; - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + args->xflag = xflag; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_unlink_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +args_unlink_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_rmdir_store (default_args_t *args, loc_t *loc, int flags, dict_t *xdata) +args_rmdir_store(default_args_t *args, loc_t *loc, int flags, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->flags = flags; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + args->flags = flags; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_rmdir_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +args_rmdir_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_symlink_store (default_args_t *args, const char *linkname, loc_t *loc, +args_symlink_store(default_args_t *args, const char *linkname, loc_t *loc, mode_t umask, dict_t *xdata) { - args->linkname = gf_strdup (linkname); - args->umask = umask; - loc_copy (&args->loc, loc); - if (xdata) - args->xdata = dict_ref (xdata); + args->linkname = gf_strdup(linkname); + args->umask = umask; + loc_copy(&args->loc, loc); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_symlink_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +args_symlink_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, inode_t *inode, struct iatt *buf, + struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_rename_store (default_args_t *args, loc_t *oldloc, loc_t *newloc, - dict_t *xdata) +args_rename_store(default_args_t *args, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { - loc_copy (&args->loc, oldloc); - loc_copy (&args->loc2, newloc); - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, oldloc); + loc_copy(&args->loc2, newloc); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_rename_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent, - dict_t *xdata) +args_rename_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (buf) - args->stat = *buf; - if (preoldparent) - args->preparent = *preoldparent; - if (postoldparent) - args->postparent = *postoldparent; - if (prenewparent) - args->preparent2 = *prenewparent; - if (postnewparent) - args->postparent2 = *postnewparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (buf) + args->stat = *buf; + if (preoldparent) + args->preparent = *preoldparent; + if (postoldparent) + args->postparent = *postoldparent; + if (prenewparent) + args->preparent2 = *prenewparent; + if (postnewparent) + args->postparent2 = *postnewparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_link_store (default_args_t *args, loc_t *oldloc, loc_t *newloc, - dict_t *xdata) +args_link_store(default_args_t *args, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) { - loc_copy (&args->loc, oldloc); - loc_copy (&args->loc2, newloc); + loc_copy(&args->loc, oldloc); + loc_copy(&args->loc2, newloc); - if (xdata) - args->xdata = dict_ref (xdata); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_link_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +args_link_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + inode_t *inode, struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_create_store (default_args_t *args, - loc_t *loc, int32_t flags, mode_t mode, +args_create_store(default_args_t *args, loc_t *loc, int32_t flags, mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->flags = flags; - args->mode = mode; - args->umask = umask; - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + args->flags = flags; + args->mode = mode; + args->umask = umask; + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_create_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - fd_t *fd, inode_t *inode, struct iatt *buf, - struct iatt *preparent, struct iatt *postparent, - dict_t *xdata) +args_create_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, fd_t *fd, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (fd) - args->fd = fd_ref (fd); - if (inode) - args->inode = inode_ref (inode); - if (buf) - args->stat = *buf; - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (fd) + args->fd = fd_ref(fd); + if (inode) + args->inode = inode_ref(inode); + if (buf) + args->stat = *buf; + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_open_store (default_args_t *args, loc_t *loc, int32_t flags, - fd_t *fd, dict_t *xdata) +args_open_store(default_args_t *args, loc_t *loc, int32_t flags, fd_t *fd, + dict_t *xdata) { - loc_copy (&args->loc, loc); - args->flags = flags; - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + args->flags = flags; + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_open_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - fd_t *fd, dict_t *xdata) +args_open_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + fd_t *fd, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_readv_store (default_args_t *args, fd_t *fd, size_t size, off_t off, - uint32_t flags, dict_t *xdata) +args_readv_store(default_args_t *args, fd_t *fd, size_t size, off_t off, + uint32_t flags, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - args->size = size; - args->offset = off; - args->flags = flags; + if (fd) + args->fd = fd_ref(fd); + args->size = size; + args->offset = off; + args->flags = flags; - if (xdata) - args->xdata = dict_ref (xdata); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_readv_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *stbuf, - struct iobref *iobref, dict_t *xdata) +args_readv_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + struct iovec *vector, int32_t count, struct iatt *stbuf, + struct iobref *iobref, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret >= 0) { - args->vector = iov_dup (vector, count); - args->count = count; - args->stat = *stbuf; - args->iobref = iobref_ref (iobref); - } - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret >= 0) { + args->vector = iov_dup(vector, count); + args->count = count; + args->stat = *stbuf; + args->iobref = iobref_ref(iobref); + } + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_writev_store (default_args_t *args, fd_t *fd, struct iovec *vector, - int32_t count, off_t off, uint32_t flags, - struct iobref *iobref, dict_t *xdata) +args_writev_store(default_args_t *args, fd_t *fd, struct iovec *vector, + int32_t count, off_t off, uint32_t flags, + struct iobref *iobref, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - args->vector = iov_dup (vector, count); - args->count = count; - args->offset = off; - args->flags = flags; - args->iobref = iobref_ref (iobref); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (fd) + args->fd = fd_ref(fd); + args->vector = iov_dup(vector, count); + args->count = count; + args->offset = off; + args->flags = flags; + args->iobref = iobref_ref(iobref); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_writev_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +args_writev_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret >= 0) - args->poststat = *postbuf; - if (prebuf) - args->prestat = *prebuf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret >= 0) + args->poststat = *postbuf; + if (prebuf) + args->prestat = *prebuf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_put_store (default_args_t *args, loc_t *loc, mode_t mode, mode_t umask, - uint32_t flags, struct iovec *vector, int32_t count, off_t off, - struct iobref *iobref, dict_t *xattr, dict_t *xdata) +args_put_store(default_args_t *args, loc_t *loc, mode_t mode, mode_t umask, + uint32_t flags, struct iovec *vector, int32_t count, off_t off, + struct iobref *iobref, dict_t *xattr, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->mode = mode; - args->umask = umask; - args->flags = flags; - args->vector = iov_dup (vector, count); - args->count = count; - args->offset = off; - args->iobref = iobref_ref (iobref); - if (xattr) - args->xattr = dict_ref (xattr); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + args->mode = mode; + args->umask = umask; + args->flags = flags; + args->vector = iov_dup(vector, count); + args->count = count; + args->offset = off; + args->iobref = iobref_ref(iobref); + if (xattr) + args->xattr = dict_ref(xattr); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_put_cbk_store (default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +args_put_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + inode_t *inode, struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret >= 0) - args->stat = *buf; - if (inode) - args->inode = inode_ref (inode); - if (preparent) - args->preparent = *preparent; - if (postparent) - args->postparent = *postparent; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret >= 0) + args->stat = *buf; + if (inode) + args->inode = inode_ref(inode); + if (preparent) + args->preparent = *preparent; + if (postparent) + args->postparent = *postparent; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_flush_store (default_args_t *args, fd_t *fd, dict_t *xdata) +args_flush_store(default_args_t *args, fd_t *fd, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_flush_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_flush_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fsync_store (default_args_t *args, fd_t *fd, int32_t datasync, - dict_t *xdata) +args_fsync_store(default_args_t *args, fd_t *fd, int32_t datasync, + dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - args->datasync = datasync; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (fd) + args->fd = fd_ref(fd); + args->datasync = datasync; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fsync_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +args_fsync_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (prebuf) - args->prestat = *prebuf; - if (postbuf) - args->poststat = *postbuf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (prebuf) + args->prestat = *prebuf; + if (postbuf) + args->poststat = *postbuf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_opendir_store (default_args_t *args, loc_t *loc, fd_t *fd, dict_t *xdata) +args_opendir_store(default_args_t *args, loc_t *loc, fd_t *fd, dict_t *xdata) { - loc_copy (&args->loc, loc); - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_opendir_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - fd_t *fd, dict_t *xdata) +args_opendir_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, fd_t *fd, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (fd) - args->fd = fd_ref (fd); - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (fd) + args->fd = fd_ref(fd); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fsyncdir_store (default_args_t *args, fd_t *fd, int32_t datasync, - dict_t *xdata) +args_fsyncdir_store(default_args_t *args, fd_t *fd, int32_t datasync, + dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - args->datasync = datasync; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (fd) + args->fd = fd_ref(fd); + args->datasync = datasync; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fsyncdir_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_fsyncdir_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_statfs_store (default_args_t *args, loc_t *loc, dict_t *xdata) +args_statfs_store(default_args_t *args, loc_t *loc, dict_t *xdata) { - loc_copy (&args->loc, loc); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_statfs_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct statvfs *buf, dict_t *xdata) +args_statfs_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct statvfs *buf, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret == 0) - args->statvfs = *buf; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret == 0) + args->statvfs = *buf; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_setxattr_store (default_args_t *args, - loc_t *loc, dict_t *dict, - int32_t flags, dict_t *xdata) +args_setxattr_store(default_args_t *args, loc_t *loc, dict_t *dict, + int32_t flags, dict_t *xdata) { - loc_copy (&args->loc, loc); - /* TODO */ - if (dict) - args->xattr = dict_ref (dict); - args->flags = flags; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + /* TODO */ + if (dict) + args->xattr = dict_ref(dict); + args->flags = flags; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_setxattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, - int32_t op_errno, dict_t *xdata) +args_setxattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_getxattr_store (default_args_t *args, - loc_t *loc, const char *name, dict_t *xdata) +args_getxattr_store(default_args_t *args, loc_t *loc, const char *name, + dict_t *xdata) { - loc_copy (&args->loc, loc); + loc_copy(&args->loc, loc); - if (name) - args->name = gf_strdup (name); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (name) + args->name = gf_strdup(name); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_getxattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - dict_t *dict, dict_t *xdata) +args_getxattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *dict, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (dict) - args->xattr = dict_ref (dict); - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (dict) + args->xattr = dict_ref(dict); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fsetxattr_store (default_args_t *args, - fd_t *fd, dict_t *dict, int32_t flags, dict_t *xdata) +args_fsetxattr_store(default_args_t *args, fd_t *fd, dict_t *dict, + int32_t flags, dict_t *xdata) { - args->fd = fd_ref (fd); + args->fd = fd_ref(fd); - if (dict) - args->xattr = dict_ref (dict); - args->flags = flags; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (dict) + args->xattr = dict_ref(dict); + args->flags = flags; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fsetxattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_fsetxattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fgetxattr_store (default_args_t *args, - fd_t *fd, const char *name, dict_t *xdata) +args_fgetxattr_store(default_args_t *args, fd_t *fd, const char *name, + dict_t *xdata) { - args->fd = fd_ref (fd); + args->fd = fd_ref(fd); - if (name) - args->name = gf_strdup (name); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (name) + args->name = gf_strdup(name); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fgetxattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - dict_t *dict, dict_t *xdata) +args_fgetxattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *dict, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (dict) - args->xattr = dict_ref (dict); - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (dict) + args->xattr = dict_ref(dict); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_removexattr_store (default_args_t *args, - loc_t *loc, const char *name, dict_t *xdata) +args_removexattr_store(default_args_t *args, loc_t *loc, const char *name, + dict_t *xdata) { - loc_copy (&args->loc, loc); - args->name = gf_strdup (name); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + args->name = gf_strdup(name); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_removexattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_removexattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fremovexattr_store (default_args_t *args, - fd_t *fd, const char *name, dict_t *xdata) +args_fremovexattr_store(default_args_t *args, fd_t *fd, const char *name, + dict_t *xdata) { - args->fd = fd_ref (fd); - args->name = gf_strdup (name); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + args->fd = fd_ref(fd); + args->name = gf_strdup(name); + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fremovexattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_fremovexattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_lk_store (default_args_t *args, - fd_t *fd, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) +args_lk_store(default_args_t *args, fd_t *fd, int32_t cmd, + struct gf_flock *lock, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); - args->cmd = cmd; - args->lock = *lock; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (fd) + args->fd = fd_ref(fd); + args->cmd = cmd; + args->lock = *lock; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_lk_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct gf_flock *lock, dict_t *xdata) +args_lk_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + struct gf_flock *lock, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret == 0) - args->lock = *lock; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret == 0) + args->lock = *lock; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_inodelk_store (default_args_t *args, - const char *volume, loc_t *loc, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) +args_inodelk_store(default_args_t *args, const char *volume, loc_t *loc, + int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - if (volume) - args->volume = gf_strdup (volume); + if (volume) + args->volume = gf_strdup(volume); - loc_copy (&args->loc, loc); - args->cmd = cmd; - args->lock = *lock; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + loc_copy(&args->loc, loc); + args->cmd = cmd; + args->lock = *lock; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_inodelk_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_inodelk_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_finodelk_store (default_args_t *args, - const char *volume, fd_t *fd, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) +args_finodelk_store(default_args_t *args, const char *volume, fd_t *fd, + int32_t cmd, struct gf_flock *lock, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - if (volume) - args->volume = gf_strdup (volume); + if (volume) + args->volume = gf_strdup(volume); - args->cmd = cmd; - args->lock = *lock; + args->cmd = cmd; + args->lock = *lock; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_finodelk_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_finodelk_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_entrylk_store (default_args_t *args, - const char *volume, loc_t *loc, const char *name, - entrylk_cmd cmd, entrylk_type type, dict_t *xdata) +args_entrylk_store(default_args_t *args, const char *volume, loc_t *loc, + const char *name, entrylk_cmd cmd, entrylk_type type, + dict_t *xdata) { - if (volume) - args->volume = gf_strdup (volume); + if (volume) + args->volume = gf_strdup(volume); - loc_copy (&args->loc, loc); + loc_copy(&args->loc, loc); - args->entrylkcmd = cmd; - args->entrylktype = type; + args->entrylkcmd = cmd; + args->entrylktype = type; - if (name) - args->name = gf_strdup (name); + if (name) + args->name = gf_strdup(name); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_entrylk_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_entrylk_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fentrylk_store (default_args_t *args, - const char *volume, fd_t *fd, const char *name, - entrylk_cmd cmd, entrylk_type type, dict_t *xdata) +args_fentrylk_store(default_args_t *args, const char *volume, fd_t *fd, + const char *name, entrylk_cmd cmd, entrylk_type type, + dict_t *xdata) { - if (volume) - args->volume = gf_strdup (volume); + if (volume) + args->volume = gf_strdup(volume); - if (fd) - args->fd = fd_ref (fd); - args->entrylkcmd = cmd; - args->entrylktype = type; - if (name) - args->name = gf_strdup (name); + if (fd) + args->fd = fd_ref(fd); + args->entrylkcmd = cmd; + args->entrylktype = type; + if (name) + args->name = gf_strdup(name); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fentrylk_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_fentrylk_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); - - return 0; -} - + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); -int -args_readdirp_store (default_args_t *args, - fd_t *fd, size_t size, off_t off, dict_t *xdata) -{ - args->fd = fd_ref (fd); - args->size = size; - args->offset = off; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + return 0; } int -args_readdirp_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries, dict_t *xdata) +args_readdirp_store(default_args_t *args, fd_t *fd, size_t size, off_t off, + dict_t *xdata) { - gf_dirent_t *stub_entry = NULL, *entry = NULL; - - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret > 0) { - list_for_each_entry (entry, &entries->list, list) { - stub_entry = gf_dirent_for_name (entry->d_name); - if (!stub_entry) - goto out; - stub_entry->d_off = entry->d_off; - stub_entry->d_ino = entry->d_ino; - stub_entry->d_stat = entry->d_stat; - stub_entry->d_type = entry->d_type; - if (entry->inode) - stub_entry->inode = inode_ref (entry->inode); - if (entry->dict) - stub_entry->dict = dict_ref (entry->dict); - list_add_tail (&stub_entry->list, - &args->entries.list); - } + args->fd = fd_ref(fd); + args->size = size; + args->offset = off; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; +} + +int +args_readdirp_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, gf_dirent_t *entries, dict_t *xdata) +{ + gf_dirent_t *stub_entry = NULL, *entry = NULL; + + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret > 0) { + list_for_each_entry(entry, &entries->list, list) + { + stub_entry = gf_dirent_for_name(entry->d_name); + if (!stub_entry) + goto out; + stub_entry->d_off = entry->d_off; + stub_entry->d_ino = entry->d_ino; + stub_entry->d_stat = entry->d_stat; + stub_entry->d_type = entry->d_type; + if (entry->inode) + stub_entry->inode = inode_ref(entry->inode); + if (entry->dict) + stub_entry->dict = dict_ref(entry->dict); + list_add_tail(&stub_entry->list, &args->entries.list); } - if (xdata) - args->xdata = dict_ref (xdata); + } + if (xdata) + args->xdata = dict_ref(xdata); out: - return 0; + return 0; } - int -args_readdir_store (default_args_t *args, - fd_t *fd, size_t size, - off_t off, dict_t *xdata) +args_readdir_store(default_args_t *args, fd_t *fd, size_t size, off_t off, + dict_t *xdata) { - args->fd = fd_ref (fd); - args->size = size; - args->offset = off; + args->fd = fd_ref(fd); + args->size = size; + args->offset = off; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_readdir_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries, dict_t *xdata) +args_readdir_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, gf_dirent_t *entries, dict_t *xdata) { - gf_dirent_t *stub_entry = NULL, *entry = NULL; + gf_dirent_t *stub_entry = NULL, *entry = NULL; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret > 0) { - list_for_each_entry (entry, &entries->list, list) { - stub_entry = gf_dirent_for_name (entry->d_name); - if (!stub_entry) - goto out; - stub_entry->d_off = entry->d_off; - stub_entry->d_ino = entry->d_ino; - stub_entry->d_type = entry->d_type; - list_add_tail (&stub_entry->list, - &args->entries.list); - } + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret > 0) { + list_for_each_entry(entry, &entries->list, list) + { + stub_entry = gf_dirent_for_name(entry->d_name); + if (!stub_entry) + goto out; + stub_entry->d_off = entry->d_off; + stub_entry->d_ino = entry->d_ino; + stub_entry->d_type = entry->d_type; + list_add_tail(&stub_entry->list, &args->entries.list); } - if (xdata) - args->xdata = dict_ref (xdata); + } + if (xdata) + args->xdata = dict_ref(xdata); out: - return 0; + return 0; } - int -args_rchecksum_store (default_args_t *args, - fd_t *fd, off_t offset, int32_t len, dict_t *xdata) +args_rchecksum_store(default_args_t *args, fd_t *fd, off_t offset, int32_t len, + dict_t *xdata) { - args->fd = fd_ref (fd); - args->offset = offset; - args->size = len; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + args->fd = fd_ref(fd); + args->offset = offset; + args->size = len; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_rchecksum_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - uint32_t weak_checksum, uint8_t *strong_checksum, - dict_t *xdata) +args_rchecksum_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, uint32_t weak_checksum, + uint8_t *strong_checksum, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret >= 0) { - args->weak_checksum = - weak_checksum; - args->strong_checksum = - memdup (strong_checksum, SHA256_DIGEST_LENGTH); - } - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret >= 0) { + args->weak_checksum = weak_checksum; + args->strong_checksum = memdup(strong_checksum, SHA256_DIGEST_LENGTH); + } + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_xattrop_store (default_args_t *args, - loc_t *loc, gf_xattrop_flags_t optype, - dict_t *xattr, dict_t *xdata) +args_xattrop_store(default_args_t *args, loc_t *loc, gf_xattrop_flags_t optype, + dict_t *xattr, dict_t *xdata) { - loc_copy (&args->loc, loc); + loc_copy(&args->loc, loc); - args->optype = optype; - args->xattr = dict_ref (xattr); + args->optype = optype; + args->xattr = dict_ref(xattr); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } - int -args_xattrop_cbk_store (default_args_cbk_t *args, int32_t op_ret, - int32_t op_errno, dict_t *xattr, dict_t *xdata) +args_xattrop_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xattr, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xattr) - args->xattr = dict_ref (xattr); - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xattr) + args->xattr = dict_ref(xattr); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_fxattrop_store (default_args_t *args, - fd_t *fd, gf_xattrop_flags_t optype, - dict_t *xattr, dict_t *xdata) +args_fxattrop_store(default_args_t *args, fd_t *fd, gf_xattrop_flags_t optype, + dict_t *xattr, dict_t *xdata) { - args->fd = fd_ref (fd); + args->fd = fd_ref(fd); - args->optype = optype; - args->xattr = dict_ref (xattr); + args->optype = optype; + args->xattr = dict_ref(xattr); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fxattrop_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - dict_t *xattr, dict_t *xdata) +args_fxattrop_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, dict_t *xattr, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xattr) - args->xattr = dict_ref (xattr); - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xattr) + args->xattr = dict_ref(xattr); + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_setattr_store (default_args_t *args, - loc_t *loc, struct iatt *stbuf, - int32_t valid, dict_t *xdata) +args_setattr_store(default_args_t *args, loc_t *loc, struct iatt *stbuf, + int32_t valid, dict_t *xdata) { - loc_copy (&args->loc, loc); + loc_copy(&args->loc, loc); - if (stbuf) - args->stat = *stbuf; + if (stbuf) + args->stat = *stbuf; - args->valid = valid; + args->valid = valid; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_setattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +args_setattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (statpre) - args->prestat = *statpre; - if (statpost) - args->poststat = *statpost; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (statpre) + args->prestat = *statpre; + if (statpost) + args->poststat = *statpost; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } - int -args_fsetattr_store (default_args_t *args, - fd_t *fd, struct iatt *stbuf, - int32_t valid, dict_t *xdata) +args_fsetattr_store(default_args_t *args, fd_t *fd, struct iatt *stbuf, + int32_t valid, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - if (stbuf) - args->stat = *stbuf; + if (stbuf) + args->stat = *stbuf; - args->valid = valid; + args->valid = valid; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fsetattr_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +args_fsetattr_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (statpre) - args->prestat = *statpre; - if (statpost) - args->poststat = *statpost; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (statpre) + args->prestat = *statpre; + if (statpost) + args->poststat = *statpost; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_fallocate_store (default_args_t *args, fd_t *fd, - int32_t mode, off_t offset, size_t len, dict_t *xdata) +args_fallocate_store(default_args_t *args, fd_t *fd, int32_t mode, off_t offset, + size_t len, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - args->flags = mode; - args->offset = offset; - args->size = len; + args->flags = mode; + args->offset = offset; + args->size = len; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_fallocate_cbk_store(default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +args_fallocate_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (statpre) - args->prestat = *statpre; - if (statpost) - args->poststat = *statpost; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (statpre) + args->prestat = *statpre; + if (statpost) + args->poststat = *statpost; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_discard_store (default_args_t *args, fd_t *fd, - off_t offset, size_t len, dict_t *xdata) +args_discard_store(default_args_t *args, fd_t *fd, off_t offset, size_t len, + dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - args->offset = offset; - args->size = len; + args->offset = offset; + args->size = len; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_discard_cbk_store(default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +args_discard_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (statpre) - args->prestat = *statpre; - if (statpost) - args->poststat = *statpost; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (statpre) + args->prestat = *statpre; + if (statpost) + args->poststat = *statpost; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_zerofill_store (default_args_t *args, fd_t *fd, - off_t offset, off_t len, dict_t *xdata) +args_zerofill_store(default_args_t *args, fd_t *fd, off_t offset, off_t len, + dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - args->offset = offset; - args->size = len; + args->offset = offset; + args->size = len; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_zerofill_cbk_store(default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - struct iatt *statpre, struct iatt *statpost, - dict_t *xdata) +args_zerofill_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, struct iatt *statpre, + struct iatt *statpost, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (statpre) - args->prestat = *statpre; - if (statpost) - args->poststat = *statpost; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (statpre) + args->prestat = *statpre; + if (statpost) + args->poststat = *statpost; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_ipc_store (default_args_t *args, - int32_t op, dict_t *xdata) +args_ipc_store(default_args_t *args, int32_t op, dict_t *xdata) { - args->cmd = op; + args->cmd = op; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_ipc_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +args_ipc_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_seek_store (default_args_t *args, fd_t *fd, - off_t offset, gf_seek_what_t what, dict_t *xdata) +args_seek_store(default_args_t *args, fd_t *fd, off_t offset, + gf_seek_what_t what, dict_t *xdata) { - if (fd) - args->fd = fd_ref (fd); + if (fd) + args->fd = fd_ref(fd); - args->offset = offset; - args->what = what; + args->offset = offset; + args->what = what; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_seek_cbk_store (default_args_cbk_t *args, int32_t op_ret, - int32_t op_errno, off_t offset, dict_t *xdata) +args_seek_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, + off_t offset, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - args->offset = offset; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + args->offset = offset; + if (xdata) + args->xdata = dict_ref(xdata); - return 0; + return 0; } int -args_getactivelk_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, - lock_migration_info_t *locklist, dict_t *xdata) +args_getactivelk_cbk_store(default_args_cbk_t *args, int32_t op_ret, + int32_t op_errno, lock_migration_info_t *locklist, + dict_t *xdata) { - lock_migration_info_t *stub_entry = NULL, *entry = NULL; - int ret = 0; + lock_migration_info_t *stub_entry = NULL, *entry = NULL; + int ret = 0; - args->op_ret = op_ret; - args->op_errno = op_errno; - /*op_ret needs to carry the number of locks present in the list*/ - if (op_ret > 0) { - list_for_each_entry (entry, &locklist->list, list) { - stub_entry = GF_CALLOC (1, sizeof (*stub_entry), - gf_common_mt_char); - if (!stub_entry) { - ret = -1; - goto out; - } + args->op_ret = op_ret; + args->op_errno = op_errno; + /*op_ret needs to carry the number of locks present in the list*/ + if (op_ret > 0) { + list_for_each_entry(entry, &locklist->list, list) + { + stub_entry = GF_CALLOC(1, sizeof(*stub_entry), gf_common_mt_char); + if (!stub_entry) { + ret = -1; + goto out; + } - INIT_LIST_HEAD (&stub_entry->list); - stub_entry->flock = entry->flock; + INIT_LIST_HEAD(&stub_entry->list); + stub_entry->flock = entry->flock; - stub_entry->lk_flags = entry->lk_flags; + stub_entry->lk_flags = entry->lk_flags; - stub_entry->client_uid = gf_strdup (entry->client_uid); - if (!stub_entry->client_uid) { - GF_FREE (stub_entry); - ret = -1; - goto out; - } + stub_entry->client_uid = gf_strdup(entry->client_uid); + if (!stub_entry->client_uid) { + GF_FREE(stub_entry); + ret = -1; + goto out; + } - list_add_tail (&stub_entry->list, - &args->locklist.list); - } + list_add_tail(&stub_entry->list, &args->locklist.list); } + } - if (xdata) - args->xdata = dict_ref (xdata); + if (xdata) + args->xdata = dict_ref(xdata); out: - return ret; + return ret; } int -args_setactivelk_store (default_args_t *args, loc_t *loc, - lock_migration_info_t *locklist, dict_t *xdata) +args_setactivelk_store(default_args_t *args, loc_t *loc, + lock_migration_info_t *locklist, dict_t *xdata) { - lock_migration_info_t *stub_entry = NULL, *entry = NULL; - int ret = 0; - - list_for_each_entry (entry, &locklist->list, list) { - stub_entry = GF_CALLOC (1, sizeof (*stub_entry), - gf_common_mt_lock_mig); - if (!stub_entry) { - ret = -1; - goto out; - } + lock_migration_info_t *stub_entry = NULL, *entry = NULL; + int ret = 0; - INIT_LIST_HEAD (&stub_entry->list); - stub_entry->flock = entry->flock; + list_for_each_entry(entry, &locklist->list, list) + { + stub_entry = GF_CALLOC(1, sizeof(*stub_entry), gf_common_mt_lock_mig); + if (!stub_entry) { + ret = -1; + goto out; + } - stub_entry->lk_flags = entry->lk_flags; + INIT_LIST_HEAD(&stub_entry->list); + stub_entry->flock = entry->flock; - stub_entry->client_uid = gf_strdup (entry->client_uid); - if (!stub_entry->client_uid) { - GF_FREE (stub_entry); - ret = -1; - goto out; - } + stub_entry->lk_flags = entry->lk_flags; - list_add_tail (&stub_entry->list, - &args->locklist.list); + stub_entry->client_uid = gf_strdup(entry->client_uid); + if (!stub_entry->client_uid) { + GF_FREE(stub_entry); + ret = -1; + goto out; } - loc_copy (&args->loc, loc); + list_add_tail(&stub_entry->list, &args->locklist.list); + } - if (xdata) - args->xdata = dict_ref (xdata); + loc_copy(&args->loc, loc); + + if (xdata) + args->xdata = dict_ref(xdata); out: - return ret; + return ret; } void -args_lease_store (default_args_t *args, loc_t *loc, struct gf_lease *lease, - dict_t *xdata) +args_lease_store(default_args_t *args, loc_t *loc, struct gf_lease *lease, + dict_t *xdata) { - loc_copy (&args->loc, loc); - args->lease = *lease; + loc_copy(&args->loc, loc); + args->lease = *lease; - if (xdata) - args->xdata = dict_ref (xdata); + if (xdata) + args->xdata = dict_ref(xdata); - return; + return; } void -args_lease_cbk_store (default_args_cbk_t *args, - int32_t op_ret, int32_t op_errno, +args_lease_cbk_store(default_args_cbk_t *args, int32_t op_ret, int32_t op_errno, struct gf_lease *lease, dict_t *xdata) { - args->op_ret = op_ret; - args->op_errno = op_errno; - if (op_ret == 0) - args->lease = *lease; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (op_ret == 0) + args->lease = *lease; + if (xdata) + args->xdata = dict_ref(xdata); } int -args_icreate_store (default_args_t *args, - loc_t *loc, mode_t mode, dict_t *xdata) +args_icreate_store(default_args_t *args, loc_t *loc, mode_t mode, dict_t *xdata) { - loc_copy (&args->loc, loc); - args->mode = mode; + loc_copy(&args->loc, loc); + args->mode = mode; - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } int -args_namelink_store (default_args_t *args, - loc_t *loc, dict_t *xdata) +args_namelink_store(default_args_t *args, loc_t *loc, dict_t *xdata) { - loc_copy (&args->loc, loc); + loc_copy(&args->loc, loc); - if (xdata) - args->xdata = dict_ref (xdata); - return 0; + if (xdata) + args->xdata = dict_ref(xdata); + return 0; } void -args_cbk_wipe (default_args_cbk_t *args_cbk) +args_cbk_wipe(default_args_cbk_t *args_cbk) { - if (!args_cbk) - return; - if (args_cbk->inode) - inode_unref (args_cbk->inode); + if (!args_cbk) + return; + if (args_cbk->inode) + inode_unref(args_cbk->inode); - GF_FREE ((char *)args_cbk->buf); + GF_FREE((char *)args_cbk->buf); - GF_FREE (args_cbk->vector); + GF_FREE(args_cbk->vector); - if (args_cbk->iobref) - iobref_unref (args_cbk->iobref); + if (args_cbk->iobref) + iobref_unref(args_cbk->iobref); - if (args_cbk->fd) - fd_unref (args_cbk->fd); + if (args_cbk->fd) + fd_unref(args_cbk->fd); - if (args_cbk->xattr) - dict_unref (args_cbk->xattr); + if (args_cbk->xattr) + dict_unref(args_cbk->xattr); - GF_FREE (args_cbk->strong_checksum); + GF_FREE(args_cbk->strong_checksum); - if (args_cbk->xdata) - dict_unref (args_cbk->xdata); + if (args_cbk->xdata) + dict_unref(args_cbk->xdata); - if (!list_empty (&args_cbk->entries.list)) - gf_dirent_free (&args_cbk->entries); + if (!list_empty(&args_cbk->entries.list)) + gf_dirent_free(&args_cbk->entries); } void -args_wipe (default_args_t *args) +args_wipe(default_args_t *args) { - if (!args) - return; - - loc_wipe (&args->loc); + if (!args) + return; - loc_wipe (&args->loc2); + loc_wipe(&args->loc); - if (args->fd) - fd_unref (args->fd); + loc_wipe(&args->loc2); - GF_FREE ((char *)args->linkname); + if (args->fd) + fd_unref(args->fd); - GF_FREE (args->vector); + GF_FREE((char *)args->linkname); - if (args->iobref) - iobref_unref (args->iobref); + GF_FREE(args->vector); - if (args->xattr) - dict_unref (args->xattr); + if (args->iobref) + iobref_unref(args->iobref); - if (args->xdata) - dict_unref (args->xdata); + if (args->xattr) + dict_unref(args->xattr); - GF_FREE ((char *)args->name); + if (args->xdata) + dict_unref(args->xdata); - GF_FREE ((char *)args->volume); + GF_FREE((char *)args->name); + GF_FREE((char *)args->volume); } void -args_cbk_init (default_args_cbk_t *args_cbk) +args_cbk_init(default_args_cbk_t *args_cbk) { - INIT_LIST_HEAD (&args_cbk->entries); + INIT_LIST_HEAD(&args_cbk->entries); } diff --git a/libglusterfs/src/defaults-tmpl.c b/libglusterfs/src/defaults-tmpl.c index 74550030446..2ce5ec7c685 100644 --- a/libglusterfs/src/defaults-tmpl.c +++ b/libglusterfs/src/defaults-tmpl.c @@ -31,206 +31,191 @@ #pragma generate struct xlator_fops _default_fops = { - .create = default_create, - .open = default_open, - .stat = default_stat, - .readlink = default_readlink, - .mknod = default_mknod, - .mkdir = default_mkdir, - .unlink = default_unlink, - .rmdir = default_rmdir, - .symlink = default_symlink, - .rename = default_rename, - .link = default_link, - .truncate = default_truncate, - .readv = default_readv, - .writev = default_writev, - .statfs = default_statfs, - .flush = default_flush, - .fsync = default_fsync, - .setxattr = default_setxattr, - .getxattr = default_getxattr, - .fsetxattr = default_fsetxattr, - .fgetxattr = default_fgetxattr, - .removexattr = default_removexattr, - .fremovexattr = default_fremovexattr, - .opendir = default_opendir, - .readdir = default_readdir, - .readdirp = default_readdirp, - .fsyncdir = default_fsyncdir, - .access = default_access, - .ftruncate = default_ftruncate, - .fstat = default_fstat, - .lk = default_lk, - .inodelk = default_inodelk, - .finodelk = default_finodelk, - .entrylk = default_entrylk, - .fentrylk = default_fentrylk, - .lookup = default_lookup, - .rchecksum = default_rchecksum, - .xattrop = default_xattrop, - .fxattrop = default_fxattrop, - .setattr = default_setattr, - .fsetattr = default_fsetattr, - .fallocate = default_fallocate, - .discard = default_discard, - .zerofill = default_zerofill, - .ipc = default_ipc, - .seek = default_seek, - - .getspec = default_getspec, - .getactivelk = default_getactivelk, - .setactivelk = default_setactivelk, - .put = default_put, - .icreate = default_icreate, - .namelink = default_namelink, + .create = default_create, + .open = default_open, + .stat = default_stat, + .readlink = default_readlink, + .mknod = default_mknod, + .mkdir = default_mkdir, + .unlink = default_unlink, + .rmdir = default_rmdir, + .symlink = default_symlink, + .rename = default_rename, + .link = default_link, + .truncate = default_truncate, + .readv = default_readv, + .writev = default_writev, + .statfs = default_statfs, + .flush = default_flush, + .fsync = default_fsync, + .setxattr = default_setxattr, + .getxattr = default_getxattr, + .fsetxattr = default_fsetxattr, + .fgetxattr = default_fgetxattr, + .removexattr = default_removexattr, + .fremovexattr = default_fremovexattr, + .opendir = default_opendir, + .readdir = default_readdir, + .readdirp = default_readdirp, + .fsyncdir = default_fsyncdir, + .access = default_access, + .ftruncate = default_ftruncate, + .fstat = default_fstat, + .lk = default_lk, + .inodelk = default_inodelk, + .finodelk = default_finodelk, + .entrylk = default_entrylk, + .fentrylk = default_fentrylk, + .lookup = default_lookup, + .rchecksum = default_rchecksum, + .xattrop = default_xattrop, + .fxattrop = default_fxattrop, + .setattr = default_setattr, + .fsetattr = default_fsetattr, + .fallocate = default_fallocate, + .discard = default_discard, + .zerofill = default_zerofill, + .ipc = default_ipc, + .seek = default_seek, + + .getspec = default_getspec, + .getactivelk = default_getactivelk, + .setactivelk = default_setactivelk, + .put = default_put, + .icreate = default_icreate, + .namelink = default_namelink, }; struct xlator_fops *default_fops = &_default_fops; - /* * Remaining functions don't follow the fop calling conventions, so they're * not generated. */ int32_t -default_forget (xlator_t *this, inode_t *inode) +default_forget(xlator_t *this, inode_t *inode) { - gf_log_callingfn (this->name, GF_LOG_DEBUG, "xlator does not " - "implement forget_cbk"); - return 0; + gf_log_callingfn(this->name, GF_LOG_DEBUG, + "xlator does not " + "implement forget_cbk"); + return 0; } - int32_t -default_releasedir (xlator_t *this, fd_t *fd) +default_releasedir(xlator_t *this, fd_t *fd) { - gf_log_callingfn (this->name, GF_LOG_DEBUG, "xlator does not " - "implement releasedir_cbk"); - return 0; + gf_log_callingfn(this->name, GF_LOG_DEBUG, + "xlator does not " + "implement releasedir_cbk"); + return 0; } int32_t -default_release (xlator_t *this, fd_t *fd) +default_release(xlator_t *this, fd_t *fd) { - gf_log_callingfn (this->name, GF_LOG_DEBUG, "xlator does not " - "implement release_cbk"); - return 0; + gf_log_callingfn(this->name, GF_LOG_DEBUG, + "xlator does not " + "implement release_cbk"); + return 0; } /* notify */ int -default_notify (xlator_t *this, int32_t event, void *data, ...) +default_notify(xlator_t *this, int32_t event, void *data, ...) { - GF_UNUSED int ret = 0; - switch (event) { + GF_UNUSED int ret = 0; + switch (event) { case GF_EVENT_PARENT_UP: - case GF_EVENT_PARENT_DOWN: - { - xlator_list_t *list = this->children; - - while (list) { - xlator_notify (list->xlator, event, this); - list = list->next; - } - } - break; + case GF_EVENT_PARENT_DOWN: { + xlator_list_t *list = this->children; + + while (list) { + xlator_notify(list->xlator, event, this); + list = list->next; + } + } break; case GF_EVENT_CHILD_CONNECTING: case GF_EVENT_CHILD_DOWN: case GF_EVENT_CHILD_UP: - case GF_EVENT_AUTH_FAILED: - { - xlator_list_t *parent = this->parents; - - /* - * Handle case of CHILD_* & AUTH_FAILED event specially, send - * it to fuse. - */ - if (!parent && this->ctx && this->ctx->master) { - xlator_notify (this->ctx->master, event, this->graph, - NULL); - } - - while (parent) { - if (parent->xlator->init_succeeded) - xlator_notify (parent->xlator, event, - this, NULL); - parent = parent->next; - } - } - break; - case GF_EVENT_UPCALL: - { - xlator_list_t *parent = this->parents; - - if (!parent && this->ctx && this->ctx->master) - xlator_notify (this->ctx->master, event, data, NULL); - - while (parent) { - if (parent->xlator->init_succeeded) - xlator_notify (parent->xlator, event, - data, NULL); - parent = parent->next; - } - } - break; - case GF_EVENT_CHILD_PING: - { - xlator_list_t *parent = this->parents; - - while (parent) { - if (parent->xlator->init_succeeded) - XLATOR_NOTIFY (ret, parent->xlator, event, - this, data); - parent = parent->next; - } + case GF_EVENT_AUTH_FAILED: { + xlator_list_t *parent = this->parents; + + /* + * Handle case of CHILD_* & AUTH_FAILED event specially, send + * it to fuse. + */ + if (!parent && this->ctx && this->ctx->master) { + xlator_notify(this->ctx->master, event, this->graph, NULL); + } + + while (parent) { + if (parent->xlator->init_succeeded) + xlator_notify(parent->xlator, event, this, NULL); + parent = parent->next; + } + } break; + case GF_EVENT_UPCALL: { + xlator_list_t *parent = this->parents; + + if (!parent && this->ctx && this->ctx->master) + xlator_notify(this->ctx->master, event, data, NULL); + + while (parent) { + if (parent->xlator->init_succeeded) + xlator_notify(parent->xlator, event, data, NULL); + parent = parent->next; + } + } break; + case GF_EVENT_CHILD_PING: { + xlator_list_t *parent = this->parents; + + while (parent) { + if (parent->xlator->init_succeeded) + XLATOR_NOTIFY(ret, parent->xlator, event, this, data); + parent = parent->next; + } + } break; + case GF_EVENT_CLEANUP: { + xlator_list_t *list = this->children; + + while (list) { + xlator_notify(list->xlator, event, this); + list = list->next; + } + } break; + + default: { + xlator_list_t *parent = this->parents; + + while (parent) { + if (parent->xlator->init_succeeded) + xlator_notify(parent->xlator, event, this, NULL); + parent = parent->next; + } } - break; - case GF_EVENT_CLEANUP: - { - xlator_list_t *list = this->children; - - while (list) { - xlator_notify (list->xlator, event, this); - list = list->next; - } - } - break; - - default: - { - xlator_list_t *parent = this->parents; - - while (parent) { - if (parent->xlator->init_succeeded) - xlator_notify (parent->xlator, event, - this, NULL); - parent = parent->next; - } - } - /* - * Apparently our picky-about-everything else coding standard allows - * adjacent same-indendation-level close braces. Clearly it has - * nothing to do with readability. - */ - } - - return 0; + /* + * Apparently our picky-about-everything else coding standard allows + * adjacent same-indendation-level close braces. Clearly it has + * nothing to do with readability. + */ + } + + return 0; } int32_t -default_mem_acct_init (xlator_t *this) +default_mem_acct_init(xlator_t *this) { - int ret = -1; + int ret = -1; - ret = xlator_mem_acct_init (this, gf_common_mt_end); + ret = xlator_mem_acct_init(this, gf_common_mt_end); - return ret; + return ret; } void -default_fini (xlator_t *this) +default_fini(xlator_t *this) { - if (this && this->private) - GF_FREE (this->private); + if (this && this->private) + GF_FREE(this->private); } diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index b7cf2b0c8fe..2e69da98fdc 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -31,213 +31,209 @@ #include "glusterfs-fops.h" struct dict_cmp { - dict_t *dict; - gf_boolean_t (*value_ignore) (char *k); + dict_t *dict; + gf_boolean_t (*value_ignore)(char *k); }; -#define VALIDATE_DATA_AND_LOG(data, type, key, ret_val) do { \ - if (!data || !data->data) { \ - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, \ - LG_MSG_INVALID_ARG, "data is NULL"); \ - return ret_val; \ - } \ - /* Not of the asked type, or old version */ \ - if ((data->data_type != type) && \ - (data->data_type != GF_DATA_TYPE_STR_OLD)) { \ - gf_msg_callingfn ("dict", GF_LOG_INFO, EINVAL, \ - LG_MSG_INVALID_ARG, \ - "key %s, %s type asked, has %s type", \ - key, data_type_name[type], \ - data_type_name[data->data_type]); \ - } \ - } while (0) +#define VALIDATE_DATA_AND_LOG(data, type, key, ret_val) \ + do { \ + if (!data || !data->data) { \ + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, \ + LG_MSG_INVALID_ARG, "data is NULL"); \ + return ret_val; \ + } \ + /* Not of the asked type, or old version */ \ + if ((data->data_type != type) && \ + (data->data_type != GF_DATA_TYPE_STR_OLD)) { \ + gf_msg_callingfn("dict", GF_LOG_INFO, EINVAL, LG_MSG_INVALID_ARG, \ + "key %s, %s type asked, has %s type", key, \ + data_type_name[type], \ + data_type_name[data->data_type]); \ + } \ + } while (0) static data_t * -get_new_data () +get_new_data() { - data_t *data = NULL; + data_t *data = NULL; - data = mem_get (THIS->ctx->dict_data_pool); - if (!data) - return NULL; + data = mem_get(THIS->ctx->dict_data_pool); + if (!data) + return NULL; - GF_ATOMIC_INIT (data->refcount, 0); - data->is_static = _gf_false; - LOCK_INIT (&data->lock); + GF_ATOMIC_INIT(data->refcount, 0); + data->is_static = _gf_false; + LOCK_INIT(&data->lock); - return data; + return data; } static dict_t * -get_new_dict_full (int size_hint) +get_new_dict_full(int size_hint) { - dict_t *dict = mem_get0 (THIS->ctx->dict_pool); + dict_t *dict = mem_get0(THIS->ctx->dict_pool); - if (!dict) { - return NULL; - } + if (!dict) { + return NULL; + } - dict->hash_size = size_hint; - if (size_hint == 1) { - /* - * This is the only case we ever see currently. If we ever - * need to support resizing the hash table, the resize function - * will have to take into account the possibility that - * "members" is not separately allocated (i.e. don't just call - * realloc() blindly. - */ - dict->members = &dict->members_internal; - } - else { - /* - * We actually need to allocate space for size_hint *pointers* - * but we actually allocate space for one *structure*. Since - * a data_pair_t consists of five pointers, we're wasting four - * pointers' worth for N=1, and will overrun what we allocated - * for N>5. If anybody ever starts using size_hint, we'll need - * to fix this. - */ - GF_ASSERT (size_hint <= - (sizeof(data_pair_t) / sizeof(data_pair_t *))); - dict->members = mem_get0 (THIS->ctx->dict_pair_pool); - if (!dict->members) { - mem_put (dict); - return NULL; - } + dict->hash_size = size_hint; + if (size_hint == 1) { + /* + * This is the only case we ever see currently. If we ever + * need to support resizing the hash table, the resize function + * will have to take into account the possibility that + * "members" is not separately allocated (i.e. don't just call + * realloc() blindly. + */ + dict->members = &dict->members_internal; + } else { + /* + * We actually need to allocate space for size_hint *pointers* + * but we actually allocate space for one *structure*. Since + * a data_pair_t consists of five pointers, we're wasting four + * pointers' worth for N=1, and will overrun what we allocated + * for N>5. If anybody ever starts using size_hint, we'll need + * to fix this. + */ + GF_ASSERT(size_hint <= (sizeof(data_pair_t) / sizeof(data_pair_t *))); + dict->members = mem_get0(THIS->ctx->dict_pair_pool); + if (!dict->members) { + mem_put(dict); + return NULL; } + } - LOCK_INIT (&dict->lock); + LOCK_INIT(&dict->lock); - return dict; + return dict; } dict_t * -get_new_dict (void) +get_new_dict(void) { - return get_new_dict_full (1); + return get_new_dict_full(1); } dict_t * -dict_new (void) +dict_new(void) { - dict_t *dict = NULL; + dict_t *dict = NULL; - dict = get_new_dict_full(1); + dict = get_new_dict_full(1); - if (dict) - dict_ref (dict); + if (dict) + dict_ref(dict); - return dict; + return dict; } int32_t -is_data_equal (data_t *one, - data_t *two) +is_data_equal(data_t *one, data_t *two) { - struct iatt *iatt1, *iatt2; + struct iatt *iatt1, *iatt2; + + if (!one || !two || !one->data || !two->data) { + gf_msg_callingfn("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "input arguments are provided " + "with value data_t as NULL"); + return -1; + } - if (!one || !two || !one->data || !two->data) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, - "input arguments are provided " - "with value data_t as NULL"); - return -1; - } + if (one == two) + return 1; - if (one == two) - return 1; + if (one->data == two->data) + return 1; - if (one->data == two->data) - return 1; + if (one->data_type != two->data_type) { + return 0; + } - if (one->data_type != two->data_type) { - return 0; + if (one->data_type == GF_DATA_TYPE_IATT) { + if ((one->len < sizeof(struct iatt)) || + (two->len < sizeof(struct iatt))) { + return 0; } - if (one->data_type == GF_DATA_TYPE_IATT) { - if ((one->len < sizeof(struct iatt)) || - (two->len < sizeof(struct iatt))) { - return 0; - } + iatt1 = (struct iatt *)one->data; + iatt2 = (struct iatt *)two->data; - iatt1 = (struct iatt *)one->data; - iatt2 = (struct iatt *)two->data; + /* Two iatt structs are considered equal if main fields are + * equal, even if times differ. + * TODO: maybe when ctime if fully operational we could + * enforce time matching. */ + if (iatt1->ia_ino != iatt2->ia_ino) { + return 0; + } + if (iatt1->ia_type != iatt2->ia_type) { + return 0; + } + if ((iatt1->ia_type == IA_IFBLK) || (iatt1->ia_type == IA_IFCHR)) { + if (iatt1->ia_rdev != iatt2->ia_rdev) { + return 0; + } + } + if (gf_uuid_compare(iatt1->ia_gfid, iatt2->ia_gfid) != 0) { + return 0; + } - /* Two iatt structs are considered equal if main fields are - * equal, even if times differ. - * TODO: maybe when ctime if fully operational we could - * enforce time matching. */ - if (iatt1->ia_ino != iatt2->ia_ino) { - return 0; - } - if (iatt1->ia_type != iatt2->ia_type) { - return 0; - } - if ((iatt1->ia_type == IA_IFBLK) || - (iatt1->ia_type == IA_IFCHR)) { - if (iatt1->ia_rdev != iatt2->ia_rdev) { - return 0; + /* TODO: ia_uid, ia_gid, ia_prot and ia_size can be changed + * with some commands. Here we don't have enough + * information to decide if they should match or not. */ + /* + if ((iatt1->ia_uid != iatt2->ia_uid) || + (iatt1->ia_gid != iatt2->ia_gid) || + (st_mode_from_ia(iatt1->ia_prot, iatt1->ia_type) != + st_mode_from_ia(iatt2->ia_prot, + iatt2->ia_type))) { return 0; } - } - if (gf_uuid_compare(iatt1->ia_gfid, iatt2->ia_gfid) != 0) { - return 0; - } - - /* TODO: ia_uid, ia_gid, ia_prot and ia_size can be changed - * with some commands. Here we don't have enough - * information to decide if they should match or not. */ -/* - if ((iatt1->ia_uid != iatt2->ia_uid) || - (iatt1->ia_gid != iatt2->ia_gid) || - (st_mode_from_ia(iatt1->ia_prot, iatt1->ia_type) != - st_mode_from_ia(iatt2->ia_prot, iatt2->ia_type))) { - return 0; - } - if (iatt1->ia_type == IA_IFREG) { - if (iatt1->ia_size != iatt2->ia_size) { - return 0; + if (iatt1->ia_type == IA_IFREG) { + if (iatt1->ia_size != iatt2->ia_size) { + return 0; + } } - } -*/ - return 1; - } + */ + return 1; + } - if (one->len != two->len) - return 0; + if (one->len != two->len) + return 0; - if (memcmp (one->data, two->data, one->len) == 0) - return 1; + if (memcmp(one->data, two->data, one->len) == 0) + return 1; - return 0; + return 0; } static int -key_value_cmp (dict_t *one, char *key1, data_t *value1, void *data) +key_value_cmp(dict_t *one, char *key1, data_t *value1, void *data) { - struct dict_cmp *cmp = data; - dict_t *two = NULL; - data_t *value2 = NULL; + struct dict_cmp *cmp = data; + dict_t *two = NULL; + data_t *value2 = NULL; - two = cmp->dict; - value2 = dict_get (two, key1); + two = cmp->dict; + value2 = dict_get(two, key1); - if (value2) { - if (cmp->value_ignore && cmp->value_ignore (key1)) - return 0; + if (value2) { + if (cmp->value_ignore && cmp->value_ignore(key1)) + return 0; - if (is_data_equal (value1, value2) == 1) - return 0; - } + if (is_data_equal(value1, value2) == 1) + return 0; + } - if (value2 == NULL) { - gf_msg_debug (THIS->name, 0, "'%s' found only on one dict", - key1); - } else { - gf_msg_debug (THIS->name, 0, "'%s' is different in two dicts " - "(%u, %u)", key1, value1->len, value2->len); - } + if (value2 == NULL) { + gf_msg_debug(THIS->name, 0, "'%s' found only on one dict", key1); + } else { + gf_msg_debug(THIS->name, 0, + "'%s' is different in two dicts " + "(%u, %u)", + key1, value1->len, value2->len); + } - return -1; + return -1; } /* If both dicts are NULL then equal. If one of the dicts is NULL but the @@ -248,93 +244,92 @@ key_value_cmp (dict_t *one, char *key1, data_t *value1, void *data) * different. */ gf_boolean_t -are_dicts_equal (dict_t *one, dict_t *two, - gf_boolean_t (*match) (dict_t *d, char *k, data_t *v, - void *data), - gf_boolean_t (*value_ignore) (char *k)) +are_dicts_equal(dict_t *one, dict_t *two, + gf_boolean_t (*match)(dict_t *d, char *k, data_t *v, + void *data), + gf_boolean_t (*value_ignore)(char *k)) { - int num_matches1 = 0; - int num_matches2 = 0; - struct dict_cmp cmp = {0}; + int num_matches1 = 0; + int num_matches2 = 0; + struct dict_cmp cmp = {0}; - if (one == two) - return _gf_true; + if (one == two) + return _gf_true; - if (!match) - match = dict_match_everything; + if (!match) + match = dict_match_everything; - if ((one == NULL) || (two == NULL)) { - num_matches1 = dict_foreach_match(one ? one : two, match, NULL, - dict_null_foreach_fn, NULL); - goto done; - } + if ((one == NULL) || (two == NULL)) { + num_matches1 = dict_foreach_match(one ? one : two, match, NULL, + dict_null_foreach_fn, NULL); + goto done; + } - cmp.dict = two; - cmp.value_ignore = value_ignore; - num_matches1 = dict_foreach_match (one, match, NULL, key_value_cmp, - &cmp); + cmp.dict = two; + cmp.value_ignore = value_ignore; + num_matches1 = dict_foreach_match(one, match, NULL, key_value_cmp, &cmp); - if (num_matches1 == -1) - return _gf_false; + if (num_matches1 == -1) + return _gf_false; - if ((num_matches1 == one->count) && (one->count == two->count)) - return _gf_true; + if ((num_matches1 == one->count) && (one->count == two->count)) + return _gf_true; - num_matches2 = dict_foreach_match (two, match, NULL, - dict_null_foreach_fn, NULL); + num_matches2 = dict_foreach_match(two, match, NULL, dict_null_foreach_fn, + NULL); done: - /* If the number of matches is same in 'two' then for all the - * valid-keys that exist in 'one' the value matched and no extra valid - * keys exist in 'two' alone. Otherwise there exists at least one extra - * valid-key in 'two' which doesn't exist in 'one' */ - if (num_matches1 == num_matches2) - return _gf_true; - return _gf_false; + /* If the number of matches is same in 'two' then for all the + * valid-keys that exist in 'one' the value matched and no extra valid + * keys exist in 'two' alone. Otherwise there exists at least one extra + * valid-key in 'two' which doesn't exist in 'one' */ + if (num_matches1 == num_matches2) + return _gf_true; + return _gf_false; } void -data_destroy (data_t *data) +data_destroy(data_t *data) { - if (data) { - LOCK_DESTROY (&data->lock); + if (data) { + LOCK_DESTROY(&data->lock); - if (!data->is_static) - GF_FREE (data->data); + if (!data->is_static) + GF_FREE(data->data); - data->len = 0xbabababa; - mem_put (data); - } + data->len = 0xbabababa; + mem_put(data); + } } data_t * -data_copy (data_t *old) +data_copy(data_t *old) { - if (!old) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, 0, LG_MSG_NULL_PTR, - "old is NULL"); - return NULL; - } + if (!old) { + gf_msg_callingfn("dict", GF_LOG_WARNING, 0, LG_MSG_NULL_PTR, + "old is NULL"); + return NULL; + } - data_t *newdata = mem_get0 (THIS->ctx->dict_data_pool); - if (!newdata) { - return NULL; - } + data_t *newdata = mem_get0(THIS->ctx->dict_data_pool); + if (!newdata) { + return NULL; + } - newdata->len = old->len; - if (old->data) { - newdata->data = memdup (old->data, old->len); - if (!newdata->data) - goto err_out; - } - newdata->data_type = old->data_type; + newdata->len = old->len; + if (old->data) { + newdata->data = memdup(old->data, old->len); + if (!newdata->data) + goto err_out; + } + newdata->data_type = old->data_type; - LOCK_INIT (&newdata->lock); - return newdata; + LOCK_INIT(&newdata->lock); + return newdata; err_out: - mem_put (newdata); + mem_put(newdata); - return NULL; + return NULL; } /* Always need to be called under lock @@ -342,986 +337,962 @@ err_out: * checked by callers. */ static data_pair_t * -dict_lookup_common (dict_t *this, char *key, uint32_t hash) +dict_lookup_common(dict_t *this, char *key, uint32_t hash) { - int hashval = 0; - data_pair_t *pair; + int hashval = 0; + data_pair_t *pair; - /* If the divisor is 1, the modulo is always 0, - * in such case avoid hash calculation. - */ - if (this->hash_size != 1) - hashval = hash % this->hash_size; + /* If the divisor is 1, the modulo is always 0, + * in such case avoid hash calculation. + */ + if (this->hash_size != 1) + hashval = hash % this->hash_size; - for (pair = this->members[hashval]; pair != NULL; pair = pair->hash_next) { - if (pair->key && (hash == pair->key_hash) && - !strcmp (pair->key, key)) - return pair; - } + for (pair = this->members[hashval]; pair != NULL; pair = pair->hash_next) { + if (pair->key && (hash == pair->key_hash) && !strcmp(pair->key, key)) + return pair; + } - return NULL; + return NULL; } int32_t -dict_lookup (dict_t *this, char *key, data_t **data) +dict_lookup(dict_t *this, char *key, data_t **data) { - uint32_t hash; + uint32_t hash; - if (!this || !key || !data) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!this || !key || " - "!data"); - return -1; - } + if (!this || !key || !data) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!this || !key || " + "!data"); + return -1; + } - data_pair_t *tmp = NULL; + data_pair_t *tmp = NULL; - hash = SuperFastHash (key, strlen (key)); + hash = SuperFastHash(key, strlen(key)); - LOCK (&this->lock); - { - tmp = dict_lookup_common (this, key, hash); - } - UNLOCK (&this->lock); + LOCK(&this->lock); + { + tmp = dict_lookup_common(this, key, hash); + } + UNLOCK(&this->lock); - if (!tmp) - return -1; + if (!tmp) + return -1; - *data = tmp->value; - return 0; + *data = tmp->value; + return 0; } static int32_t -dict_set_lk (dict_t *this, char *key, data_t *value, const uint32_t hash, gf_boolean_t replace) -{ - int hashval = 0; - data_pair_t *pair; - int key_free = 0; - uint32_t key_hash; - int keylen; - - if (!key) { - keylen = gf_asprintf (&key, "ref:%p", value); - if (-1 == keylen) { - return -1; - } - key_free = 1; - key_hash = SuperFastHash (key, keylen); - } - else { - keylen = strlen(key); - key_hash = hash; - } - - /* Search for a existing key if 'replace' is asked for */ - if (replace) { - pair = dict_lookup_common (this, key, key_hash); - - if (pair) { - data_t *unref_data = pair->value; - pair->value = data_ref (value); - data_unref (unref_data); - if (key_free) - GF_FREE (key); - /* Indicates duplicate key */ - return 0; - } - } - - if (this->free_pair_in_use) { - pair = mem_get (THIS->ctx->dict_pair_pool); - if (!pair) { - if (key_free) - GF_FREE (key); - return -1; - } - } - else { - pair = &this->free_pair; - this->free_pair_in_use = _gf_true; - } - - if (key_free) { - /* It's ours. Use it. */ - pair->key = key; - key_free = 0; - } - else { - pair->key = (char *) GF_MALLOC (keylen + 1, - gf_common_mt_char); - if (!pair->key) { - if (pair == &this->free_pair) { - this->free_pair_in_use = _gf_false; - } - else { - mem_put (pair); - } - return -1; - } - strcpy (pair->key, key); - } - pair->key_hash = key_hash; - pair->value = data_ref (value); +dict_set_lk(dict_t *this, char *key, data_t *value, const uint32_t hash, + gf_boolean_t replace) +{ + int hashval = 0; + data_pair_t *pair; + int key_free = 0; + uint32_t key_hash; + int keylen; + + if (!key) { + keylen = gf_asprintf(&key, "ref:%p", value); + if (-1 == keylen) { + return -1; + } + key_free = 1; + key_hash = SuperFastHash(key, keylen); + } else { + keylen = strlen(key); + key_hash = hash; + } + + /* Search for a existing key if 'replace' is asked for */ + if (replace) { + pair = dict_lookup_common(this, key, key_hash); - /* If the divisor is 1, the modulo is always 0, - * in such case avoid hash calculation. - */ - if (this->hash_size != 1) { - hashval = (key_hash % this->hash_size); - } - pair->hash_next = this->members[hashval]; - this->members[hashval] = pair; - - pair->next = this->members_list; - pair->prev = NULL; - if (this->members_list) - this->members_list->prev = pair; - this->members_list = pair; - this->count++; - - if (key_free) - GF_FREE (key); - - if (this->max_count < this->count) - this->max_count = this->count; - return 0; + if (pair) { + data_t *unref_data = pair->value; + pair->value = data_ref(value); + data_unref(unref_data); + if (key_free) + GF_FREE(key); + /* Indicates duplicate key */ + return 0; + } + } + + if (this->free_pair_in_use) { + pair = mem_get(THIS->ctx->dict_pair_pool); + if (!pair) { + if (key_free) + GF_FREE(key); + return -1; + } + } else { + pair = &this->free_pair; + this->free_pair_in_use = _gf_true; + } + + if (key_free) { + /* It's ours. Use it. */ + pair->key = key; + key_free = 0; + } else { + pair->key = (char *)GF_MALLOC(keylen + 1, gf_common_mt_char); + if (!pair->key) { + if (pair == &this->free_pair) { + this->free_pair_in_use = _gf_false; + } else { + mem_put(pair); + } + return -1; + } + strcpy(pair->key, key); + } + pair->key_hash = key_hash; + pair->value = data_ref(value); + + /* If the divisor is 1, the modulo is always 0, + * in such case avoid hash calculation. + */ + if (this->hash_size != 1) { + hashval = (key_hash % this->hash_size); + } + pair->hash_next = this->members[hashval]; + this->members[hashval] = pair; + + pair->next = this->members_list; + pair->prev = NULL; + if (this->members_list) + this->members_list->prev = pair; + this->members_list = pair; + this->count++; + + if (key_free) + GF_FREE(key); + + if (this->max_count < this->count) + this->max_count = this->count; + return 0; } int32_t -dict_set (dict_t *this, - char *key, - data_t *value) +dict_set(dict_t *this, char *key, data_t *value) { - if (key) - return dict_setn (this, key, strlen (key), value); - else - return dict_setn (this, NULL, 0, value); + if (key) + return dict_setn(this, key, strlen(key), value); + else + return dict_setn(this, NULL, 0, value); } int32_t -dict_setn (dict_t *this, - char *key, - const int keylen, - data_t *value) -{ - int32_t ret; - uint32_t key_hash = 0; - - if (!this || !value) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!this || !value for " - "key=%s", key); - return -1; - } +dict_setn(dict_t *this, char *key, const int keylen, data_t *value) +{ + int32_t ret; + uint32_t key_hash = 0; - if (key) { - key_hash = SuperFastHash (key, keylen); - } + if (!this || !value) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!this || !value for " + "key=%s", + key); + return -1; + } - LOCK (&this->lock); + if (key) { + key_hash = SuperFastHash(key, keylen); + } - ret = dict_set_lk (this, key, value, key_hash, 1); + LOCK(&this->lock); - UNLOCK (&this->lock); + ret = dict_set_lk(this, key, value, key_hash, 1); - return ret; -} + UNLOCK(&this->lock); + return ret; +} int32_t -dict_add (dict_t *this, char *key, data_t *value) +dict_add(dict_t *this, char *key, data_t *value) { - if (key) - return dict_addn(this, key, strlen (key), value); - else - return dict_addn(this, NULL, 0, value); + if (key) + return dict_addn(this, key, strlen(key), value); + else + return dict_addn(this, NULL, 0, value); } int32_t -dict_addn (dict_t *this, char *key, const int keylen, data_t *value) +dict_addn(dict_t *this, char *key, const int keylen, data_t *value) { - int32_t ret; - uint32_t key_hash = 0; + int32_t ret; + uint32_t key_hash = 0; - if (!this || !value) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "!this || !value for key=%s", key); - return -1; - } + if (!this || !value) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!this || !value for key=%s", key); + return -1; + } - if (key) { - key_hash = SuperFastHash (key, keylen); - } + if (key) { + key_hash = SuperFastHash(key, keylen); + } - LOCK (&this->lock); + LOCK(&this->lock); - ret = dict_set_lk (this, key, value, key_hash, 0); + ret = dict_set_lk(this, key, value, key_hash, 0); - UNLOCK (&this->lock); + UNLOCK(&this->lock); - return ret; + return ret; } - data_t * -dict_get (dict_t *this, char *key) +dict_get(dict_t *this, char *key) { - if (!this || !key) { - gf_msg_callingfn ("dict", GF_LOG_INFO, EINVAL, - LG_MSG_INVALID_ARG, - "!this || key=%s", (key) ? key : "()"); - return NULL; - } + if (!this || !key) { + gf_msg_callingfn("dict", GF_LOG_INFO, EINVAL, LG_MSG_INVALID_ARG, + "!this || key=%s", (key) ? key : "()"); + return NULL; + } - return dict_getn(this, key, strlen (key)); + return dict_getn(this, key, strlen(key)); } data_t * -dict_getn (dict_t *this, char *key, const int keylen) +dict_getn(dict_t *this, char *key, const int keylen) { - data_pair_t *pair; - uint32_t hash; + data_pair_t *pair; + uint32_t hash; - if (!this || !key) { - gf_msg_callingfn ("dict", GF_LOG_INFO, EINVAL, - LG_MSG_INVALID_ARG, - "!this || key=%s", (key) ? key : "()"); - return NULL; - } + if (!this || !key) { + gf_msg_callingfn("dict", GF_LOG_INFO, EINVAL, LG_MSG_INVALID_ARG, + "!this || key=%s", (key) ? key : "()"); + return NULL; + } - hash = SuperFastHash (key, keylen); + hash = SuperFastHash(key, keylen); - LOCK (&this->lock); - { - pair = dict_lookup_common (this, key, hash); - } - UNLOCK (&this->lock); + LOCK(&this->lock); + { + pair = dict_lookup_common(this, key, hash); + } + UNLOCK(&this->lock); - if (pair) - return pair->value; + if (pair) + return pair->value; - return NULL; + return NULL; } int -dict_key_count (dict_t *this) +dict_key_count(dict_t *this) { - int ret = -1; + int ret = -1; - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict passed is NULL"); - return ret; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict passed is NULL"); + return ret; + } - LOCK (&this->lock); - { - ret = this->count; - } - UNLOCK (&this->lock); + LOCK(&this->lock); + { + ret = this->count; + } + UNLOCK(&this->lock); - return ret; + return ret; } void -dict_del (dict_t *this, char *key) +dict_del(dict_t *this, char *key) { - if (!this || !key) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!this || key=%s", key); - return; - } + if (!this || !key) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!this || key=%s", key); + return; + } - return dict_deln(this, key, strlen (key)); + return dict_deln(this, key, strlen(key)); } void -dict_deln (dict_t *this, char *key, const int keylen) +dict_deln(dict_t *this, char *key, const int keylen) { - int hashval = 0; - uint32_t hash; + int hashval = 0; + uint32_t hash; - if (!this || !key) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!this || key=%s", key); - return; - } + if (!this || !key) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!this || key=%s", key); + return; + } - hash = SuperFastHash (key, keylen); + hash = SuperFastHash(key, keylen); - LOCK (&this->lock); + LOCK(&this->lock); - /* If the divisor is 1, the modulo is always 0, - * in such case avoid hash calculation. - */ - if (this->hash_size != 1) - hashval = hash % this->hash_size; + /* If the divisor is 1, the modulo is always 0, + * in such case avoid hash calculation. + */ + if (this->hash_size != 1) + hashval = hash % this->hash_size; - data_pair_t *pair = this->members[hashval]; - data_pair_t *prev = NULL; + data_pair_t *pair = this->members[hashval]; + data_pair_t *prev = NULL; - while (pair) { - if ((hash == pair->key_hash) && strcmp (pair->key, key) == 0) { - if (prev) - prev->hash_next = pair->hash_next; - else - this->members[hashval] = pair->hash_next; + while (pair) { + if ((hash == pair->key_hash) && strcmp(pair->key, key) == 0) { + if (prev) + prev->hash_next = pair->hash_next; + else + this->members[hashval] = pair->hash_next; - data_unref (pair->value); + data_unref(pair->value); - if (pair->prev) - pair->prev->next = pair->next; - else - this->members_list = pair->next; + if (pair->prev) + pair->prev->next = pair->next; + else + this->members_list = pair->next; - if (pair->next) - pair->next->prev = pair->prev; + if (pair->next) + pair->next->prev = pair->prev; - GF_FREE (pair->key); - if (pair == &this->free_pair) { - this->free_pair_in_use = _gf_false; - } - else { - mem_put (pair); - } - this->count--; - break; - } - - prev = pair; - pair = pair->hash_next; + GF_FREE(pair->key); + if (pair == &this->free_pair) { + this->free_pair_in_use = _gf_false; + } else { + mem_put(pair); + } + this->count--; + break; } - UNLOCK (&this->lock); + prev = pair; + pair = pair->hash_next; + } - return; + UNLOCK(&this->lock); + + return; } void -dict_destroy (dict_t *this) +dict_destroy(dict_t *this) { - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - return; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + return; + } - data_pair_t *pair = this->members_list; - data_pair_t *prev = this->members_list; - glusterfs_ctx_t *ctx = NULL; - uint64_t current_max = 0; - uint32_t total_pairs = 0; + data_pair_t *pair = this->members_list; + data_pair_t *prev = this->members_list; + glusterfs_ctx_t *ctx = NULL; + uint64_t current_max = 0; + uint32_t total_pairs = 0; - LOCK_DESTROY (&this->lock); + LOCK_DESTROY(&this->lock); - while (prev) { - pair = pair->next; - data_unref (prev->value); - GF_FREE (prev->key); - if (prev != &this->free_pair) { - mem_put (prev); - } - total_pairs++; - prev = pair; + while (prev) { + pair = pair->next; + data_unref(prev->value); + GF_FREE(prev->key); + if (prev != &this->free_pair) { + mem_put(prev); } + total_pairs++; + prev = pair; + } - if (this->members != &this->members_internal) { - mem_put (this->members); - } + if (this->members != &this->members_internal) { + mem_put(this->members); + } - GF_FREE (this->extra_free); - free (this->extra_stdfree); + GF_FREE(this->extra_free); + free(this->extra_stdfree); - /* update 'ctx->stats.dict.details' using max_count */ - ctx = THIS->ctx; + /* update 'ctx->stats.dict.details' using max_count */ + ctx = THIS->ctx; - /* NOTE: below logic is not totaly race proof */ - /* thread0 and thread1 gets current_max as 10 */ - /* thread0 has 'this->max_count as 11 */ - /* thread1 has 'this->max_count as 20 */ - /* thread1 goes ahead and sets the max_dict_pairs to 20 */ - /* thread0 then goes and sets it to 11 */ - /* As it is for information purpose only, no functionality will be - broken by this, but a point to consider about ATOMIC macros. */ - current_max = GF_ATOMIC_GET (ctx->stats.max_dict_pairs); - if (current_max < this->max_count) - GF_ATOMIC_INIT (ctx->stats.max_dict_pairs, this->max_count); + /* NOTE: below logic is not totaly race proof */ + /* thread0 and thread1 gets current_max as 10 */ + /* thread0 has 'this->max_count as 11 */ + /* thread1 has 'this->max_count as 20 */ + /* thread1 goes ahead and sets the max_dict_pairs to 20 */ + /* thread0 then goes and sets it to 11 */ + /* As it is for information purpose only, no functionality will be + broken by this, but a point to consider about ATOMIC macros. */ + current_max = GF_ATOMIC_GET(ctx->stats.max_dict_pairs); + if (current_max < this->max_count) + GF_ATOMIC_INIT(ctx->stats.max_dict_pairs, this->max_count); - GF_ATOMIC_ADD (ctx->stats.total_pairs_used, total_pairs); - GF_ATOMIC_INC (ctx->stats.total_dicts_used); + GF_ATOMIC_ADD(ctx->stats.total_pairs_used, total_pairs); + GF_ATOMIC_INC(ctx->stats.total_dicts_used); - mem_put (this); + mem_put(this); - return; + return; } void -dict_unref (dict_t *this) +dict_unref(dict_t *this) { - uint64_t ref = 0; + uint64_t ref = 0; - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - return; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + return; + } - ref = GF_ATOMIC_DEC (this->refcount); + ref = GF_ATOMIC_DEC(this->refcount); - if (!ref) - dict_destroy (this); + if (!ref) + dict_destroy(this); } dict_t * -dict_ref (dict_t *this) +dict_ref(dict_t *this) { - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - return NULL; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + return NULL; + } - GF_ATOMIC_INC (this->refcount); - return this; + GF_ATOMIC_INC(this->refcount); + return this; } void -data_unref (data_t *this) +data_unref(data_t *this) { + int32_t ref; - int32_t ref; - - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "data is NULL"); - return; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "data is NULL"); + return; + } - ref = GF_ATOMIC_DEC (this->refcount); + ref = GF_ATOMIC_DEC(this->refcount); - if (!ref) - data_destroy (this); + if (!ref) + data_destroy(this); } data_t * -data_ref (data_t *this) +data_ref(data_t *this) { - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "data is NULL"); - return NULL; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "data is NULL"); + return NULL; + } - GF_ATOMIC_INC (this->refcount); + GF_ATOMIC_INC(this->refcount); - return this; + return this; } data_t * -int_to_data (int64_t value) +int_to_data(int64_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } + if (!data) { + return NULL; + } - data->len = gf_asprintf (&data->data, "%"PRId64, value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_INT; + data->len = gf_asprintf(&data->data, "%" PRId64, value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_INT; - return data; + return data; } data_t * -data_from_int64 (int64_t value) +data_from_int64(int64_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%"PRId64, value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_INT; + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%" PRId64, value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_INT; - return data; + return data; } data_t * -data_from_int32 (int32_t value) +data_from_int32(int32_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%"PRId32, value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%" PRId32, value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_INT; + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_INT; - return data; + return data; } data_t * -data_from_int16 (int16_t value) +data_from_int16(int16_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%"PRId16, value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%" PRId16, value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_INT; + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_INT; - return data; + return data; } data_t * -data_from_int8 (int8_t value) +data_from_int8(int8_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%d", value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%d", value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_INT; + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_INT; - return data; + return data; } data_t * -data_from_uint64 (uint64_t value) +data_from_uint64(uint64_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%"PRIu64, value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%" PRIu64, value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_UINT; + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_UINT; - return data; + return data; } data_t * -data_from_double (double value) +data_from_double(double value) { - data_t *data = NULL; + data_t *data = NULL; - data = get_new_data (); + data = get_new_data(); - if (!data) { - return NULL; - } + if (!data) { + return NULL; + } - data->len = gf_asprintf (&data->data, "%f", value); - if (data->len == -1) { - return NULL; - } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_DOUBLE; + data->len = gf_asprintf(&data->data, "%f", value); + if (data->len == -1) { + return NULL; + } + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_DOUBLE; - return data; + return data; } - data_t * -data_from_uint32 (uint32_t value) +data_from_uint32(uint32_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%"PRIu32, value); - if (-1 == data->len) { - gf_msg_debug ("dict", 0, "asprintf failed"); - return NULL; - } + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%" PRIu32, value); + if (-1 == data->len) { + gf_msg_debug("dict", 0, "asprintf failed"); + return NULL; + } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_UINT; + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_UINT; - return data; + return data; } - data_t * -data_from_uint16 (uint16_t value) +data_from_uint16(uint16_t value) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = gf_asprintf (&data->data, "%"PRIu16, value); - if (-1 == data->len) { - return NULL; - } + if (!data) { + return NULL; + } + data->len = gf_asprintf(&data->data, "%" PRIu16, value); + if (-1 == data->len) { + return NULL; + } - data->len++; /* account for terminating NULL */ - data->data_type = GF_DATA_TYPE_UINT; + data->len++; /* account for terminating NULL */ + data->data_type = GF_DATA_TYPE_UINT; - return data; + return data; } static data_t * -data_from_ptr_common (void *value, gf_boolean_t is_static) +data_from_ptr_common(void *value, gf_boolean_t is_static) { - /* it is valid to set 0/NULL as a value, no need to check *value */ + /* it is valid to set 0/NULL as a value, no need to check *value */ - data_t *data = get_new_data (); - if (!data) { - return NULL; - } + data_t *data = get_new_data(); + if (!data) { + return NULL; + } - data->data = value; - data->len = 0; - data->is_static = is_static; + data->data = value; + data->len = 0; + data->is_static = is_static; - data->data_type = GF_DATA_TYPE_PTR; - return data; + data->data_type = GF_DATA_TYPE_PTR; + return data; } data_t * -str_to_data (char *value) +str_to_data(char *value) { - if (!value) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "value is NULL"); - return NULL; - } + if (!value) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "value is NULL"); + return NULL; + } - return strn_to_data(value, strlen (value)); + return strn_to_data(value, strlen(value)); } data_t * -strn_to_data (char *value, const int vallen) +strn_to_data(char *value, const int vallen) { - if (!value) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "value is NULL"); - return NULL; - } - data_t *data = get_new_data (); + if (!value) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "value is NULL"); + return NULL; + } + data_t *data = get_new_data(); - if (!data) { - return NULL; - } - data->len = vallen + 1; - data->data_type = GF_DATA_TYPE_STR; + if (!data) { + return NULL; + } + data->len = vallen + 1; + data->data_type = GF_DATA_TYPE_STR; - data->data = value; - data->is_static = _gf_true; + data->data = value; + data->is_static = _gf_true; - return data; + return data; } static data_t * -data_from_dynstr (char *value) +data_from_dynstr(char *value) { - if (!value) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "value is NULL"); - return NULL; - } + if (!value) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "value is NULL"); + return NULL; + } - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) - return NULL; - data->len = strlen (value) + 1; - data->data = value; - data->data_type = GF_DATA_TYPE_STR; + if (!data) + return NULL; + data->len = strlen(value) + 1; + data->data = value; + data->data_type = GF_DATA_TYPE_STR; - return data; + return data; } data_t * -data_from_dynptr (void *value, int32_t len) +data_from_dynptr(void *value, int32_t len) { - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) - return NULL; + if (!data) + return NULL; - data->len = len; - data->data = value; - data->data_type = GF_DATA_TYPE_PTR; + data->len = len; + data->data = value; + data->data_type = GF_DATA_TYPE_PTR; - return data; + return data; } data_t * -bin_to_data (void *value, int32_t len) +bin_to_data(void *value, int32_t len) { - if (!value) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "value is NULL"); - return NULL; - } + if (!value) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "value is NULL"); + return NULL; + } - data_t *data = get_new_data (); + data_t *data = get_new_data(); - if (!data) - return NULL; + if (!data) + return NULL; - data->is_static = _gf_true; - data->len = len; - data->data = value; + data->is_static = _gf_true; + data->len = len; + data->data = value; - return data; + return data; } static char *data_type_name[GF_DATA_TYPE_MAX] = { - [GF_DATA_TYPE_UNKNOWN] = "unknown", - [GF_DATA_TYPE_STR_OLD] = "string-old-version", - [GF_DATA_TYPE_INT] = "integer", - [GF_DATA_TYPE_UINT] = "unsigned integer", - [GF_DATA_TYPE_DOUBLE] = "float", - [GF_DATA_TYPE_STR] = "string", - [GF_DATA_TYPE_PTR] = "pointer", - [GF_DATA_TYPE_GFUUID] = "gf-uuid", - [GF_DATA_TYPE_IATT] = "iatt", + [GF_DATA_TYPE_UNKNOWN] = "unknown", + [GF_DATA_TYPE_STR_OLD] = "string-old-version", + [GF_DATA_TYPE_INT] = "integer", + [GF_DATA_TYPE_UINT] = "unsigned integer", + [GF_DATA_TYPE_DOUBLE] = "float", + [GF_DATA_TYPE_STR] = "string", + [GF_DATA_TYPE_PTR] = "pointer", + [GF_DATA_TYPE_GFUUID] = "gf-uuid", + [GF_DATA_TYPE_IATT] = "iatt", }; int64_t -data_to_int64 (data_t *data) +data_to_int64(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); - return (int64_t) strtoull (data->data, NULL, 0); + return (int64_t)strtoull(data->data, NULL, 0); } int32_t -data_to_int32 (data_t *data) +data_to_int32(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); - return strtoul (data->data, NULL, 0); + return strtoul(data->data, NULL, 0); } int16_t -data_to_int16 (data_t *data) +data_to_int16(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); - int16_t value = 0; + int16_t value = 0; - errno = 0; - value = strtol (data->data, NULL, 0); + errno = 0; + value = strtol(data->data, NULL, 0); - if ((value > SHRT_MAX) || (value < SHRT_MIN)) { - errno = ERANGE; - gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, - LG_MSG_DATA_CONVERSION_ERROR, "Error in data" - " conversion: detected overflow"); - return -1; - } + if ((value > SHRT_MAX) || (value < SHRT_MIN)) { + errno = ERANGE; + gf_msg_callingfn("dict", GF_LOG_WARNING, errno, + LG_MSG_DATA_CONVERSION_ERROR, + "Error in data" + " conversion: detected overflow"); + return -1; + } - return (int16_t)value; + return (int16_t)value; } - int8_t -data_to_int8 (data_t *data) +data_to_int8(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, "null", -1); - int8_t value = 0; + int8_t value = 0; - errno = 0; - value = strtol (data->data, NULL, 0); + errno = 0; + value = strtol(data->data, NULL, 0); - if ((value > SCHAR_MAX) || (value < SCHAR_MIN)) { - errno = ERANGE; - gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, - LG_MSG_DATA_CONVERSION_ERROR, "Error in data" - " conversion: detected overflow"); - return -1; - } + if ((value > SCHAR_MAX) || (value < SCHAR_MIN)) { + errno = ERANGE; + gf_msg_callingfn("dict", GF_LOG_WARNING, errno, + LG_MSG_DATA_CONVERSION_ERROR, + "Error in data" + " conversion: detected overflow"); + return -1; + } - return (int8_t)value; + return (int8_t)value; } - uint64_t -data_to_uint64 (data_t *data) +data_to_uint64(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); - return strtoll (data->data, NULL, 0); + return strtoll(data->data, NULL, 0); } uint32_t -data_to_uint32 (data_t *data) +data_to_uint32(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); - return strtol (data->data, NULL, 0); + return strtol(data->data, NULL, 0); } uint16_t -data_to_uint16 (data_t *data) +data_to_uint16(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); - uint16_t value = 0; + uint16_t value = 0; - errno = 0; - value = strtol (data->data, NULL, 0); + errno = 0; + value = strtol(data->data, NULL, 0); - if ((USHRT_MAX - value) < 0) { - errno = ERANGE; - gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, - LG_MSG_DATA_CONVERSION_ERROR, - "Error in data conversion: " - "overflow detected"); - return -1; - } + if ((USHRT_MAX - value) < 0) { + errno = ERANGE; + gf_msg_callingfn("dict", GF_LOG_WARNING, errno, + LG_MSG_DATA_CONVERSION_ERROR, + "Error in data conversion: " + "overflow detected"); + return -1; + } - return (uint16_t)value; + return (uint16_t)value; } uint8_t -data_to_uint8 (data_t *data) +data_to_uint8(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, "null", -1); - uint32_t value = 0; + uint32_t value = 0; - errno = 0; - value = strtol (data->data, NULL, 0); + errno = 0; + value = strtol(data->data, NULL, 0); - if ((UCHAR_MAX - (uint8_t)value) < 0) { - errno = ERANGE; - gf_msg_callingfn ("dict", GF_LOG_WARNING, errno, - LG_MSG_DATA_CONVERSION_ERROR, "data " - "conversion overflow detected"); - return -1; - } + if ((UCHAR_MAX - (uint8_t)value) < 0) { + errno = ERANGE; + gf_msg_callingfn("dict", GF_LOG_WARNING, errno, + LG_MSG_DATA_CONVERSION_ERROR, + "data " + "conversion overflow detected"); + return -1; + } - return (uint8_t) value; + return (uint8_t)value; } char * -data_to_str (data_t *data) +data_to_str(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_STR, "null", NULL); - return data->data; + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_STR, "null", NULL); + return data->data; } void * -data_to_ptr (data_t *data) +data_to_ptr(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, "null", NULL); - return data->data; + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, "null", NULL); + return data->data; } void * -data_to_bin (data_t *data) +data_to_bin(data_t *data) { - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, "null", NULL); - return data->data; + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, "null", NULL); + return data->data; } struct iatt * -data_to_iatt (data_t *data, char *key) -{ - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_IATT, key, NULL); - - /* We only check for smaller size. If it's bigger we simply ignore - * the extra data. This way it's easy to do changes in the future that - * pass more data but are backward compatible (if the initial contents - * of the struct are maintained, of course). */ - if (data->len < sizeof(struct iatt)) { - gf_msg("glusterfs", GF_LOG_ERROR, ENOBUFS, - LG_MSG_UNDERSIZED_BUF, - "data value for '%s' is smaller than expected", key); - return NULL; - } +data_to_iatt(data_t *data, char *key) +{ + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_IATT, key, NULL); - return (struct iatt *)data->data; + /* We only check for smaller size. If it's bigger we simply ignore + * the extra data. This way it's easy to do changes in the future that + * pass more data but are backward compatible (if the initial contents + * of the struct are maintained, of course). */ + if (data->len < sizeof(struct iatt)) { + gf_msg("glusterfs", GF_LOG_ERROR, ENOBUFS, LG_MSG_UNDERSIZED_BUF, + "data value for '%s' is smaller than expected", key); + return NULL; + } + + return (struct iatt *)data->data; } int -dict_null_foreach_fn (dict_t *d, char *k, - data_t *v, void *tmp) +dict_null_foreach_fn(dict_t *d, char *k, data_t *v, void *tmp) { - return 0; + return 0; } int -dict_remove_foreach_fn (dict_t *d, char *k, - data_t *v, void *_tmp) -{ - if (!d || !k) { - gf_msg ("glusterfs", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ENTRY, "%s is NULL", - d?"key":"dictionary"); - return -1; - } +dict_remove_foreach_fn(dict_t *d, char *k, data_t *v, void *_tmp) +{ + if (!d || !k) { + gf_msg("glusterfs", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ENTRY, + "%s is NULL", d ? "key" : "dictionary"); + return -1; + } - dict_del (d, k); - return 0; + dict_del(d, k); + return 0; } gf_boolean_t -dict_match_everything (dict_t *d, char *k, data_t *v, void *data) +dict_match_everything(dict_t *d, char *k, data_t *v, void *data) { - return _gf_true; + return _gf_true; } int -dict_foreach (dict_t *dict, - int (*fn)(dict_t *this, - char *key, - data_t *value, - void *data), - void *data) +dict_foreach(dict_t *dict, + int (*fn)(dict_t *this, char *key, data_t *value, void *data), + void *data) { - int ret = 0; + int ret = 0; - ret = dict_foreach_match (dict, dict_match_everything, NULL, fn, data); + ret = dict_foreach_match(dict, dict_match_everything, NULL, fn, data); - if (ret > 0) - ret = 0; + if (ret > 0) + ret = 0; - return ret; + return ret; } /* return values: @@ -1330,50 +1301,45 @@ dict_foreach (dict_t *dict, +n = n number of matches */ int -dict_foreach_match (dict_t *dict, - gf_boolean_t (*match)(dict_t *this, - char *key, - data_t *value, - void *mdata), - void *match_data, - int (*action)(dict_t *this, - char *key, - data_t *value, - void *adata), - void *action_data) -{ - if (!dict || !match || !action) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict|match|action is " - "NULL"); - return -1; - } - - int ret = -1; - int count = 0; - data_pair_t *pairs = NULL; - data_pair_t *next = NULL; - - pairs = dict->members_list; - while (pairs) { - next = pairs->next; - if (match (dict, pairs->key, pairs->value, match_data)) { - ret = action (dict, pairs->key, pairs->value, - action_data); - if (ret < 0) - return ret; - count++; - } - pairs = next; +dict_foreach_match(dict_t *dict, + gf_boolean_t (*match)(dict_t *this, char *key, data_t *value, + void *mdata), + void *match_data, + int (*action)(dict_t *this, char *key, data_t *value, + void *adata), + void *action_data) +{ + if (!dict || !match || !action) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict|match|action is " + "NULL"); + return -1; + } + + int ret = -1; + int count = 0; + data_pair_t *pairs = NULL; + data_pair_t *next = NULL; + + pairs = dict->members_list; + while (pairs) { + next = pairs->next; + if (match(dict, pairs->key, pairs->value, match_data)) { + ret = action(dict, pairs->key, pairs->value, action_data); + if (ret < 0) + return ret; + count++; } + pairs = next; + } - return count; + return count; } static gf_boolean_t -dict_fnmatch (dict_t *d, char *k, data_t *val, void *match_data) +dict_fnmatch(dict_t *d, char *k, data_t *val, void *match_data) { - return (fnmatch (match_data, k, 0) == 0); + return (fnmatch(match_data, k, 0) == 0); } /* return values: -1 = failure, @@ -1381,17 +1347,14 @@ dict_fnmatch (dict_t *d, char *k, data_t *val, void *match_data) +n = n number of matches */ int -dict_foreach_fnmatch (dict_t *dict, char *pattern, - int (*fn)(dict_t *this, - char *key, - data_t *value, - void *data), - void *data) +dict_foreach_fnmatch(dict_t *dict, char *pattern, + int (*fn)(dict_t *this, char *key, data_t *value, + void *data), + void *data) { - return dict_foreach_match (dict, dict_fnmatch, pattern, fn, data); + return dict_foreach_match(dict, dict_fnmatch, pattern, fn, data); } - /** * dict_keys_join - pack the keys of the dictionary in a buffer. * @@ -1406,89 +1369,86 @@ dict_foreach_fnmatch (dict_t *dict, char *pattern, */ int -dict_keys_join (void *value, int size, dict_t *dict, - int (*filter_fn)(char *k)) +dict_keys_join(void *value, int size, dict_t *dict, int (*filter_fn)(char *k)) { - int len = 0; - data_pair_t *pairs = NULL; - data_pair_t *next = NULL; + int len = 0; + data_pair_t *pairs = NULL; + data_pair_t *next = NULL; - pairs = dict->members_list; - while (pairs) { - next = pairs->next; + pairs = dict->members_list; + while (pairs) { + next = pairs->next; - if (filter_fn && filter_fn (pairs->key)){ - pairs = next; - continue; - } + if (filter_fn && filter_fn(pairs->key)) { + pairs = next; + continue; + } - if (value && (size > len)) - strncpy (value + len, pairs->key, size - len); + if (value && (size > len)) + strncpy(value + len, pairs->key, size - len); - len += (strlen (pairs->key) + 1); + len += (strlen(pairs->key) + 1); - pairs = next; - } + pairs = next; + } - return len; + return len; } static int -dict_copy_one (dict_t *unused, char *key, data_t *value, void *newdict) +dict_copy_one(dict_t *unused, char *key, data_t *value, void *newdict) { - return dict_set ((dict_t *)newdict, key, (value)); + return dict_set((dict_t *)newdict, key, (value)); } dict_t * -dict_copy (dict_t *dict, - dict_t *new) +dict_copy(dict_t *dict, dict_t *new) { - if (!dict) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - return NULL; - } + if (!dict) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + return NULL; + } - if (!new) - new = get_new_dict_full (dict->hash_size); + if (!new) + new = get_new_dict_full(dict->hash_size); - dict_foreach (dict, dict_copy_one, new); + dict_foreach(dict, dict_copy_one, new); - return new; + return new; } int -dict_reset (dict_t *dict) -{ - int32_t ret = -1; - if (!dict) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - goto out; - } - dict_foreach (dict, dict_remove_foreach_fn, NULL); - ret = 0; +dict_reset(dict_t *dict) +{ + int32_t ret = -1; + if (!dict) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + goto out; + } + dict_foreach(dict, dict_remove_foreach_fn, NULL); + ret = 0; out: - return ret; + return ret; } dict_t * -dict_copy_with_ref (dict_t *dict, - dict_t *new) +dict_copy_with_ref(dict_t *dict, dict_t *new) { - dict_t *local_new = NULL; + dict_t *local_new = NULL; - GF_VALIDATE_OR_GOTO("dict", dict, fail); + GF_VALIDATE_OR_GOTO("dict", dict, fail); - if (new == NULL) { - local_new = dict_new (); - GF_VALIDATE_OR_GOTO("dict", local_new, fail); - new = local_new; - } + if (new == NULL) { + local_new = dict_new(); + GF_VALIDATE_OR_GOTO("dict", local_new, fail); + new = local_new; + } - dict_foreach (dict, dict_copy_one, new); + dict_foreach(dict, dict_copy_one, new); fail: - return new; + return new; } /* @@ -1502,592 +1462,581 @@ fail: * -val error, val = errno */ - int -dict_get_with_ref (dict_t *this, char *key, data_t **data) +dict_get_with_ref(dict_t *this, char *key, data_t **data) { - if (!this || !key || !data) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "dict OR key (%s) is NULL", key); - return -EINVAL; - } + if (!this || !key || !data) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict OR key (%s) is NULL", key); + return -EINVAL; + } - return dict_get_with_refn(this, key, strlen (key), data); + return dict_get_with_refn(this, key, strlen(key), data); } int -dict_get_with_refn (dict_t *this, char *key, const int keylen, data_t **data) +dict_get_with_refn(dict_t *this, char *key, const int keylen, data_t **data) { - data_pair_t * pair = NULL; - int ret = -ENOENT; - uint32_t hash; + data_pair_t *pair = NULL; + int ret = -ENOENT; + uint32_t hash; - if (!this || !key || !data) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "dict OR key (%s) is NULL", key); - ret = -EINVAL; - goto err; - } + if (!this || !key || !data) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict OR key (%s) is NULL", key); + ret = -EINVAL; + goto err; + } - hash = SuperFastHash (key, keylen); + hash = SuperFastHash(key, keylen); - LOCK (&this->lock); - { - pair = dict_lookup_common (this, key, hash); + LOCK(&this->lock); + { + pair = dict_lookup_common(this, key, hash); - if (pair) { - ret = 0; - *data = data_ref (pair->value); - } + if (pair) { + ret = 0; + *data = data_ref(pair->value); } - UNLOCK (&this->lock); + } + UNLOCK(&this->lock); err: - return ret; + return ret; } static int -data_to_ptr_common (data_t *data, void **val) +data_to_ptr_common(data_t *data, void **val) { - int ret = 0; + int ret = 0; - if (!data) { - ret = -EINVAL; - goto err; - } + if (!data) { + ret = -EINVAL; + goto err; + } - *val = data->data; + *val = data->data; err: - return ret; + return ret; } - static int -data_to_int8_ptr (data_t *data, int8_t *val) +data_to_int8_ptr(data_t *data, int8_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtol (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtol(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_int16_ptr (data_t *data, int16_t *val) +data_to_int16_ptr(data_t *data, int16_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtol (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtol(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_int32_ptr (data_t *data, int32_t *val) +data_to_int32_ptr(data_t *data, int32_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtol (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtol(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_int64_ptr (data_t *data, int64_t *val) +data_to_int64_ptr(data_t *data, int64_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtoll (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtoll(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_uint16_ptr (data_t *data, uint16_t *val) +data_to_uint16_ptr(data_t *data, uint16_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtoul (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtoul(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_uint32_ptr (data_t *data, uint32_t *val) +data_to_uint32_ptr(data_t *data, uint32_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtoul (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtoul(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_uint64_ptr (data_t *data, uint64_t *val) +data_to_uint64_ptr(data_t *data, uint64_t *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtoull (data->data, NULL, 0); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtoull(data->data, NULL, 0); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } static int -data_to_double_ptr (data_t *data, double *val) +data_to_double_ptr(data_t *data, double *val) { - int ret = 0; + int ret = 0; - if (!data || !val) { - ret = -EINVAL; - goto err; - } + if (!data || !val) { + ret = -EINVAL; + goto err; + } - errno = 0; - *val = strtod (data->data, NULL); - if (errno != 0) - ret = -errno; + errno = 0; + *val = strtod(data->data, NULL); + if (errno != 0) + ret = -errno; err: - return ret; + return ret; } int -dict_get_int8 (dict_t *this, char *key, int8_t *val) +dict_get_int8(dict_t *this, char *key, int8_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = data_to_int8_ptr (data, val); + ret = data_to_int8_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } - int -dict_set_int8 (dict_t *this, char *key, int8_t val) +dict_set_int8(dict_t *this, char *key, int8_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_int8 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_int8(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_int16 (dict_t *this, char *key, int16_t *val) +dict_get_int16(dict_t *this, char *key, int16_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = data_to_int16_ptr (data, val); + ret = data_to_int16_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } - int -dict_set_int16 (dict_t *this, char *key, int16_t val) +dict_set_int16(dict_t *this, char *key, int16_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_int16 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_int16(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_int32n (dict_t *this, char *key, const int keylen, int32_t *val) +dict_get_int32n(dict_t *this, char *key, const int keylen, int32_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_refn (this, key, keylen, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_refn(this, key, keylen, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = data_to_int32_ptr (data, val); + ret = data_to_int32_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } int -dict_get_int32 (dict_t *this, char *key, int32_t *val) +dict_get_int32(dict_t *this, char *key, int32_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = data_to_int32_ptr (data, val); + ret = data_to_int32_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } int -dict_set_int32n (dict_t *this, char *key, const int keylen, int32_t val) +dict_set_int32n(dict_t *this, char *key, const int keylen, int32_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_int32 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_int32(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_setn (this, key, keylen, data); - if (ret < 0) - data_destroy (data); + ret = dict_setn(this, key, keylen, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_set_int32 (dict_t *this, char *key, int32_t val) +dict_set_int32(dict_t *this, char *key, int32_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_int32 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_int32(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_int64 (dict_t *this, char *key, int64_t *val) +dict_get_int64(dict_t *this, char *key, int64_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = data_to_int64_ptr (data, val); + ret = data_to_int64_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } - int -dict_set_int64 (dict_t *this, char *key, int64_t val) +dict_set_int64(dict_t *this, char *key, int64_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_int64 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_int64(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_uint16 (dict_t *this, char *key, uint16_t *val) +dict_get_uint16(dict_t *this, char *key, uint16_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, key, -EINVAL); - ret = data_to_uint16_ptr (data, val); + ret = data_to_uint16_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } - int -dict_set_uint16 (dict_t *this, char *key, uint16_t val) +dict_set_uint16(dict_t *this, char *key, uint16_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_uint16 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_uint16(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_uint32 (dict_t *this, char *key, uint32_t *val) +dict_get_uint32(dict_t *this, char *key, uint32_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, key, -EINVAL); - ret = data_to_uint32_ptr (data, val); + ret = data_to_uint32_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } - - int -dict_set_uint32 (dict_t *this, char *key, uint32_t val) +dict_set_uint32(dict_t *this, char *key, uint32_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_uint32 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_uint32(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_uint64 (dict_t *this, char *key, uint64_t *val) +dict_get_uint64(dict_t *this, char *key, uint64_t *val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_UINT, key, -EINVAL); - ret = data_to_uint64_ptr (data, val); + ret = data_to_uint64_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } - int -dict_set_uint64 (dict_t *this, char *key, uint64_t val) +dict_set_uint64(dict_t *this, char *key, uint64_t val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_uint64 (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_uint64(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } /* @@ -2100,23 +2049,23 @@ err: * <0: Error */ int -dict_check_flag (dict_t *this, char *key, int flag) +dict_check_flag(dict_t *this, char *key, int flag) { - data_t *data = NULL; - int ret = -ENOENT; + data_t *data = NULL; + int ret = -ENOENT; - ret = dict_get_with_ref (this, key, &data); - if (ret < 0) { - return ret; - } + ret = dict_get_with_ref(this, key, &data); + if (ret < 0) { + return ret; + } - if (BIT_VALUE((unsigned char *)(data->data), flag)) - ret = 1; - else - ret = 0; + if (BIT_VALUE((unsigned char *)(data->data), flag)) + ret = 1; + else + ret = 0; - data_unref(data); - return ret; + data_unref(data); + return ret; } /* @@ -2125,138 +2074,128 @@ dict_check_flag (dict_t *this, char *key, int flag) * op: Indicates operation DICT_FLAG_SET / DICT_FLAG_CLEAR */ static int -_dict_modify_flag (dict_t *this, char *key, int flag, int op) -{ - data_t *data = NULL; - int ret = 0; - data_pair_t *pair = NULL; - char *ptr = NULL; - int hashval = 0; - uint32_t hash; - - if (!this || !key) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "dict OR key (%s) is NULL", key); - ret = -EINVAL; - goto err; - } - - /* - * Using a size of 32 bytes to support max of 256 - * flags in a single key. This should be suffcient. - */ - GF_ASSERT(flag >= 0 && flag < DICT_MAX_FLAGS); - - hash = SuperFastHash (key, strlen (key)); - LOCK (&this->lock); - { - pair = dict_lookup_common (this, key, hash); - - if (pair) { - data = pair->value; - if (op == DICT_FLAG_SET) - BIT_SET((unsigned char *)(data->data), flag); - else - BIT_CLEAR((unsigned char *)(data->data), flag); - } else { - ptr = GF_CALLOC(1, DICT_MAX_FLAGS / 8, - gf_common_mt_char); - if (!ptr) { - gf_msg("dict", GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, - "unable to allocate flag bit array"); - ret = -ENOMEM; - goto err; - } +_dict_modify_flag(dict_t *this, char *key, int flag, int op) +{ + data_t *data = NULL; + int ret = 0; + data_pair_t *pair = NULL; + char *ptr = NULL; + int hashval = 0; + uint32_t hash; + + if (!this || !key) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict OR key (%s) is NULL", key); + ret = -EINVAL; + goto err; + } + + /* + * Using a size of 32 bytes to support max of 256 + * flags in a single key. This should be suffcient. + */ + GF_ASSERT(flag >= 0 && flag < DICT_MAX_FLAGS); + + hash = SuperFastHash(key, strlen(key)); + LOCK(&this->lock); + { + pair = dict_lookup_common(this, key, hash); - data = data_from_dynptr(ptr, DICT_MAX_FLAGS / 8); - - if (!data) { - gf_msg("dict", GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, - "unable to allocate data"); - GF_FREE(ptr); - ret = -ENOMEM; - goto err; - } - - if (op == DICT_FLAG_SET) - BIT_SET((unsigned char *)(data->data), flag); - else - BIT_CLEAR((unsigned char *)(data->data), flag); - - if (this->free_pair_in_use) { - pair = mem_get0 (THIS->ctx->dict_pair_pool); - if (!pair) { - gf_msg("dict", GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, - "unable to allocate dict pair"); - ret = -ENOMEM; - goto err; - } - } else { - pair = &this->free_pair; - this->free_pair_in_use = _gf_true; - } - - pair->key = (char *)GF_MALLOC(strlen (key) + 1, - gf_common_mt_char); - if (!pair->key) { - gf_msg("dict", GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, - "unable to allocate dict pair"); - ret = -ENOMEM; - goto err; - } - strcpy (pair->key, key); - pair->key_hash = hash; - pair->value = data_ref (data); + if (pair) { + data = pair->value; + if (op == DICT_FLAG_SET) + BIT_SET((unsigned char *)(data->data), flag); + else + BIT_CLEAR((unsigned char *)(data->data), flag); + } else { + ptr = GF_CALLOC(1, DICT_MAX_FLAGS / 8, gf_common_mt_char); + if (!ptr) { + gf_msg("dict", GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "unable to allocate flag bit array"); + ret = -ENOMEM; + goto err; + } - hashval = hash % this->hash_size; - pair->hash_next = this->members[hashval]; - this->members[hashval] = pair; + data = data_from_dynptr(ptr, DICT_MAX_FLAGS / 8); - pair->next = this->members_list; - pair->prev = NULL; - if (this->members_list) - this->members_list->prev = pair; - this->members_list = pair; - this->count++; + if (!data) { + gf_msg("dict", GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "unable to allocate data"); + GF_FREE(ptr); + ret = -ENOMEM; + goto err; + } + if (op == DICT_FLAG_SET) + BIT_SET((unsigned char *)(data->data), flag); + else + BIT_CLEAR((unsigned char *)(data->data), flag); - if (this->max_count < this->count) - this->max_count = this->count; + if (this->free_pair_in_use) { + pair = mem_get0(THIS->ctx->dict_pair_pool); + if (!pair) { + gf_msg("dict", GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "unable to allocate dict pair"); + ret = -ENOMEM; + goto err; } + } else { + pair = &this->free_pair; + this->free_pair_in_use = _gf_true; + } + + pair->key = (char *)GF_MALLOC(strlen(key) + 1, gf_common_mt_char); + if (!pair->key) { + gf_msg("dict", GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "unable to allocate dict pair"); + ret = -ENOMEM; + goto err; + } + strcpy(pair->key, key); + pair->key_hash = hash; + pair->value = data_ref(data); + + hashval = hash % this->hash_size; + pair->hash_next = this->members[hashval]; + this->members[hashval] = pair; + + pair->next = this->members_list; + pair->prev = NULL; + if (this->members_list) + this->members_list->prev = pair; + this->members_list = pair; + this->count++; + + if (this->max_count < this->count) + this->max_count = this->count; } + } - UNLOCK (&this->lock); - return 0; + UNLOCK(&this->lock); + return 0; err: - if (key && this) - UNLOCK (&this->lock); + if (key && this) + UNLOCK(&this->lock); - if (pair) { - if (pair->key) - free(pair->key); + if (pair) { + if (pair->key) + free(pair->key); - if (pair == &this->free_pair) { - this->free_pair_in_use = _gf_false; - } else { - mem_put (pair); - } + if (pair == &this->free_pair) { + this->free_pair_in_use = _gf_false; + } else { + mem_put(pair); } + } - if (data) - data_destroy(data); - + if (data) + data_destroy(data); - gf_msg("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_DICT_SET_FAILED, - "unable to set key (%s) in dict ", key); + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_DICT_SET_FAILED, + "unable to set key (%s) in dict ", key); - return ret; + return ret; } /* @@ -2269,396 +2208,395 @@ err: */ int -dict_set_flag (dict_t *this, char *key, int flag) +dict_set_flag(dict_t *this, char *key, int flag) { - return _dict_modify_flag (this, key, flag, DICT_FLAG_SET); + return _dict_modify_flag(this, key, flag, DICT_FLAG_SET); } int -dict_clear_flag (dict_t *this, char *key, int flag) +dict_clear_flag(dict_t *this, char *key, int flag) { - return _dict_modify_flag (this, key, flag, DICT_FLAG_CLEAR); + return _dict_modify_flag(this, key, flag, DICT_FLAG_CLEAR); } - int -dict_get_double (dict_t *this, char *key, double *val) +dict_get_double(dict_t *this, char *key, double *val) { - data_t *data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !val) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !val) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_DOUBLE, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_DOUBLE, key, -EINVAL); - ret = data_to_double_ptr (data, val); + ret = data_to_double_ptr(data, val); err: - if (data) - data_unref (data); - return ret; + if (data) + data_unref(data); + return ret; } int -dict_set_double (dict_t *this, char *key, double val) +dict_set_double(dict_t *this, char *key, double val) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_double (val); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_double(val); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_set_static_ptr (dict_t *this, char *key, void *ptr) +dict_set_static_ptr(dict_t *this, char *key, void *ptr) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_ptr_common (ptr, _gf_true); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_ptr_common(ptr, _gf_true); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_set_dynptr (dict_t *this, char *key, void *ptr, size_t len) +dict_set_dynptr(dict_t *this, char *key, void *ptr, size_t len) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_dynptr (ptr, len); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_dynptr(ptr, len); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_get_ptr (dict_t *this, char *key, void **ptr) +dict_get_ptr(dict_t *this, char *key, void **ptr) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !ptr) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !ptr) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, -EINVAL); - ret = data_to_ptr_common (data, ptr); - if (ret != 0) { - goto err; - } + ret = data_to_ptr_common(data, ptr); + if (ret != 0) { + goto err; + } err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } int -dict_get_ptr_and_len (dict_t *this, char *key, void **ptr, int *len) +dict_get_ptr_and_len(dict_t *this, char *key, void **ptr, int *len) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!this || !key || !ptr) { - ret = -EINVAL; - goto err; - } + if (!this || !key || !ptr) { + ret = -EINVAL; + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret != 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret != 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, -EINVAL); - *len = data->len; + *len = data->len; - ret = data_to_ptr_common (data, ptr); - if (ret != 0) { - goto err; - } + ret = data_to_ptr_common(data, ptr); + if (ret != 0) { + goto err; + } err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } /* Get string - with known key length */ int -dict_get_strn (dict_t *this, char *key, const int keylen, char **str) +dict_get_strn(dict_t *this, char *key, const int keylen, char **str) { - data_t * data = NULL; - int ret = -EINVAL; + data_t *data = NULL; + int ret = -EINVAL; - if (!this || !key || !str) { - goto err; - } - ret = dict_get_with_refn (this, key, keylen, &data); - if (ret < 0) { - goto err; - } + if (!this || !key || !str) { + goto err; + } + ret = dict_get_with_refn(this, key, keylen, &data); + if (ret < 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_STR, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_STR, key, -EINVAL); - *str = data->data; + *str = data->data; err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } int -dict_get_str (dict_t *this, char *key, char **str) +dict_get_str(dict_t *this, char *key, char **str) { - data_t * data = NULL; - int ret = -EINVAL; + data_t *data = NULL; + int ret = -EINVAL; - if (!this || !key || !str) { - goto err; - } - ret = dict_get_with_ref (this, key, &data); - if (ret < 0) { - goto err; - } + if (!this || !key || !str) { + goto err; + } + ret = dict_get_with_ref(this, key, &data); + if (ret < 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_STR, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_STR, key, -EINVAL); - *str = data->data; + *str = data->data; err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } int -dict_set_str (dict_t *this, char *key, char *str) +dict_set_str(dict_t *this, char *key, char *str) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = str_to_data (str); - if (!data) { - ret = -EINVAL; - goto err; - } + data = str_to_data(str); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } /* Set string - with known key length */ int -dict_set_strn (dict_t *this, char *key, const int keylen, char *str) +dict_set_strn(dict_t *this, char *key, const int keylen, char *str) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = str_to_data (str); - if (!data) { - ret = -EINVAL; - goto err; - } + data = str_to_data(str); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_setn (this, key, keylen, data); - if (ret < 0) - data_destroy (data); + ret = dict_setn(this, key, keylen, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } /* Set string - with known key length and known value length */ int -dict_set_nstrn (dict_t *this, char *key, const int keylen, char *str, const int vallen) +dict_set_nstrn(dict_t *this, char *key, const int keylen, char *str, + const int vallen) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = strn_to_data (str, vallen); - if (!data) { - ret = -EINVAL; - goto err; - } + data = strn_to_data(str, vallen); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_setn (this, key, keylen, data); - if (ret < 0) - data_destroy (data); + ret = dict_setn(this, key, keylen, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_set_dynstr_with_alloc (dict_t *this, char *key, const char *str) +dict_set_dynstr_with_alloc(dict_t *this, char *key, const char *str) { - char *alloc_str = NULL; - int ret = -1; + char *alloc_str = NULL; + int ret = -1; - alloc_str = gf_strdup (str); - if (!alloc_str) - return -1; + alloc_str = gf_strdup(str); + if (!alloc_str) + return -1; - ret = dict_set_dynstr (this, key, alloc_str); - if (ret == -EINVAL) - GF_FREE (alloc_str); + ret = dict_set_dynstr(this, key, alloc_str); + if (ret == -EINVAL) + GF_FREE(alloc_str); - return ret; + return ret; } int -dict_set_dynstr (dict_t *this, char *key, char *str) +dict_set_dynstr(dict_t *this, char *key, char *str) { - const int keylen = strlen(key); - return dict_set_dynstrn(this, key, keylen, str); + const int keylen = strlen(key); + return dict_set_dynstrn(this, key, keylen, str); } int -dict_set_dynstrn (dict_t *this, char *key, const int keylen, char *str) +dict_set_dynstrn(dict_t *this, char *key, const int keylen, char *str) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_dynstr (str); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_dynstr(str); + if (!data) { + ret = -EINVAL; + goto err; + } - ret = dict_setn (this, key, keylen, data); - if (ret < 0) - data_destroy (data); + ret = dict_setn(this, key, keylen, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } /* This function is called only by the volgen for now. Check how else you can handle it */ int -dict_set_option (dict_t *this, char *key, char *str) +dict_set_option(dict_t *this, char *key, char *str) { - data_t *data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - data = data_from_dynstr (str); - if (!data) { - ret = -EINVAL; - goto err; - } + data = data_from_dynstr(str); + if (!data) { + ret = -EINVAL; + goto err; + } - data->data_type = GF_DATA_TYPE_STR_OLD; - ret = dict_set (this, key, data); - if (ret < 0) - data_destroy (data); + data->data_type = GF_DATA_TYPE_STR_OLD; + ret = dict_set(this, key, data); + if (ret < 0) + data_destroy(data); err: - return ret; + return ret; } int -dict_add_dynstr_with_alloc (dict_t *this, char *key, char *str) +dict_add_dynstr_with_alloc(dict_t *this, char *key, char *str) { - data_t *data = NULL; - int ret = 0; - char *alloc_str = NULL; + data_t *data = NULL; + int ret = 0; + char *alloc_str = NULL; - alloc_str = gf_strdup (str); - if (!alloc_str) - goto out; + alloc_str = gf_strdup(str); + if (!alloc_str) + goto out; - data = data_from_dynstr (alloc_str); - if (!data) { - GF_FREE (alloc_str); - ret = -EINVAL; - goto out; - } + data = data_from_dynstr(alloc_str); + if (!data) { + GF_FREE(alloc_str); + ret = -EINVAL; + goto out; + } - ret = dict_add (this, key, data); - if (ret < 0) - data_destroy (data); + ret = dict_add(this, key, data); + if (ret < 0) + data_destroy(data); out: - return ret; + return ret; } - int -dict_get_bin (dict_t *this, char *key, void **bin) +dict_get_bin(dict_t *this, char *key, void **bin) { - data_t * data = NULL; - int ret = -EINVAL; + data_t *data = NULL; + int ret = -EINVAL; - if (!this || !key || !bin) { - goto err; - } + if (!this || !key || !bin) { + goto err; + } - ret = dict_get_with_ref (this, key, &data); - if (ret < 0) { - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret < 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, ret); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, ret); - *bin = data->data; + *bin = data->data; err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } /******************************************************************** @@ -2671,35 +2609,35 @@ err: * *******************************************************************/ static int -dict_set_bin_common (dict_t *this, char *key, void *ptr, size_t size, - gf_boolean_t is_static, gf_dict_data_type_t type) +dict_set_bin_common(dict_t *this, char *key, void *ptr, size_t size, + gf_boolean_t is_static, gf_dict_data_type_t type) { - data_t * data = NULL; - int ret = 0; + data_t *data = NULL; + int ret = 0; - if (!ptr || (size > DICT_KEY_VALUE_MAX_SIZE)) { - ret = -EINVAL; - goto err; - } + if (!ptr || (size > DICT_KEY_VALUE_MAX_SIZE)) { + ret = -EINVAL; + goto err; + } - data = bin_to_data (ptr, size); - if (!data) { - ret = -EINVAL; - goto err; - } + data = bin_to_data(ptr, size); + if (!data) { + ret = -EINVAL; + goto err; + } - data->is_static = is_static; - data->data_type = type; + data->is_static = is_static; + data->data_type = type; - ret = dict_set (this, key, data); - if (ret < 0) { - /* don't free data->data, let callers handle it */ - data->data = NULL; - data_destroy (data); - } + ret = dict_set(this, key, data); + if (ret < 0) { + /* don't free data->data, let callers handle it */ + data->data = NULL; + data_destroy(data); + } err: - return ret; + return ret; } /******************************************************************** @@ -2710,10 +2648,10 @@ err: * *******************************************************************/ int -dict_set_bin (dict_t *this, char *key, void *ptr, size_t size) +dict_set_bin(dict_t *this, char *key, void *ptr, size_t size) { - return dict_set_bin_common (this, key, ptr, size, _gf_false, - GF_DATA_TYPE_PTR); + return dict_set_bin_common(this, key, ptr, size, _gf_false, + GF_DATA_TYPE_PTR); } /******************************************************************** @@ -2724,78 +2662,77 @@ dict_set_bin (dict_t *this, char *key, void *ptr, size_t size) * *******************************************************************/ int -dict_set_static_bin (dict_t *this, char *key, void *ptr, size_t size) +dict_set_static_bin(dict_t *this, char *key, void *ptr, size_t size) { - return dict_set_bin_common (this, key, ptr, size, _gf_true, - GF_DATA_TYPE_PTR); + return dict_set_bin_common(this, key, ptr, size, _gf_true, + GF_DATA_TYPE_PTR); } /* */ int -dict_set_gfuuid (dict_t *this, char *key, uuid_t gfid, bool is_static) +dict_set_gfuuid(dict_t *this, char *key, uuid_t gfid, bool is_static) { - return dict_set_bin_common (this, key, gfid, sizeof (uuid_t), - is_static, GF_DATA_TYPE_GFUUID); + return dict_set_bin_common(this, key, gfid, sizeof(uuid_t), is_static, + GF_DATA_TYPE_GFUUID); } int -dict_get_gfuuid (dict_t *this, char *key, uuid_t *gfid) +dict_get_gfuuid(dict_t *this, char *key, uuid_t *gfid) { - data_t *data = NULL; - int ret = -EINVAL; + data_t *data = NULL; + int ret = -EINVAL; - if (!this || !key || !gfid) { - goto err; - } - ret = dict_get_with_ref (this, key, &data); - if (ret < 0) { - goto err; - } + if (!this || !key || !gfid) { + goto err; + } + ret = dict_get_with_ref(this, key, &data); + if (ret < 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_GFUUID, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_GFUUID, key, -EINVAL); - memcpy (*gfid, data->data, min(data->len, sizeof (uuid_t))); + memcpy(*gfid, data->data, min(data->len, sizeof(uuid_t))); err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } int -dict_set_iatt (dict_t *this, char *key, struct iatt *iatt, bool is_static) +dict_set_iatt(dict_t *this, char *key, struct iatt *iatt, bool is_static) { - return dict_set_bin_common (this, key, iatt, sizeof (struct iatt), - is_static, GF_DATA_TYPE_IATT); + return dict_set_bin_common(this, key, iatt, sizeof(struct iatt), is_static, + GF_DATA_TYPE_IATT); } int -dict_get_iatt (dict_t *this, char *key, struct iatt *iatt) +dict_get_iatt(dict_t *this, char *key, struct iatt *iatt) { - data_t *data = NULL; - int ret = -EINVAL; + data_t *data = NULL; + int ret = -EINVAL; - if (!this || !key || !iatt) { - goto err; - } - ret = dict_get_with_ref (this, key, &data); - if (ret < 0) { - goto err; - } + if (!this || !key || !iatt) { + goto err; + } + ret = dict_get_with_ref(this, key, &data); + if (ret < 0) { + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_IATT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_IATT, key, -EINVAL); - memcpy (iatt, data->data, min(data->len, sizeof (struct iatt))); + memcpy(iatt, data->data, min(data->len, sizeof(struct iatt))); err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } - /** * dict_get_str_boolean - get a boolean value based on string representation. * @@ -2820,75 +2757,74 @@ err: */ int -dict_get_str_boolean (dict_t *this, char *key, int default_val) +dict_get_str_boolean(dict_t *this, char *key, int default_val) { - data_t *data = NULL; - gf_boolean_t boo = _gf_false; - int ret = 0; + data_t *data = NULL; + gf_boolean_t boo = _gf_false; + int ret = 0; - ret = dict_get_with_ref (this, key, &data); - if (ret < 0) { - if (ret == -ENOENT) - ret = default_val; - else - ret = -1; - goto err; - } + ret = dict_get_with_ref(this, key, &data); + if (ret < 0) { + if (ret == -ENOENT) + ret = default_val; + else + ret = -1; + goto err; + } - VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); + VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_INT, key, -EINVAL); - ret = gf_string2boolean (data->data, &boo); - if (ret == -1) - goto err; + ret = gf_string2boolean(data->data, &boo); + if (ret == -1) + goto err; - ret = boo; + ret = boo; err: - if (data) - data_unref (data); + if (data) + data_unref(data); - return ret; + return ret; } int -dict_rename_key (dict_t *this, char *key, char *replace_key) +dict_rename_key(dict_t *this, char *key, char *replace_key) { - data_pair_t *pair = NULL; - int ret = -EINVAL; - uint32_t hash; - uint32_t replacekey_hash; + data_pair_t *pair = NULL; + int ret = -EINVAL; + uint32_t hash; + uint32_t replacekey_hash; - /* replacing a key by itself is a NO-OP */ - if (strcmp (key, replace_key) == 0) - return 0; + /* replacing a key by itself is a NO-OP */ + if (strcmp(key, replace_key) == 0) + return 0; - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - return ret; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + return ret; + } - hash = SuperFastHash (key, strlen (key)); - replacekey_hash = SuperFastHash (replace_key, - strlen(replace_key)); - - LOCK (&this->lock); - { - /* no need to data_ref(pair->value), dict_set_lk() does it */ - pair = dict_lookup_common (this, key, hash); - if (!pair) - ret = -ENODATA; - else - ret = dict_set_lk (this, replace_key, pair->value, - replacekey_hash, 1); - } - UNLOCK (&this->lock); + hash = SuperFastHash(key, strlen(key)); + replacekey_hash = SuperFastHash(replace_key, strlen(replace_key)); - if (!ret) - /* only delete the key on success */ - dict_del (this, key); + LOCK(&this->lock); + { + /* no need to data_ref(pair->value), dict_set_lk() does it */ + pair = dict_lookup_common(this, key, hash); + if (!pair) + ret = -ENODATA; + else + ret = dict_set_lk(this, replace_key, pair->value, replacekey_hash, + 1); + } + UNLOCK(&this->lock); - return ret; + if (!ret) + /* only delete the key on success */ + dict_del(this, key); + + return ret; } /** @@ -2899,9 +2835,9 @@ dict_rename_key (dict_t *this, char *key, char *replace_key) * 4 4 4 <key len> <value len> */ -#define DICT_HDR_LEN 4 -#define DICT_DATA_HDR_KEY_LEN 4 -#define DICT_DATA_HDR_VAL_LEN 4 +#define DICT_HDR_LEN 4 +#define DICT_DATA_HDR_KEY_LEN 4 +#define DICT_DATA_HDR_VAL_LEN 4 /** * dict_serialized_length_lk - return the length of serialized dict. This @@ -2913,59 +2849,59 @@ dict_rename_key (dict_t *this, char *key, char *replace_key) */ static int -dict_serialized_length_lk (dict_t *this) +dict_serialized_length_lk(dict_t *this) { - int ret = -EINVAL; - int count = this->count; - int len = DICT_HDR_LEN; - data_pair_t * pair = this->members_list; + int ret = -EINVAL; + int count = this->count; + int len = DICT_HDR_LEN; + data_pair_t *pair = this->members_list; - if (count < 0) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_COUNT_LESS_THAN_ZERO, "count (%d) < 0!", count); - goto out; - } + if (count < 0) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_COUNT_LESS_THAN_ZERO, + "count (%d) < 0!", count); + goto out; + } - while (count) { - if (!pair) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_COUNT_LESS_THAN_DATA_PAIRS, - "less than count data pairs found!"); - goto out; - } + while (count) { + if (!pair) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, + LG_MSG_COUNT_LESS_THAN_DATA_PAIRS, + "less than count data pairs found!"); + goto out; + } - len += DICT_DATA_HDR_KEY_LEN + DICT_DATA_HDR_VAL_LEN; + len += DICT_DATA_HDR_KEY_LEN + DICT_DATA_HDR_VAL_LEN; - if (!pair->key) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_NULL_PTR, "pair->key is null!"); - goto out; - } + if (!pair->key) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_NULL_PTR, + "pair->key is null!"); + goto out; + } - len += strlen (pair->key) + 1 /* for '\0' */; + len += strlen(pair->key) + 1 /* for '\0' */; - if (!pair->value) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_NULL_PTR, "pair->value is null!"); - goto out; - } + if (!pair->value) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_NULL_PTR, + "pair->value is null!"); + goto out; + } - if (pair->value->len < 0) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_VALUE_LENGTH_LESS_THAN_ZERO, - "value->len (%d) < 0", pair->value->len); - goto out; - } + if (pair->value->len < 0) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, + LG_MSG_VALUE_LENGTH_LESS_THAN_ZERO, "value->len (%d) < 0", + pair->value->len); + goto out; + } - len += pair->value->len; + len += pair->value->len; - pair = pair->next; - count--; - } + pair = pair->next; + count--; + } - ret = len; + ret = len; out: - return ret; + return ret; } /** @@ -2981,80 +2917,76 @@ out: */ static int -dict_serialize_lk (dict_t *this, char *buf) +dict_serialize_lk(dict_t *this, char *buf) { - int ret = -1; - data_pair_t * pair = this->members_list; - int32_t count = this->count; - int32_t keylen = 0; - int32_t netword = 0; + int ret = -1; + data_pair_t *pair = this->members_list; + int32_t count = this->count; + int32_t keylen = 0; + int32_t netword = 0; + if (!buf) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "buf is null!"); + goto out; + } - if (!buf) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, - "buf is null!"); - goto out; - } - - if (count < 0) { - gf_msg ("dict", GF_LOG_ERROR, 0, LG_MSG_COUNT_LESS_THAN_ZERO, - "count (%d) < 0!", count); - goto out; - } + if (count < 0) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_COUNT_LESS_THAN_ZERO, + "count (%d) < 0!", count); + goto out; + } - netword = hton32 (count); - memcpy (buf, &netword, sizeof(netword)); - buf += DICT_HDR_LEN; + netword = hton32(count); + memcpy(buf, &netword, sizeof(netword)); + buf += DICT_HDR_LEN; - while (count) { - if (!pair) { - gf_msg ("dict", GF_LOG_ERROR, 0, - LG_MSG_PAIRS_LESS_THAN_COUNT, - "less than count data pairs found!"); - goto out; - } - - if (!pair->key) { - gf_msg ("dict", GF_LOG_ERROR, 0, LG_MSG_NULL_PTR, - "pair->key is null!"); - goto out; - } + while (count) { + if (!pair) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_PAIRS_LESS_THAN_COUNT, + "less than count data pairs found!"); + goto out; + } - keylen = strlen (pair->key); - netword = hton32 (keylen); - memcpy (buf, &netword, sizeof(netword)); - buf += DICT_DATA_HDR_KEY_LEN; + if (!pair->key) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_NULL_PTR, + "pair->key is null!"); + goto out; + } - if (!pair->value) { - gf_msg ("dict", GF_LOG_ERROR, 0, - LG_MSG_NULL_PTR, - "pair->value is null!"); - goto out; - } + keylen = strlen(pair->key); + netword = hton32(keylen); + memcpy(buf, &netword, sizeof(netword)); + buf += DICT_DATA_HDR_KEY_LEN; - netword = hton32 (pair->value->len); - memcpy (buf, &netword, sizeof(netword)); - buf += DICT_DATA_HDR_VAL_LEN; + if (!pair->value) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_NULL_PTR, + "pair->value is null!"); + goto out; + } - memcpy (buf, pair->key, keylen); - buf += keylen; - *buf++ = '\0'; + netword = hton32(pair->value->len); + memcpy(buf, &netword, sizeof(netword)); + buf += DICT_DATA_HDR_VAL_LEN; - if (pair->value->data) { - memcpy (buf, pair->value->data, pair->value->len); - buf += pair->value->len; - } + memcpy(buf, pair->key, keylen); + buf += keylen; + *buf++ = '\0'; - pair = pair->next; - count--; + if (pair->value->data) { + memcpy(buf, pair->value->data, pair->value->len); + buf += pair->value->len; } - ret = 0; + pair = pair->next; + count--; + } + + ret = 0; out: - return ret; + return ret; } - /** * dict_serialized_length - return the length of serialized dict * @@ -3064,24 +2996,24 @@ out: */ int -dict_serialized_length (dict_t *this) +dict_serialized_length(dict_t *this) { - int ret = -EINVAL; + int ret = -EINVAL; - if (!this) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is null!"); - goto out; - } + if (!this) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is null!"); + goto out; + } - LOCK (&this->lock); - { - ret = dict_serialized_length_lk (this); - } - UNLOCK (&this->lock); + LOCK(&this->lock); + { + ret = dict_serialized_length_lk(this); + } + UNLOCK(&this->lock); out: - return ret; + return ret; } /** @@ -3096,26 +3028,25 @@ out: */ int -dict_serialize (dict_t *this, char *buf) +dict_serialize(dict_t *this, char *buf) { - int ret = -1; + int ret = -1; - if (!this || !buf) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is null!"); - goto out; - } + if (!this || !buf) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is null!"); + goto out; + } - LOCK (&this->lock); - { - ret = dict_serialize_lk (this, buf); - } - UNLOCK (&this->lock); + LOCK(&this->lock); + { + ret = dict_serialize_lk(this, buf); + } + UNLOCK(&this->lock); out: - return ret; + return ret; } - /** * dict_unserialize - unserialize a buffer into a dict * @@ -3128,143 +3059,137 @@ out: */ int32_t -dict_unserialize (char *orig_buf, int32_t size, dict_t **fill) -{ - char *buf = orig_buf; - int ret = -1; - int32_t count = 0; - int i = 0; - - data_t * value = NULL; - char * key = NULL; - int32_t keylen = 0; - int32_t vallen = 0; - int32_t hostord = 0; - - if (!buf) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "buf is null!"); - goto out; - } +dict_unserialize(char *orig_buf, int32_t size, dict_t **fill) +{ + char *buf = orig_buf; + int ret = -1; + int32_t count = 0; + int i = 0; + + data_t *value = NULL; + char *key = NULL; + int32_t keylen = 0; + int32_t vallen = 0; + int32_t hostord = 0; + + if (!buf) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "buf is null!"); + goto out; + } + + if (size == 0) { + gf_msg_callingfn("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "size is 0!"); + goto out; + } + + if (!fill) { + gf_msg_callingfn("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "fill is null!"); + goto out; + } + + if (!*fill) { + gf_msg_callingfn("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "*fill is null!"); + goto out; + } + + if ((buf + DICT_HDR_LEN) > (orig_buf + size)) { + gf_msg_callingfn("dict", GF_LOG_ERROR, 0, LG_MSG_UNDERSIZED_BUF, + "undersized buffer " + "passed. available (%lu) < required (%lu)", + (long)(orig_buf + size), (long)(buf + DICT_HDR_LEN)); + goto out; + } + + memcpy(&hostord, buf, sizeof(hostord)); + count = ntoh32(hostord); + buf += DICT_HDR_LEN; + + if (count < 0) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_COUNT_LESS_THAN_ZERO, + "count (%d) <= 0", count); + goto out; + } + + /* count will be set by the dict_set's below */ + (*fill)->count = 0; + + for (i = 0; i < count; i++) { + if ((buf + DICT_DATA_HDR_KEY_LEN) > (orig_buf + size)) { + gf_msg_callingfn("dict", GF_LOG_ERROR, 0, LG_MSG_UNDERSIZED_BUF, + "undersized " + "buffer passed. available (%lu) < " + "required (%lu)", + (long)(orig_buf + size), + (long)(buf + DICT_DATA_HDR_KEY_LEN)); + goto out; + } + memcpy(&hostord, buf, sizeof(hostord)); + keylen = ntoh32(hostord); + buf += DICT_DATA_HDR_KEY_LEN; + + if ((buf + DICT_DATA_HDR_VAL_LEN) > (orig_buf + size)) { + gf_msg_callingfn("dict", GF_LOG_ERROR, 0, LG_MSG_UNDERSIZED_BUF, + "undersized " + "buffer passed. available (%lu) < " + "required (%lu)", + (long)(orig_buf + size), + (long)(buf + DICT_DATA_HDR_VAL_LEN)); + goto out; + } + memcpy(&hostord, buf, sizeof(hostord)); + vallen = ntoh32(hostord); + buf += DICT_DATA_HDR_VAL_LEN; + + if ((keylen < 0) || (vallen < 0)) { + gf_msg_callingfn("dict", GF_LOG_ERROR, 0, LG_MSG_UNDERSIZED_BUF, + "undersized length passed " + "key:%d val:%d", + keylen, vallen); + goto out; + } + if ((buf + keylen) > (orig_buf + size)) { + gf_msg_callingfn("dict", GF_LOG_ERROR, 0, LG_MSG_UNDERSIZED_BUF, + "undersized buffer passed. " + "available (%lu) < required (%lu)", + (long)(orig_buf + size), (long)(buf + keylen)); + goto out; + } + key = buf; + buf += keylen + 1; /* for '\0' */ + + if ((buf + vallen) > (orig_buf + size)) { + gf_msg_callingfn("dict", GF_LOG_ERROR, 0, LG_MSG_UNDERSIZED_BUF, + "undersized buffer passed. " + "available (%lu) < required (%lu)", + (long)(orig_buf + size), (long)(buf + vallen)); + goto out; + } + value = get_new_data(); - if (size == 0) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "size is 0!"); - goto out; - } - - if (!fill) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "fill is null!"); - goto out; - } - - if (!*fill) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "*fill is null!"); - goto out; - } - - if ((buf + DICT_HDR_LEN) > (orig_buf + size)) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, 0, - LG_MSG_UNDERSIZED_BUF, "undersized buffer " - "passed. available (%lu) < required (%lu)", - (long)(orig_buf + size), - (long)(buf + DICT_HDR_LEN)); - goto out; - } - - memcpy (&hostord, buf, sizeof(hostord)); - count = ntoh32 (hostord); - buf += DICT_HDR_LEN; - - if (count < 0) { - gf_msg ("dict", GF_LOG_ERROR, 0, LG_MSG_COUNT_LESS_THAN_ZERO, - "count (%d) <= 0", count); - goto out; + if (!value) { + ret = -1; + goto out; } + value->len = vallen; + value->data = memdup(buf, vallen); + value->data_type = GF_DATA_TYPE_STR_OLD; + value->is_static = _gf_false; + buf += vallen; - /* count will be set by the dict_set's below */ - (*fill)->count = 0; - - for (i = 0; i < count; i++) { - if ((buf + DICT_DATA_HDR_KEY_LEN) > (orig_buf + size)) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, 0, - LG_MSG_UNDERSIZED_BUF, "undersized " - "buffer passed. available (%lu) < " - "required (%lu)", - (long)(orig_buf + size), - (long)(buf + DICT_DATA_HDR_KEY_LEN)); - goto out; - } - memcpy (&hostord, buf, sizeof(hostord)); - keylen = ntoh32 (hostord); - buf += DICT_DATA_HDR_KEY_LEN; - - if ((buf + DICT_DATA_HDR_VAL_LEN) > (orig_buf + size)) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, 0, - LG_MSG_UNDERSIZED_BUF, "undersized " - "buffer passed. available (%lu) < " - "required (%lu)", - (long)(orig_buf + size), - (long)(buf + DICT_DATA_HDR_VAL_LEN)); - goto out; - } - memcpy (&hostord, buf, sizeof(hostord)); - vallen = ntoh32 (hostord); - buf += DICT_DATA_HDR_VAL_LEN; - - if ((keylen < 0) || (vallen < 0)) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, 0, - LG_MSG_UNDERSIZED_BUF, - "undersized length passed " - "key:%d val:%d", keylen, vallen); - goto out; - } - if ((buf + keylen) > (orig_buf + size)) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, 0, - LG_MSG_UNDERSIZED_BUF, - "undersized buffer passed. " - "available (%lu) < required (%lu)", - (long)(orig_buf + size), - (long)(buf + keylen)); - goto out; - } - key = buf; - buf += keylen + 1; /* for '\0' */ - - if ((buf + vallen) > (orig_buf + size)) { - gf_msg_callingfn ("dict", GF_LOG_ERROR, 0, - LG_MSG_UNDERSIZED_BUF, - "undersized buffer passed. " - "available (%lu) < required (%lu)", - (long)(orig_buf + size), - (long)(buf + vallen)); - goto out; - } - value = get_new_data (); - - if (!value) { - ret = -1; - goto out; - } - value->len = vallen; - value->data = memdup (buf, vallen); - value->data_type = GF_DATA_TYPE_STR_OLD; - value->is_static = _gf_false; - buf += vallen; - - ret = dict_add (*fill, key, value); - if (ret < 0) - goto out; - } + ret = dict_add(*fill, key, value); + if (ret < 0) + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } - /** * dict_allocate_and_serialize - serialize a dictionary into an allocated buffer * @@ -3277,45 +3202,45 @@ out: */ int32_t -dict_allocate_and_serialize (dict_t *this, char **buf, u_int *length) +dict_allocate_and_serialize(dict_t *this, char **buf, u_int *length) { - int ret = -EINVAL; - ssize_t len = 0; + int ret = -EINVAL; + ssize_t len = 0; - if (!this || !buf) { - gf_msg_debug ("dict", 0, "dict OR buf is NULL"); - goto out; - } + if (!this || !buf) { + gf_msg_debug("dict", 0, "dict OR buf is NULL"); + goto out; + } - LOCK (&this->lock); - { - len = dict_serialized_length_lk (this); - if (len < 0) { - ret = len; - goto unlock; - } + LOCK(&this->lock); + { + len = dict_serialized_length_lk(this); + if (len < 0) { + ret = len; + goto unlock; + } - *buf = GF_MALLOC (len, gf_common_mt_char); - if (*buf == NULL) { - ret = -ENOMEM; - goto unlock; - } + *buf = GF_MALLOC(len, gf_common_mt_char); + if (*buf == NULL) { + ret = -ENOMEM; + goto unlock; + } - ret = dict_serialize_lk (this, *buf); - if (ret < 0) { - GF_FREE (*buf); - *buf = NULL; - goto unlock; - } + ret = dict_serialize_lk(this, *buf); + if (ret < 0) { + GF_FREE(*buf); + *buf = NULL; + goto unlock; + } - if (length != NULL) { - *length = len; - } + if (length != NULL) { + *length = len; } + } unlock: - UNLOCK (&this->lock); + UNLOCK(&this->lock); out: - return ret; + return ret; } /** @@ -3331,236 +3256,232 @@ out: * : -errno -> failure */ int -dict_serialize_value_with_delim_lk (dict_t *this, char *buf, int32_t *serz_len, - char delimiter) -{ - int ret = -1; - int32_t count = this->count; - int32_t vallen = 0; - int32_t total_len = 0; - data_pair_t *pair = this->members_list; - - if (!buf) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "buf is null"); - goto out; - } +dict_serialize_value_with_delim_lk(dict_t *this, char *buf, int32_t *serz_len, + char delimiter) +{ + int ret = -1; + int32_t count = this->count; + int32_t vallen = 0; + int32_t total_len = 0; + data_pair_t *pair = this->members_list; - if (count < 0) { - gf_msg ("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, - "count (%d) < 0", count); - goto out; - } + if (!buf) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, "buf is null"); + goto out; + } - while (count) { - if (!pair) { - gf_msg ("dict", GF_LOG_ERROR, 0, - LG_MSG_PAIRS_LESS_THAN_COUNT, - "less than count data pairs found"); - goto out; - } + if (count < 0) { + gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "count (%d) < 0", count); + goto out; + } - if (!pair->key || !pair->value) { - gf_msg ("dict", GF_LOG_ERROR, 0, - LG_MSG_KEY_OR_VALUE_NULL, - "key or value is null"); - goto out; - } + while (count) { + if (!pair) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_PAIRS_LESS_THAN_COUNT, + "less than count data pairs found"); + goto out; + } - if (!pair->value->data) { - gf_msg ("dict", GF_LOG_ERROR, 0, - LG_MSG_NULL_VALUE_IN_DICT, - "null value found in dict"); - goto out; - } + if (!pair->key || !pair->value) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_KEY_OR_VALUE_NULL, + "key or value is null"); + goto out; + } - vallen = pair->value->len - 1; // length includes \0 - memcpy (buf, pair->value->data, vallen); - buf += vallen; - *buf++ = delimiter; + if (!pair->value->data) { + gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_NULL_VALUE_IN_DICT, + "null value found in dict"); + goto out; + } - total_len += (vallen + 1); + vallen = pair->value->len - 1; // length includes \0 + memcpy(buf, pair->value->data, vallen); + buf += vallen; + *buf++ = delimiter; - pair = pair->next; - count--; - } + total_len += (vallen + 1); - *--buf = '\0'; // remove the last delimiter - total_len--; // adjust the length - ret = 0; + pair = pair->next; + count--; + } - if (serz_len) - *serz_len = total_len; + *--buf = '\0'; // remove the last delimiter + total_len--; // adjust the length + ret = 0; - out: - return ret; + if (serz_len) + *serz_len = total_len; + +out: + return ret; } int -dict_serialize_value_with_delim (dict_t *this, char *buf, int32_t *serz_len, - char delimiter) -{ - int ret = -1; - - if (!this || !buf) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is null!"); - goto out; - } - - LOCK (&this->lock); - { - ret = dict_serialize_value_with_delim_lk (this, buf, serz_len, - delimiter); - } - UNLOCK (&this->lock); +dict_serialize_value_with_delim(dict_t *this, char *buf, int32_t *serz_len, + char delimiter) +{ + int ret = -1; + + if (!this || !buf) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is null!"); + goto out; + } + + LOCK(&this->lock); + { + ret = dict_serialize_value_with_delim_lk(this, buf, serz_len, + delimiter); + } + UNLOCK(&this->lock); out: - return ret; + return ret; } int -dict_dump_to_str (dict_t *dict, char *dump, int dumpsize, char *format) +dict_dump_to_str(dict_t *dict, char *dump, int dumpsize, char *format) { - int ret = 0; - int dumplen = 0; - data_pair_t *trav = NULL; + int ret = 0; + int dumplen = 0; + data_pair_t *trav = NULL; - if (!dict) - return 0; + if (!dict) + return 0; - for (trav = dict->members_list; trav; trav = trav->next) { - ret = snprintf (&dump[dumplen], dumpsize - dumplen, - format, trav->key, trav->value->data); - if ((ret == -1) || !ret) - return ret; + for (trav = dict->members_list; trav; trav = trav->next) { + ret = snprintf(&dump[dumplen], dumpsize - dumplen, format, trav->key, + trav->value->data); + if ((ret == -1) || !ret) + return ret; - dumplen += ret; - } - return 0; + dumplen += ret; + } + return 0; } void -dict_dump_to_log (dict_t *dict) -{ - int ret = -1; - char *dump = NULL; - int dump_size = 64*1024; - char *format = "(%s:%s)"; - - if (!dict) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - goto out; - } - - dump = GF_MALLOC (dump_size, gf_common_mt_char); - if (!dump) { - gf_msg_callingfn ("dict", GF_LOG_WARNING, ENOMEM, - LG_MSG_NO_MEMORY, "dump buffer is NULL"); - goto out; - } - - ret = dict_dump_to_str (dict, dump, dump_size, format); - if (ret) { - gf_msg ("dict", GF_LOG_WARNING, 0, LG_MSG_FAILED_TO_LOG_DICT, - "Failed to log dictionary"); - goto out; - } - gf_msg ("dict", GF_LOG_INFO, 0, LG_MSG_DICT_ERROR, - "dict=%p (%s)", dict, dump); +dict_dump_to_log(dict_t *dict) +{ + int ret = -1; + char *dump = NULL; + int dump_size = 64 * 1024; + char *format = "(%s:%s)"; + + if (!dict) { + gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + goto out; + } + + dump = GF_MALLOC(dump_size, gf_common_mt_char); + if (!dump) { + gf_msg_callingfn("dict", GF_LOG_WARNING, ENOMEM, LG_MSG_NO_MEMORY, + "dump buffer is NULL"); + goto out; + } + + ret = dict_dump_to_str(dict, dump, dump_size, format); + if (ret) { + gf_msg("dict", GF_LOG_WARNING, 0, LG_MSG_FAILED_TO_LOG_DICT, + "Failed to log dictionary"); + goto out; + } + gf_msg("dict", GF_LOG_INFO, 0, LG_MSG_DICT_ERROR, "dict=%p (%s)", dict, + dump); out: - GF_FREE (dump); - + GF_FREE(dump); - return; + return; } void -dict_dump_to_statedump (dict_t *dict, char *dict_name, char *domain) -{ - int ret = -1; - char *dump = NULL; - int dump_size = 64*1024; - char key[4096] = {0,}; - char *format = "\n\t%s:%s"; - - if (!dict) { - gf_msg_callingfn (domain, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "dict is NULL"); - goto out; - } - - dump = GF_MALLOC (dump_size, gf_common_mt_char); - if (!dump) { - gf_msg_callingfn (domain, GF_LOG_WARNING, ENOMEM, - LG_MSG_NO_MEMORY, "dump buffer is NULL"); - goto out; - } - - ret = dict_dump_to_str (dict, dump, dump_size, format); - if (ret) { - gf_msg (domain, GF_LOG_WARNING, 0, LG_MSG_FAILED_TO_LOG_DICT, - "Failed to log dictionary %s", dict_name); - goto out; - } - gf_proc_dump_build_key (key, domain, "%s", dict_name); - gf_proc_dump_write (key, "%s", dump); +dict_dump_to_statedump(dict_t *dict, char *dict_name, char *domain) +{ + int ret = -1; + char *dump = NULL; + int dump_size = 64 * 1024; + char key[4096] = { + 0, + }; + char *format = "\n\t%s:%s"; + + if (!dict) { + gf_msg_callingfn(domain, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "dict is NULL"); + goto out; + } + + dump = GF_MALLOC(dump_size, gf_common_mt_char); + if (!dump) { + gf_msg_callingfn(domain, GF_LOG_WARNING, ENOMEM, LG_MSG_NO_MEMORY, + "dump buffer is NULL"); + goto out; + } + + ret = dict_dump_to_str(dict, dump, dump_size, format); + if (ret) { + gf_msg(domain, GF_LOG_WARNING, 0, LG_MSG_FAILED_TO_LOG_DICT, + "Failed to log dictionary %s", dict_name); + goto out; + } + gf_proc_dump_build_key(key, domain, "%s", dict_name); + gf_proc_dump_write(key, "%s", dump); out: - GF_FREE (dump); + GF_FREE(dump); - return; + return; } dict_t * -dict_for_key_value (const char *name, const char *value, size_t size, - gf_boolean_t is_static) +dict_for_key_value(const char *name, const char *value, size_t size, + gf_boolean_t is_static) { - dict_t *xattr = NULL; - int ret = 0; + dict_t *xattr = NULL; + int ret = 0; - xattr = dict_new (); - if (!xattr) - return NULL; + xattr = dict_new(); + if (!xattr) + return NULL; - if (is_static) - ret = dict_set_static_bin (xattr, (char *)name, (void *)value, - size); - else - ret = dict_set_bin (xattr, (char *)name, (void *)value, size); + if (is_static) + ret = dict_set_static_bin(xattr, (char *)name, (void *)value, size); + else + ret = dict_set_bin(xattr, (char *)name, (void *)value, size); - if (ret) { - dict_destroy (xattr); - xattr = NULL; - } + if (ret) { + dict_destroy(xattr); + xattr = NULL; + } - return xattr; + return xattr; } /* * "strings" should be NULL terminated strings array. */ int -dict_has_key_from_array (dict_t *dict, char **strings, gf_boolean_t *result) +dict_has_key_from_array(dict_t *dict, char **strings, gf_boolean_t *result) { - int i = 0; - uint32_t hash = 0; + int i = 0; + uint32_t hash = 0; - if (!dict || !strings || !result) - return -EINVAL; + if (!dict || !strings || !result) + return -EINVAL; - LOCK (&dict->lock); - { - for (i = 0; strings[i]; i++) { - hash = SuperFastHash (strings[i], strlen (strings[i])); - if (dict_lookup_common (dict, strings[i], hash)) { - *result = _gf_true; - goto unlock; - } - } - *result = _gf_false; + LOCK(&dict->lock); + { + for (i = 0; strings[i]; i++) { + hash = SuperFastHash(strings[i], strlen(strings[i])); + if (dict_lookup_common(dict, strings[i], hash)) { + *result = _gf_true; + goto unlock; + } } + *result = _gf_false; + } unlock: - UNLOCK (&dict->lock); - return 0; + UNLOCK(&dict->lock); + return 0; } diff --git a/libglusterfs/src/event-epoll.c b/libglusterfs/src/event-epoll.c index b144b77a11c..9826cc9e275 100644 --- a/libglusterfs/src/event-epoll.c +++ b/libglusterfs/src/event-epoll.c @@ -23,766 +23,747 @@ #include "syscall.h" #include "libglusterfs-messages.h" - #ifdef HAVE_SYS_EPOLL_H #include <sys/epoll.h> - struct event_slot_epoll { - int fd; - int events; - int gen; - gf_atomic_t ref; - int do_close; - int in_handler; - int handled_error; - void *data; - event_handler_t handler; - gf_lock_t lock; + int fd; + int events; + int gen; + gf_atomic_t ref; + int do_close; + int in_handler; + int handled_error; + void *data; + event_handler_t handler; + gf_lock_t lock; }; struct event_thread_data { - struct event_pool *event_pool; - int event_index; + struct event_pool *event_pool; + int event_index; }; static struct event_slot_epoll * -__event_newtable (struct event_pool *event_pool, int table_idx) +__event_newtable(struct event_pool *event_pool, int table_idx) { - struct event_slot_epoll *table = NULL; - int i = -1; + struct event_slot_epoll *table = NULL; + int i = -1; - table = GF_CALLOC (sizeof (*table), EVENT_EPOLL_SLOTS, - gf_common_mt_ereg); - if (!table) - return NULL; + table = GF_CALLOC(sizeof(*table), EVENT_EPOLL_SLOTS, gf_common_mt_ereg); + if (!table) + return NULL; - for (i = 0; i < EVENT_EPOLL_SLOTS; i++) { - table[i].fd = -1; - LOCK_INIT (&table[i].lock); - } + for (i = 0; i < EVENT_EPOLL_SLOTS; i++) { + table[i].fd = -1; + LOCK_INIT(&table[i].lock); + } - event_pool->ereg[table_idx] = table; - event_pool->slots_used[table_idx] = 0; + event_pool->ereg[table_idx] = table; + event_pool->slots_used[table_idx] = 0; - return table; + return table; } - static int -__event_slot_alloc (struct event_pool *event_pool, int fd) +__event_slot_alloc(struct event_pool *event_pool, int fd) { - int i = 0; - int table_idx = -1; - int gen = -1; - struct event_slot_epoll *table = NULL; - - for (i = 0; i < EVENT_EPOLL_TABLES; i++) { - switch (event_pool->slots_used[i]) { - case EVENT_EPOLL_SLOTS: - continue; - case 0: - if (!event_pool->ereg[i]) { - table = __event_newtable (event_pool, i); - if (!table) - return -1; - } else { - table = event_pool->ereg[i]; - } - break; - default: - table = event_pool->ereg[i]; - break; - } - - if (table) - /* break out of the loop */ - break; - } - - if (!table) - return -1; - - table_idx = i; - - for (i = 0; i < EVENT_EPOLL_SLOTS; i++) { - if (table[i].fd == -1) { - /* wipe everything except bump the generation */ - gen = table[i].gen; - memset (&table[i], 0, sizeof (table[i])); - table[i].gen = gen + 1; - - LOCK_INIT (&table[i].lock); - - table[i].fd = fd; - event_pool->slots_used[table_idx]++; - - break; - } - } - - return table_idx * EVENT_EPOLL_SLOTS + i; -} + int i = 0; + int table_idx = -1; + int gen = -1; + struct event_slot_epoll *table = NULL; + + for (i = 0; i < EVENT_EPOLL_TABLES; i++) { + switch (event_pool->slots_used[i]) { + case EVENT_EPOLL_SLOTS: + continue; + case 0: + if (!event_pool->ereg[i]) { + table = __event_newtable(event_pool, i); + if (!table) + return -1; + } else { + table = event_pool->ereg[i]; + } + break; + default: + table = event_pool->ereg[i]; + break; + } + if (table) + /* break out of the loop */ + break; + } -static int -event_slot_alloc (struct event_pool *event_pool, int fd) -{ - int idx = -1; + if (!table) + return -1; + + table_idx = i; + + for (i = 0; i < EVENT_EPOLL_SLOTS; i++) { + if (table[i].fd == -1) { + /* wipe everything except bump the generation */ + gen = table[i].gen; + memset(&table[i], 0, sizeof(table[i])); + table[i].gen = gen + 1; - pthread_mutex_lock (&event_pool->mutex); - { - idx = __event_slot_alloc (event_pool, fd); - } - pthread_mutex_unlock (&event_pool->mutex); + LOCK_INIT(&table[i].lock); - return idx; + table[i].fd = fd; + event_pool->slots_used[table_idx]++; + + break; + } + } + + return table_idx * EVENT_EPOLL_SLOTS + i; } +static int +event_slot_alloc(struct event_pool *event_pool, int fd) +{ + int idx = -1; + pthread_mutex_lock(&event_pool->mutex); + { + idx = __event_slot_alloc(event_pool, fd); + } + pthread_mutex_unlock(&event_pool->mutex); + + return idx; +} static void -__event_slot_dealloc (struct event_pool *event_pool, int idx) +__event_slot_dealloc(struct event_pool *event_pool, int idx) { - int table_idx = 0; - int offset = 0; - struct event_slot_epoll *table = NULL; - struct event_slot_epoll *slot = NULL; + int table_idx = 0; + int offset = 0; + struct event_slot_epoll *table = NULL; + struct event_slot_epoll *slot = NULL; - table_idx = idx / EVENT_EPOLL_SLOTS; - offset = idx % EVENT_EPOLL_SLOTS; + table_idx = idx / EVENT_EPOLL_SLOTS; + offset = idx % EVENT_EPOLL_SLOTS; - table = event_pool->ereg[table_idx]; - if (!table) - return; + table = event_pool->ereg[table_idx]; + if (!table) + return; - slot = &table[offset]; - slot->gen++; + slot = &table[offset]; + slot->gen++; - slot->fd = -1; - slot->handled_error = 0; - slot->in_handler = 0; - event_pool->slots_used[table_idx]--; + slot->fd = -1; + slot->handled_error = 0; + slot->in_handler = 0; + event_pool->slots_used[table_idx]--; - return; + return; } - static void -event_slot_dealloc (struct event_pool *event_pool, int idx) +event_slot_dealloc(struct event_pool *event_pool, int idx) { - pthread_mutex_lock (&event_pool->mutex); - { - __event_slot_dealloc (event_pool, idx); - } - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_lock(&event_pool->mutex); + { + __event_slot_dealloc(event_pool, idx); + } + pthread_mutex_unlock(&event_pool->mutex); - return; + return; } - static struct event_slot_epoll * -event_slot_get (struct event_pool *event_pool, int idx) +event_slot_get(struct event_pool *event_pool, int idx) { - struct event_slot_epoll *slot = NULL; - struct event_slot_epoll *table = NULL; - int table_idx = 0; - int offset = 0; + struct event_slot_epoll *slot = NULL; + struct event_slot_epoll *table = NULL; + int table_idx = 0; + int offset = 0; - table_idx = idx / EVENT_EPOLL_SLOTS; - offset = idx % EVENT_EPOLL_SLOTS; + table_idx = idx / EVENT_EPOLL_SLOTS; + offset = idx % EVENT_EPOLL_SLOTS; - table = event_pool->ereg[table_idx]; - if (!table) - return NULL; + table = event_pool->ereg[table_idx]; + if (!table) + return NULL; - slot = &table[offset]; - GF_ATOMIC_INC (slot->ref); + slot = &table[offset]; + GF_ATOMIC_INC(slot->ref); - return slot; + return slot; } - static void -event_slot_unref (struct event_pool *event_pool, struct event_slot_epoll *slot, - int idx) +event_slot_unref(struct event_pool *event_pool, struct event_slot_epoll *slot, + int idx) { - int ref = -1; - int fd = -1; - int do_close = 0; - - ref = GF_ATOMIC_DEC (slot->ref); - if (ref) - /* slot still alive */ - goto done; - - LOCK (&slot->lock); - { - fd = slot->fd; - do_close = slot->do_close; - slot->do_close = 0; - } - UNLOCK (&slot->lock); - - event_slot_dealloc (event_pool, idx); - - if (do_close) - sys_close (fd); + int ref = -1; + int fd = -1; + int do_close = 0; + + ref = GF_ATOMIC_DEC(slot->ref); + if (ref) + /* slot still alive */ + goto done; + + LOCK(&slot->lock); + { + fd = slot->fd; + do_close = slot->do_close; + slot->do_close = 0; + } + UNLOCK(&slot->lock); + + event_slot_dealloc(event_pool, idx); + + if (do_close) + sys_close(fd); done: - return; + return; } - static struct event_pool * -event_pool_new_epoll (int count, int eventthreadcount) +event_pool_new_epoll(int count, int eventthreadcount) { - struct event_pool *event_pool = NULL; - int epfd = -1; + struct event_pool *event_pool = NULL; + int epfd = -1; - event_pool = GF_CALLOC (1, sizeof (*event_pool), - gf_common_mt_event_pool); + event_pool = GF_CALLOC(1, sizeof(*event_pool), gf_common_mt_event_pool); - if (!event_pool) - goto out; + if (!event_pool) + goto out; - epfd = epoll_create (count); + epfd = epoll_create(count); - if (epfd == -1) { - gf_msg ("epoll", GF_LOG_ERROR, errno, - LG_MSG_EPOLL_FD_CREATE_FAILED, "epoll fd creation " - "failed"); - GF_FREE (event_pool->reg); - GF_FREE (event_pool); - event_pool = NULL; - goto out; - } + if (epfd == -1) { + gf_msg("epoll", GF_LOG_ERROR, errno, LG_MSG_EPOLL_FD_CREATE_FAILED, + "epoll fd creation " + "failed"); + GF_FREE(event_pool->reg); + GF_FREE(event_pool); + event_pool = NULL; + goto out; + } - event_pool->fd = epfd; + event_pool->fd = epfd; - event_pool->count = count; + event_pool->count = count; - event_pool->eventthreadcount = eventthreadcount; - event_pool->auto_thread_count = 0; + event_pool->eventthreadcount = eventthreadcount; + event_pool->auto_thread_count = 0; - pthread_mutex_init (&event_pool->mutex, NULL); + pthread_mutex_init(&event_pool->mutex, NULL); out: - return event_pool; + return event_pool; } - static void -__slot_update_events (struct event_slot_epoll *slot, int poll_in, int poll_out) +__slot_update_events(struct event_slot_epoll *slot, int poll_in, int poll_out) { - switch (poll_in) { - case 1: - slot->events |= EPOLLIN; - break; - case 0: - slot->events &= ~EPOLLIN; - break; - case -1: - /* do nothing */ - break; - default: - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_IN, - "invalid poll_in value %d", poll_in); - break; - } - - switch (poll_out) { - case 1: - slot->events |= EPOLLOUT; - break; - case 0: - slot->events &= ~EPOLLOUT; - break; - case -1: - /* do nothing */ - break; - default: - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_OUT, - "invalid poll_out value %d", poll_out); - break; - } + switch (poll_in) { + case 1: + slot->events |= EPOLLIN; + break; + case 0: + slot->events &= ~EPOLLIN; + break; + case -1: + /* do nothing */ + break; + default: + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_IN, + "invalid poll_in value %d", poll_in); + break; + } + + switch (poll_out) { + case 1: + slot->events |= EPOLLOUT; + break; + case 0: + slot->events &= ~EPOLLOUT; + break; + case -1: + /* do nothing */ + break; + default: + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_OUT, + "invalid poll_out value %d", poll_out); + break; + } } - int -event_register_epoll (struct event_pool *event_pool, int fd, - event_handler_t handler, - void *data, int poll_in, int poll_out) +event_register_epoll(struct event_pool *event_pool, int fd, + event_handler_t handler, void *data, int poll_in, + int poll_out) { - int idx = -1; - int ret = -1; - int destroy = 0; - struct epoll_event epoll_event = {0, }; - struct event_data *ev_data = (void *)&epoll_event.data; - struct event_slot_epoll *slot = NULL; - - - GF_VALIDATE_OR_GOTO ("event", event_pool, out); - - /* TODO: Even with the below check, there is a possibility of race, - * What if the destroy mode is set after the check is done. - * Not sure of the best way to prevent this race, ref counting - * is one possibility. - * There is no harm in registering and unregistering the fd - * even after destroy mode is set, just that such fds will remain - * open until unregister is called, also the events on that fd will be - * notified, until one of the poller thread is alive. - */ - pthread_mutex_lock (&event_pool->mutex); - { - destroy = event_pool->destroy; - } - pthread_mutex_unlock (&event_pool->mutex); - - if (destroy == 1) - goto out; - - idx = event_slot_alloc (event_pool, fd); - if (idx == -1) { - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, - "could not find slot for fd=%d", fd); - return -1; - } - - slot = event_slot_get (event_pool, idx); - if (!slot) { - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, - "could not find slot for fd=%d idx=%d", fd, idx); - return -1; - } - - assert (slot->fd == fd); - - LOCK (&slot->lock); - { - /* make epoll 'singleshot', which - means we need to re-add the fd with - epoll_ctl(EPOLL_CTL_MOD) after delivery of every - single event. This assures us that while a poller - thread has picked up and is processing an event, - another poller will not try to pick this at the same - time as well. - */ - - slot->events = EPOLLPRI | EPOLLHUP | EPOLLERR | EPOLLONESHOT; - slot->handler = handler; - slot->data = data; - - __slot_update_events (slot, poll_in, poll_out); - - epoll_event.events = slot->events; - ev_data->idx = idx; - ev_data->gen = slot->gen; - - ret = epoll_ctl (event_pool->fd, EPOLL_CTL_ADD, fd, - &epoll_event); - /* check ret after UNLOCK() to avoid deadlock in - event_slot_unref() - */ - } - UNLOCK (&slot->lock); - - if (ret == -1) { - gf_msg ("epoll", GF_LOG_ERROR, errno, - LG_MSG_EPOLL_FD_ADD_FAILED, "failed to add fd(=%d) to " - "epoll fd(=%d)", fd, event_pool->fd); - event_slot_unref (event_pool, slot, idx); - idx = -1; - } - - /* keep slot->ref (do not event_slot_unref) if successful */ + int idx = -1; + int ret = -1; + int destroy = 0; + struct epoll_event epoll_event = { + 0, + }; + struct event_data *ev_data = (void *)&epoll_event.data; + struct event_slot_epoll *slot = NULL; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); + + /* TODO: Even with the below check, there is a possibility of race, + * What if the destroy mode is set after the check is done. + * Not sure of the best way to prevent this race, ref counting + * is one possibility. + * There is no harm in registering and unregistering the fd + * even after destroy mode is set, just that such fds will remain + * open until unregister is called, also the events on that fd will be + * notified, until one of the poller thread is alive. + */ + pthread_mutex_lock(&event_pool->mutex); + { + destroy = event_pool->destroy; + } + pthread_mutex_unlock(&event_pool->mutex); + + if (destroy == 1) + goto out; + + idx = event_slot_alloc(event_pool, fd); + if (idx == -1) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, + "could not find slot for fd=%d", fd); + return -1; + } + + slot = event_slot_get(event_pool, idx); + if (!slot) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, + "could not find slot for fd=%d idx=%d", fd, idx); + return -1; + } + + assert(slot->fd == fd); + + LOCK(&slot->lock); + { + /* make epoll 'singleshot', which + means we need to re-add the fd with + epoll_ctl(EPOLL_CTL_MOD) after delivery of every + single event. This assures us that while a poller + thread has picked up and is processing an event, + another poller will not try to pick this at the same + time as well. + */ + + slot->events = EPOLLPRI | EPOLLHUP | EPOLLERR | EPOLLONESHOT; + slot->handler = handler; + slot->data = data; + + __slot_update_events(slot, poll_in, poll_out); + + epoll_event.events = slot->events; + ev_data->idx = idx; + ev_data->gen = slot->gen; + + ret = epoll_ctl(event_pool->fd, EPOLL_CTL_ADD, fd, &epoll_event); + /* check ret after UNLOCK() to avoid deadlock in + event_slot_unref() + */ + } + UNLOCK(&slot->lock); + + if (ret == -1) { + gf_msg("epoll", GF_LOG_ERROR, errno, LG_MSG_EPOLL_FD_ADD_FAILED, + "failed to add fd(=%d) to " + "epoll fd(=%d)", + fd, event_pool->fd); + event_slot_unref(event_pool, slot, idx); + idx = -1; + } + + /* keep slot->ref (do not event_slot_unref) if successful */ out: - return idx; + return idx; } - static int -event_unregister_epoll_common (struct event_pool *event_pool, int fd, - int idx, int do_close) +event_unregister_epoll_common(struct event_pool *event_pool, int fd, int idx, + int do_close) { - int ret = -1; - struct event_slot_epoll *slot = NULL; - - GF_VALIDATE_OR_GOTO ("event", event_pool, out); - - /* During shutdown, it may happen that a socket registration with - * the event sub-system may fail and an rpc_transport_unref() may - * be called for such an unregistered socket with idx == -1. This - * may cause the following assert(slot->fd == fd) to fail. - */ - if (idx < 0) - goto out; - - slot = event_slot_get (event_pool, idx); - if (!slot) { - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, - "could not find slot for fd=%d idx=%d", fd, idx); - return -1; + int ret = -1; + struct event_slot_epoll *slot = NULL; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); + + /* During shutdown, it may happen that a socket registration with + * the event sub-system may fail and an rpc_transport_unref() may + * be called for such an unregistered socket with idx == -1. This + * may cause the following assert(slot->fd == fd) to fail. + */ + if (idx < 0) + goto out; + + slot = event_slot_get(event_pool, idx); + if (!slot) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, + "could not find slot for fd=%d idx=%d", fd, idx); + return -1; + } + + assert(slot->fd == fd); + + LOCK(&slot->lock); + { + ret = epoll_ctl(event_pool->fd, EPOLL_CTL_DEL, fd, NULL); + + if (ret == -1) { + gf_msg("epoll", GF_LOG_ERROR, errno, LG_MSG_EPOLL_FD_DEL_FAILED, + "fail to del " + "fd(=%d) from epoll fd(=%d)", + fd, event_pool->fd); + goto unlock; } - assert (slot->fd == fd); - - LOCK (&slot->lock); - { - ret = epoll_ctl (event_pool->fd, EPOLL_CTL_DEL, fd, NULL); - - if (ret == -1) { - gf_msg ("epoll", GF_LOG_ERROR, errno, - LG_MSG_EPOLL_FD_DEL_FAILED, "fail to del " - "fd(=%d) from epoll fd(=%d)", fd, - event_pool->fd); - goto unlock; - } - - slot->do_close = do_close; - slot->gen++; /* detect unregister in dispatch_handler() */ - } + slot->do_close = do_close; + slot->gen++; /* detect unregister in dispatch_handler() */ + } unlock: - UNLOCK (&slot->lock); + UNLOCK(&slot->lock); - event_slot_unref (event_pool, slot, idx); /* one for event_register() */ - event_slot_unref (event_pool, slot, idx); /* one for event_slot_get() */ + event_slot_unref(event_pool, slot, idx); /* one for event_register() */ + event_slot_unref(event_pool, slot, idx); /* one for event_slot_get() */ out: - return ret; + return ret; } - static int -event_unregister_epoll (struct event_pool *event_pool, int fd, int idx_hint) +event_unregister_epoll(struct event_pool *event_pool, int fd, int idx_hint) { - int ret = -1; + int ret = -1; - ret = event_unregister_epoll_common (event_pool, fd, idx_hint, 0); + ret = event_unregister_epoll_common(event_pool, fd, idx_hint, 0); - return ret; + return ret; } - static int -event_unregister_close_epoll (struct event_pool *event_pool, int fd, - int idx_hint) +event_unregister_close_epoll(struct event_pool *event_pool, int fd, + int idx_hint) { - int ret = -1; + int ret = -1; - ret = event_unregister_epoll_common (event_pool, fd, idx_hint, 1); + ret = event_unregister_epoll_common(event_pool, fd, idx_hint, 1); - return ret; + return ret; } - static int -event_select_on_epoll (struct event_pool *event_pool, int fd, int idx, - int poll_in, int poll_out) +event_select_on_epoll(struct event_pool *event_pool, int fd, int idx, + int poll_in, int poll_out) { - int ret = -1; - struct event_slot_epoll *slot = NULL; - struct epoll_event epoll_event = {0, }; - struct event_data *ev_data = (void *)&epoll_event.data; - - - GF_VALIDATE_OR_GOTO ("event", event_pool, out); - - slot = event_slot_get (event_pool, idx); - if (!slot) { - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, - "could not find slot for fd=%d idx=%d", fd, idx); - return -1; + int ret = -1; + struct event_slot_epoll *slot = NULL; + struct epoll_event epoll_event = { + 0, + }; + struct event_data *ev_data = (void *)&epoll_event.data; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); + + slot = event_slot_get(event_pool, idx); + if (!slot) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, + "could not find slot for fd=%d idx=%d", fd, idx); + return -1; + } + + assert(slot->fd == fd); + + LOCK(&slot->lock); + { + __slot_update_events(slot, poll_in, poll_out); + + epoll_event.events = slot->events; + ev_data->idx = idx; + ev_data->gen = slot->gen; + + if (slot->in_handler) + /* + * in_handler indicates at least one thread + * executing event_dispatch_epoll_handler() + * which will perform epoll_ctl(EPOLL_CTL_MOD) + * anyways (because of EPOLLET) + * + * This not only saves a system call, but also + * avoids possibility of another epoll thread + * picking up the next event while the ongoing + * handler is still in progress (and resulting + * in unnecessary contention on rpc_transport_t->mutex). + */ + goto unlock; + + ret = epoll_ctl(event_pool->fd, EPOLL_CTL_MOD, fd, &epoll_event); + if (ret == -1) { + gf_msg("epoll", GF_LOG_ERROR, errno, LG_MSG_EPOLL_FD_MODIFY_FAILED, + "failed to " + "modify fd(=%d) events to %d", + fd, epoll_event.events); } - - assert (slot->fd == fd); - - LOCK (&slot->lock); - { - __slot_update_events (slot, poll_in, poll_out); - - epoll_event.events = slot->events; - ev_data->idx = idx; - ev_data->gen = slot->gen; - - if (slot->in_handler) - /* - * in_handler indicates at least one thread - * executing event_dispatch_epoll_handler() - * which will perform epoll_ctl(EPOLL_CTL_MOD) - * anyways (because of EPOLLET) - * - * This not only saves a system call, but also - * avoids possibility of another epoll thread - * picking up the next event while the ongoing - * handler is still in progress (and resulting - * in unnecessary contention on rpc_transport_t->mutex). - */ - goto unlock; - - ret = epoll_ctl (event_pool->fd, EPOLL_CTL_MOD, fd, - &epoll_event); - if (ret == -1) { - gf_msg ("epoll", GF_LOG_ERROR, errno, - LG_MSG_EPOLL_FD_MODIFY_FAILED, "failed to " - "modify fd(=%d) events to %d", fd, - epoll_event.events); - } - } + } unlock: - UNLOCK (&slot->lock); + UNLOCK(&slot->lock); - event_slot_unref (event_pool, slot, idx); + event_slot_unref(event_pool, slot, idx); out: - return idx; + return idx; } - static int -event_dispatch_epoll_handler (struct event_pool *event_pool, - struct epoll_event *event) +event_dispatch_epoll_handler(struct event_pool *event_pool, + struct epoll_event *event) { - struct event_data *ev_data = NULL; - struct event_slot_epoll *slot = NULL; - event_handler_t handler = NULL; - void *data = NULL; - int idx = -1; - int gen = -1; - int ret = -1; - int fd = -1; - gf_boolean_t handled_error_previously = _gf_false; - - ev_data = (void *)&event->data; - handler = NULL; - data = NULL; - - idx = ev_data->idx; - gen = ev_data->gen; - - slot = event_slot_get (event_pool, idx); - if (!slot) { - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, - "could not find slot for idx=%d", idx); - return -1; + struct event_data *ev_data = NULL; + struct event_slot_epoll *slot = NULL; + event_handler_t handler = NULL; + void *data = NULL; + int idx = -1; + int gen = -1; + int ret = -1; + int fd = -1; + gf_boolean_t handled_error_previously = _gf_false; + + ev_data = (void *)&event->data; + handler = NULL; + data = NULL; + + idx = ev_data->idx; + gen = ev_data->gen; + + slot = event_slot_get(event_pool, idx); + if (!slot) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, + "could not find slot for idx=%d", idx); + return -1; + } + + LOCK(&slot->lock); + { + fd = slot->fd; + if (fd == -1) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_STALE_FD_FOUND, + "stale fd found on " + "idx=%d, gen=%d, events=%d, slot->gen=%d", + idx, gen, event->events, slot->gen); + /* fd got unregistered in another thread */ + goto pre_unlock; } - LOCK (&slot->lock); - { - fd = slot->fd; - if (fd == -1) { - gf_msg ("epoll", GF_LOG_ERROR, 0, - LG_MSG_STALE_FD_FOUND, "stale fd found on " - "idx=%d, gen=%d, events=%d, slot->gen=%d", - idx, gen, event->events, slot->gen); - /* fd got unregistered in another thread */ - goto pre_unlock; - } - - if (gen != slot->gen) { - gf_msg ("epoll", GF_LOG_ERROR, 0, - LG_MSG_GENERATION_MISMATCH, "generation " - "mismatch on idx=%d, gen=%d, slot->gen=%d, " - "slot->fd=%d", idx, gen, slot->gen, slot->fd); - /* slot was re-used and therefore is another fd! */ - goto pre_unlock; - } - - handler = slot->handler; - data = slot->data; - - if (slot->handled_error) { - handled_error_previously = _gf_true; - } else { - slot->handled_error = (event->events - & (EPOLLERR|EPOLLHUP)); - slot->in_handler++; - } - } + if (gen != slot->gen) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_GENERATION_MISMATCH, + "generation " + "mismatch on idx=%d, gen=%d, slot->gen=%d, " + "slot->fd=%d", + idx, gen, slot->gen, slot->fd); + /* slot was re-used and therefore is another fd! */ + goto pre_unlock; + } + + handler = slot->handler; + data = slot->data; + + if (slot->handled_error) { + handled_error_previously = _gf_true; + } else { + slot->handled_error = (event->events & (EPOLLERR | EPOLLHUP)); + slot->in_handler++; + } + } pre_unlock: - UNLOCK (&slot->lock); + UNLOCK(&slot->lock); - ret = 0; + ret = 0; - if (!handler) - goto out; + if (!handler) + goto out; - if (!handled_error_previously) { - ret = handler (fd, idx, gen, data, - (event->events & (EPOLLIN|EPOLLPRI)), - (event->events & (EPOLLOUT)), - (event->events & (EPOLLERR|EPOLLHUP))); - } + if (!handled_error_previously) { + ret = handler(fd, idx, gen, data, + (event->events & (EPOLLIN | EPOLLPRI)), + (event->events & (EPOLLOUT)), + (event->events & (EPOLLERR | EPOLLHUP))); + } out: - event_slot_unref (event_pool, slot, idx); + event_slot_unref(event_pool, slot, idx); - return ret; + return ret; } - static void * -event_dispatch_epoll_worker (void *data) +event_dispatch_epoll_worker(void *data) { - struct epoll_event event; - int ret = -1; - struct event_thread_data *ev_data = data; - struct event_pool *event_pool; - int myindex = -1; - int timetodie = 0; - - GF_VALIDATE_OR_GOTO ("event", ev_data, out); - - event_pool = ev_data->event_pool; - myindex = ev_data->event_index; - - GF_VALIDATE_OR_GOTO ("event", event_pool, out); - - gf_msg ("epoll", GF_LOG_INFO, 0, LG_MSG_STARTED_EPOLL_THREAD, "Started" - " thread with index %d", myindex); - - pthread_mutex_lock (&event_pool->mutex); - { - event_pool->activethreadcount++; - } - pthread_mutex_unlock (&event_pool->mutex); - - for (;;) { + struct epoll_event event; + int ret = -1; + struct event_thread_data *ev_data = data; + struct event_pool *event_pool; + int myindex = -1; + int timetodie = 0; + + GF_VALIDATE_OR_GOTO("event", ev_data, out); + + event_pool = ev_data->event_pool; + myindex = ev_data->event_index; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); + + gf_msg("epoll", GF_LOG_INFO, 0, LG_MSG_STARTED_EPOLL_THREAD, + "Started" + " thread with index %d", + myindex); + + pthread_mutex_lock(&event_pool->mutex); + { + event_pool->activethreadcount++; + } + pthread_mutex_unlock(&event_pool->mutex); + + for (;;) { + if (event_pool->eventthreadcount < myindex) { + /* ...time to die, thread count was decreased below + * this threads index */ + /* Start with extra safety at this point, reducing + * lock conention in normal case when threads are not + * reconfigured always */ + pthread_mutex_lock(&event_pool->mutex); + { if (event_pool->eventthreadcount < myindex) { - /* ...time to die, thread count was decreased below - * this threads index */ - /* Start with extra safety at this point, reducing - * lock conention in normal case when threads are not - * reconfigured always */ - pthread_mutex_lock (&event_pool->mutex); - { - if (event_pool->eventthreadcount < - myindex) { - /* if found true in critical section, - * die */ - event_pool->pollers[myindex - 1] = 0; - event_pool->activethreadcount--; - timetodie = 1; - pthread_cond_broadcast (&event_pool->cond); - } - } - pthread_mutex_unlock (&event_pool->mutex); - if (timetodie) { - gf_msg ("epoll", GF_LOG_INFO, 0, - LG_MSG_EXITED_EPOLL_THREAD, "Exited " - "thread with index %d", myindex); - goto out; - } + /* if found true in critical section, + * die */ + event_pool->pollers[myindex - 1] = 0; + event_pool->activethreadcount--; + timetodie = 1; + pthread_cond_broadcast(&event_pool->cond); } + } + pthread_mutex_unlock(&event_pool->mutex); + if (timetodie) { + gf_msg("epoll", GF_LOG_INFO, 0, LG_MSG_EXITED_EPOLL_THREAD, + "Exited " + "thread with index %d", + myindex); + goto out; + } + } - ret = epoll_wait (event_pool->fd, &event, 1, -1); + ret = epoll_wait(event_pool->fd, &event, 1, -1); - if (ret == 0) - /* timeout */ - continue; + if (ret == 0) + /* timeout */ + continue; - if (ret == -1 && errno == EINTR) - /* sys call */ - continue; + if (ret == -1 && errno == EINTR) + /* sys call */ + continue; - ret = event_dispatch_epoll_handler (event_pool, &event); - if (ret) { - gf_msg ("epoll", GF_LOG_ERROR, 0, - LG_MSG_EXITED_EPOLL_THREAD, - "Failed to dispatch handler"); - } + ret = event_dispatch_epoll_handler(event_pool, &event); + if (ret) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_EXITED_EPOLL_THREAD, + "Failed to dispatch handler"); } + } out: - if (ev_data) - GF_FREE (ev_data); - return NULL; + if (ev_data) + GF_FREE(ev_data); + return NULL; } /* Attempts to start the # of configured pollers, ensuring at least the first * is started in a joinable state */ static int -event_dispatch_epoll (struct event_pool *event_pool) +event_dispatch_epoll(struct event_pool *event_pool) { - int i = 0; - pthread_t t_id; - int pollercount = 0; - int ret = -1; - struct event_thread_data *ev_data = NULL; - char thread_name[GF_THREAD_NAMEMAX] = {0,}; - - /* Start the configured number of pollers */ - pthread_mutex_lock (&event_pool->mutex); - { - pollercount = event_pool->eventthreadcount; - - /* Set to MAX if greater */ - if (pollercount > EVENT_MAX_THREADS) - pollercount = EVENT_MAX_THREADS; - - /* Default pollers to 1 in case this is incorrectly set */ - if (pollercount <= 0) - pollercount = 1; - - event_pool->activethreadcount++; - - for (i = 0; i < pollercount; i++) { - ev_data = GF_CALLOC (1, sizeof (*ev_data), - gf_common_mt_event_pool); - if (!ev_data) { - if (i == 0) { - /* Need to succeed creating 0'th - * thread, to joinable and wait */ - break; - } else { - /* Inability to create other threads - * are a lesser evil, and ignored */ - continue; - } - } - - ev_data->event_pool = event_pool; - ev_data->event_index = i + 1; - - snprintf (thread_name, sizeof(thread_name), - "epoll%03hx", (i & 0x3ff)); - ret = gf_thread_create (&t_id, NULL, - event_dispatch_epoll_worker, - ev_data, thread_name); - if (!ret) { - event_pool->pollers[i] = t_id; - - /* mark all threads other than one in index 0 - * as detachable. Errors can be ignored, they - * spend their time as zombies if not detched - * and the thread counts are decreased */ - if (i != 0) - pthread_detach (event_pool->pollers[i]); - } else { - gf_msg ("epoll", GF_LOG_WARNING, 0, - LG_MSG_START_EPOLL_THREAD_FAILED, - "Failed to start thread for index %d", - i); - if (i == 0) { - GF_FREE (ev_data); - break; - } else { - GF_FREE (ev_data); - continue; - } - } + int i = 0; + pthread_t t_id; + int pollercount = 0; + int ret = -1; + struct event_thread_data *ev_data = NULL; + char thread_name[GF_THREAD_NAMEMAX] = { + 0, + }; + + /* Start the configured number of pollers */ + pthread_mutex_lock(&event_pool->mutex); + { + pollercount = event_pool->eventthreadcount; + + /* Set to MAX if greater */ + if (pollercount > EVENT_MAX_THREADS) + pollercount = EVENT_MAX_THREADS; + + /* Default pollers to 1 in case this is incorrectly set */ + if (pollercount <= 0) + pollercount = 1; + + event_pool->activethreadcount++; + + for (i = 0; i < pollercount; i++) { + ev_data = GF_CALLOC(1, sizeof(*ev_data), gf_common_mt_event_pool); + if (!ev_data) { + if (i == 0) { + /* Need to succeed creating 0'th + * thread, to joinable and wait */ + break; + } else { + /* Inability to create other threads + * are a lesser evil, and ignored */ + continue; } + } + + ev_data->event_pool = event_pool; + ev_data->event_index = i + 1; + + snprintf(thread_name, sizeof(thread_name), "epoll%03hx", + (i & 0x3ff)); + ret = gf_thread_create(&t_id, NULL, event_dispatch_epoll_worker, + ev_data, thread_name); + if (!ret) { + event_pool->pollers[i] = t_id; + + /* mark all threads other than one in index 0 + * as detachable. Errors can be ignored, they + * spend their time as zombies if not detched + * and the thread counts are decreased */ + if (i != 0) + pthread_detach(event_pool->pollers[i]); + } else { + gf_msg("epoll", GF_LOG_WARNING, 0, + LG_MSG_START_EPOLL_THREAD_FAILED, + "Failed to start thread for index %d", i); + if (i == 0) { + GF_FREE(ev_data); + break; + } else { + GF_FREE(ev_data); + continue; + } + } } - pthread_mutex_unlock (&event_pool->mutex); + } + pthread_mutex_unlock(&event_pool->mutex); - /* Just wait for the first thread, that is created in a joinable state - * and will never die, ensuring this function never returns */ - if (event_pool->pollers[0] != 0) - pthread_join (event_pool->pollers[0], NULL); + /* Just wait for the first thread, that is created in a joinable state + * and will never die, ensuring this function never returns */ + if (event_pool->pollers[0] != 0) + pthread_join(event_pool->pollers[0], NULL); - pthread_mutex_lock (&event_pool->mutex); - { - event_pool->activethreadcount--; - } - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_lock(&event_pool->mutex); + { + event_pool->activethreadcount--; + } + pthread_mutex_unlock(&event_pool->mutex); - return ret; + return ret; } /** @@ -795,89 +776,87 @@ event_dispatch_epoll (struct event_pool *event_pool) */ static int -event_pool_dispatched_unlocked (struct event_pool *event_pool) +event_pool_dispatched_unlocked(struct event_pool *event_pool) { - return (event_pool->pollers[0] != 0); - + return (event_pool->pollers[0] != 0); } - int -event_reconfigure_threads_epoll (struct event_pool *event_pool, int value) +event_reconfigure_threads_epoll(struct event_pool *event_pool, int value) { - int i; - int ret = 0; - pthread_t t_id; - int oldthreadcount; - struct event_thread_data *ev_data = NULL; - char thread_name[GF_THREAD_NAMEMAX] = {0,}; - - pthread_mutex_lock (&event_pool->mutex); - { - /* Reconfigure to 0 threads is allowed only in destroy mode */ - if (event_pool->destroy == 1) { - value = 0; - } else { - /* Set to MAX if greater */ - if (value > EVENT_MAX_THREADS) - value = EVENT_MAX_THREADS; - - /* Default pollers to 1 in case this is set incorrectly */ - if (value <= 0) - value = 1; - } + int i; + int ret = 0; + pthread_t t_id; + int oldthreadcount; + struct event_thread_data *ev_data = NULL; + char thread_name[GF_THREAD_NAMEMAX] = { + 0, + }; + + pthread_mutex_lock(&event_pool->mutex); + { + /* Reconfigure to 0 threads is allowed only in destroy mode */ + if (event_pool->destroy == 1) { + value = 0; + } else { + /* Set to MAX if greater */ + if (value > EVENT_MAX_THREADS) + value = EVENT_MAX_THREADS; + + /* Default pollers to 1 in case this is set incorrectly */ + if (value <= 0) + value = 1; + } - oldthreadcount = event_pool->eventthreadcount; - - /* Start 'worker' threads as necessary only if event_dispatch() - * was called before. If event_dispatch() was not called, there - * will be no epoll 'worker' threads running yet. */ - - if (event_pool_dispatched_unlocked(event_pool) - && (oldthreadcount < value)) { - /* create more poll threads */ - for (i = oldthreadcount; i < value; i++) { - /* Start a thread if the index at this location - * is a 0, so that the older thread is confirmed - * as dead */ - if (event_pool->pollers[i] == 0) { - ev_data = GF_CALLOC (1, - sizeof (*ev_data), - gf_common_mt_event_pool); - if (!ev_data) { - continue; - } - - ev_data->event_pool = event_pool; - ev_data->event_index = i + 1; - - snprintf (thread_name, - sizeof(thread_name), - "epoll%03hx", (i & 0x3ff)); - ret = gf_thread_create (&t_id, NULL, - event_dispatch_epoll_worker, - ev_data, thread_name); - if (ret) { - gf_msg ("epoll", GF_LOG_WARNING, - 0, - LG_MSG_START_EPOLL_THREAD_FAILED, - "Failed to start thread" - " for index %d", i); - GF_FREE (ev_data); - } else { - pthread_detach (t_id); - event_pool->pollers[i] = t_id; - } - } - } + oldthreadcount = event_pool->eventthreadcount; + + /* Start 'worker' threads as necessary only if event_dispatch() + * was called before. If event_dispatch() was not called, there + * will be no epoll 'worker' threads running yet. */ + + if (event_pool_dispatched_unlocked(event_pool) && + (oldthreadcount < value)) { + /* create more poll threads */ + for (i = oldthreadcount; i < value; i++) { + /* Start a thread if the index at this location + * is a 0, so that the older thread is confirmed + * as dead */ + if (event_pool->pollers[i] == 0) { + ev_data = GF_CALLOC(1, sizeof(*ev_data), + gf_common_mt_event_pool); + if (!ev_data) { + continue; + } + + ev_data->event_pool = event_pool; + ev_data->event_index = i + 1; + + snprintf(thread_name, sizeof(thread_name), "epoll%03hx", + (i & 0x3ff)); + ret = gf_thread_create(&t_id, NULL, + event_dispatch_epoll_worker, ev_data, + thread_name); + if (ret) { + gf_msg("epoll", GF_LOG_WARNING, 0, + LG_MSG_START_EPOLL_THREAD_FAILED, + "Failed to start thread" + " for index %d", + i); + GF_FREE(ev_data); + } else { + pthread_detach(t_id); + event_pool->pollers[i] = t_id; + } } - - /* if value decreases, threads will terminate, themselves */ - event_pool->eventthreadcount = value; + } } - pthread_mutex_unlock (&event_pool->mutex); - return 0; + /* if value decreases, threads will terminate, themselves */ + event_pool->eventthreadcount = value; + } + pthread_mutex_unlock(&event_pool->mutex); + + return 0; } /* This function is the destructor for the event_pool data structure @@ -885,98 +864,99 @@ event_reconfigure_threads_epoll (struct event_pool *event_pool, int value) * else will lead to crashes. */ static int -event_pool_destroy_epoll (struct event_pool *event_pool) +event_pool_destroy_epoll(struct event_pool *event_pool) { - int ret = 0, i = 0, j = 0; - struct event_slot_epoll *table = NULL; - - ret = sys_close (event_pool->fd); - - for (i = 0; i < EVENT_EPOLL_TABLES; i++) { - if (event_pool->ereg[i]) { - table = event_pool->ereg[i]; - event_pool->ereg[i] = NULL; - for (j = 0; j < EVENT_EPOLL_SLOTS; j++) { - LOCK_DESTROY (&table[j].lock); - } - GF_FREE (table); - } + int ret = 0, i = 0, j = 0; + struct event_slot_epoll *table = NULL; + + ret = sys_close(event_pool->fd); + + for (i = 0; i < EVENT_EPOLL_TABLES; i++) { + if (event_pool->ereg[i]) { + table = event_pool->ereg[i]; + event_pool->ereg[i] = NULL; + for (j = 0; j < EVENT_EPOLL_SLOTS; j++) { + LOCK_DESTROY(&table[j].lock); + } + GF_FREE(table); } + } - pthread_mutex_destroy (&event_pool->mutex); - pthread_cond_destroy (&event_pool->cond); + pthread_mutex_destroy(&event_pool->mutex); + pthread_cond_destroy(&event_pool->cond); - GF_FREE (event_pool->evcache); - GF_FREE (event_pool->reg); - GF_FREE (event_pool); + GF_FREE(event_pool->evcache); + GF_FREE(event_pool->reg); + GF_FREE(event_pool); - return ret; + return ret; } static int -event_handled_epoll (struct event_pool *event_pool, int fd, int idx, int gen) +event_handled_epoll(struct event_pool *event_pool, int fd, int idx, int gen) { - struct event_slot_epoll *slot = NULL; - struct epoll_event epoll_event = {0, }; - struct event_data *ev_data = (void *)&epoll_event.data; - int ret = 0; - - slot = event_slot_get (event_pool, idx); - if (!slot) { - gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, - "could not find slot for fd=%d idx=%d", fd, idx); - return -1; + struct event_slot_epoll *slot = NULL; + struct epoll_event epoll_event = { + 0, + }; + struct event_data *ev_data = (void *)&epoll_event.data; + int ret = 0; + + slot = event_slot_get(event_pool, idx); + if (!slot) { + gf_msg("epoll", GF_LOG_ERROR, 0, LG_MSG_SLOT_NOT_FOUND, + "could not find slot for fd=%d idx=%d", fd, idx); + return -1; + } + + assert(slot->fd == fd); + + LOCK(&slot->lock); + { + slot->in_handler--; + + if (gen != slot->gen) { + /* event_unregister() happened while we were + in handler() + */ + gf_msg_debug("epoll", 0, + "generation bumped on idx=%d" + " from gen=%d to slot->gen=%d, fd=%d, " + "slot->fd=%d", + idx, gen, slot->gen, fd, slot->fd); + goto post_unlock; } - assert (slot->fd == fd); - - LOCK (&slot->lock); - { - slot->in_handler--; - - if (gen != slot->gen) { - /* event_unregister() happened while we were - in handler() - */ - gf_msg_debug ("epoll", 0, "generation bumped on idx=%d" - " from gen=%d to slot->gen=%d, fd=%d, " - "slot->fd=%d", idx, gen, slot->gen, fd, - slot->fd); - goto post_unlock; - } - - /* This call also picks up the changes made by another - thread calling event_select_on_epoll() while this - thread was busy in handler() - */ - if (slot->in_handler == 0) { - epoll_event.events = slot->events; - ev_data->idx = idx; - ev_data->gen = gen; - - ret = epoll_ctl (event_pool->fd, EPOLL_CTL_MOD, - fd, &epoll_event); - } - } + /* This call also picks up the changes made by another + thread calling event_select_on_epoll() while this + thread was busy in handler() + */ + if (slot->in_handler == 0) { + epoll_event.events = slot->events; + ev_data->idx = idx; + ev_data->gen = gen; + + ret = epoll_ctl(event_pool->fd, EPOLL_CTL_MOD, fd, &epoll_event); + } + } post_unlock: - UNLOCK (&slot->lock); + UNLOCK(&slot->lock); - event_slot_unref (event_pool, slot, idx); + event_slot_unref(event_pool, slot, idx); - return ret; + return ret; } - struct event_ops event_ops_epoll = { - .new = event_pool_new_epoll, - .event_register = event_register_epoll, - .event_select_on = event_select_on_epoll, - .event_unregister = event_unregister_epoll, - .event_unregister_close = event_unregister_close_epoll, - .event_dispatch = event_dispatch_epoll, - .event_reconfigure_threads = event_reconfigure_threads_epoll, - .event_pool_destroy = event_pool_destroy_epoll, - .event_handled = event_handled_epoll, + .new = event_pool_new_epoll, + .event_register = event_register_epoll, + .event_select_on = event_select_on_epoll, + .event_unregister = event_unregister_epoll, + .event_unregister_close = event_unregister_close_epoll, + .event_dispatch = event_dispatch_epoll, + .event_reconfigure_threads = event_reconfigure_threads_epoll, + .event_pool_destroy = event_pool_destroy_epoll, + .event_handled = event_handled_epoll, }; #endif diff --git a/libglusterfs/src/event-history.c b/libglusterfs/src/event-history.c index 95484a4322b..4845330f62b 100644 --- a/libglusterfs/src/event-history.c +++ b/libglusterfs/src/event-history.c @@ -12,72 +12,71 @@ #include "libglusterfs-messages.h" eh_t * -eh_new (size_t buffer_size, gf_boolean_t use_buffer_once, - void (*destroy_buffer_data) (void *data)) +eh_new(size_t buffer_size, gf_boolean_t use_buffer_once, + void (*destroy_buffer_data)(void *data)) { - eh_t *history = NULL; - buffer_t *buffer = NULL; + eh_t *history = NULL; + buffer_t *buffer = NULL; - history = GF_CALLOC (1, sizeof (eh_t), gf_common_mt_eh_t); - if (!history) { - goto out; - } + history = GF_CALLOC(1, sizeof(eh_t), gf_common_mt_eh_t); + if (!history) { + goto out; + } - buffer = cb_buffer_new (buffer_size, use_buffer_once, - destroy_buffer_data); - if (!buffer) { - GF_FREE (history); - history = NULL; - goto out; - } + buffer = cb_buffer_new(buffer_size, use_buffer_once, destroy_buffer_data); + if (!buffer) { + GF_FREE(history); + history = NULL; + goto out; + } - history->buffer = buffer; + history->buffer = buffer; - pthread_mutex_init (&history->lock, NULL); + pthread_mutex_init(&history->lock, NULL); out: - return history; + return history; } void -eh_dump (eh_t *history, void *data, - int (dump_fn) (circular_buffer_t *buffer, void *data)) +eh_dump(eh_t *history, void *data, + int(dump_fn)(circular_buffer_t *buffer, void *data)) { - if (!history) { - gf_msg_debug ("event-history", 0, "history is NULL"); - goto out; - } + if (!history) { + gf_msg_debug("event-history", 0, "history is NULL"); + goto out; + } - cb_buffer_dump (history->buffer, data, dump_fn); + cb_buffer_dump(history->buffer, data, dump_fn); out: - return; + return; } int -eh_save_history (eh_t *history, void *data) +eh_save_history(eh_t *history, void *data) { - int ret = -1; + int ret = -1; - ret = cb_add_entry_buffer (history->buffer, data); + ret = cb_add_entry_buffer(history->buffer, data); - return ret; + return ret; } int -eh_destroy (eh_t *history) +eh_destroy(eh_t *history) { - if (!history) { - gf_msg ("event-history", GF_LOG_INFO, 0, LG_MSG_INVALID_ARG, - "history for the xlator is NULL"); - return -1; - } + if (!history) { + gf_msg("event-history", GF_LOG_INFO, 0, LG_MSG_INVALID_ARG, + "history for the xlator is NULL"); + return -1; + } - cb_buffer_destroy (history->buffer); - history->buffer = NULL; + cb_buffer_destroy(history->buffer); + history->buffer = NULL; - pthread_mutex_destroy (&history->lock); + pthread_mutex_destroy(&history->lock); - GF_FREE (history); + GF_FREE(history); - return 0; + return 0; } diff --git a/libglusterfs/src/event-poll.c b/libglusterfs/src/event-poll.c index 283e2861b2b..727d2a000a2 100644 --- a/libglusterfs/src/event-poll.c +++ b/libglusterfs/src/event-poll.c @@ -23,490 +23,469 @@ #include "syscall.h" #include "libglusterfs-messages.h" - - struct event_slot_poll { - int fd; - int events; - void *data; - event_handler_t handler; + int fd; + int events; + void *data; + event_handler_t handler; }; - static int -event_register_poll (struct event_pool *event_pool, int fd, - event_handler_t handler, - void *data, int poll_in, int poll_out); - +event_register_poll(struct event_pool *event_pool, int fd, + event_handler_t handler, void *data, int poll_in, + int poll_out); static int -__flush_fd (int fd, int idx, int gen, void *data, - int poll_in, int poll_out, int poll_err) +__flush_fd(int fd, int idx, int gen, void *data, int poll_in, int poll_out, + int poll_err) { - char buf[64]; - int ret = -1; + char buf[64]; + int ret = -1; - if (!poll_in) - return ret; + if (!poll_in) + return ret; - do { - ret = sys_read (fd, buf, 64); - if (ret == -1 && errno != EAGAIN) { - gf_msg ("poll", GF_LOG_ERROR, errno, - LG_MSG_FILE_OP_FAILED, "read on %d returned " - "error", fd); - } - } while (ret == 64); + do { + ret = sys_read(fd, buf, 64); + if (ret == -1 && errno != EAGAIN) { + gf_msg("poll", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "read on %d returned " + "error", + fd); + } + } while (ret == 64); - return ret; + return ret; } - static int -__event_getindex (struct event_pool *event_pool, int fd, int idx) +__event_getindex(struct event_pool *event_pool, int fd, int idx) { - int ret = -1; - int i = 0; + int ret = -1; + int i = 0; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - /* lookup in used space based on index provided */ - if (idx > -1 && idx < event_pool->used) { - if (event_pool->reg[idx].fd == fd) { - ret = idx; - goto out; - } + /* lookup in used space based on index provided */ + if (idx > -1 && idx < event_pool->used) { + if (event_pool->reg[idx].fd == fd) { + ret = idx; + goto out; } + } - /* search in used space, if lookup fails */ - for (i = 0; i < event_pool->used; i++) { - if (event_pool->reg[i].fd == fd) { - ret = i; - break; - } + /* search in used space, if lookup fails */ + for (i = 0; i < event_pool->used; i++) { + if (event_pool->reg[i].fd == fd) { + ret = i; + break; } + } out: - return ret; + return ret; } - static struct event_pool * -event_pool_new_poll (int count, int eventthreadcount) +event_pool_new_poll(int count, int eventthreadcount) { - struct event_pool *event_pool = NULL; - int ret = -1; + struct event_pool *event_pool = NULL; + int ret = -1; - event_pool = GF_CALLOC (1, sizeof (*event_pool), - gf_common_mt_event_pool); + event_pool = GF_CALLOC(1, sizeof(*event_pool), gf_common_mt_event_pool); - if (!event_pool) - return NULL; + if (!event_pool) + return NULL; - event_pool->count = count; - event_pool->reg = GF_CALLOC (event_pool->count, - sizeof (*event_pool->reg), - gf_common_mt_reg); + event_pool->count = count; + event_pool->reg = GF_CALLOC(event_pool->count, sizeof(*event_pool->reg), + gf_common_mt_reg); - if (!event_pool->reg) { - GF_FREE (event_pool); - return NULL; - } + if (!event_pool->reg) { + GF_FREE(event_pool); + return NULL; + } - pthread_mutex_init (&event_pool->mutex, NULL); + pthread_mutex_init(&event_pool->mutex, NULL); - ret = pipe (event_pool->breaker); + ret = pipe(event_pool->breaker); - if (ret == -1) { - gf_msg ("poll", GF_LOG_ERROR, errno, LG_MSG_PIPE_CREATE_FAILED, - "pipe creation failed"); - GF_FREE (event_pool->reg); - GF_FREE (event_pool); - return NULL; - } + if (ret == -1) { + gf_msg("poll", GF_LOG_ERROR, errno, LG_MSG_PIPE_CREATE_FAILED, + "pipe creation failed"); + GF_FREE(event_pool->reg); + GF_FREE(event_pool); + return NULL; + } - ret = fcntl (event_pool->breaker[0], F_SETFL, O_NONBLOCK); - if (ret == -1) { - gf_msg ("poll", GF_LOG_ERROR, errno, LG_MSG_SET_PIPE_FAILED, - "could not set pipe to non blocking mode"); - sys_close (event_pool->breaker[0]); - sys_close (event_pool->breaker[1]); - event_pool->breaker[0] = event_pool->breaker[1] = -1; - - GF_FREE (event_pool->reg); - GF_FREE (event_pool); - return NULL; - } - - ret = fcntl (event_pool->breaker[1], F_SETFL, O_NONBLOCK); - if (ret == -1) { - gf_msg ("poll", GF_LOG_ERROR, errno, LG_MSG_SET_PIPE_FAILED, - "could not set pipe to non blocking mode"); - - sys_close (event_pool->breaker[0]); - sys_close (event_pool->breaker[1]); - event_pool->breaker[0] = event_pool->breaker[1] = -1; + ret = fcntl(event_pool->breaker[0], F_SETFL, O_NONBLOCK); + if (ret == -1) { + gf_msg("poll", GF_LOG_ERROR, errno, LG_MSG_SET_PIPE_FAILED, + "could not set pipe to non blocking mode"); + sys_close(event_pool->breaker[0]); + sys_close(event_pool->breaker[1]); + event_pool->breaker[0] = event_pool->breaker[1] = -1; - GF_FREE (event_pool->reg); - GF_FREE (event_pool); - return NULL; - } + GF_FREE(event_pool->reg); + GF_FREE(event_pool); + return NULL; + } - ret = event_register_poll (event_pool, event_pool->breaker[0], - __flush_fd, NULL, 1, 0); - if (ret == -1) { - gf_msg ("poll", GF_LOG_ERROR, 0, LG_MSG_REGISTER_PIPE_FAILED, - "could not register pipe fd with poll event loop"); - sys_close (event_pool->breaker[0]); - sys_close (event_pool->breaker[1]); - event_pool->breaker[0] = event_pool->breaker[1] = -1; - - GF_FREE (event_pool->reg); - GF_FREE (event_pool); - return NULL; - } + ret = fcntl(event_pool->breaker[1], F_SETFL, O_NONBLOCK); + if (ret == -1) { + gf_msg("poll", GF_LOG_ERROR, errno, LG_MSG_SET_PIPE_FAILED, + "could not set pipe to non blocking mode"); - if (eventthreadcount > 1) { - gf_msg ("poll", GF_LOG_INFO, 0, - LG_MSG_POLL_IGNORE_MULTIPLE_THREADS, "Currently poll " - "does not use multiple event processing threads, " - "thread count (%d) ignored", eventthreadcount); - } + sys_close(event_pool->breaker[0]); + sys_close(event_pool->breaker[1]); + event_pool->breaker[0] = event_pool->breaker[1] = -1; - /* although, eventhreadcount for poll implementation is always - * going to be 1, eventthreadcount needs to be set to 1 so that - * rpcsvc_request_handler() thread scaling works flawlessly in - * both epoll and poll models - */ - event_pool->eventthreadcount = 1; + GF_FREE(event_pool->reg); + GF_FREE(event_pool); + return NULL; + } + + ret = event_register_poll(event_pool, event_pool->breaker[0], __flush_fd, + NULL, 1, 0); + if (ret == -1) { + gf_msg("poll", GF_LOG_ERROR, 0, LG_MSG_REGISTER_PIPE_FAILED, + "could not register pipe fd with poll event loop"); + sys_close(event_pool->breaker[0]); + sys_close(event_pool->breaker[1]); + event_pool->breaker[0] = event_pool->breaker[1] = -1; - return event_pool; + GF_FREE(event_pool->reg); + GF_FREE(event_pool); + return NULL; + } + + if (eventthreadcount > 1) { + gf_msg("poll", GF_LOG_INFO, 0, LG_MSG_POLL_IGNORE_MULTIPLE_THREADS, + "Currently poll " + "does not use multiple event processing threads, " + "thread count (%d) ignored", + eventthreadcount); + } + + /* although, eventhreadcount for poll implementation is always + * going to be 1, eventthreadcount needs to be set to 1 so that + * rpcsvc_request_handler() thread scaling works flawlessly in + * both epoll and poll models + */ + event_pool->eventthreadcount = 1; + + return event_pool; } - static int -event_register_poll (struct event_pool *event_pool, int fd, - event_handler_t handler, - void *data, int poll_in, int poll_out) +event_register_poll(struct event_pool *event_pool, int fd, + event_handler_t handler, void *data, int poll_in, + int poll_out) { - int idx = -1; + int idx = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - pthread_mutex_lock (&event_pool->mutex); - { - if (event_pool->count == event_pool->used) - { - event_pool->count += 256; - - event_pool->reg = GF_REALLOC (event_pool->reg, - event_pool->count * - sizeof (*event_pool->reg)); - if (!event_pool->reg) - goto unlock; - } - - idx = event_pool->used++; - - event_pool->reg[idx].fd = fd; - event_pool->reg[idx].events = POLLPRI; - event_pool->reg[idx].handler = handler; - event_pool->reg[idx].data = data; - - switch (poll_in) { - case 1: - event_pool->reg[idx].events |= POLLIN; - break; - case 0: - event_pool->reg[idx].events &= ~POLLIN; - break; - case -1: - /* do nothing */ - break; - default: - gf_msg ("poll", GF_LOG_ERROR, 0, - LG_MSG_INVALID_POLL_IN, - "invalid poll_in value %d", poll_in); - break; - } - - switch (poll_out) { - case 1: - event_pool->reg[idx].events |= POLLOUT; - break; - case 0: - event_pool->reg[idx].events &= ~POLLOUT; - break; - case -1: - /* do nothing */ - break; - default: - gf_msg ("poll", GF_LOG_ERROR, 0, - LG_MSG_INVALID_POLL_OUT, - "invalid poll_out value %d", poll_out); - break; - } - - event_pool->changed = 1; + pthread_mutex_lock(&event_pool->mutex); + { + if (event_pool->count == event_pool->used) { + event_pool->count += 256; + + event_pool->reg = GF_REALLOC( + event_pool->reg, event_pool->count * sizeof(*event_pool->reg)); + if (!event_pool->reg) + goto unlock; + } + + idx = event_pool->used++; + + event_pool->reg[idx].fd = fd; + event_pool->reg[idx].events = POLLPRI; + event_pool->reg[idx].handler = handler; + event_pool->reg[idx].data = data; + + switch (poll_in) { + case 1: + event_pool->reg[idx].events |= POLLIN; + break; + case 0: + event_pool->reg[idx].events &= ~POLLIN; + break; + case -1: + /* do nothing */ + break; + default: + gf_msg("poll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_IN, + "invalid poll_in value %d", poll_in); + break; + } + switch (poll_out) { + case 1: + event_pool->reg[idx].events |= POLLOUT; + break; + case 0: + event_pool->reg[idx].events &= ~POLLOUT; + break; + case -1: + /* do nothing */ + break; + default: + gf_msg("poll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_OUT, + "invalid poll_out value %d", poll_out); + break; } + + event_pool->changed = 1; + } unlock: - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_unlock(&event_pool->mutex); out: - return idx; + return idx; } - static int -event_unregister_poll (struct event_pool *event_pool, int fd, int idx_hint) +event_unregister_poll(struct event_pool *event_pool, int fd, int idx_hint) { - int idx = -1; + int idx = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - pthread_mutex_lock (&event_pool->mutex); - { - idx = __event_getindex (event_pool, fd, idx_hint); - - if (idx == -1) { - gf_msg ("poll", GF_LOG_ERROR, 0, LG_MSG_INDEX_NOT_FOUND, - "index not found for fd=%d (idx_hint=%d)", - fd, idx_hint); - errno = ENOENT; - goto unlock; - } - - event_pool->reg[idx] = event_pool->reg[--event_pool->used]; - event_pool->changed = 1; + pthread_mutex_lock(&event_pool->mutex); + { + idx = __event_getindex(event_pool, fd, idx_hint); + + if (idx == -1) { + gf_msg("poll", GF_LOG_ERROR, 0, LG_MSG_INDEX_NOT_FOUND, + "index not found for fd=%d (idx_hint=%d)", fd, idx_hint); + errno = ENOENT; + goto unlock; } + + event_pool->reg[idx] = event_pool->reg[--event_pool->used]; + event_pool->changed = 1; + } unlock: - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_unlock(&event_pool->mutex); out: - return idx; + return idx; } - static int -event_unregister_close_poll (struct event_pool *event_pool, int fd, - int idx_hint) +event_unregister_close_poll(struct event_pool *event_pool, int fd, int idx_hint) { - int ret = -1; + int ret = -1; - ret = event_unregister_poll (event_pool, fd, idx_hint); + ret = event_unregister_poll(event_pool, fd, idx_hint); - sys_close (fd); + sys_close(fd); - return ret; + return ret; } - static int -event_select_on_poll (struct event_pool *event_pool, int fd, int idx_hint, - int poll_in, int poll_out) +event_select_on_poll(struct event_pool *event_pool, int fd, int idx_hint, + int poll_in, int poll_out) { - int idx = -1; + int idx = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - pthread_mutex_lock (&event_pool->mutex); - { - idx = __event_getindex (event_pool, fd, idx_hint); - - if (idx == -1) { - gf_msg ("poll", GF_LOG_ERROR, 0, LG_MSG_INDEX_NOT_FOUND, - "index not found for fd=%d (idx_hint=%d)", - fd, idx_hint); - errno = ENOENT; - goto unlock; - } - - switch (poll_in) { - case 1: - event_pool->reg[idx].events |= POLLIN; - break; - case 0: - event_pool->reg[idx].events &= ~POLLIN; - break; - case -1: - /* do nothing */ - break; - default: - /* TODO: log error */ - break; - } - - switch (poll_out) { - case 1: - event_pool->reg[idx].events |= POLLOUT; - break; - case 0: - event_pool->reg[idx].events &= ~POLLOUT; - break; - case -1: - /* do nothing */ - break; - default: - /* TODO: log error */ - break; - } - - if (poll_in + poll_out > -2) - event_pool->changed = 1; + pthread_mutex_lock(&event_pool->mutex); + { + idx = __event_getindex(event_pool, fd, idx_hint); + + if (idx == -1) { + gf_msg("poll", GF_LOG_ERROR, 0, LG_MSG_INDEX_NOT_FOUND, + "index not found for fd=%d (idx_hint=%d)", fd, idx_hint); + errno = ENOENT; + goto unlock; } + + switch (poll_in) { + case 1: + event_pool->reg[idx].events |= POLLIN; + break; + case 0: + event_pool->reg[idx].events &= ~POLLIN; + break; + case -1: + /* do nothing */ + break; + default: + /* TODO: log error */ + break; + } + + switch (poll_out) { + case 1: + event_pool->reg[idx].events |= POLLOUT; + break; + case 0: + event_pool->reg[idx].events &= ~POLLOUT; + break; + case -1: + /* do nothing */ + break; + default: + /* TODO: log error */ + break; + } + + if (poll_in + poll_out > -2) + event_pool->changed = 1; + } unlock: - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_unlock(&event_pool->mutex); out: - return idx; + return idx; } - static int -event_dispatch_poll_handler (struct event_pool *event_pool, - struct pollfd *ufds, int i) +event_dispatch_poll_handler(struct event_pool *event_pool, struct pollfd *ufds, + int i) { - event_handler_t handler = NULL; - void *data = NULL; - int idx = -1; - int ret = 0; - - handler = NULL; - data = NULL; - - pthread_mutex_lock (&event_pool->mutex); - { - idx = __event_getindex (event_pool, ufds[i].fd, i); - - if (idx == -1) { - gf_msg ("poll", GF_LOG_ERROR, 0, - LG_MSG_INDEX_NOT_FOUND, "index not found for " - "fd=%d (idx_hint=%d)", ufds[i].fd, i); - goto unlock; - } - - handler = event_pool->reg[idx].handler; - data = event_pool->reg[idx].data; + event_handler_t handler = NULL; + void *data = NULL; + int idx = -1; + int ret = 0; + + handler = NULL; + data = NULL; + + pthread_mutex_lock(&event_pool->mutex); + { + idx = __event_getindex(event_pool, ufds[i].fd, i); + + if (idx == -1) { + gf_msg("poll", GF_LOG_ERROR, 0, LG_MSG_INDEX_NOT_FOUND, + "index not found for " + "fd=%d (idx_hint=%d)", + ufds[i].fd, i); + goto unlock; } + + handler = event_pool->reg[idx].handler; + data = event_pool->reg[idx].data; + } unlock: - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_unlock(&event_pool->mutex); - if (handler) - ret = handler (ufds[i].fd, idx, 0, data, - (ufds[i].revents & (POLLIN|POLLPRI)), - (ufds[i].revents & (POLLOUT)), - (ufds[i].revents & (POLLERR|POLLHUP|POLLNVAL))); + if (handler) + ret = handler(ufds[i].fd, idx, 0, data, + (ufds[i].revents & (POLLIN | POLLPRI)), + (ufds[i].revents & (POLLOUT)), + (ufds[i].revents & (POLLERR | POLLHUP | POLLNVAL))); - return ret; + return ret; } - static int -event_dispatch_poll_resize (struct event_pool *event_pool, - struct pollfd *ufds, int size) +event_dispatch_poll_resize(struct event_pool *event_pool, struct pollfd *ufds, + int size) { - int i = 0; - - pthread_mutex_lock (&event_pool->mutex); - { - if (event_pool->changed == 0) { - goto unlock; - } + int i = 0; - if (event_pool->used > event_pool->evcache_size) { - GF_FREE (event_pool->evcache); + pthread_mutex_lock(&event_pool->mutex); + { + if (event_pool->changed == 0) { + goto unlock; + } - event_pool->evcache = ufds = NULL; + if (event_pool->used > event_pool->evcache_size) { + GF_FREE(event_pool->evcache); - event_pool->evcache_size = event_pool->used; + event_pool->evcache = ufds = NULL; - ufds = GF_CALLOC (sizeof (struct pollfd), - event_pool->evcache_size, - gf_common_mt_pollfd); - if (!ufds) - goto unlock; - event_pool->evcache = ufds; - } + event_pool->evcache_size = event_pool->used; - if (ufds == NULL) { - goto unlock; - } + ufds = GF_CALLOC(sizeof(struct pollfd), event_pool->evcache_size, + gf_common_mt_pollfd); + if (!ufds) + goto unlock; + event_pool->evcache = ufds; + } - for (i = 0; i < event_pool->used; i++) { - ufds[i].fd = event_pool->reg[i].fd; - ufds[i].events = event_pool->reg[i].events; - ufds[i].revents = 0; - } + if (ufds == NULL) { + goto unlock; + } - size = i; + for (i = 0; i < event_pool->used; i++) { + ufds[i].fd = event_pool->reg[i].fd; + ufds[i].events = event_pool->reg[i].events; + ufds[i].revents = 0; } + + size = i; + } unlock: - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_unlock(&event_pool->mutex); - return size; + return size; } - static int -event_dispatch_poll (struct event_pool *event_pool) +event_dispatch_poll(struct event_pool *event_pool) { - struct pollfd *ufds = NULL; - int size = 0; - int i = 0; - int ret = -1; + struct pollfd *ufds = NULL; + int size = 0; + int i = 0; + int ret = -1; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + pthread_mutex_lock(&event_pool->mutex); + { + event_pool->activethreadcount = 1; + } + pthread_mutex_unlock(&event_pool->mutex); - pthread_mutex_lock (&event_pool->mutex); + while (1) { + pthread_mutex_lock(&event_pool->mutex); { - event_pool->activethreadcount = 1; + if (event_pool->destroy == 1) { + event_pool->activethreadcount = 0; + pthread_cond_broadcast(&event_pool->cond); + pthread_mutex_unlock(&event_pool->mutex); + return 0; + } } - pthread_mutex_unlock (&event_pool->mutex); - - while (1) { - pthread_mutex_lock (&event_pool->mutex); - { - if (event_pool->destroy == 1) { - event_pool->activethreadcount = 0; - pthread_cond_broadcast (&event_pool->cond); - pthread_mutex_unlock (&event_pool->mutex); - return 0; - } - } - pthread_mutex_unlock (&event_pool->mutex); - - size = event_dispatch_poll_resize (event_pool, ufds, size); - ufds = event_pool->evcache; - - ret = poll (ufds, size, 1); - - if (ret == 0) - /* timeout */ - continue; - - if (ret == -1 && errno == EINTR) - /* sys call */ - continue; - - for (i = 0; i < size; i++) { - if (!ufds[i].revents) - continue; - - event_dispatch_poll_handler (event_pool, ufds, i); - } + pthread_mutex_unlock(&event_pool->mutex); + + size = event_dispatch_poll_resize(event_pool, ufds, size); + ufds = event_pool->evcache; + + ret = poll(ufds, size, 1); + + if (ret == 0) + /* timeout */ + continue; + + if (ret == -1 && errno == EINTR) + /* sys call */ + continue; + + for (i = 0; i < size; i++) { + if (!ufds[i].revents) + continue; + + event_dispatch_poll_handler(event_pool, ufds, i); } + } out: - return -1; + return -1; } int -event_reconfigure_threads_poll (struct event_pool *event_pool, int value) +event_reconfigure_threads_poll(struct event_pool *event_pool, int value) { - /* No-op for poll */ + /* No-op for poll */ - return 0; + return 0; } /* This function is the destructor for the event_pool data structure @@ -514,33 +493,32 @@ event_reconfigure_threads_poll (struct event_pool *event_pool, int value) * else will lead to crashes. */ static int -event_pool_destroy_poll (struct event_pool *event_pool) +event_pool_destroy_poll(struct event_pool *event_pool) { - int ret = 0; + int ret = 0; - ret = sys_close (event_pool->breaker[0]); - if (ret) - return ret; + ret = sys_close(event_pool->breaker[0]); + if (ret) + return ret; - ret = sys_close (event_pool->breaker[1]); - if (ret) - return ret; + ret = sys_close(event_pool->breaker[1]); + if (ret) + return ret; - event_pool->breaker[0] = event_pool->breaker[1] = -1; + event_pool->breaker[0] = event_pool->breaker[1] = -1; - GF_FREE (event_pool->reg); - GF_FREE (event_pool); + GF_FREE(event_pool->reg); + GF_FREE(event_pool); - return ret; + return ret; } struct event_ops event_ops_poll = { - .new = event_pool_new_poll, - .event_register = event_register_poll, - .event_select_on = event_select_on_poll, - .event_unregister = event_unregister_poll, - .event_unregister_close = event_unregister_close_poll, - .event_dispatch = event_dispatch_poll, - .event_reconfigure_threads = event_reconfigure_threads_poll, - .event_pool_destroy = event_pool_destroy_poll -}; + .new = event_pool_new_poll, + .event_register = event_register_poll, + .event_select_on = event_select_on_poll, + .event_unregister = event_unregister_poll, + .event_unregister_close = event_unregister_close_poll, + .event_dispatch = event_dispatch_poll, + .event_reconfigure_threads = event_reconfigure_threads_poll, + .event_pool_destroy = event_pool_destroy_poll}; diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index 2598cd305a8..5b4d43e8650 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -23,173 +23,164 @@ #include "libglusterfs-messages.h" #include "syscall.h" - - struct event_pool * -event_pool_new (int count, int eventthreadcount) +event_pool_new(int count, int eventthreadcount) { - struct event_pool *event_pool = NULL; - extern struct event_ops event_ops_poll; + struct event_pool *event_pool = NULL; + extern struct event_ops event_ops_poll; #ifdef HAVE_SYS_EPOLL_H - extern struct event_ops event_ops_epoll; + extern struct event_ops event_ops_epoll; - event_pool = event_ops_epoll.new (count, eventthreadcount); + event_pool = event_ops_epoll.new(count, eventthreadcount); - if (event_pool) { - event_pool->ops = &event_ops_epoll; - } else { - gf_msg ("event", GF_LOG_WARNING, 0, LG_MSG_FALLBACK_TO_POLL, - "falling back to poll based event handling"); - } + if (event_pool) { + event_pool->ops = &event_ops_epoll; + } else { + gf_msg("event", GF_LOG_WARNING, 0, LG_MSG_FALLBACK_TO_POLL, + "falling back to poll based event handling"); + } #endif - if (!event_pool) { - event_pool = event_ops_poll.new (count, eventthreadcount); + if (!event_pool) { + event_pool = event_ops_poll.new(count, eventthreadcount); - if (event_pool) - event_pool->ops = &event_ops_poll; - } + if (event_pool) + event_pool->ops = &event_ops_poll; + } - return event_pool; + return event_pool; } - int -event_register (struct event_pool *event_pool, int fd, - event_handler_t handler, - void *data, int poll_in, int poll_out) +event_register(struct event_pool *event_pool, int fd, event_handler_t handler, + void *data, int poll_in, int poll_out) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_register (event_pool, fd, handler, data, - poll_in, poll_out); + ret = event_pool->ops->event_register(event_pool, fd, handler, data, + poll_in, poll_out); out: - return ret; + return ret; } - int -event_unregister (struct event_pool *event_pool, int fd, int idx) +event_unregister(struct event_pool *event_pool, int fd, int idx) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_unregister (event_pool, fd, idx); + ret = event_pool->ops->event_unregister(event_pool, fd, idx); out: - return ret; + return ret; } - int -event_unregister_close (struct event_pool *event_pool, int fd, int idx) +event_unregister_close(struct event_pool *event_pool, int fd, int idx) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_unregister_close (event_pool, fd, idx); + ret = event_pool->ops->event_unregister_close(event_pool, fd, idx); out: - return ret; + return ret; } - int -event_select_on (struct event_pool *event_pool, int fd, int idx_hint, - int poll_in, int poll_out) +event_select_on(struct event_pool *event_pool, int fd, int idx_hint, + int poll_in, int poll_out) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_select_on (event_pool, fd, idx_hint, - poll_in, poll_out); + ret = event_pool->ops->event_select_on(event_pool, fd, idx_hint, poll_in, + poll_out); out: - return ret; + return ret; } - int -event_dispatch (struct event_pool *event_pool) +event_dispatch(struct event_pool *event_pool) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - ret = event_pool->ops->event_dispatch (event_pool); - if (ret) - goto out; + ret = event_pool->ops->event_dispatch(event_pool); + if (ret) + goto out; out: - return ret; + return ret; } int -event_reconfigure_threads (struct event_pool *event_pool, int value) +event_reconfigure_threads(struct event_pool *event_pool, int value) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - /* call event refresh function */ - ret = event_pool->ops->event_reconfigure_threads (event_pool, - value); + /* call event refresh function */ + ret = event_pool->ops->event_reconfigure_threads(event_pool, value); out: - return ret; + return ret; } int -event_pool_destroy (struct event_pool *event_pool) +event_pool_destroy(struct event_pool *event_pool) { - int ret = -1; - int destroy = 0, activethreadcount = 0; + int ret = -1; + int destroy = 0, activethreadcount = 0; - GF_VALIDATE_OR_GOTO ("event", event_pool, out); + GF_VALIDATE_OR_GOTO("event", event_pool, out); - pthread_mutex_lock (&event_pool->mutex); - { - destroy = event_pool->destroy; - activethreadcount = event_pool->activethreadcount; - } - pthread_mutex_unlock (&event_pool->mutex); + pthread_mutex_lock(&event_pool->mutex); + { + destroy = event_pool->destroy; + activethreadcount = event_pool->activethreadcount; + } + pthread_mutex_unlock(&event_pool->mutex); - if (!destroy || (activethreadcount > 0)) { - goto out; - } + if (!destroy || (activethreadcount > 0)) { + goto out; + } - ret = event_pool->ops->event_pool_destroy (event_pool); + ret = event_pool->ops->event_pool_destroy(event_pool); out: - return ret; + return ret; } int -poller_destroy_handler (int fd, int idx, int gen, void *data, - int poll_out, int poll_in, int poll_err) +poller_destroy_handler(int fd, int idx, int gen, void *data, int poll_out, + int poll_in, int poll_err) { - struct event_destroy_data *destroy = NULL; - int readfd = -1, ret = -1; - char buf = '\0'; - - destroy = data; - readfd = destroy->readfd; - if (readfd < 0) { - goto out; - } + struct event_destroy_data *destroy = NULL; + int readfd = -1, ret = -1; + char buf = '\0'; - while (sys_read (readfd, &buf, 1) > 0) { - } + destroy = data; + readfd = destroy->readfd; + if (readfd < 0) { + goto out; + } + + while (sys_read(readfd, &buf, 1) > 0) { + } - ret = 0; + ret = 0; out: - event_handled (destroy->pool, fd, idx, gen); + event_handled(destroy->pool, fd, idx, gen); - return ret; + return ret; } /* This function destroys all the poller threads. @@ -204,109 +195,111 @@ out: * threads are destroyed) */ int -event_dispatch_destroy (struct event_pool *event_pool) +event_dispatch_destroy(struct event_pool *event_pool) { - int ret = -1, threadcount = 0; - int fd[2] = {-1}; - int idx = -1; - int flags = 0; - struct timespec sleep_till = {0, }; - struct event_destroy_data data = {0, }; - - GF_VALIDATE_OR_GOTO ("event", event_pool, out); - - ret = pipe (fd); - if (ret < 0) - goto out; - - /* Make the read end of the pipe nonblocking */ - flags = fcntl(fd[0], F_GETFL); - flags |= O_NONBLOCK; - ret = fcntl(fd[0], F_SETFL, flags); - if (ret < 0) - goto out; - - /* Make the write end of the pipe nonblocking */ - flags = fcntl(fd[1], F_GETFL); - flags |= O_NONBLOCK; - ret = fcntl(fd[1], F_SETFL, flags); - if (ret < 0) - goto out; - - data.pool = event_pool; - data.readfd = fd[1]; - - /* From the main thread register an event on the pipe fd[0], - */ - idx = event_register (event_pool, fd[0], poller_destroy_handler, - &data, 1, 0); - if (idx < 0) - goto out; - - /* Enter the destroy mode first, set this before reconfiguring to 0 - * threads, to prevent further reconfigure to thread count > 0. + int ret = -1, threadcount = 0; + int fd[2] = {-1}; + int idx = -1; + int flags = 0; + struct timespec sleep_till = { + 0, + }; + struct event_destroy_data data = { + 0, + }; + + GF_VALIDATE_OR_GOTO("event", event_pool, out); + + ret = pipe(fd); + if (ret < 0) + goto out; + + /* Make the read end of the pipe nonblocking */ + flags = fcntl(fd[0], F_GETFL); + flags |= O_NONBLOCK; + ret = fcntl(fd[0], F_SETFL, flags); + if (ret < 0) + goto out; + + /* Make the write end of the pipe nonblocking */ + flags = fcntl(fd[1], F_GETFL); + flags |= O_NONBLOCK; + ret = fcntl(fd[1], F_SETFL, flags); + if (ret < 0) + goto out; + + data.pool = event_pool; + data.readfd = fd[1]; + + /* From the main thread register an event on the pipe fd[0], + */ + idx = event_register(event_pool, fd[0], poller_destroy_handler, &data, 1, + 0); + if (idx < 0) + goto out; + + /* Enter the destroy mode first, set this before reconfiguring to 0 + * threads, to prevent further reconfigure to thread count > 0. + */ + pthread_mutex_lock(&event_pool->mutex); + { + threadcount = event_pool->eventthreadcount; + event_pool->destroy = 1; + } + pthread_mutex_unlock(&event_pool->mutex); + + ret = event_reconfigure_threads(event_pool, 0); + if (ret < 0) + goto out; + + /* Write something onto the write end of the pipe(fd[1]) so that + * poll wakes up and calls the handler, poller_destroy_handler() + */ + pthread_mutex_lock(&event_pool->mutex); + { + /* Write to pipe(fd[1]) and then wait for 1 second or until + * a poller thread that is dying, broadcasts. Make sure we + * do not loop forever by limiting to 10 retries */ - pthread_mutex_lock (&event_pool->mutex); - { - threadcount = event_pool->eventthreadcount; - event_pool->destroy = 1; + int retry = 0; + + while (event_pool->activethreadcount > 0 && + (retry++ < (threadcount + 10))) { + if (sys_write(fd[1], "dummy", 6) == -1) { + break; + } + sleep_till.tv_sec = time(NULL) + 1; + ret = pthread_cond_timedwait(&event_pool->cond, &event_pool->mutex, + &sleep_till); + if (ret) { + gf_msg_debug("event", 0, + "thread cond-timedwait failed " + "active-thread-count: %d, " + "retry: %d", + event_pool->activethreadcount, retry); + } } - pthread_mutex_unlock (&event_pool->mutex); + } + pthread_mutex_unlock(&event_pool->mutex); - ret = event_reconfigure_threads (event_pool, 0); - if (ret < 0) - goto out; + ret = event_unregister(event_pool, fd[0], idx); - /* Write something onto the write end of the pipe(fd[1]) so that - * poll wakes up and calls the handler, poller_destroy_handler() - */ - pthread_mutex_lock (&event_pool->mutex); - { - /* Write to pipe(fd[1]) and then wait for 1 second or until - * a poller thread that is dying, broadcasts. Make sure we - * do not loop forever by limiting to 10 retries - */ - int retry = 0; - - while (event_pool->activethreadcount > 0 - && (retry++ < (threadcount + 10))) { - if (sys_write (fd[1], "dummy", 6) == -1) { - break; - } - sleep_till.tv_sec = time (NULL) + 1; - ret = pthread_cond_timedwait (&event_pool->cond, - &event_pool->mutex, - &sleep_till); - if (ret) { - gf_msg_debug ("event", 0, - "thread cond-timedwait failed " - "active-thread-count: %d, " - "retry: %d", - event_pool->activethreadcount, - retry); - } - } - } - pthread_mutex_unlock (&event_pool->mutex); - - ret = event_unregister (event_pool, fd[0], idx); - - out: - if (fd[0] != -1) - sys_close (fd[0]); - if (fd[1] != -1) - sys_close (fd[1]); +out: + if (fd[0] != -1) + sys_close(fd[0]); + if (fd[1] != -1) + sys_close(fd[1]); - return ret; + return ret; } int -event_handled (struct event_pool *event_pool, int fd, int idx, int gen) +event_handled(struct event_pool *event_pool, int fd, int idx, int gen) { - int ret = 0; + int ret = 0; - if (event_pool->ops->event_handled) - ret = event_pool->ops->event_handled (event_pool, fd, idx, gen); + if (event_pool->ops->event_handled) + ret = event_pool->ops->event_handled(event_pool, fd, idx, gen); - return ret; + return ret; } diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c index 5a1b4c06e57..b1fa057b81e 100644 --- a/libglusterfs/src/events.c +++ b/libglusterfs/src/events.c @@ -25,112 +25,109 @@ #include "globals.h" #include "events.h" - #define EVENT_HOST "127.0.0.1" #define EVENT_PORT 24009 - int -_gf_event (eventtypes_t event, const char *fmt, ...) +_gf_event(eventtypes_t event, const char *fmt, ...) { - int ret = 0; - int sock = -1; - char *eventstr = NULL; - struct sockaddr_in server; - va_list arguments; - char *msg = NULL; - glusterfs_ctx_t *ctx = NULL; - char *host = NULL; - struct addrinfo hints; - struct addrinfo *result = NULL; - - /* Global context */ - ctx = THIS->ctx; - - if (event < 0 || event >= EVENT_LAST) { - ret = EVENT_ERROR_INVALID_INPUTS; - goto out; - } - - /* Initialize UDP socket */ - sock = socket (AF_INET, SOCK_DGRAM, 0); - if (sock < 0) { - ret = EVENT_ERROR_SOCKET; - goto out; - } - - memset (&hints, 0, sizeof (hints)); - hints.ai_family = AF_UNSPEC; - - /* Get Host name to send message */ - if (ctx && ctx->cmd_args.volfile_server) { - /* If it is client code then volfile_server is set - use that information to push the events. */ - if ((getaddrinfo (ctx->cmd_args.volfile_server, - NULL, &hints, &result)) != 0) { - ret = EVENT_ERROR_RESOLVE; - goto out; - } - - if (get_ip_from_addrinfo (result, &host) == NULL) { - ret = EVENT_ERROR_RESOLVE; - goto out; - } - } else { - /* Localhost, Use the defined IP for localhost */ - host = gf_strdup (EVENT_HOST); + int ret = 0; + int sock = -1; + char *eventstr = NULL; + struct sockaddr_in server; + va_list arguments; + char *msg = NULL; + glusterfs_ctx_t *ctx = NULL; + char *host = NULL; + struct addrinfo hints; + struct addrinfo *result = NULL; + + /* Global context */ + ctx = THIS->ctx; + + if (event < 0 || event >= EVENT_LAST) { + ret = EVENT_ERROR_INVALID_INPUTS; + goto out; + } + + /* Initialize UDP socket */ + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) { + ret = EVENT_ERROR_SOCKET; + goto out; + } + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + + /* Get Host name to send message */ + if (ctx && ctx->cmd_args.volfile_server) { + /* If it is client code then volfile_server is set + use that information to push the events. */ + if ((getaddrinfo(ctx->cmd_args.volfile_server, NULL, &hints, + &result)) != 0) { + ret = EVENT_ERROR_RESOLVE; + goto out; } - /* Socket Configurations */ - server.sin_family = AF_INET; - server.sin_port = htons (EVENT_PORT); - server.sin_addr.s_addr = inet_addr (host); - memset (&server.sin_zero, '\0', sizeof (server.sin_zero)); - - va_start (arguments, fmt); - ret = gf_vasprintf (&msg, fmt, arguments); - va_end (arguments); - - if (ret < 0) { - ret = EVENT_ERROR_INVALID_INPUTS; - goto out; - } - - ret = gf_asprintf (&eventstr, "%u %d %s", - (unsigned)time(NULL), event, msg); - - if (ret <= 0) { - ret = EVENT_ERROR_MSG_FORMAT; - goto out; + if (get_ip_from_addrinfo(result, &host) == NULL) { + ret = EVENT_ERROR_RESOLVE; + goto out; } - - /* Send Message */ - if (sendto (sock, eventstr, strlen (eventstr), - 0, (struct sockaddr *)&server, sizeof (server)) <= 0) { - ret = EVENT_ERROR_SEND; - goto out; - } - - ret = EVENT_SEND_OK; - - out: - if (sock >= 0) { - sys_close (sock); - } - - /* Allocated by gf_vasprintf */ - if (msg) - GF_FREE (msg); - - /* Allocated by gf_asprintf */ - if (eventstr) - GF_FREE (eventstr); - - if (host) - GF_FREE (host); - - if (result) - freeaddrinfo (result); - - return ret; + } else { + /* Localhost, Use the defined IP for localhost */ + host = gf_strdup(EVENT_HOST); + } + + /* Socket Configurations */ + server.sin_family = AF_INET; + server.sin_port = htons(EVENT_PORT); + server.sin_addr.s_addr = inet_addr(host); + memset(&server.sin_zero, '\0', sizeof(server.sin_zero)); + + va_start(arguments, fmt); + ret = gf_vasprintf(&msg, fmt, arguments); + va_end(arguments); + + if (ret < 0) { + ret = EVENT_ERROR_INVALID_INPUTS; + goto out; + } + + ret = gf_asprintf(&eventstr, "%u %d %s", (unsigned)time(NULL), event, msg); + + if (ret <= 0) { + ret = EVENT_ERROR_MSG_FORMAT; + goto out; + } + + /* Send Message */ + if (sendto(sock, eventstr, strlen(eventstr), 0, (struct sockaddr *)&server, + sizeof(server)) <= 0) { + ret = EVENT_ERROR_SEND; + goto out; + } + + ret = EVENT_SEND_OK; + +out: + if (sock >= 0) { + sys_close(sock); + } + + /* Allocated by gf_vasprintf */ + if (msg) + GF_FREE(msg); + + /* Allocated by gf_asprintf */ + if (eventstr) + GF_FREE(eventstr); + + if (host) + GF_FREE(host); + + if (result) + freeaddrinfo(result); + + return ret; } diff --git a/libglusterfs/src/fd-lk.c b/libglusterfs/src/fd-lk.c index e516f64bff6..a6680661be6 100644 --- a/libglusterfs/src/fd-lk.c +++ b/libglusterfs/src/fd-lk.c @@ -13,430 +13,421 @@ #include "libglusterfs-messages.h" int32_t -_fd_lk_delete_lock (fd_lk_ctx_node_t *lock) +_fd_lk_delete_lock(fd_lk_ctx_node_t *lock) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("fd-lk", lock, out); + GF_VALIDATE_OR_GOTO("fd-lk", lock, out); - list_del_init (&lock->next); + list_del_init(&lock->next); - ret = 0; + ret = 0; out: - return ret; + return ret; } int32_t -_fd_lk_destroy_lock (fd_lk_ctx_node_t *lock) +_fd_lk_destroy_lock(fd_lk_ctx_node_t *lock) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("fd-lk", lock, out); + GF_VALIDATE_OR_GOTO("fd-lk", lock, out); - GF_FREE (lock); + GF_FREE(lock); - ret = 0; + ret = 0; out: - return ret; + return ret; } int -_fd_lk_destroy_lock_list (fd_lk_ctx_t *lk_ctx) +_fd_lk_destroy_lock_list(fd_lk_ctx_t *lk_ctx) { - int ret = -1; - fd_lk_ctx_node_t *lk = NULL; - fd_lk_ctx_node_t *tmp = NULL; - - GF_VALIDATE_OR_GOTO ("fd-lk", lk_ctx, out); - - list_for_each_entry_safe (lk, tmp, &lk_ctx->lk_list, next) { - _fd_lk_delete_lock (lk); - _fd_lk_destroy_lock (lk); - } - ret = 0; + int ret = -1; + fd_lk_ctx_node_t *lk = NULL; + fd_lk_ctx_node_t *tmp = NULL; + + GF_VALIDATE_OR_GOTO("fd-lk", lk_ctx, out); + + list_for_each_entry_safe(lk, tmp, &lk_ctx->lk_list, next) + { + _fd_lk_delete_lock(lk); + _fd_lk_destroy_lock(lk); + } + ret = 0; out: - return ret; + return ret; } int -fd_lk_ctx_unref (fd_lk_ctx_t *lk_ctx) +fd_lk_ctx_unref(fd_lk_ctx_t *lk_ctx) { - int ref = -1; + int ref = -1; - GF_VALIDATE_OR_GOTO ("fd-lk", lk_ctx, err); + GF_VALIDATE_OR_GOTO("fd-lk", lk_ctx, err); - ref = GF_ATOMIC_DEC (lk_ctx->ref); - if (ref < 0) - GF_ASSERT (!ref); - if (ref == 0) - _fd_lk_destroy_lock_list (lk_ctx); + ref = GF_ATOMIC_DEC(lk_ctx->ref); + if (ref < 0) + GF_ASSERT(!ref); + if (ref == 0) + _fd_lk_destroy_lock_list(lk_ctx); - if (ref == 0) { - LOCK_DESTROY (&lk_ctx->lock); - GF_FREE (lk_ctx); - } + if (ref == 0) { + LOCK_DESTROY(&lk_ctx->lock); + GF_FREE(lk_ctx); + } - return 0; + return 0; err: - return -1; + return -1; } fd_lk_ctx_t * -fd_lk_ctx_ref (fd_lk_ctx_t *lk_ctx) +fd_lk_ctx_ref(fd_lk_ctx_t *lk_ctx) { - if (!lk_ctx) { - gf_msg_callingfn ("fd-lk", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return NULL; - } + if (!lk_ctx) { + gf_msg_callingfn("fd-lk", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return NULL; + } - GF_ATOMIC_INC (lk_ctx->ref); + GF_ATOMIC_INC(lk_ctx->ref); - return lk_ctx; + return lk_ctx; } fd_lk_ctx_t * -fd_lk_ctx_create () +fd_lk_ctx_create() { - fd_lk_ctx_t *fd_lk_ctx = NULL; + fd_lk_ctx_t *fd_lk_ctx = NULL; - fd_lk_ctx = GF_CALLOC (1, sizeof (fd_lk_ctx_t), - gf_common_mt_fd_lk_ctx_t); - if (!fd_lk_ctx) - goto out; + fd_lk_ctx = GF_CALLOC(1, sizeof(fd_lk_ctx_t), gf_common_mt_fd_lk_ctx_t); + if (!fd_lk_ctx) + goto out; - INIT_LIST_HEAD (&fd_lk_ctx->lk_list); + INIT_LIST_HEAD(&fd_lk_ctx->lk_list); - LOCK_INIT (&fd_lk_ctx->lock); + LOCK_INIT(&fd_lk_ctx->lock); - fd_lk_ctx = fd_lk_ctx_ref (fd_lk_ctx); + fd_lk_ctx = fd_lk_ctx_ref(fd_lk_ctx); out: - return fd_lk_ctx; + return fd_lk_ctx; } int -_fd_lk_insert_lock (fd_lk_ctx_t *lk_ctx, - fd_lk_ctx_node_t *lock) +_fd_lk_insert_lock(fd_lk_ctx_t *lk_ctx, fd_lk_ctx_node_t *lock) { - list_add_tail (&lock->next, &lk_ctx->lk_list); - return 0; + list_add_tail(&lock->next, &lk_ctx->lk_list); + return 0; } static off_t -_fd_lk_get_lock_len (off_t start, off_t end) +_fd_lk_get_lock_len(off_t start, off_t end) { - if (end == LLONG_MAX) - return 0; - else - return (end - start + 1); + if (end == LLONG_MAX) + return 0; + else + return (end - start + 1); } fd_lk_ctx_node_t * -fd_lk_ctx_node_new (int32_t cmd, struct gf_flock *flock) +fd_lk_ctx_node_new(int32_t cmd, struct gf_flock *flock) { - fd_lk_ctx_node_t *new_lock = NULL; + fd_lk_ctx_node_t *new_lock = NULL; - /* TODO: get from mem-pool */ - new_lock = GF_CALLOC (1, sizeof (fd_lk_ctx_node_t), - gf_common_mt_fd_lk_ctx_node_t); - if (!new_lock) - goto out; + /* TODO: get from mem-pool */ + new_lock = GF_CALLOC(1, sizeof(fd_lk_ctx_node_t), + gf_common_mt_fd_lk_ctx_node_t); + if (!new_lock) + goto out; - new_lock->cmd = cmd; + new_lock->cmd = cmd; - if (flock) { - new_lock->fl_type = flock->l_type; - new_lock->fl_start = flock->l_start; + if (flock) { + new_lock->fl_type = flock->l_type; + new_lock->fl_start = flock->l_start; - if (flock->l_len == 0) - new_lock->fl_end = LLONG_MAX; - else - new_lock->fl_end = flock->l_start + flock->l_len - 1; + if (flock->l_len == 0) + new_lock->fl_end = LLONG_MAX; + else + new_lock->fl_end = flock->l_start + flock->l_len - 1; - memcpy (&new_lock->user_flock, flock, - sizeof (struct gf_flock)); - } + memcpy(&new_lock->user_flock, flock, sizeof(struct gf_flock)); + } - INIT_LIST_HEAD (&new_lock->next); + INIT_LIST_HEAD(&new_lock->next); out: - return new_lock; + return new_lock; } int32_t -_fd_lk_delete_unlck_locks (fd_lk_ctx_t *lk_ctx) +_fd_lk_delete_unlck_locks(fd_lk_ctx_t *lk_ctx) { - int32_t ret = -1; - fd_lk_ctx_node_t *tmp = NULL; - fd_lk_ctx_node_t *lk = NULL; + int32_t ret = -1; + fd_lk_ctx_node_t *tmp = NULL; + fd_lk_ctx_node_t *lk = NULL; - GF_VALIDATE_OR_GOTO ("fd-lk", lk_ctx, out); + GF_VALIDATE_OR_GOTO("fd-lk", lk_ctx, out); - list_for_each_entry_safe (lk, tmp, &lk_ctx->lk_list, next) { - if (lk->fl_type == F_UNLCK) { - _fd_lk_delete_lock (lk); - _fd_lk_destroy_lock (lk); - } + list_for_each_entry_safe(lk, tmp, &lk_ctx->lk_list, next) + { + if (lk->fl_type == F_UNLCK) { + _fd_lk_delete_lock(lk); + _fd_lk_destroy_lock(lk); } + } out: - return ret; + return ret; } int -fd_lk_overlap (fd_lk_ctx_node_t *l1, - fd_lk_ctx_node_t *l2) +fd_lk_overlap(fd_lk_ctx_node_t *l1, fd_lk_ctx_node_t *l2) { - if (l1->fl_end >= l2->fl_start && - l2->fl_end >= l1->fl_start) - return 1; + if (l1->fl_end >= l2->fl_start && l2->fl_end >= l1->fl_start) + return 1; - return 0; + return 0; } fd_lk_ctx_node_t * -_fd_lk_add_locks (fd_lk_ctx_node_t *l1, - fd_lk_ctx_node_t *l2) +_fd_lk_add_locks(fd_lk_ctx_node_t *l1, fd_lk_ctx_node_t *l2) { - fd_lk_ctx_node_t *sum = NULL; + fd_lk_ctx_node_t *sum = NULL; - sum = fd_lk_ctx_node_new (0, NULL); - if (!sum) - goto out; + sum = fd_lk_ctx_node_new(0, NULL); + if (!sum) + goto out; - sum->fl_start = min (l1->fl_start, l2->fl_start); - sum->fl_end = max (l1->fl_end, l2->fl_end); + sum->fl_start = min(l1->fl_start, l2->fl_start); + sum->fl_end = max(l1->fl_end, l2->fl_end); - sum->user_flock.l_start = sum->fl_start; - sum->user_flock.l_len = _fd_lk_get_lock_len (sum->fl_start, - sum->fl_end); + sum->user_flock.l_start = sum->fl_start; + sum->user_flock.l_len = _fd_lk_get_lock_len(sum->fl_start, sum->fl_end); out: - return sum; + return sum; } /* Subtract two locks */ struct _values { - fd_lk_ctx_node_t *locks[3]; + fd_lk_ctx_node_t *locks[3]; }; int32_t -_fd_lk_sub_locks (struct _values *v, - fd_lk_ctx_node_t *big, - fd_lk_ctx_node_t *small) +_fd_lk_sub_locks(struct _values *v, fd_lk_ctx_node_t *big, + fd_lk_ctx_node_t *small) { - int32_t ret = -1; - - if ((big->fl_start == small->fl_start) && - (big->fl_end == small->fl_end)) { - /* both edges coincide with big */ - v->locks[0] = fd_lk_ctx_node_new (small->cmd, NULL); - if (!v->locks[0]) - goto out; - - memcpy (v->locks[0], big, sizeof (fd_lk_ctx_node_t)); - - v->locks[0]->fl_type = small->fl_type; - v->locks[0]->user_flock.l_type = small->fl_type; - } else if ((small->fl_start > big->fl_start) && - (small->fl_end < big->fl_end)) { - /* small lock is completely inside big lock, - break it down into 3 different locks. */ - v->locks[0] = fd_lk_ctx_node_new (big->cmd, NULL); - if (!v->locks[0]) - goto out; - - v->locks[1] = fd_lk_ctx_node_new (small->cmd, NULL); - if (!v->locks[1]) - goto out; - - v->locks[2] = fd_lk_ctx_node_new (big->cmd, NULL); - if (!v->locks[2]) - goto out; - - memcpy (v->locks[0], big, sizeof (fd_lk_ctx_node_t)); - v->locks[0]->fl_end = small->fl_start - 1; - v->locks[0]->user_flock.l_len = - _fd_lk_get_lock_len (v->locks[0]->fl_start, - v->locks[0]->fl_end); - - memcpy (v->locks[1], small, sizeof (fd_lk_ctx_node_t)); - - memcpy (v->locks[2], big, sizeof (fd_lk_ctx_node_t)); - v->locks[2]->fl_start = small->fl_end + 1; - v->locks[2]->user_flock.l_len = - _fd_lk_get_lock_len (v->locks[2]->fl_start, - v->locks[2]->fl_end); - } else if (small->fl_start == big->fl_start) { - /* One of the ends co-incide, break the - locks into two separate parts */ - v->locks[0] = fd_lk_ctx_node_new (small->cmd, NULL); - if (!v->locks[0]) - goto out; - - v->locks[1] = fd_lk_ctx_node_new (big->cmd, NULL); - if (!v->locks[1]) - goto out; - - memcpy (v->locks[0], small, sizeof (fd_lk_ctx_node_t)); - - memcpy (v->locks[1], big, sizeof (fd_lk_ctx_node_t)); - v->locks[1]->fl_start = small->fl_end + 1; - v->locks[1]->user_flock.l_start = small->fl_end + 1; - } else if (small->fl_end == big->fl_end) { - /* One of the ends co-incide, break the - locks into two separate parts */ - v->locks[0] = fd_lk_ctx_node_new (small->cmd, NULL); - if (!v->locks[0]) - goto out; - - v->locks[1] = fd_lk_ctx_node_new (big->cmd, NULL); - if (!v->locks[1]) - goto out; - - memcpy (v->locks[0], big, sizeof (fd_lk_ctx_node_t)); - v->locks[0]->fl_end = small->fl_start - 1; - v->locks[0]->user_flock.l_len = - _fd_lk_get_lock_len (v->locks[0]->fl_start, - v->locks[0]->fl_end); - - memcpy (v->locks[1], small, sizeof (fd_lk_ctx_node_t)); - } else { - /* We should never come to this case */ - GF_ASSERT (!"Invalid case"); - } - ret = 0; + int32_t ret = -1; + + if ((big->fl_start == small->fl_start) && (big->fl_end == small->fl_end)) { + /* both edges coincide with big */ + v->locks[0] = fd_lk_ctx_node_new(small->cmd, NULL); + if (!v->locks[0]) + goto out; + + memcpy(v->locks[0], big, sizeof(fd_lk_ctx_node_t)); + + v->locks[0]->fl_type = small->fl_type; + v->locks[0]->user_flock.l_type = small->fl_type; + } else if ((small->fl_start > big->fl_start) && + (small->fl_end < big->fl_end)) { + /* small lock is completely inside big lock, + break it down into 3 different locks. */ + v->locks[0] = fd_lk_ctx_node_new(big->cmd, NULL); + if (!v->locks[0]) + goto out; + + v->locks[1] = fd_lk_ctx_node_new(small->cmd, NULL); + if (!v->locks[1]) + goto out; + + v->locks[2] = fd_lk_ctx_node_new(big->cmd, NULL); + if (!v->locks[2]) + goto out; + + memcpy(v->locks[0], big, sizeof(fd_lk_ctx_node_t)); + v->locks[0]->fl_end = small->fl_start - 1; + v->locks[0]->user_flock.l_len = _fd_lk_get_lock_len( + v->locks[0]->fl_start, v->locks[0]->fl_end); + + memcpy(v->locks[1], small, sizeof(fd_lk_ctx_node_t)); + + memcpy(v->locks[2], big, sizeof(fd_lk_ctx_node_t)); + v->locks[2]->fl_start = small->fl_end + 1; + v->locks[2]->user_flock.l_len = _fd_lk_get_lock_len( + v->locks[2]->fl_start, v->locks[2]->fl_end); + } else if (small->fl_start == big->fl_start) { + /* One of the ends co-incide, break the + locks into two separate parts */ + v->locks[0] = fd_lk_ctx_node_new(small->cmd, NULL); + if (!v->locks[0]) + goto out; + + v->locks[1] = fd_lk_ctx_node_new(big->cmd, NULL); + if (!v->locks[1]) + goto out; + + memcpy(v->locks[0], small, sizeof(fd_lk_ctx_node_t)); + + memcpy(v->locks[1], big, sizeof(fd_lk_ctx_node_t)); + v->locks[1]->fl_start = small->fl_end + 1; + v->locks[1]->user_flock.l_start = small->fl_end + 1; + } else if (small->fl_end == big->fl_end) { + /* One of the ends co-incide, break the + locks into two separate parts */ + v->locks[0] = fd_lk_ctx_node_new(small->cmd, NULL); + if (!v->locks[0]) + goto out; + + v->locks[1] = fd_lk_ctx_node_new(big->cmd, NULL); + if (!v->locks[1]) + goto out; + + memcpy(v->locks[0], big, sizeof(fd_lk_ctx_node_t)); + v->locks[0]->fl_end = small->fl_start - 1; + v->locks[0]->user_flock.l_len = _fd_lk_get_lock_len( + v->locks[0]->fl_start, v->locks[0]->fl_end); + + memcpy(v->locks[1], small, sizeof(fd_lk_ctx_node_t)); + } else { + /* We should never come to this case */ + GF_ASSERT(!"Invalid case"); + } + ret = 0; out: - return ret; + return ret; } static void -_fd_lk_insert_and_merge (fd_lk_ctx_t *lk_ctx, - fd_lk_ctx_node_t *lock) +_fd_lk_insert_and_merge(fd_lk_ctx_t *lk_ctx, fd_lk_ctx_node_t *lock) { - int32_t ret = -1; - int32_t i = 0; - fd_lk_ctx_node_t *entry = NULL; - fd_lk_ctx_node_t *t = NULL; - fd_lk_ctx_node_t *sum = NULL; - struct _values v = {.locks = {0, 0, 0 }}; - - list_for_each_entry_safe (entry, t, &lk_ctx->lk_list, next) { - if (!fd_lk_overlap (entry, lock)) - continue; - - if (entry->fl_type == lock->fl_type) { - sum = _fd_lk_add_locks (entry, lock); - if (!sum) - return; - sum->fl_type = entry->fl_type; - sum->user_flock.l_type = entry->fl_type; - _fd_lk_delete_lock (entry); - _fd_lk_destroy_lock (entry); - _fd_lk_destroy_lock (lock); - _fd_lk_insert_and_merge (lk_ctx, sum); - return; - } else { - sum = _fd_lk_add_locks (entry, lock); - sum->fl_type = lock->fl_type; - sum->user_flock.l_type = lock->fl_type; - ret = _fd_lk_sub_locks (&v, sum, lock); - if (ret) - return; - _fd_lk_delete_lock (entry); - _fd_lk_destroy_lock (entry); - - _fd_lk_delete_lock (lock); - _fd_lk_destroy_lock (lock); - - _fd_lk_destroy_lock (sum); - - for (i = 0; i < 3; i++) { - if (!v.locks[i]) - continue; - - INIT_LIST_HEAD (&v.locks[i]->next); - _fd_lk_insert_and_merge (lk_ctx, v.locks[i]); - } - _fd_lk_delete_unlck_locks (lk_ctx); - return; - } - } - - /* no conflicts, so just insert */ - if (lock->fl_type != F_UNLCK) { - _fd_lk_insert_lock (lk_ctx, lock); + int32_t ret = -1; + int32_t i = 0; + fd_lk_ctx_node_t *entry = NULL; + fd_lk_ctx_node_t *t = NULL; + fd_lk_ctx_node_t *sum = NULL; + struct _values v = {.locks = {0, 0, 0}}; + + list_for_each_entry_safe(entry, t, &lk_ctx->lk_list, next) + { + if (!fd_lk_overlap(entry, lock)) + continue; + + if (entry->fl_type == lock->fl_type) { + sum = _fd_lk_add_locks(entry, lock); + if (!sum) + return; + sum->fl_type = entry->fl_type; + sum->user_flock.l_type = entry->fl_type; + _fd_lk_delete_lock(entry); + _fd_lk_destroy_lock(entry); + _fd_lk_destroy_lock(lock); + _fd_lk_insert_and_merge(lk_ctx, sum); + return; } else { - _fd_lk_destroy_lock (lock); + sum = _fd_lk_add_locks(entry, lock); + sum->fl_type = lock->fl_type; + sum->user_flock.l_type = lock->fl_type; + ret = _fd_lk_sub_locks(&v, sum, lock); + if (ret) + return; + _fd_lk_delete_lock(entry); + _fd_lk_destroy_lock(entry); + + _fd_lk_delete_lock(lock); + _fd_lk_destroy_lock(lock); + + _fd_lk_destroy_lock(sum); + + for (i = 0; i < 3; i++) { + if (!v.locks[i]) + continue; + + INIT_LIST_HEAD(&v.locks[i]->next); + _fd_lk_insert_and_merge(lk_ctx, v.locks[i]); + } + _fd_lk_delete_unlck_locks(lk_ctx); + return; } + } + + /* no conflicts, so just insert */ + if (lock->fl_type != F_UNLCK) { + _fd_lk_insert_lock(lk_ctx, lock); + } else { + _fd_lk_destroy_lock(lock); + } } static void -print_lock_list (fd_lk_ctx_t *lk_ctx) +print_lock_list(fd_lk_ctx_t *lk_ctx) { - fd_lk_ctx_node_t *lk = NULL; - - gf_msg_debug ("fd-lk", 0, "lock list:"); - - list_for_each_entry (lk, &lk_ctx->lk_list, next) - gf_msg_debug ("fd-lk", 0, "owner = %s, cmd = %s fl_type = %s," - " fs_start = %"PRId64", fs_end = %"PRId64", " - "user_flock: l_type = %s, l_start = %"PRId64", " - "l_len = %"PRId64", ", - lkowner_utoa (&lk->user_flock.l_owner), - get_lk_cmd (lk->cmd), get_lk_type (lk->fl_type), - lk->fl_start, lk->fl_end, - get_lk_type (lk->user_flock.l_type), - lk->user_flock.l_start, lk->user_flock.l_len); + fd_lk_ctx_node_t *lk = NULL; + + gf_msg_debug("fd-lk", 0, "lock list:"); + + list_for_each_entry(lk, &lk_ctx->lk_list, next) + gf_msg_debug("fd-lk", 0, + "owner = %s, cmd = %s fl_type = %s," + " fs_start = %" PRId64 ", fs_end = %" PRId64 + ", " + "user_flock: l_type = %s, l_start = %" PRId64 + ", " + "l_len = %" PRId64 ", ", + lkowner_utoa(&lk->user_flock.l_owner), get_lk_cmd(lk->cmd), + get_lk_type(lk->fl_type), lk->fl_start, lk->fl_end, + get_lk_type(lk->user_flock.l_type), lk->user_flock.l_start, + lk->user_flock.l_len); } int -fd_lk_insert_and_merge (fd_t *fd, int32_t cmd, - struct gf_flock *flock) +fd_lk_insert_and_merge(fd_t *fd, int32_t cmd, struct gf_flock *flock) { - int32_t ret = -1; - fd_lk_ctx_t *lk_ctx = NULL; - fd_lk_ctx_node_t *lk = NULL; - - GF_VALIDATE_OR_GOTO ("fd-lk", fd, out); - GF_VALIDATE_OR_GOTO ("fd-lk", flock, out); - - lk_ctx = fd_lk_ctx_ref (fd->lk_ctx); - lk = fd_lk_ctx_node_new (cmd, flock); - - gf_msg_debug ("fd-lk", 0, "new lock request: owner = %s, fl_type = %s" - ", fs_start = %"PRId64", fs_end = %"PRId64", user_flock:" - " l_type = %s, l_start = %"PRId64", l_len = %"PRId64, - lkowner_utoa (&flock->l_owner), - get_lk_type (lk->fl_type), lk->fl_start, lk->fl_end, - get_lk_type (lk->user_flock.l_type), - lk->user_flock.l_start, lk->user_flock.l_len); - - LOCK (&lk_ctx->lock); - { - _fd_lk_insert_and_merge (lk_ctx, lk); - print_lock_list (lk_ctx); - } - UNLOCK (&lk_ctx->lock); - - fd_lk_ctx_unref (lk_ctx); - - ret = 0; + int32_t ret = -1; + fd_lk_ctx_t *lk_ctx = NULL; + fd_lk_ctx_node_t *lk = NULL; + + GF_VALIDATE_OR_GOTO("fd-lk", fd, out); + GF_VALIDATE_OR_GOTO("fd-lk", flock, out); + + lk_ctx = fd_lk_ctx_ref(fd->lk_ctx); + lk = fd_lk_ctx_node_new(cmd, flock); + + gf_msg_debug("fd-lk", 0, + "new lock request: owner = %s, fl_type = %s" + ", fs_start = %" PRId64 ", fs_end = %" PRId64 + ", user_flock:" + " l_type = %s, l_start = %" PRId64 ", l_len = %" PRId64, + lkowner_utoa(&flock->l_owner), get_lk_type(lk->fl_type), + lk->fl_start, lk->fl_end, get_lk_type(lk->user_flock.l_type), + lk->user_flock.l_start, lk->user_flock.l_len); + + LOCK(&lk_ctx->lock); + { + _fd_lk_insert_and_merge(lk_ctx, lk); + print_lock_list(lk_ctx); + } + UNLOCK(&lk_ctx->lock); + + fd_lk_ctx_unref(lk_ctx); + + ret = 0; out: - return ret; + return ret; } - gf_boolean_t -fd_lk_ctx_empty (fd_lk_ctx_t *lk_ctx) +fd_lk_ctx_empty(fd_lk_ctx_t *lk_ctx) { - gf_boolean_t verdict = _gf_true; + gf_boolean_t verdict = _gf_true; - if (!lk_ctx) - return _gf_true; + if (!lk_ctx) + return _gf_true; - LOCK (&lk_ctx->lock); - { - verdict = list_empty (&lk_ctx->lk_list); - } - UNLOCK (&lk_ctx->lock); + LOCK(&lk_ctx->lock); + { + verdict = list_empty(&lk_ctx->lk_list); + } + UNLOCK(&lk_ctx->lock); - return verdict; + return verdict; } diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index ee14dc8fe43..d26b7097fd4 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -14,1218 +14,1173 @@ #include "statedump.h" #include "libglusterfs-messages.h" - static int -gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr); - +gf_fd_fdtable_expand(fdtable_t *fdtable, uint32_t nr); fd_t * -__fd_ref (fd_t *fd); +__fd_ref(fd_t *fd); static int -gf_fd_chain_fd_entries (fdentry_t *entries, uint32_t startidx, - uint32_t endcount) +gf_fd_chain_fd_entries(fdentry_t *entries, uint32_t startidx, uint32_t endcount) { - uint32_t i = 0; + uint32_t i = 0; - if (!entries) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!entries"); - return -1; - } + if (!entries) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!entries"); + return -1; + } - /* Chain only till the second to last entry because we want to - * ensure that the last entry has GF_FDTABLE_END. - */ - for (i = startidx; i < (endcount - 1); i++) - entries[i].next_free = i + 1; + /* Chain only till the second to last entry because we want to + * ensure that the last entry has GF_FDTABLE_END. + */ + for (i = startidx; i < (endcount - 1); i++) + entries[i].next_free = i + 1; - /* i has already been incremented up to the last entry. */ - entries[i].next_free = GF_FDTABLE_END; + /* i has already been incremented up to the last entry. */ + entries[i].next_free = GF_FDTABLE_END; - return 0; + return 0; } - static int -gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) +gf_fd_fdtable_expand(fdtable_t *fdtable, uint32_t nr) { - fdentry_t *oldfds = NULL; - uint32_t oldmax_fds = -1; - int ret = -1; - - if (fdtable == NULL || nr > UINT32_MAX) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - ret = EINVAL; - goto out; - } - - nr /= (1024 / sizeof (fdentry_t)); - nr = gf_roundup_next_power_of_two (nr + 1); - nr *= (1024 / sizeof (fdentry_t)); - - oldfds = fdtable->fdentries; - oldmax_fds = fdtable->max_fds; - - fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t), - gf_common_mt_fdentry_t); - if (!fdtable->fdentries) { - ret = ENOMEM; - goto out; - } - fdtable->max_fds = nr; - - if (oldfds) { - uint32_t cpy = oldmax_fds * sizeof (fdentry_t); - memcpy (fdtable->fdentries, oldfds, cpy); - } - - gf_fd_chain_fd_entries (fdtable->fdentries, oldmax_fds, - fdtable->max_fds); - - /* Now that expansion is done, we must update the fd list - * head pointer so that the fd allocation functions can continue - * using the expanded table. - */ - fdtable->first_free = oldmax_fds; - GF_FREE (oldfds); - ret = 0; + fdentry_t *oldfds = NULL; + uint32_t oldmax_fds = -1; + int ret = -1; + + if (fdtable == NULL || nr > UINT32_MAX) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + ret = EINVAL; + goto out; + } + + nr /= (1024 / sizeof(fdentry_t)); + nr = gf_roundup_next_power_of_two(nr + 1); + nr *= (1024 / sizeof(fdentry_t)); + + oldfds = fdtable->fdentries; + oldmax_fds = fdtable->max_fds; + + fdtable->fdentries = GF_CALLOC(nr, sizeof(fdentry_t), + gf_common_mt_fdentry_t); + if (!fdtable->fdentries) { + ret = ENOMEM; + goto out; + } + fdtable->max_fds = nr; + + if (oldfds) { + uint32_t cpy = oldmax_fds * sizeof(fdentry_t); + memcpy(fdtable->fdentries, oldfds, cpy); + } + + gf_fd_chain_fd_entries(fdtable->fdentries, oldmax_fds, fdtable->max_fds); + + /* Now that expansion is done, we must update the fd list + * head pointer so that the fd allocation functions can continue + * using the expanded table. + */ + fdtable->first_free = oldmax_fds; + GF_FREE(oldfds); + ret = 0; out: - return ret; + return ret; } - fdtable_t * -gf_fd_fdtable_alloc (void) +gf_fd_fdtable_alloc(void) { - fdtable_t *fdtable = NULL; + fdtable_t *fdtable = NULL; - fdtable = GF_CALLOC (1, sizeof (*fdtable), gf_common_mt_fdtable_t); - if (!fdtable) - return NULL; + fdtable = GF_CALLOC(1, sizeof(*fdtable), gf_common_mt_fdtable_t); + if (!fdtable) + return NULL; - pthread_rwlock_init (&fdtable->lock, NULL); + pthread_rwlock_init(&fdtable->lock, NULL); - pthread_rwlock_wrlock (&fdtable->lock); - { - gf_fd_fdtable_expand (fdtable, 0); - } - pthread_rwlock_unlock (&fdtable->lock); + pthread_rwlock_wrlock(&fdtable->lock); + { + gf_fd_fdtable_expand(fdtable, 0); + } + pthread_rwlock_unlock(&fdtable->lock); - return fdtable; + return fdtable; } - static fdentry_t * -__gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count) +__gf_fd_fdtable_get_all_fds(fdtable_t *fdtable, uint32_t *count) { - fdentry_t *fdentries = NULL; + fdentry_t *fdentries = NULL; - if (count == NULL) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!count"); - goto out; - } + if (count == NULL) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!count"); + goto out; + } - fdentries = fdtable->fdentries; - fdtable->fdentries = GF_CALLOC (fdtable->max_fds, sizeof (fdentry_t), - gf_common_mt_fdentry_t); - gf_fd_chain_fd_entries (fdtable->fdentries, 0, fdtable->max_fds); - *count = fdtable->max_fds; + fdentries = fdtable->fdentries; + fdtable->fdentries = GF_CALLOC(fdtable->max_fds, sizeof(fdentry_t), + gf_common_mt_fdentry_t); + gf_fd_chain_fd_entries(fdtable->fdentries, 0, fdtable->max_fds); + *count = fdtable->max_fds; out: - return fdentries; + return fdentries; } - fdentry_t * -gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count) +gf_fd_fdtable_get_all_fds(fdtable_t *fdtable, uint32_t *count) { - fdentry_t *entries = NULL; - - if (fdtable) { - pthread_rwlock_wrlock (&fdtable->lock); - { - entries = __gf_fd_fdtable_get_all_fds (fdtable, count); - } - pthread_rwlock_unlock (&fdtable->lock); + fdentry_t *entries = NULL; + + if (fdtable) { + pthread_rwlock_wrlock(&fdtable->lock); + { + entries = __gf_fd_fdtable_get_all_fds(fdtable, count); } + pthread_rwlock_unlock(&fdtable->lock); + } - return entries; + return entries; } - static fdentry_t * -__gf_fd_fdtable_copy_all_fds (fdtable_t *fdtable, uint32_t *count) +__gf_fd_fdtable_copy_all_fds(fdtable_t *fdtable, uint32_t *count) { - fdentry_t *fdentries = NULL; - int i = 0; + fdentry_t *fdentries = NULL; + int i = 0; - if (count == NULL) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!count"); - goto out; - } + if (count == NULL) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!count"); + goto out; + } - fdentries = GF_CALLOC (fdtable->max_fds, sizeof (fdentry_t), - gf_common_mt_fdentry_t); - if (fdentries == NULL) { - goto out; - } + fdentries = GF_CALLOC(fdtable->max_fds, sizeof(fdentry_t), + gf_common_mt_fdentry_t); + if (fdentries == NULL) { + goto out; + } - *count = fdtable->max_fds; + *count = fdtable->max_fds; - for (i = 0; i < fdtable->max_fds; i++) { - if (fdtable->fdentries[i].fd != NULL) { - fdentries[i].fd = fd_ref (fdtable->fdentries[i].fd); - } + for (i = 0; i < fdtable->max_fds; i++) { + if (fdtable->fdentries[i].fd != NULL) { + fdentries[i].fd = fd_ref(fdtable->fdentries[i].fd); } + } out: - return fdentries; + return fdentries; } - fdentry_t * -gf_fd_fdtable_copy_all_fds (fdtable_t *fdtable, uint32_t *count) +gf_fd_fdtable_copy_all_fds(fdtable_t *fdtable, uint32_t *count) { - fdentry_t *entries = NULL; - - if (fdtable) { - pthread_rwlock_rdlock (&fdtable->lock); - { - entries = __gf_fd_fdtable_copy_all_fds (fdtable, count); - } - pthread_rwlock_unlock (&fdtable->lock); + fdentry_t *entries = NULL; + + if (fdtable) { + pthread_rwlock_rdlock(&fdtable->lock); + { + entries = __gf_fd_fdtable_copy_all_fds(fdtable, count); } + pthread_rwlock_unlock(&fdtable->lock); + } - return entries; + return entries; } - void -gf_fd_fdtable_destroy (fdtable_t *fdtable) +gf_fd_fdtable_destroy(fdtable_t *fdtable) { - struct list_head list = {0, }; - fd_t *fd = NULL; - fdentry_t *fdentries = NULL; - uint32_t fd_count = 0; - int32_t i = 0; - - INIT_LIST_HEAD (&list); - - if (!fdtable) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!fdtable"); - return; - } - - pthread_rwlock_wrlock (&fdtable->lock); - { - fdentries = __gf_fd_fdtable_get_all_fds (fdtable, &fd_count); - GF_FREE (fdtable->fdentries); - } - pthread_rwlock_unlock (&fdtable->lock); - - if (fdentries != NULL) { - for (i = 0; i < fd_count; i++) { - fd = fdentries[i].fd; - if (fd != NULL) { - fd_unref (fd); - } - } - - GF_FREE (fdentries); - pthread_rwlock_destroy (&fdtable->lock); - GF_FREE (fdtable); - } + struct list_head list = { + 0, + }; + fd_t *fd = NULL; + fdentry_t *fdentries = NULL; + uint32_t fd_count = 0; + int32_t i = 0; + + INIT_LIST_HEAD(&list); + + if (!fdtable) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!fdtable"); + return; + } + + pthread_rwlock_wrlock(&fdtable->lock); + { + fdentries = __gf_fd_fdtable_get_all_fds(fdtable, &fd_count); + GF_FREE(fdtable->fdentries); + } + pthread_rwlock_unlock(&fdtable->lock); + + if (fdentries != NULL) { + for (i = 0; i < fd_count; i++) { + fd = fdentries[i].fd; + if (fd != NULL) { + fd_unref(fd); + } + } + + GF_FREE(fdentries); + pthread_rwlock_destroy(&fdtable->lock); + GF_FREE(fdtable); + } } - int -gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr) +gf_fd_unused_get(fdtable_t *fdtable, fd_t *fdptr) { - int32_t fd = -1; - fdentry_t *fde = NULL; - int error; - int alloc_attempts = 0; - - if (fdtable == NULL || fdptr == NULL) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return EINVAL; - } - - pthread_rwlock_wrlock (&fdtable->lock); - { - fd_alloc_try_again: - if (fdtable->first_free != GF_FDTABLE_END) { - fde = &fdtable->fdentries[fdtable->first_free]; - fd = fdtable->first_free; - fdtable->first_free = fde->next_free; - fde->next_free = GF_FDENTRY_ALLOCATED; - fde->fd = fdptr; - } else { - /* If this is true, there is something - * seriously wrong with our data structures. - */ - if (alloc_attempts >= 2) { - gf_msg ("fd", GF_LOG_ERROR, 0, - LG_MSG_EXPAND_FD_TABLE_FAILED, - "multiple attempts to expand fd table" - " have failed."); - goto out; - } - error = gf_fd_fdtable_expand (fdtable, - fdtable->max_fds + 1); - if (error) { - gf_msg ("fd", GF_LOG_ERROR, error, - LG_MSG_EXPAND_FD_TABLE_FAILED, - "Cannot expand fdtable"); - goto out; - } - ++alloc_attempts; - /* At this point, the table stands expanded - * with the first_free referring to the first - * free entry in the new set of fdentries that - * have just been allocated. That means, the - * above logic should just work. - */ - goto fd_alloc_try_again; - } - } + int32_t fd = -1; + fdentry_t *fde = NULL; + int error; + int alloc_attempts = 0; + + if (fdtable == NULL || fdptr == NULL) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return EINVAL; + } + + pthread_rwlock_wrlock(&fdtable->lock); + { + fd_alloc_try_again: + if (fdtable->first_free != GF_FDTABLE_END) { + fde = &fdtable->fdentries[fdtable->first_free]; + fd = fdtable->first_free; + fdtable->first_free = fde->next_free; + fde->next_free = GF_FDENTRY_ALLOCATED; + fde->fd = fdptr; + } else { + /* If this is true, there is something + * seriously wrong with our data structures. + */ + if (alloc_attempts >= 2) { + gf_msg("fd", GF_LOG_ERROR, 0, LG_MSG_EXPAND_FD_TABLE_FAILED, + "multiple attempts to expand fd table" + " have failed."); + goto out; + } + error = gf_fd_fdtable_expand(fdtable, fdtable->max_fds + 1); + if (error) { + gf_msg("fd", GF_LOG_ERROR, error, LG_MSG_EXPAND_FD_TABLE_FAILED, + "Cannot expand fdtable"); + goto out; + } + ++alloc_attempts; + /* At this point, the table stands expanded + * with the first_free referring to the first + * free entry in the new set of fdentries that + * have just been allocated. That means, the + * above logic should just work. + */ + goto fd_alloc_try_again; + } + } out: - pthread_rwlock_unlock (&fdtable->lock); + pthread_rwlock_unlock(&fdtable->lock); - return fd; + return fd; } - void -gf_fd_put (fdtable_t *fdtable, int32_t fd) +gf_fd_put(fdtable_t *fdtable, int32_t fd) { - fd_t *fdptr = NULL; - fdentry_t *fde = NULL; + fd_t *fdptr = NULL; + fdentry_t *fde = NULL; - if (fd == GF_ANON_FD_NO) - return; - - if (fdtable == NULL || fd < 0) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return; - } + if (fd == GF_ANON_FD_NO) + return; - if (!(fd < fdtable->max_fds)) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return; - } + if (fdtable == NULL || fd < 0) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return; + } - pthread_rwlock_wrlock (&fdtable->lock); - { - fde = &fdtable->fdentries[fd]; - /* If the entry is not allocated, put operation must return - * without doing anything. - * This has the potential of masking out any bugs in a user of - * fd that ends up calling gf_fd_put twice for the same fd or - * for an unallocated fd, but it is a price we have to pay for - * ensuring sanity of our fd-table. - */ - if (fde->next_free != GF_FDENTRY_ALLOCATED) - goto unlock_out; - fdptr = fde->fd; - fde->fd = NULL; - fde->next_free = fdtable->first_free; - fdtable->first_free = fd; - } + if (!(fd < fdtable->max_fds)) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return; + } + + pthread_rwlock_wrlock(&fdtable->lock); + { + fde = &fdtable->fdentries[fd]; + /* If the entry is not allocated, put operation must return + * without doing anything. + * This has the potential of masking out any bugs in a user of + * fd that ends up calling gf_fd_put twice for the same fd or + * for an unallocated fd, but it is a price we have to pay for + * ensuring sanity of our fd-table. + */ + if (fde->next_free != GF_FDENTRY_ALLOCATED) + goto unlock_out; + fdptr = fde->fd; + fde->fd = NULL; + fde->next_free = fdtable->first_free; + fdtable->first_free = fd; + } unlock_out: - pthread_rwlock_unlock (&fdtable->lock); + pthread_rwlock_unlock(&fdtable->lock); - if (fdptr) { - fd_unref (fdptr); - } + if (fdptr) { + fd_unref(fdptr); + } } - void -gf_fdptr_put (fdtable_t *fdtable, fd_t *fd) +gf_fdptr_put(fdtable_t *fdtable, fd_t *fd) { - fdentry_t *fde = NULL; - int32_t i = 0; + fdentry_t *fde = NULL; + int32_t i = 0; + + if ((fdtable == NULL) || (fd == NULL)) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return; + } - if ((fdtable == NULL) || (fd == NULL)) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return; + pthread_rwlock_wrlock(&fdtable->lock); + { + for (i = 0; i < fdtable->max_fds; i++) { + if (fdtable->fdentries[i].fd == fd) { + fde = &fdtable->fdentries[i]; + break; + } } - pthread_rwlock_wrlock (&fdtable->lock); - { - for (i = 0; i < fdtable->max_fds; i++) { - if (fdtable->fdentries[i].fd == fd) { - fde = &fdtable->fdentries[i]; - break; - } - } - - if (fde == NULL) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, 0, - LG_MSG_FD_NOT_FOUND_IN_FDTABLE, - "fd (%p) is not present in fdtable", - fd); - goto unlock_out; - } - - /* If the entry is not allocated, put operation must return - * without doing anything. - * This has the potential of masking out any bugs in a user of - * fd that ends up calling gf_fd_put twice for the same fd or - * for an unallocated fd, but it is a price we have to pay for - * ensuring sanity of our fd-table. - */ - if (fde->next_free != GF_FDENTRY_ALLOCATED) - goto unlock_out; - fde->fd = NULL; - fde->next_free = fdtable->first_free; - fdtable->first_free = i; + if (fde == NULL) { + gf_msg_callingfn("fd", GF_LOG_WARNING, 0, + LG_MSG_FD_NOT_FOUND_IN_FDTABLE, + "fd (%p) is not present in fdtable", fd); + goto unlock_out; } + + /* If the entry is not allocated, put operation must return + * without doing anything. + * This has the potential of masking out any bugs in a user of + * fd that ends up calling gf_fd_put twice for the same fd or + * for an unallocated fd, but it is a price we have to pay for + * ensuring sanity of our fd-table. + */ + if (fde->next_free != GF_FDENTRY_ALLOCATED) + goto unlock_out; + fde->fd = NULL; + fde->next_free = fdtable->first_free; + fdtable->first_free = i; + } unlock_out: - pthread_rwlock_unlock (&fdtable->lock); + pthread_rwlock_unlock(&fdtable->lock); - if ((fd != NULL) && (fde != NULL)) { - fd_unref (fd); - } + if ((fd != NULL) && (fde != NULL)) { + fd_unref(fd); + } } - fd_t * -gf_fd_fdptr_get (fdtable_t *fdtable, int64_t fd) +gf_fd_fdptr_get(fdtable_t *fdtable, int64_t fd) { - fd_t *fdptr = NULL; + fd_t *fdptr = NULL; - if (fdtable == NULL || fd < 0) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - errno = EINVAL; - return NULL; - } + if (fdtable == NULL || fd < 0) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + errno = EINVAL; + return NULL; + } - if (!(fd < fdtable->max_fds)) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - errno = EINVAL; - return NULL; - } + if (!(fd < fdtable->max_fds)) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + errno = EINVAL; + return NULL; + } - pthread_rwlock_rdlock (&fdtable->lock); - { - fdptr = fdtable->fdentries[fd].fd; - if (fdptr) { - fd_ref (fdptr); - } + pthread_rwlock_rdlock(&fdtable->lock); + { + fdptr = fdtable->fdentries[fd].fd; + if (fdptr) { + fd_ref(fdptr); } - pthread_rwlock_unlock (&fdtable->lock); + } + pthread_rwlock_unlock(&fdtable->lock); - return fdptr; + return fdptr; } - fd_t * -__fd_ref (fd_t *fd) +__fd_ref(fd_t *fd) { - GF_ATOMIC_INC (fd->refcount); + GF_ATOMIC_INC(fd->refcount); - return fd; + return fd; } - fd_t * -fd_ref (fd_t *fd) +fd_ref(fd_t *fd) { - if (!fd) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "null fd"); - return NULL; - } + if (!fd) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "null fd"); + return NULL; + } - GF_ATOMIC_INC (fd->refcount); + GF_ATOMIC_INC(fd->refcount); - return fd; + return fd; } - static void -fd_destroy (fd_t *fd, gf_boolean_t bound) +fd_destroy(fd_t *fd, gf_boolean_t bound) { - xlator_t *xl = NULL; - int i = 0; - xlator_t *old_THIS = NULL; - - if (fd == NULL){ - gf_msg_callingfn ("xlator", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - goto out; - } - - if (fd->inode == NULL){ - gf_msg_callingfn ("xlator", GF_LOG_ERROR, 0, - LG_MSG_FD_INODE_NULL, - "fd->inode is NULL"); - goto out; - } - if (!fd->_ctx) - goto out; - - if (IA_ISDIR (fd->inode->ia_type)) { - for (i = 0; i < fd->xl_count; i++) { - if (fd->_ctx[i].key) { - xl = fd->_ctx[i].xl_key; - old_THIS = THIS; - THIS = xl; - if (!xl->call_cleanup && xl->cbks->releasedir) - xl->cbks->releasedir (xl, fd); - THIS = old_THIS; - } - } - } else { - for (i = 0; i < fd->xl_count; i++) { - if (fd->_ctx[i].key) { - xl = fd->_ctx[i].xl_key; - old_THIS = THIS; - THIS = xl; - if (!xl->call_cleanup && xl->cbks->release) - xl->cbks->release (xl, fd); - THIS = old_THIS; - } - } - } - - LOCK_DESTROY (&fd->lock); - - GF_FREE (fd->_ctx); - if (bound) { - /*Decrease the count only after close happens on file*/ - LOCK (&fd->inode->lock); - { - fd->inode->fd_count--; - } - UNLOCK (&fd->inode->lock); - } - inode_unref (fd->inode); - fd->inode = NULL; - fd_lk_ctx_unref (fd->lk_ctx); - mem_put (fd); + xlator_t *xl = NULL; + int i = 0; + xlator_t *old_THIS = NULL; + + if (fd == NULL) { + gf_msg_callingfn("xlator", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + goto out; + } + + if (fd->inode == NULL) { + gf_msg_callingfn("xlator", GF_LOG_ERROR, 0, LG_MSG_FD_INODE_NULL, + "fd->inode is NULL"); + goto out; + } + if (!fd->_ctx) + goto out; + + if (IA_ISDIR(fd->inode->ia_type)) { + for (i = 0; i < fd->xl_count; i++) { + if (fd->_ctx[i].key) { + xl = fd->_ctx[i].xl_key; + old_THIS = THIS; + THIS = xl; + if (!xl->call_cleanup && xl->cbks->releasedir) + xl->cbks->releasedir(xl, fd); + THIS = old_THIS; + } + } + } else { + for (i = 0; i < fd->xl_count; i++) { + if (fd->_ctx[i].key) { + xl = fd->_ctx[i].xl_key; + old_THIS = THIS; + THIS = xl; + if (!xl->call_cleanup && xl->cbks->release) + xl->cbks->release(xl, fd); + THIS = old_THIS; + } + } + } + + LOCK_DESTROY(&fd->lock); + + GF_FREE(fd->_ctx); + if (bound) { + /*Decrease the count only after close happens on file*/ + LOCK(&fd->inode->lock); + { + fd->inode->fd_count--; + } + UNLOCK(&fd->inode->lock); + } + inode_unref(fd->inode); + fd->inode = NULL; + fd_lk_ctx_unref(fd->lk_ctx); + mem_put(fd); out: - return; + return; } - void -fd_unref (fd_t *fd) +fd_unref(fd_t *fd) { - int32_t refcount = 0; - gf_boolean_t bound = _gf_false; - - if (!fd) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "fd is NULL"); - return; - } - - LOCK (&fd->inode->lock); - { - refcount = GF_ATOMIC_DEC (fd->refcount); - if (refcount == 0) { - if (!list_empty (&fd->inode_list)) { - list_del_init (&fd->inode_list); - fd->inode->active_fd_count--; - bound = _gf_true; - } - } + int32_t refcount = 0; + gf_boolean_t bound = _gf_false; - } - UNLOCK (&fd->inode->lock); + if (!fd) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "fd is NULL"); + return; + } + LOCK(&fd->inode->lock); + { + refcount = GF_ATOMIC_DEC(fd->refcount); if (refcount == 0) { - fd_destroy (fd, bound); + if (!list_empty(&fd->inode_list)) { + list_del_init(&fd->inode_list); + fd->inode->active_fd_count--; + bound = _gf_true; + } } + } + UNLOCK(&fd->inode->lock); - return ; -} + if (refcount == 0) { + fd_destroy(fd, bound); + } + return; +} fd_t * -__fd_bind (fd_t *fd) +__fd_bind(fd_t *fd) { - list_del_init (&fd->inode_list); - list_add (&fd->inode_list, &fd->inode->fd_list); - fd->inode->fd_count++; - fd->inode->active_fd_count++; + list_del_init(&fd->inode_list); + list_add(&fd->inode_list, &fd->inode->fd_list); + fd->inode->fd_count++; + fd->inode->active_fd_count++; - return fd; + return fd; } - fd_t * -fd_bind (fd_t *fd) +fd_bind(fd_t *fd) { - if (!fd || !fd->inode) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "!fd || !fd->inode"); - return NULL; - } + if (!fd || !fd->inode) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "!fd || !fd->inode"); + return NULL; + } - LOCK (&fd->inode->lock); - { - fd = __fd_bind (fd); - } - UNLOCK (&fd->inode->lock); + LOCK(&fd->inode->lock); + { + fd = __fd_bind(fd); + } + UNLOCK(&fd->inode->lock); - return fd; + return fd; } - static fd_t * -__fd_create (inode_t *inode, uint64_t pid) +__fd_create(inode_t *inode, uint64_t pid) { - fd_t *fd = NULL; + fd_t *fd = NULL; - if (inode == NULL) { - gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return NULL; - } + if (inode == NULL) { + gf_msg_callingfn("fd", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return NULL; + } - fd = mem_get0 (inode->table->fd_mem_pool); - if (!fd) - goto out; + fd = mem_get0(inode->table->fd_mem_pool); + if (!fd) + goto out; - fd->xl_count = inode->table->xl->graph->xl_count + 1; + fd->xl_count = inode->table->xl->graph->xl_count + 1; - fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) * fd->xl_count), - gf_common_mt_fd_ctx); - if (!fd->_ctx) - goto free_fd; + fd->_ctx = GF_CALLOC(1, (sizeof(struct _fd_ctx) * fd->xl_count), + gf_common_mt_fd_ctx); + if (!fd->_ctx) + goto free_fd; - fd->lk_ctx = fd_lk_ctx_create (); - if (!fd->lk_ctx) - goto free_fd_ctx; + fd->lk_ctx = fd_lk_ctx_create(); + if (!fd->lk_ctx) + goto free_fd_ctx; - fd->inode = inode_ref (inode); - fd->pid = pid; - INIT_LIST_HEAD (&fd->inode_list); + fd->inode = inode_ref(inode); + fd->pid = pid; + INIT_LIST_HEAD(&fd->inode_list); - LOCK_INIT (&fd->lock); + LOCK_INIT(&fd->lock); out: - return fd; + return fd; free_fd_ctx: - GF_FREE (fd->_ctx); + GF_FREE(fd->_ctx); free_fd: - mem_put (fd); + mem_put(fd); - return NULL; + return NULL; } - fd_t * -fd_create (inode_t *inode, pid_t pid) +fd_create(inode_t *inode, pid_t pid) { - fd_t *fd = NULL; + fd_t *fd = NULL; - fd = __fd_create (inode, (uint64_t)pid); - if (!fd) - goto out; + fd = __fd_create(inode, (uint64_t)pid); + if (!fd) + goto out; - fd = fd_ref (fd); + fd = fd_ref(fd); out: - return fd; + return fd; } fd_t * -fd_create_uint64 (inode_t *inode, uint64_t pid) +fd_create_uint64(inode_t *inode, uint64_t pid) { - fd_t *fd = NULL; + fd_t *fd = NULL; - fd = __fd_create (inode, pid); - if (!fd) - goto out; + fd = __fd_create(inode, pid); + if (!fd) + goto out; - fd = fd_ref (fd); + fd = fd_ref(fd); out: - return fd; + return fd; } - static fd_t * -__fd_lookup (inode_t *inode, uint64_t pid) +__fd_lookup(inode_t *inode, uint64_t pid) { - fd_t *iter_fd = NULL; - fd_t *fd = NULL; - - if (list_empty (&inode->fd_list)) - return NULL; + fd_t *iter_fd = NULL; + fd_t *fd = NULL; + if (list_empty(&inode->fd_list)) + return NULL; - list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { - if (iter_fd->anonymous) - /* If someone was interested in getting an - anonymous fd (or was OK getting an anonymous fd), - they can as well call fd_anonymous() directly */ - continue; + list_for_each_entry(iter_fd, &inode->fd_list, inode_list) + { + if (iter_fd->anonymous) + /* If someone was interested in getting an + anonymous fd (or was OK getting an anonymous fd), + they can as well call fd_anonymous() directly */ + continue; - if (!pid || iter_fd->pid == pid) { - fd = __fd_ref (iter_fd); - break; - } + if (!pid || iter_fd->pid == pid) { + fd = __fd_ref(iter_fd); + break; } + } - return fd; + return fd; } - fd_t * -fd_lookup (inode_t *inode, pid_t pid) +fd_lookup(inode_t *inode, pid_t pid) { - fd_t *fd = NULL; + fd_t *fd = NULL; - if (!inode) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!inode"); - return NULL; - } + if (!inode) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!inode"); + return NULL; + } - LOCK (&inode->lock); - { - fd = __fd_lookup (inode, (uint64_t)pid); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + fd = __fd_lookup(inode, (uint64_t)pid); + } + UNLOCK(&inode->lock); - return fd; + return fd; } fd_t * -fd_lookup_uint64 (inode_t *inode, uint64_t pid) +fd_lookup_uint64(inode_t *inode, uint64_t pid) { - fd_t *fd = NULL; + fd_t *fd = NULL; - if (!inode) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!inode"); - return NULL; - } + if (!inode) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!inode"); + return NULL; + } - LOCK (&inode->lock); - { - fd = __fd_lookup (inode, pid); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + fd = __fd_lookup(inode, pid); + } + UNLOCK(&inode->lock); - return fd; + return fd; } static fd_t * -__fd_lookup_anonymous (inode_t *inode, int32_t flags) +__fd_lookup_anonymous(inode_t *inode, int32_t flags) { - fd_t *iter_fd = NULL; - fd_t *fd = NULL; + fd_t *iter_fd = NULL; + fd_t *fd = NULL; - if (list_empty (&inode->fd_list)) - return NULL; + if (list_empty(&inode->fd_list)) + return NULL; - list_for_each_entry (iter_fd, &inode->fd_list, inode_list) { - if ((iter_fd->anonymous) && (flags == iter_fd->flags)) { - fd = __fd_ref (iter_fd); - break; - } + list_for_each_entry(iter_fd, &inode->fd_list, inode_list) + { + if ((iter_fd->anonymous) && (flags == iter_fd->flags)) { + fd = __fd_ref(iter_fd); + break; } + } - return fd; + return fd; } static fd_t * -__fd_anonymous (inode_t *inode, int32_t flags) +__fd_anonymous(inode_t *inode, int32_t flags) { - fd_t *fd = NULL; + fd_t *fd = NULL; - fd = __fd_lookup_anonymous (inode, flags); + fd = __fd_lookup_anonymous(inode, flags); - /* if (fd); then we already have increased the refcount in - __fd_lookup_anonymous(), so no need of one more fd_ref(). - if (!fd); then both create and bind won't bump up the ref - count, so we have to call fd_ref() after bind. */ - if (!fd) { - fd = __fd_create (inode, 0); + /* if (fd); then we already have increased the refcount in + __fd_lookup_anonymous(), so no need of one more fd_ref(). + if (!fd); then both create and bind won't bump up the ref + count, so we have to call fd_ref() after bind. */ + if (!fd) { + fd = __fd_create(inode, 0); - if (!fd) - return NULL; + if (!fd) + return NULL; - fd->anonymous = _gf_true; - fd->flags = GF_ANON_FD_FLAGS|flags; + fd->anonymous = _gf_true; + fd->flags = GF_ANON_FD_FLAGS | flags; - __fd_bind (fd); + __fd_bind(fd); - __fd_ref (fd); - } + __fd_ref(fd); + } - return fd; + return fd; } - fd_t * -fd_anonymous (inode_t *inode) +fd_anonymous(inode_t *inode) { - fd_t *fd = NULL; + fd_t *fd = NULL; - LOCK (&inode->lock); - { - fd = __fd_anonymous (inode, GF_ANON_FD_FLAGS); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + fd = __fd_anonymous(inode, GF_ANON_FD_FLAGS); + } + UNLOCK(&inode->lock); - return fd; + return fd; } fd_t * -fd_anonymous_with_flags (inode_t *inode, int32_t flags) +fd_anonymous_with_flags(inode_t *inode, int32_t flags) { - fd_t *fd = NULL; + fd_t *fd = NULL; - LOCK (&inode->lock); - { - if (flags & O_DIRECT) - flags = GF_ANON_FD_FLAGS | O_DIRECT; - else - flags = GF_ANON_FD_FLAGS; + LOCK(&inode->lock); + { + if (flags & O_DIRECT) + flags = GF_ANON_FD_FLAGS | O_DIRECT; + else + flags = GF_ANON_FD_FLAGS; - fd = __fd_anonymous (inode, flags); - } - UNLOCK (&inode->lock); + fd = __fd_anonymous(inode, flags); + } + UNLOCK(&inode->lock); - return fd; + return fd; } -fd_t* -fd_lookup_anonymous (inode_t *inode, int32_t flags) +fd_t * +fd_lookup_anonymous(inode_t *inode, int32_t flags) { - fd_t *fd = NULL; - - if (!inode) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "!inode"); - return NULL; - } + fd_t *fd = NULL; - LOCK (&inode->lock); - { - fd = __fd_lookup_anonymous (inode, flags); - } - UNLOCK (&inode->lock); - return fd; + if (!inode) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "!inode"); + return NULL; + } + + LOCK(&inode->lock); + { + fd = __fd_lookup_anonymous(inode, flags); + } + UNLOCK(&inode->lock); + return fd; } gf_boolean_t -fd_is_anonymous (fd_t *fd) +fd_is_anonymous(fd_t *fd) { - return (fd && fd->anonymous); + return (fd && fd->anonymous); } - uint8_t -fd_list_empty (inode_t *inode) +fd_list_empty(inode_t *inode) { - uint8_t empty = 0; + uint8_t empty = 0; - LOCK (&inode->lock); - { - empty = list_empty (&inode->fd_list); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + empty = list_empty(&inode->fd_list); + } + UNLOCK(&inode->lock); - return empty; + return empty; } - int -__fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) +__fd_ctx_set(fd_t *fd, xlator_t *xlator, uint64_t value) { - int index = 0, new_xl_count = 0; - int ret = 0; - int set_idx = -1; - void *begin = NULL; - size_t diff = 0; - struct _fd_ctx *tmp = NULL; - - if (!fd || !xlator) - return -1; - - for (index = 0; index < fd->xl_count; index++) { - if (!fd->_ctx[index].key) { - if (set_idx == -1) - set_idx = index; - /* don't break, to check if key already exists - further on */ - } - if (fd->_ctx[index].xl_key == xlator) { - set_idx = index; - break; - } + int index = 0, new_xl_count = 0; + int ret = 0; + int set_idx = -1; + void *begin = NULL; + size_t diff = 0; + struct _fd_ctx *tmp = NULL; + + if (!fd || !xlator) + return -1; + + for (index = 0; index < fd->xl_count; index++) { + if (!fd->_ctx[index].key) { + if (set_idx == -1) + set_idx = index; + /* don't break, to check if key already exists + further on */ } + if (fd->_ctx[index].xl_key == xlator) { + set_idx = index; + break; + } + } - if (set_idx == -1) { - set_idx = fd->xl_count; + if (set_idx == -1) { + set_idx = fd->xl_count; - new_xl_count = fd->xl_count + xlator->graph->xl_count; + new_xl_count = fd->xl_count + xlator->graph->xl_count; - tmp = GF_REALLOC (fd->_ctx, - (sizeof (struct _fd_ctx) - * new_xl_count)); - if (tmp == NULL) { - ret = -1; - goto out; - } + tmp = GF_REALLOC(fd->_ctx, (sizeof(struct _fd_ctx) * new_xl_count)); + if (tmp == NULL) { + ret = -1; + goto out; + } - fd->_ctx = tmp; + fd->_ctx = tmp; - begin = fd->_ctx; - begin += (fd->xl_count * sizeof (struct _fd_ctx)); + begin = fd->_ctx; + begin += (fd->xl_count * sizeof(struct _fd_ctx)); - diff = (new_xl_count - fd->xl_count ) - * sizeof (struct _fd_ctx); + diff = (new_xl_count - fd->xl_count) * sizeof(struct _fd_ctx); - memset (begin, 0, diff); + memset(begin, 0, diff); - fd->xl_count = new_xl_count; - } + fd->xl_count = new_xl_count; + } - fd->_ctx[set_idx].xl_key = xlator; - fd->_ctx[set_idx].value1 = value; + fd->_ctx[set_idx].xl_key = xlator; + fd->_ctx[set_idx].value1 = value; out: - return ret; + return ret; } - int -fd_ctx_set (fd_t *fd, xlator_t *xlator, uint64_t value) +fd_ctx_set(fd_t *fd, xlator_t *xlator, uint64_t value) { - int ret = 0; + int ret = 0; - if (!fd || !xlator) { - gf_msg_callingfn ("fd", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "%p %p", fd, xlator); - return -1; - } + if (!fd || !xlator) { + gf_msg_callingfn("fd", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "%p %p", fd, xlator); + return -1; + } - LOCK (&fd->lock); - { - ret = __fd_ctx_set (fd, xlator, value); - } - UNLOCK (&fd->lock); + LOCK(&fd->lock); + { + ret = __fd_ctx_set(fd, xlator, value); + } + UNLOCK(&fd->lock); - return ret; + return ret; } - int -__fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) +__fd_ctx_get(fd_t *fd, xlator_t *xlator, uint64_t *value) { - int index = 0; - int ret = 0; + int index = 0; + int ret = 0; - if (!fd || !xlator) - return -1; + if (!fd || !xlator) + return -1; - for (index = 0; index < fd->xl_count; index++) { - if (fd->_ctx[index].xl_key == xlator) - break; - } + for (index = 0; index < fd->xl_count; index++) { + if (fd->_ctx[index].xl_key == xlator) + break; + } - if (index == fd->xl_count) { - ret = -1; - goto out; - } + if (index == fd->xl_count) { + ret = -1; + goto out; + } - if (value) - *value = fd->_ctx[index].value1; + if (value) + *value = fd->_ctx[index].value1; out: - return ret; + return ret; } - int -fd_ctx_get (fd_t *fd, xlator_t *xlator, uint64_t *value) +fd_ctx_get(fd_t *fd, xlator_t *xlator, uint64_t *value) { - int ret = 0; + int ret = 0; - if (!fd || !xlator) - return -1; + if (!fd || !xlator) + return -1; - LOCK (&fd->lock); - { - ret = __fd_ctx_get (fd, xlator, value); - } - UNLOCK (&fd->lock); + LOCK(&fd->lock); + { + ret = __fd_ctx_get(fd, xlator, value); + } + UNLOCK(&fd->lock); - return ret; + return ret; } - int -__fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) +__fd_ctx_del(fd_t *fd, xlator_t *xlator, uint64_t *value) { - int index = 0; - int ret = 0; + int index = 0; + int ret = 0; - if (!fd || !xlator) - return -1; + if (!fd || !xlator) + return -1; - for (index = 0; index < fd->xl_count; index++) { - if (fd->_ctx[index].xl_key == xlator) - break; - } + for (index = 0; index < fd->xl_count; index++) { + if (fd->_ctx[index].xl_key == xlator) + break; + } - if (index == fd->xl_count) { - ret = -1; - goto out; - } + if (index == fd->xl_count) { + ret = -1; + goto out; + } - if (value) - *value = fd->_ctx[index].value1; + if (value) + *value = fd->_ctx[index].value1; - fd->_ctx[index].key = 0; - fd->_ctx[index].value1 = 0; + fd->_ctx[index].key = 0; + fd->_ctx[index].value1 = 0; out: - return ret; + return ret; } - int -fd_ctx_del (fd_t *fd, xlator_t *xlator, uint64_t *value) +fd_ctx_del(fd_t *fd, xlator_t *xlator, uint64_t *value) { - int ret = 0; + int ret = 0; - if (!fd || !xlator) - return -1; + if (!fd || !xlator) + return -1; - LOCK (&fd->lock); - { - ret = __fd_ctx_del (fd, xlator, value); - } - UNLOCK (&fd->lock); + LOCK(&fd->lock); + { + ret = __fd_ctx_del(fd, xlator, value); + } + UNLOCK(&fd->lock); - return ret; + return ret; } - void -fd_dump (fd_t *fd, char *prefix) +fd_dump(fd_t *fd, char *prefix) { - char key[GF_DUMP_MAX_BUF_LEN]; + char key[GF_DUMP_MAX_BUF_LEN]; - if (!fd) - return; - - gf_proc_dump_write("pid", "%llu", fd->pid); - gf_proc_dump_write("refcount", "%d", fd->refcount); - gf_proc_dump_write("flags", "%d", fd->flags); + if (!fd) + return; - if (fd->inode) { - gf_proc_dump_build_key (key, "inode", NULL); - gf_proc_dump_add_section(key); - inode_dump (fd->inode, key); - } + gf_proc_dump_write("pid", "%llu", fd->pid); + gf_proc_dump_write("refcount", "%d", fd->refcount); + gf_proc_dump_write("flags", "%d", fd->flags); + if (fd->inode) { + gf_proc_dump_build_key(key, "inode", NULL); + gf_proc_dump_add_section(key); + inode_dump(fd->inode, key); + } } - void -fdentry_dump (fdentry_t *fdentry, char *prefix) +fdentry_dump(fdentry_t *fdentry, char *prefix) { - if (!fdentry) - return; + if (!fdentry) + return; - if (GF_FDENTRY_ALLOCATED != fdentry->next_free) - return; + if (GF_FDENTRY_ALLOCATED != fdentry->next_free) + return; - if (fdentry->fd) - fd_dump(fdentry->fd, prefix); + if (fdentry->fd) + fd_dump(fdentry->fd, prefix); } - void -fdtable_dump (fdtable_t *fdtable, char *prefix) +fdtable_dump(fdtable_t *fdtable, char *prefix) { - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 0; - int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN]; + int i = 0; + int ret = -1; - if (!fdtable) - return; + if (!fdtable) + return; - ret = pthread_rwlock_tryrdlock (&fdtable->lock); - if (ret) - goto out; + ret = pthread_rwlock_tryrdlock(&fdtable->lock); + if (ret) + goto out; - gf_proc_dump_build_key(key, prefix, "refcount"); - gf_proc_dump_write(key, "%d", fdtable->refcount); - gf_proc_dump_build_key(key, prefix, "maxfds"); - gf_proc_dump_write(key, "%d", fdtable->max_fds); - gf_proc_dump_build_key(key, prefix, "first_free"); - gf_proc_dump_write(key, "%d", fdtable->first_free); - - for ( i = 0 ; i < fdtable->max_fds; i++) { - if (GF_FDENTRY_ALLOCATED == - fdtable->fdentries[i].next_free) { - gf_proc_dump_build_key(key, prefix, "fdentry[%d]", i); - gf_proc_dump_add_section(key); - fdentry_dump(&fdtable->fdentries[i], key); - } + gf_proc_dump_build_key(key, prefix, "refcount"); + gf_proc_dump_write(key, "%d", fdtable->refcount); + gf_proc_dump_build_key(key, prefix, "maxfds"); + gf_proc_dump_write(key, "%d", fdtable->max_fds); + gf_proc_dump_build_key(key, prefix, "first_free"); + gf_proc_dump_write(key, "%d", fdtable->first_free); + + for (i = 0; i < fdtable->max_fds; i++) { + if (GF_FDENTRY_ALLOCATED == fdtable->fdentries[i].next_free) { + gf_proc_dump_build_key(key, prefix, "fdentry[%d]", i); + gf_proc_dump_add_section(key); + fdentry_dump(&fdtable->fdentries[i], key); } + } - pthread_rwlock_unlock(&fdtable->lock); + pthread_rwlock_unlock(&fdtable->lock); out: - if (ret != 0) - gf_proc_dump_write ("Unable to dump the fdtable", - "(Lock acquistion failed) %p", fdtable); - return; + if (ret != 0) + gf_proc_dump_write("Unable to dump the fdtable", + "(Lock acquistion failed) %p", fdtable); + return; } - void -fd_ctx_dump (fd_t *fd, char *prefix) +fd_ctx_dump(fd_t *fd, char *prefix) { - struct _fd_ctx *fd_ctx = NULL; - xlator_t *xl = NULL; - int i = 0; - - - if ((fd == NULL) || (fd->_ctx == NULL)) { - goto out; - } - - LOCK (&fd->lock); - { - if (fd->_ctx != NULL) { - fd_ctx = GF_CALLOC (fd->xl_count, sizeof (*fd_ctx), - gf_common_mt_fd_ctx); - if (fd_ctx == NULL) { - goto unlock; - } - - for (i = 0; i < fd->xl_count; i++) { - fd_ctx[i] = fd->_ctx[i]; - } - } - } + struct _fd_ctx *fd_ctx = NULL; + xlator_t *xl = NULL; + int i = 0; + + if ((fd == NULL) || (fd->_ctx == NULL)) { + goto out; + } + + LOCK(&fd->lock); + { + if (fd->_ctx != NULL) { + fd_ctx = GF_CALLOC(fd->xl_count, sizeof(*fd_ctx), + gf_common_mt_fd_ctx); + if (fd_ctx == NULL) { + goto unlock; + } + + for (i = 0; i < fd->xl_count; i++) { + fd_ctx[i] = fd->_ctx[i]; + } + } + } unlock: - UNLOCK (&fd->lock); + UNLOCK(&fd->lock); - if (fd_ctx == NULL) { - goto out; - } + if (fd_ctx == NULL) { + goto out; + } - for (i = 0; i < fd->xl_count; i++) { - if (fd_ctx[i].xl_key) { - xl = (xlator_t *)(long)fd_ctx[i].xl_key; - if (xl->dumpops && xl->dumpops->fdctx) - xl->dumpops->fdctx (xl, fd); - } + for (i = 0; i < fd->xl_count; i++) { + if (fd_ctx[i].xl_key) { + xl = (xlator_t *)(long)fd_ctx[i].xl_key; + if (xl->dumpops && xl->dumpops->fdctx) + xl->dumpops->fdctx(xl, fd); } + } out: - GF_FREE (fd_ctx); + GF_FREE(fd_ctx); - return; + return; } void -fdentry_dump_to_dict (fdentry_t *fdentry, char *prefix, dict_t *dict, - int *openfds) +fdentry_dump_to_dict(fdentry_t *fdentry, char *prefix, dict_t *dict, + int *openfds) { - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + int ret = -1; - if (!fdentry) - return; - if (!dict) - return; + if (!fdentry) + return; + if (!dict) + return; - if (GF_FDENTRY_ALLOCATED != fdentry->next_free) - return; + if (GF_FDENTRY_ALLOCATED != fdentry->next_free) + return; - if (fdentry->fd) { - snprintf (key, sizeof (key), "%s.pid", prefix); - ret = dict_set_uint64 (dict, key, fdentry->fd->pid); - if (ret) - return; + if (fdentry->fd) { + snprintf(key, sizeof(key), "%s.pid", prefix); + ret = dict_set_uint64(dict, key, fdentry->fd->pid); + if (ret) + return; - snprintf (key, sizeof (key), "%s.refcount", prefix); - ret = dict_set_int32 (dict, key, GF_ATOMIC_GET (fdentry->fd->refcount)); - if (ret) - return; + snprintf(key, sizeof(key), "%s.refcount", prefix); + ret = dict_set_int32(dict, key, GF_ATOMIC_GET(fdentry->fd->refcount)); + if (ret) + return; - snprintf (key, sizeof (key), "%s.flags", prefix); - ret = dict_set_int32 (dict, key, fdentry->fd->flags); + snprintf(key, sizeof(key), "%s.flags", prefix); + ret = dict_set_int32(dict, key, fdentry->fd->flags); - (*openfds)++; - } - return; + (*openfds)++; + } + return; } void -fdtable_dump_to_dict (fdtable_t *fdtable, char *prefix, dict_t *dict) +fdtable_dump_to_dict(fdtable_t *fdtable, char *prefix, dict_t *dict) { - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - int i = 0; - int openfds = 0; - int ret = -1; - - if (!fdtable) - return; - if (!dict) - return; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + int i = 0; + int openfds = 0; + int ret = -1; + + if (!fdtable) + return; + if (!dict) + return; - ret = pthread_rwlock_tryrdlock (&fdtable->lock); - if (ret) - return; + ret = pthread_rwlock_tryrdlock(&fdtable->lock); + if (ret) + return; - snprintf (key, sizeof (key), "%s.fdtable.refcount", prefix); - ret = dict_set_int32 (dict, key, fdtable->refcount); - if (ret) - goto out; + snprintf(key, sizeof(key), "%s.fdtable.refcount", prefix); + ret = dict_set_int32(dict, key, fdtable->refcount); + if (ret) + goto out; - snprintf (key, sizeof (key), "%s.fdtable.maxfds", prefix); - ret = dict_set_uint32 (dict, key, fdtable->max_fds); - if (ret) - goto out; + snprintf(key, sizeof(key), "%s.fdtable.maxfds", prefix); + ret = dict_set_uint32(dict, key, fdtable->max_fds); + if (ret) + goto out; - snprintf (key, sizeof (key), "%s.fdtable.firstfree", prefix); - ret = dict_set_int32 (dict, key, fdtable->first_free); - if (ret) - goto out; + snprintf(key, sizeof(key), "%s.fdtable.firstfree", prefix); + ret = dict_set_int32(dict, key, fdtable->first_free); + if (ret) + goto out; - for (i = 0; i < fdtable->max_fds; i++) { - if (GF_FDENTRY_ALLOCATED == - fdtable->fdentries[i].next_free) { - snprintf (key, sizeof (key), "%s.fdtable.fdentry%d", - prefix, i); - fdentry_dump_to_dict (&fdtable->fdentries[i], key, - dict, &openfds); - } + for (i = 0; i < fdtable->max_fds; i++) { + if (GF_FDENTRY_ALLOCATED == fdtable->fdentries[i].next_free) { + snprintf(key, sizeof(key), "%s.fdtable.fdentry%d", prefix, i); + fdentry_dump_to_dict(&fdtable->fdentries[i], key, dict, &openfds); } + } - snprintf (key, sizeof (key), "%s.fdtable.openfds", prefix); - ret = dict_set_int32 (dict, key, openfds); + snprintf(key, sizeof(key), "%s.fdtable.openfds", prefix); + ret = dict_set_int32(dict, key, openfds); out: - pthread_rwlock_unlock (&fdtable->lock); - return; + pthread_rwlock_unlock(&fdtable->lock); + return; } diff --git a/libglusterfs/src/gf-dirent.c b/libglusterfs/src/gf-dirent.c index d0df80e2886..c06e959aeba 100644 --- a/libglusterfs/src/gf-dirent.c +++ b/libglusterfs/src/gf-dirent.c @@ -8,8 +8,6 @@ cases as published by the Free Software Foundation. */ - - #include <stdio.h> #include <string.h> #include <stdint.h> @@ -22,223 +20,221 @@ #define BACKEND_D_OFF_BITS 63 #define TOP_BIT (ONE << (PRESENT_D_OFF_BITS - 1)) #define MASK (~0ULL) -#define SHIFT_BITS (max (0, (BACKEND_D_OFF_BITS - PRESENT_D_OFF_BITS + 1))) +#define SHIFT_BITS (max(0, (BACKEND_D_OFF_BITS - PRESENT_D_OFF_BITS + 1))) #define PRESENT_MASK (MASK >> (64 - PRESENT_D_OFF_BITS)) static uint64_t -bits_for (uint64_t num) +bits_for(uint64_t num) { - uint64_t bits = 0, ctrl = 1; + uint64_t bits = 0, ctrl = 1; - while (ctrl < num) { - ctrl *= 2; - bits++; - } + while (ctrl < num) { + ctrl *= 2; + bits++; + } - return bits; + return bits; } int -gf_deitransform(xlator_t *this, - uint64_t offset) +gf_deitransform(xlator_t *this, uint64_t offset) { - int cnt = 0; - int max = 0; - int max_bits = 0; - uint64_t off_mask = 0; - uint64_t host_mask = 0; - - max = glusterfs_get_leaf_count(this->graph); - - if (max == 1) { - cnt = 0; - goto out; - } - - if (offset & TOP_BIT) { - /* HUGE d_off */ - max_bits = bits_for (max); - off_mask = (MASK << max_bits); - host_mask = ~(off_mask); - - cnt = offset & host_mask; - } else { - /* small d_off */ - cnt = offset % max; - } + int cnt = 0; + int max = 0; + int max_bits = 0; + uint64_t off_mask = 0; + uint64_t host_mask = 0; + + max = glusterfs_get_leaf_count(this->graph); + + if (max == 1) { + cnt = 0; + goto out; + } + + if (offset & TOP_BIT) { + /* HUGE d_off */ + max_bits = bits_for(max); + off_mask = (MASK << max_bits); + host_mask = ~(off_mask); + + cnt = offset & host_mask; + } else { + /* small d_off */ + cnt = offset % max; + } out: - return cnt; + return cnt; } uint64_t -gf_dirent_orig_offset(xlator_t *this, - uint64_t offset) +gf_dirent_orig_offset(xlator_t *this, uint64_t offset) { - int max = 0; - int max_bits = 0; - uint64_t off_mask = 0; - uint64_t orig_offset; - - max = glusterfs_get_leaf_count(this->graph); - - if (max == 1) { - orig_offset = offset; - goto out; - } - - if (offset & TOP_BIT) { - /* HUGE d_off */ - max_bits = bits_for (max); - off_mask = (MASK << max_bits); - orig_offset = ((offset & ~TOP_BIT) & off_mask) << SHIFT_BITS; - } else { - /* small d_off */ - orig_offset = offset / max; - } + int max = 0; + int max_bits = 0; + uint64_t off_mask = 0; + uint64_t orig_offset; + + max = glusterfs_get_leaf_count(this->graph); + + if (max == 1) { + orig_offset = offset; + goto out; + } + + if (offset & TOP_BIT) { + /* HUGE d_off */ + max_bits = bits_for(max); + off_mask = (MASK << max_bits); + orig_offset = ((offset & ~TOP_BIT) & off_mask) << SHIFT_BITS; + } else { + /* small d_off */ + orig_offset = offset / max; + } out: - return orig_offset; + return orig_offset; } int -gf_itransform (xlator_t *this, uint64_t x, uint64_t *y_p, int client_id) +gf_itransform(xlator_t *this, uint64_t x, uint64_t *y_p, int client_id) { - int max = 0; - uint64_t y = 0; - uint64_t hi_mask = 0; - uint64_t off_mask = 0; - int max_bits = 0; - - if (x == ((uint64_t) -1)) { - y = (uint64_t) -1; - goto out; - } - - if (!x) { - y = 0; - goto out; - } - - max = glusterfs_get_leaf_count(this->graph); - - if (max == 1) { - y = x; - goto out; - } - - max_bits = bits_for (max); - - hi_mask = ~(PRESENT_MASK >> (max_bits + 1)); - - if (x & hi_mask) { - /* HUGE d_off */ - off_mask = MASK << max_bits; - y = TOP_BIT | ((x >> SHIFT_BITS) & off_mask) | client_id; - } else { - /* small d_off */ - y = ((x * max) + client_id); - } + int max = 0; + uint64_t y = 0; + uint64_t hi_mask = 0; + uint64_t off_mask = 0; + int max_bits = 0; + + if (x == ((uint64_t)-1)) { + y = (uint64_t)-1; + goto out; + } + + if (!x) { + y = 0; + goto out; + } + + max = glusterfs_get_leaf_count(this->graph); + + if (max == 1) { + y = x; + goto out; + } + + max_bits = bits_for(max); + + hi_mask = ~(PRESENT_MASK >> (max_bits + 1)); + + if (x & hi_mask) { + /* HUGE d_off */ + off_mask = MASK << max_bits; + y = TOP_BIT | ((x >> SHIFT_BITS) & off_mask) | client_id; + } else { + /* small d_off */ + y = ((x * max) + client_id); + } out: - if (y_p) - *y_p = y; + if (y_p) + *y_p = y; - return 0; + return 0; } gf_dirent_t * -gf_dirent_for_name (const char *name) +gf_dirent_for_name(const char *name) { - gf_dirent_t *gf_dirent = NULL; + gf_dirent_t *gf_dirent = NULL; - /* TODO: use mem-pool */ - gf_dirent = GF_CALLOC (gf_dirent_size (name), 1, - gf_common_mt_gf_dirent_t); - if (!gf_dirent) - return NULL; + /* TODO: use mem-pool */ + gf_dirent = GF_CALLOC(gf_dirent_size(name), 1, gf_common_mt_gf_dirent_t); + if (!gf_dirent) + return NULL; - INIT_LIST_HEAD (&gf_dirent->list); - strcpy (gf_dirent->d_name, name); + INIT_LIST_HEAD(&gf_dirent->list); + strcpy(gf_dirent->d_name, name); - gf_dirent->d_off = 0; - gf_dirent->d_ino = -1; - gf_dirent->d_type = 0; - gf_dirent->d_len = strlen (name); + gf_dirent->d_off = 0; + gf_dirent->d_ino = -1; + gf_dirent->d_type = 0; + gf_dirent->d_len = strlen(name); - return gf_dirent; + return gf_dirent; } void -gf_dirent_entry_free (gf_dirent_t *entry) +gf_dirent_entry_free(gf_dirent_t *entry) { - if (!entry) - return; + if (!entry) + return; - if (entry->dict) - dict_unref (entry->dict); - if (entry->inode) - inode_unref (entry->inode); + if (entry->dict) + dict_unref(entry->dict); + if (entry->inode) + inode_unref(entry->inode); - list_del_init (&entry->list); - GF_FREE (entry); + list_del_init(&entry->list); + GF_FREE(entry); } void -gf_dirent_free (gf_dirent_t *entries) +gf_dirent_free(gf_dirent_t *entries) { - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; + gf_dirent_t *entry = NULL; + gf_dirent_t *tmp = NULL; - if (!entries) - return; + if (!entries) + return; - if (list_empty (&entries->list)) - return; + if (list_empty(&entries->list)) + return; - list_for_each_entry_safe (entry, tmp, &entries->list, list) { - gf_dirent_entry_free (entry); - } + list_for_each_entry_safe(entry, tmp, &entries->list, list) + { + gf_dirent_entry_free(entry); + } } gf_dirent_t * -entry_copy (gf_dirent_t *source) +entry_copy(gf_dirent_t *source) { - gf_dirent_t *sink = NULL; + gf_dirent_t *sink = NULL; - sink = gf_dirent_for_name (source->d_name); - if (!sink) - return NULL; + sink = gf_dirent_for_name(source->d_name); + if (!sink) + return NULL; - sink->d_off = source->d_off; - sink->d_ino = source->d_ino; - sink->d_type = source->d_type; - sink->d_stat = source->d_stat; - sink->d_len = source->d_len; + sink->d_off = source->d_off; + sink->d_ino = source->d_ino; + sink->d_type = source->d_type; + sink->d_stat = source->d_stat; + sink->d_len = source->d_len; - if (source->inode) - sink->inode = inode_ref (source->inode); + if (source->inode) + sink->inode = inode_ref(source->inode); - if (source->dict) - sink->dict = dict_ref (source->dict); - return sink; + if (source->dict) + sink->dict = dict_ref(source->dict); + return sink; } void -gf_link_inode_from_dirent (xlator_t *this, inode_t *parent, gf_dirent_t *entry) +gf_link_inode_from_dirent(xlator_t *this, inode_t *parent, gf_dirent_t *entry) { - inode_t *link_inode = NULL; - inode_t *tmp = NULL; - - if (!entry->inode) - return; - link_inode = inode_link (entry->inode, parent, - entry->d_name, &entry->d_stat); - if (!link_inode) - return; - - inode_lookup (link_inode); - tmp = entry->inode; - entry->inode = link_inode; - inode_unref (tmp); + inode_t *link_inode = NULL; + inode_t *tmp = NULL; + + if (!entry->inode) + return; + link_inode = inode_link(entry->inode, parent, entry->d_name, + &entry->d_stat); + if (!link_inode) + return; + + inode_lookup(link_inode); + tmp = entry->inode; + entry->inode = link_inode; + inode_unref(tmp); } /* TODO: Currently, with this function, we will be breaking the @@ -247,55 +243,60 @@ gf_link_inode_from_dirent (xlator_t *this, inode_t *parent, gf_dirent_t *entry) Need more thoughts before finalizing this function */ int -gf_link_inodes_from_dirent (xlator_t *this, inode_t *parent, - gf_dirent_t *entries) +gf_link_inodes_from_dirent(xlator_t *this, inode_t *parent, + gf_dirent_t *entries) { - gf_dirent_t *entry = NULL; + gf_dirent_t *entry = NULL; - list_for_each_entry (entry, &entries->list, list) { - gf_link_inode_from_dirent (this, parent, entry); - } + list_for_each_entry(entry, &entries->list, list) + { + gf_link_inode_from_dirent(this, parent, entry); + } - return 0; + return 0; } int -gf_fill_iatt_for_dirent (gf_dirent_t *entry, inode_t *parent, xlator_t *subvol) +gf_fill_iatt_for_dirent(gf_dirent_t *entry, inode_t *parent, xlator_t *subvol) { - loc_t loc = {0, }; - int ret = -1; - char *path = NULL; - struct iatt iatt = {0,}; - - loc.inode = inode_grep (parent->table, parent, entry->d_name); - if (!loc.inode) { - loc.inode = inode_new (parent->table); - gf_uuid_copy (loc.inode->gfid, entry->d_stat.ia_gfid); - } - - gf_uuid_copy (loc.pargfid, parent->gfid); - loc.name = entry->d_name; - loc.parent = inode_ref (parent); - ret = inode_path (loc.inode, entry->d_name, &path); - loc.path = path; - if (ret < 0) - goto out; - - ret = syncop_lookup (subvol, &loc, &iatt, NULL, NULL, NULL); - if (ret) - goto out; - - entry->d_stat = iatt; - entry->inode = inode_ref (loc.inode); - /* We don't need to link inode here, because as part of readdirp_cbk - * we will link all dirents. - * - * Since we did a proper lookup, we don't need to set need_lookup - * flag. - */ - - ret = 0; + loc_t loc = { + 0, + }; + int ret = -1; + char *path = NULL; + struct iatt iatt = { + 0, + }; + + loc.inode = inode_grep(parent->table, parent, entry->d_name); + if (!loc.inode) { + loc.inode = inode_new(parent->table); + gf_uuid_copy(loc.inode->gfid, entry->d_stat.ia_gfid); + } + + gf_uuid_copy(loc.pargfid, parent->gfid); + loc.name = entry->d_name; + loc.parent = inode_ref(parent); + ret = inode_path(loc.inode, entry->d_name, &path); + loc.path = path; + if (ret < 0) + goto out; + + ret = syncop_lookup(subvol, &loc, &iatt, NULL, NULL, NULL); + if (ret) + goto out; + + entry->d_stat = iatt; + entry->inode = inode_ref(loc.inode); + /* We don't need to link inode here, because as part of readdirp_cbk + * we will link all dirents. + * + * Since we did a proper lookup, we don't need to set need_lookup + * flag. + */ + + ret = 0; out: - loc_wipe (&loc); - return ret; + loc_wipe(&loc); + return ret; } diff --git a/libglusterfs/src/gfdb/gfdb_data_store.c b/libglusterfs/src/gfdb/gfdb_data_store.c index 78fd22ee252..426596c571e 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store.c +++ b/libglusterfs/src/gfdb/gfdb_data_store.c @@ -30,11 +30,10 @@ * gfdb_conn_node_t is an opaque structure. * */ struct gfdb_conn_node_t { - gfdb_connection_t gfdb_connection; - struct list_head conn_list; + gfdb_connection_t gfdb_connection; + struct list_head conn_list; }; - /* * db_conn_list is the circular linked list which * will have all the database connections for the process @@ -48,173 +47,168 @@ static gfdb_conn_node_t *db_conn_list; * */ static pthread_mutex_t db_conn_mutex = PTHREAD_MUTEX_INITIALIZER; - /*Checks the sanity of the connection node*/ -#define CHECK_CONN_NODE(_conn_node)\ -do {\ - GF_ASSERT (_conn_node);\ - GF_ASSERT (_conn_node->gfdb_connection.gf_db_connection);\ -} while (0) +#define CHECK_CONN_NODE(_conn_node) \ + do { \ + GF_ASSERT(_conn_node); \ + GF_ASSERT(_conn_node->gfdb_connection.gf_db_connection); \ + } while (0) /* Checks the sanity of the connection node and goto */ -#define CHECK_CONN_NODE_GOTO(_conn_node, label)\ -do {\ - if (!_conn_node) {\ - goto label;\ - };\ - if (!_conn_node->gfdb_connection.gf_db_connection) {\ - goto label;\ - };\ -} while (0) +#define CHECK_CONN_NODE_GOTO(_conn_node, label) \ + do { \ + if (!_conn_node) { \ + goto label; \ + }; \ + if (!_conn_node->gfdb_connection.gf_db_connection) { \ + goto label; \ + }; \ + } while (0) /*Check if the conn node is first in the list*/ -#define IS_FIRST_NODE(db_conn_list, _conn_node)\ - ((_conn_node == db_conn_list) ? _gf_true : _gf_false) - +#define IS_FIRST_NODE(db_conn_list, _conn_node) \ + ((_conn_node == db_conn_list) ? _gf_true : _gf_false) /*Check if the conn node is the only node in the list*/ -#define IS_THE_ONLY_NODE(_conn_node)\ -((_conn_node->conn_list.next == _conn_node->conn_list.prev)\ - ? _gf_true : _gf_false) - - +#define IS_THE_ONLY_NODE(_conn_node) \ + ((_conn_node->conn_list.next == _conn_node->conn_list.prev) ? _gf_true \ + : _gf_false) /*Internal Function: Adds connection node to the end of * the db connection list.*/ static int -add_connection_node (gfdb_conn_node_t *_conn_node) { - int ret = -1; - - GF_ASSERT (_conn_node); - - /*Lock the list*/ - ret = pthread_mutex_lock (&db_conn_mutex); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ret, - LG_MSG_LOCK_LIST_FAILED, "Failed lock db connection " - "list %s", strerror(ret)); - ret = -1; - goto out; - } - - if (db_conn_list == NULL) { - db_conn_list = _conn_node; - } else { - list_add_tail (&_conn_node->conn_list, - &db_conn_list->conn_list); - } - - /*unlock the list*/ - ret = pthread_mutex_unlock (&db_conn_mutex); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ret, - LG_MSG_UNLOCK_LIST_FAILED, "Failed unlock db " - "connection list %s", strerror(ret)); - ret = -1; - goto out; - /*TODO What if the unlock fails. - * Will it lead to deadlock? - * Most of the gluster code - * no check for unlock or destroy of mutex!*/ - } - ret = 0; +add_connection_node(gfdb_conn_node_t *_conn_node) +{ + int ret = -1; + + GF_ASSERT(_conn_node); + + /*Lock the list*/ + ret = pthread_mutex_lock(&db_conn_mutex); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ret, LG_MSG_LOCK_LIST_FAILED, + "Failed lock db connection " + "list %s", + strerror(ret)); + ret = -1; + goto out; + } + + if (db_conn_list == NULL) { + db_conn_list = _conn_node; + } else { + list_add_tail(&_conn_node->conn_list, &db_conn_list->conn_list); + } + + /*unlock the list*/ + ret = pthread_mutex_unlock(&db_conn_mutex); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ret, LG_MSG_UNLOCK_LIST_FAILED, + "Failed unlock db " + "connection list %s", + strerror(ret)); + ret = -1; + goto out; + /*TODO What if the unlock fails. + * Will it lead to deadlock? + * Most of the gluster code + * no check for unlock or destroy of mutex!*/ + } + ret = 0; out: - return ret; + return ret; } - /*Internal Function: * Delete connection node from the list*/ static int -delete_conn_node (gfdb_conn_node_t *_conn_node) +delete_conn_node(gfdb_conn_node_t *_conn_node) { - int ret = -1; - - GF_ASSERT (_conn_node); - - /*Lock of the list*/ - ret = pthread_mutex_lock (&db_conn_mutex); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ret, - LG_MSG_LOCK_LIST_FAILED, "Failed lock on db connection" - " list %s", strerror(ret)); - goto out; + int ret = -1; + + GF_ASSERT(_conn_node); + + /*Lock of the list*/ + ret = pthread_mutex_lock(&db_conn_mutex); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ret, LG_MSG_LOCK_LIST_FAILED, + "Failed lock on db connection" + " list %s", + strerror(ret)); + goto out; + } + + /*Remove the connection object from list*/ + if (IS_THE_ONLY_NODE(_conn_node)) { + db_conn_list = NULL; + GF_FREE(_conn_node); + } else { + if (IS_FIRST_NODE(db_conn_list, _conn_node)) { + db_conn_list = list_entry(db_conn_list->conn_list.next, + gfdb_conn_node_t, conn_list); } - - /*Remove the connection object from list*/ - if (IS_THE_ONLY_NODE(_conn_node)) { - db_conn_list = NULL; - GF_FREE (_conn_node); - } else { - if (IS_FIRST_NODE(db_conn_list, _conn_node)) { - db_conn_list = list_entry (db_conn_list->conn_list.next, - gfdb_conn_node_t, conn_list); - } - list_del(&_conn_node->conn_list); - GF_FREE (_conn_node); - } - - /*Release the list lock*/ - ret = pthread_mutex_unlock (&db_conn_mutex); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_WARNING, ret, - LG_MSG_UNLOCK_LIST_FAILED, "Failed unlock on db " - "connection list %s", strerror(ret)); - /*TODO What if the unlock fails. - * Will it lead to deadlock? - * Most of the gluster code - * no check for unlock or destroy of mutex!*/ - ret = -1; - goto out; - } - ret = 0; + list_del(&_conn_node->conn_list); + GF_FREE(_conn_node); + } + + /*Release the list lock*/ + ret = pthread_mutex_unlock(&db_conn_mutex); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_WARNING, ret, LG_MSG_UNLOCK_LIST_FAILED, + "Failed unlock on db " + "connection list %s", + strerror(ret)); + /*TODO What if the unlock fails. + * Will it lead to deadlock? + * Most of the gluster code + * no check for unlock or destroy of mutex!*/ + ret = -1; + goto out; + } + ret = 0; out: - return ret; + return ret; } - /*Internal function: Used initialize/map db operation of * specified type of db plugin*/ static int -init_db_operations (gfdb_db_type_t gfdb_db_type, - gfdb_db_operations_t *gfdb_db_operations) +init_db_operations(gfdb_db_type_t gfdb_db_type, + gfdb_db_operations_t *gfdb_db_operations) { + int ret = -1; - int ret = -1; + GF_ASSERT(gfdb_db_operations); - GF_ASSERT (gfdb_db_operations); - - /*Clear the gfdb_db_operations*/ - gfdb_db_operations = memset(gfdb_db_operations, 0, - sizeof(*gfdb_db_operations)); - switch (gfdb_db_type) { + /*Clear the gfdb_db_operations*/ + gfdb_db_operations = memset(gfdb_db_operations, 0, + sizeof(*gfdb_db_operations)); + switch (gfdb_db_type) { case GFDB_SQLITE3: - gf_sqlite3_fill_db_operations (gfdb_db_operations); - ret = 0; - break; + gf_sqlite3_fill_db_operations(gfdb_db_operations); + ret = 0; + break; case GFDB_HYPERDEX: case GFDB_HASH_FILE_STORE: case GFDB_ROCKS_DB: - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_UNSUPPORTED_PLUGIN, "Plugin not supported"); - break; + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_UNSUPPORTED_PLUGIN, + "Plugin not supported"); + break; case GFDB_INVALID_DB: case GFDB_DB_END: - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_INVALID_DB_TYPE, "Invalid DB Type"); - break; - } - return ret; + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INVALID_DB_TYPE, + "Invalid DB Type"); + break; + } + return ret; } - /****************************************************************************** * * LIBGFDB API Functions * * ****************************************************************************/ - /*Libgfdb API Function: Used to initialize a db connection * (Constructor function for db connection object) * Arguments: @@ -225,85 +219,79 @@ init_db_operations (gfdb_db_type_t gfdb_db_type, * Returns : if successful return the GFDB Connection node to the caller or * NULL in case of failure*/ gfdb_conn_node_t * -init_db (dict_t *args, gfdb_db_type_t gfdb_db_type) +init_db(dict_t *args, gfdb_db_type_t gfdb_db_type) { - int ret = -1; - gfdb_conn_node_t *_conn_node = NULL; - gfdb_db_operations_t *db_operations_t = NULL; - - /*Create data base connection object*/ - _conn_node = GF_CALLOC (1, sizeof(gfdb_conn_node_t), - gf_mt_db_conn_node_t); - if (!_conn_node) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, "Failed mem alloc for " - "gfdb_conn_node_t"); - goto alloc_failed; - } - - /*Init the list component of db connection object*/ - INIT_LIST_HEAD (&_conn_node->conn_list); - - - /*Add created connection node to the list*/ - ret = add_connection_node (_conn_node); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_ADD_TO_LIST_FAILED, "Failed to add connection " - "node to list"); - goto _conn_failed; - } - - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - - /*init the db ops object of db connection object*/ - ret = init_db_operations(gfdb_db_type, db_operations_t); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_INIT_DB_FAILED, "Failed initializing database " - "operation failed."); - goto init_db_failed; - } - - /*Calling the init_db_op of the respected db type*/ - GF_ASSERT (db_operations_t->init_db_op); - ret = db_operations_t->init_db_op (args, &_conn_node->gfdb_connection. - gf_db_connection); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_INIT_DB_FAILED, "Failed initializing database"); - goto init_db_failed; - } - _conn_node->gfdb_connection.gfdb_db_type = gfdb_db_type; - ret = 0; - - return _conn_node; - - /*****Error Handling********/ - /* If init_db_operations or init_db of plugin failed delete - * conn node from the list. - * connection node will be free by delete_conn_node*/ + int ret = -1; + gfdb_conn_node_t *_conn_node = NULL; + gfdb_db_operations_t *db_operations_t = NULL; + + /*Create data base connection object*/ + _conn_node = GF_CALLOC(1, sizeof(gfdb_conn_node_t), gf_mt_db_conn_node_t); + if (!_conn_node) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "Failed mem alloc for " + "gfdb_conn_node_t"); + goto alloc_failed; + } + + /*Init the list component of db connection object*/ + INIT_LIST_HEAD(&_conn_node->conn_list); + + /*Add created connection node to the list*/ + ret = add_connection_node(_conn_node); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_ADD_TO_LIST_FAILED, + "Failed to add connection " + "node to list"); + goto _conn_failed; + } + + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + + /*init the db ops object of db connection object*/ + ret = init_db_operations(gfdb_db_type, db_operations_t); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INIT_DB_FAILED, + "Failed initializing database " + "operation failed."); + goto init_db_failed; + } + + /*Calling the init_db_op of the respected db type*/ + GF_ASSERT(db_operations_t->init_db_op); + ret = db_operations_t->init_db_op( + args, &_conn_node->gfdb_connection.gf_db_connection); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_INIT_DB_FAILED, + "Failed initializing database"); + goto init_db_failed; + } + _conn_node->gfdb_connection.gfdb_db_type = gfdb_db_type; + ret = 0; + + return _conn_node; + + /*****Error Handling********/ + /* If init_db_operations or init_db of plugin failed delete + * conn node from the list. + * connection node will be free by delete_conn_node*/ init_db_failed: - ret = delete_conn_node (_conn_node); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DELETE_FROM_LIST_FAILED, "Failed deleting " - "connection node from list"); - } - return NULL; - /*if adding to the list failed free connection node*/ + ret = delete_conn_node(_conn_node); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FROM_LIST_FAILED, + "Failed deleting " + "connection node from list"); + } + return NULL; + /*if adding to the list failed free connection node*/ _conn_failed: - GF_FREE (_conn_node); - /*if allocation failed*/ + GF_FREE(_conn_node); + /*if allocation failed*/ alloc_failed: - return NULL; - /*****Error Handling********/ + return NULL; + /*****Error Handling********/ } - - - - /*Libgfdb API Function: Used to terminate/de-initialize db connection * (Destructor function for db connection object) * Arguments: @@ -311,43 +299,38 @@ alloc_failed: * Returns : if successful return 0 or * -ve value in case of failure*/ int -fini_db (gfdb_conn_node_t *_conn_node) +fini_db(gfdb_conn_node_t *_conn_node) { - int ret = -1; - gfdb_db_operations_t *db_operations_t = NULL; - - CHECK_CONN_NODE_GOTO (_conn_node, empty); - - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - - GF_ASSERT (db_operations_t->fini_db_op); - - ret = db_operations_t->fini_db_op(&_conn_node->gfdb_connection. - gf_db_connection); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_CLOSE_CONNECTION_FAILED, "Failed close the db " - "connection"); - goto out; - } - - ret = delete_conn_node (_conn_node); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DELETE_FROM_LIST_FAILED, "Failed deleting " - "connection node from list"); - } + int ret = -1; + gfdb_db_operations_t *db_operations_t = NULL; + + CHECK_CONN_NODE_GOTO(_conn_node, empty); + + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + + GF_ASSERT(db_operations_t->fini_db_op); + + ret = db_operations_t->fini_db_op( + &_conn_node->gfdb_connection.gf_db_connection); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_CLOSE_CONNECTION_FAILED, + "Failed close the db " + "connection"); + goto out; + } + + ret = delete_conn_node(_conn_node); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FROM_LIST_FAILED, + "Failed deleting " + "connection node from list"); + } empty: - ret = 0; + ret = 0; out: - return ret; + return ret; } - - - - - /*Libgfdb API Function: Used to insert/update records in the database * NOTE: In current gfdb_sqlite plugin we use that * same function to delete the record. Set the @@ -364,36 +347,32 @@ out: * Returns : if successful return 0 or * -ve value in case of failure*/ int -insert_record (gfdb_conn_node_t *_conn_node, - gfdb_db_record_t *gfdb_db_record) +insert_record(gfdb_conn_node_t *_conn_node, gfdb_db_record_t *gfdb_db_record) { - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - CHECK_CONN_NODE(_conn_node); + CHECK_CONN_NODE(_conn_node); - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; - if (db_operations_t->insert_record_op) { - - ret = db_operations_t->insert_record_op (gf_db_connection, - gfdb_db_record); - if (ret) { - gf_msg (GFDB_DATA_STORE, _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), 0, - LG_MSG_INSERT_OR_UPDATE_FAILED, "Insert/Update" - " operation failed"); - } + if (db_operations_t->insert_record_op) { + ret = db_operations_t->insert_record_op(gf_db_connection, + gfdb_db_record); + if (ret) { + gf_msg(GFDB_DATA_STORE, + _gfdb_log_level(GF_LOG_ERROR, gfdb_db_record->ignore_errors), + 0, LG_MSG_INSERT_OR_UPDATE_FAILED, + "Insert/Update" + " operation failed"); } + } - return ret; + return ret; } - - - /*Libgfdb API Function: Used to delete record from the database * NOTE: In the current gfdb_sqlite3 plugin * implementation this function is dummy. @@ -405,31 +384,28 @@ insert_record (gfdb_conn_node_t *_conn_node, * Returns : if successful return 0 or * -ve value in case of failure*/ int -delete_record (gfdb_conn_node_t *_conn_node, - gfdb_db_record_t *gfdb_db_record) +delete_record(gfdb_conn_node_t *_conn_node, gfdb_db_record_t *gfdb_db_record) { - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(_conn_node); + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + CHECK_CONN_NODE(_conn_node); - if (db_operations_t->delete_record_op) { - - ret = db_operations_t->delete_record_op (gf_db_connection, - gfdb_db_record); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DELETE_FAILED, "Delete operation " - "failed"); - } + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->delete_record_op) { + ret = db_operations_t->delete_record_op(gf_db_connection, + gfdb_db_record); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DELETE_FAILED, + "Delete operation " + "failed"); } + } - return ret; + return ret; } /*Libgfdb API Function: Compact the database. @@ -441,38 +417,31 @@ delete_record (gfdb_conn_node_t *_conn_node, * Returns : if successful return 0 or * -ve value in case of failure*/ int -compact_db (gfdb_conn_node_t *_conn_node, gf_boolean_t _compact_active, - gf_boolean_t _compact_mode_switched) +compact_db(gfdb_conn_node_t *_conn_node, gf_boolean_t _compact_active, + gf_boolean_t _compact_mode_switched) { - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - CHECK_CONN_NODE(_conn_node); + CHECK_CONN_NODE(_conn_node); - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; - - if (db_operations_t->compact_db_op) { - - ret = db_operations_t->compact_db_op (gf_db_connection, - _compact_active, - _compact_mode_switched); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_COMPACT_FAILED, "Compaction operation " - "failed"); - } + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->compact_db_op) { + ret = db_operations_t->compact_db_op(gf_db_connection, _compact_active, + _compact_mode_switched); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_COMPACT_FAILED, + "Compaction operation " + "failed"); } + } - return ret; + return ret; } - - - - /*Libgfdb API Function: Query all the records from the database * Arguments: * _conn_node : GFDB Connection node @@ -484,37 +453,30 @@ compact_db (gfdb_conn_node_t *_conn_node, gf_boolean_t _compact_active, * Returns : if successful return 0 or * -ve value in case of failure*/ int -find_all (gfdb_conn_node_t *_conn_node, - gf_query_callback_t query_callback, - void *_query_cbk_args, - int query_limit) +find_all(gfdb_conn_node_t *_conn_node, gf_query_callback_t query_callback, + void *_query_cbk_args, int query_limit) { - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(_conn_node); - - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; - - if (db_operations_t->find_all_op) { - ret = db_operations_t->find_all_op (gf_db_connection, - query_callback, - _query_cbk_args, - query_limit); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, "Find all operation " - "failed"); - } + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - } + CHECK_CONN_NODE(_conn_node); - return ret; -} + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->find_all_op) { + ret = db_operations_t->find_all_op(gf_db_connection, query_callback, + _query_cbk_args, query_limit); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Find all operation " + "failed"); + } + } + return ret; +} /*Libgfdb API Function: Query records/files that have not changed/accessed * from a time in past to current time @@ -529,35 +491,30 @@ find_all (gfdb_conn_node_t *_conn_node, * Returns : if successful return 0 or * -ve value in case of failure*/ int -find_unchanged_for_time(gfdb_conn_node_t *_conn_node, - gf_query_callback_t query_callback, - void *_query_cbk_args, - gfdb_time_t *for_time) +find_unchanged_for_time(gfdb_conn_node_t *_conn_node, + gf_query_callback_t query_callback, + void *_query_cbk_args, gfdb_time_t *for_time) { + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(_conn_node); - - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; - - if (db_operations_t->find_unchanged_for_time_op) { + CHECK_CONN_NODE(_conn_node); - ret = db_operations_t->find_unchanged_for_time_op - (gf_db_connection, query_callback, - _query_cbk_args, for_time); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, "Find unchanged " - "operation failed"); - } + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->find_unchanged_for_time_op) { + ret = db_operations_t->find_unchanged_for_time_op( + gf_db_connection, query_callback, _query_cbk_args, for_time); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Find unchanged " + "operation failed"); } + } - return ret; + return ret; } /*Libgfdb API Function: Query records/files that have changed/accessed from a @@ -573,36 +530,29 @@ find_unchanged_for_time(gfdb_conn_node_t *_conn_node, * Returns : if successful return 0 or * -ve value in case of failure*/ int -find_recently_changed_files(gfdb_conn_node_t *_conn_node, +find_recently_changed_files(gfdb_conn_node_t *_conn_node, gf_query_callback_t query_callback, - void *_query_cbk_args, - gfdb_time_t *from_time) + void *_query_cbk_args, gfdb_time_t *from_time) { + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(_conn_node); - - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + CHECK_CONN_NODE(_conn_node); - if (db_operations_t->find_recently_changed_files_op) { - - ret = db_operations_t->find_recently_changed_files_op ( - gf_db_connection, query_callback, - _query_cbk_args, from_time); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, - "Find changed operation failed"); - } + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->find_recently_changed_files_op) { + ret = db_operations_t->find_recently_changed_files_op( + gf_db_connection, query_callback, _query_cbk_args, from_time); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Find changed operation failed"); } + } - return ret; - + return ret; } /*Libgfdb API Function: Query records/files that have not changed/accessed @@ -624,38 +574,31 @@ find_recently_changed_files(gfdb_conn_node_t *_conn_node, * -ve value in case of failure*/ int find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node, - gf_query_callback_t query_callback, - void *_query_cbk_args, - gfdb_time_t *for_time, - int write_freq_thresold, - int read_freq_thresold, - gf_boolean_t _clear_counters) + gf_query_callback_t query_callback, + void *_query_cbk_args, gfdb_time_t *for_time, + int write_freq_thresold, int read_freq_thresold, + gf_boolean_t _clear_counters) { - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(_conn_node); + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + CHECK_CONN_NODE(_conn_node); - if (db_operations_t->find_unchanged_for_time_freq_op) { - - ret = db_operations_t->find_unchanged_for_time_freq_op( - gf_db_connection, query_callback, - _query_cbk_args, for_time, - write_freq_thresold, read_freq_thresold, - _clear_counters); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, - "Find unchanged with freq operation failed"); - } + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->find_unchanged_for_time_freq_op) { + ret = db_operations_t->find_unchanged_for_time_freq_op( + gf_db_connection, query_callback, _query_cbk_args, for_time, + write_freq_thresold, read_freq_thresold, _clear_counters); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Find unchanged with freq operation failed"); } + } - return ret; + return ret; } /*Libgfdb API Function: Query records/files that have changed/accessed from a @@ -677,44 +620,34 @@ find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node, * -ve value in case of failure*/ int find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node, - gf_query_callback_t query_callback, - void *_query_cbk_args, - gfdb_time_t *from_time, - int write_freq_thresold, - int read_freq_thresold, - gf_boolean_t _clear_counters) + gf_query_callback_t query_callback, + void *_query_cbk_args, gfdb_time_t *from_time, + int write_freq_thresold, + int read_freq_thresold, + gf_boolean_t _clear_counters) { + int ret = 0; + gfdb_db_operations_t *db_operations_t = NULL; + void *gf_db_connection = NULL; - int ret = 0; - gfdb_db_operations_t *db_operations_t = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(_conn_node); - - db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + CHECK_CONN_NODE(_conn_node); - if (db_operations_t->find_recently_changed_files_freq_op) { - - ret = db_operations_t->find_recently_changed_files_freq_op( - gf_db_connection, query_callback, - _query_cbk_args, from_time, - write_freq_thresold, read_freq_thresold, - _clear_counters); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, - "Find changed with freq operation failed"); - } + db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = _conn_node->gfdb_connection.gf_db_connection; + if (db_operations_t->find_recently_changed_files_freq_op) { + ret = db_operations_t->find_recently_changed_files_freq_op( + gf_db_connection, query_callback, _query_cbk_args, from_time, + write_freq_thresold, read_freq_thresold, _clear_counters); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Find changed with freq operation failed"); } + } - return ret; - + return ret; } - - /*Libgfdb API Function: Clear the heat for all the files * * Arguments: @@ -725,30 +658,29 @@ find_recently_changed_files_freq(gfdb_conn_node_t *_conn_node, **/ int -clear_files_heat (gfdb_conn_node_t *conn_node) +clear_files_heat(gfdb_conn_node_t *conn_node) { - int ret = 0; - gfdb_db_operations_t *db_operations = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(conn_node); - - db_operations = &conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = conn_node->gfdb_connection.gf_db_connection; - - if (db_operations->clear_files_heat_op) { - ret = db_operations->clear_files_heat_op (gf_db_connection); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_INSERT_OR_UPDATE_FAILED, - "Clear files heat operation failed"); - } + int ret = 0; + gfdb_db_operations_t *db_operations = NULL; + void *gf_db_connection = NULL; + + CHECK_CONN_NODE(conn_node); + + db_operations = &conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = conn_node->gfdb_connection.gf_db_connection; + + if (db_operations->clear_files_heat_op) { + ret = db_operations->clear_files_heat_op(gf_db_connection); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, + LG_MSG_INSERT_OR_UPDATE_FAILED, + "Clear files heat operation failed"); } + } - return ret; + return ret; } - /* Libgfdb API Function: Function to extract version of the db * Input: * gfdb_conn_node_t *conn_node : GFDB Connection node @@ -761,122 +693,111 @@ clear_files_heat (gfdb_conn_node_t *conn_node) * On failure return -1 * */ int -get_db_version (gfdb_conn_node_t *conn_node, char **version) +get_db_version(gfdb_conn_node_t *conn_node, char **version) { - int ret = 0; - gfdb_db_operations_t *db_operations = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(conn_node); - - db_operations = &conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = conn_node->gfdb_connection.gf_db_connection; - - if (db_operations->get_db_version) { - ret = db_operations->get_db_version (gf_db_connection, - version); - if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, - "Get version failed"); - } + int ret = 0; + gfdb_db_operations_t *db_operations = NULL; + void *gf_db_connection = NULL; + + CHECK_CONN_NODE(conn_node); + + db_operations = &conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = conn_node->gfdb_connection.gf_db_connection; + + if (db_operations->get_db_version) { + ret = db_operations->get_db_version(gf_db_connection, version); + if (ret < 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Get version failed"); } + } - return ret; + return ret; } int -get_db_params (gfdb_conn_node_t *conn_node, char *param_key, - char **param_value) +get_db_params(gfdb_conn_node_t *conn_node, char *param_key, char **param_value) { - int ret = -1; - gfdb_db_operations_t *db_operations = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(conn_node); - - db_operations = &conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = conn_node->gfdb_connection.gf_db_connection; - - if (db_operations->get_db_params) { - ret = db_operations->get_db_params (gf_db_connection, - param_key, - param_value); - if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_FIND_OP_FAILED, - "Get setting failed"); - } + int ret = -1; + gfdb_db_operations_t *db_operations = NULL; + void *gf_db_connection = NULL; + + CHECK_CONN_NODE(conn_node); + + db_operations = &conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = conn_node->gfdb_connection.gf_db_connection; + + if (db_operations->get_db_params) { + ret = db_operations->get_db_params(gf_db_connection, param_key, + param_value); + if (ret < 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_FIND_OP_FAILED, + "Get setting failed"); } + } - return ret; + return ret; } - int -set_db_params (gfdb_conn_node_t *conn_node, char *param_key, - char *param_value) +set_db_params(gfdb_conn_node_t *conn_node, char *param_key, char *param_value) { - int ret = -1; - gfdb_db_operations_t *db_operations = NULL; - void *gf_db_connection = NULL; - - CHECK_CONN_NODE(conn_node); - - db_operations = &conn_node->gfdb_connection.gfdb_db_operations; - gf_db_connection = conn_node->gfdb_connection.gf_db_connection; - - if (db_operations->set_db_params) { - ret = db_operations->set_db_params (gf_db_connection, - param_key, - param_value); - if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_INSERT_OR_UPDATE_FAILED, - "Failed to set database setting"); - } + int ret = -1; + gfdb_db_operations_t *db_operations = NULL; + void *gf_db_connection = NULL; + + CHECK_CONN_NODE(conn_node); + + db_operations = &conn_node->gfdb_connection.gfdb_db_operations; + gf_db_connection = conn_node->gfdb_connection.gf_db_connection; + + if (db_operations->set_db_params) { + ret = db_operations->set_db_params(gf_db_connection, param_key, + param_value); + if (ret < 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, + LG_MSG_INSERT_OR_UPDATE_FAILED, + "Failed to set database setting"); } + } - return ret; + return ret; } - - - -static const -char *get_db_path_key() +static const char * +get_db_path_key() { - return GFDB_SQL_PARAM_DBPATH; + return GFDB_SQL_PARAM_DBPATH; } -void get_gfdb_methods (gfdb_methods_t *methods) +void +get_gfdb_methods(gfdb_methods_t *methods) { - methods->init_db = init_db; - methods->fini_db = fini_db; - methods->find_all = find_all; - methods->find_unchanged_for_time = find_unchanged_for_time; - methods->find_recently_changed_files = find_recently_changed_files; - methods->find_unchanged_for_time_freq = find_unchanged_for_time_freq; - methods->find_recently_changed_files_freq = - find_recently_changed_files_freq; - methods->clear_files_heat = clear_files_heat; - methods->get_db_version = get_db_version; - methods->get_db_params = get_db_params; - methods->set_db_params = set_db_params; - methods->get_db_path_key = get_db_path_key; - - /* Query Record related functions */ - methods->gfdb_query_record_new = gfdb_query_record_new; - methods->gfdb_query_record_free = gfdb_query_record_free; - methods->gfdb_add_link_to_query_record = gfdb_add_link_to_query_record; - methods->gfdb_write_query_record = gfdb_write_query_record; - methods->gfdb_read_query_record = gfdb_read_query_record; - - /* Link info related functions */ - methods->gfdb_link_info_new = gfdb_link_info_new; - methods->gfdb_link_info_free = gfdb_link_info_free; - - /* Compaction related functions */ - methods->compact_db = compact_db; + methods->init_db = init_db; + methods->fini_db = fini_db; + methods->find_all = find_all; + methods->find_unchanged_for_time = find_unchanged_for_time; + methods->find_recently_changed_files = find_recently_changed_files; + methods->find_unchanged_for_time_freq = find_unchanged_for_time_freq; + methods + ->find_recently_changed_files_freq = find_recently_changed_files_freq; + methods->clear_files_heat = clear_files_heat; + methods->get_db_version = get_db_version; + methods->get_db_params = get_db_params; + methods->set_db_params = set_db_params; + methods->get_db_path_key = get_db_path_key; + + /* Query Record related functions */ + methods->gfdb_query_record_new = gfdb_query_record_new; + methods->gfdb_query_record_free = gfdb_query_record_free; + methods->gfdb_add_link_to_query_record = gfdb_add_link_to_query_record; + methods->gfdb_write_query_record = gfdb_write_query_record; + methods->gfdb_read_query_record = gfdb_read_query_record; + + /* Link info related functions */ + methods->gfdb_link_info_new = gfdb_link_info_new; + methods->gfdb_link_info_free = gfdb_link_info_free; + + /* Compaction related functions */ + methods->compact_db = compact_db; } - diff --git a/libglusterfs/src/gfdb/gfdb_data_store_helper.c b/libglusterfs/src/gfdb/gfdb_data_store_helper.c index 39a97ff73d9..fb01a6c699b 100644 --- a/libglusterfs/src/gfdb/gfdb_data_store_helper.c +++ b/libglusterfs/src/gfdb/gfdb_data_store_helper.c @@ -9,151 +9,139 @@ * ****************************************************************************/ /*Create a single link info structure*/ -gfdb_link_info_t* -gfdb_link_info_new () +gfdb_link_info_t * +gfdb_link_info_new() { - gfdb_link_info_t *link_info = NULL; + gfdb_link_info_t *link_info = NULL; - link_info = GF_CALLOC (1, sizeof(gfdb_link_info_t), - gf_mt_gfdb_link_info_t); - if (!link_info) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, "Memory allocation failed for " - "link_info "); - goto out; - } + link_info = GF_CALLOC(1, sizeof(gfdb_link_info_t), gf_mt_gfdb_link_info_t); + if (!link_info) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "Memory allocation failed for " + "link_info "); + goto out; + } - INIT_LIST_HEAD (&link_info->list); + INIT_LIST_HEAD(&link_info->list); out: - return link_info; + return link_info; } /*Destroy a link info structure*/ void gfdb_link_info_free(gfdb_link_info_t *link_info) { - GF_FREE (link_info); + GF_FREE(link_info); } - /*Function to create the query_record*/ gfdb_query_record_t * gfdb_query_record_new() { - int ret = -1; - gfdb_query_record_t *query_record = NULL; - - query_record = GF_CALLOC (1, sizeof(gfdb_query_record_t), - gf_mt_gfdb_query_record_t); - if (!query_record) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, "Memory allocation failed for " - "query_record "); - goto out; - } + int ret = -1; + gfdb_query_record_t *query_record = NULL; - INIT_LIST_HEAD (&query_record->link_list); + query_record = GF_CALLOC(1, sizeof(gfdb_query_record_t), + gf_mt_gfdb_query_record_t); + if (!query_record) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "Memory allocation failed for " + "query_record "); + goto out; + } - ret = 0; + INIT_LIST_HEAD(&query_record->link_list); + + ret = 0; out: - if (ret == -1) { - GF_FREE (query_record); - } - return query_record; + if (ret == -1) { + GF_FREE(query_record); + } + return query_record; } - /*Function to delete a single linkinfo from list*/ static void -gfdb_delete_linkinfo_from_list (gfdb_link_info_t **link_info) +gfdb_delete_linkinfo_from_list(gfdb_link_info_t **link_info) { - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, link_info, out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, *link_info, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, link_info, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, *link_info, out); - /*Remove hard link from list*/ - list_del(&(*link_info)->list); - gfdb_link_info_free (*link_info); - link_info = NULL; + /*Remove hard link from list*/ + list_del(&(*link_info)->list); + gfdb_link_info_free(*link_info); + link_info = NULL; out: - return; + return; } - /*Function to destroy link_info list*/ void -gfdb_free_link_info_list (gfdb_query_record_t *query_record) +gfdb_free_link_info_list(gfdb_query_record_t *query_record) { - gfdb_link_info_t *link_info = NULL; - gfdb_link_info_t *temp = NULL; + gfdb_link_info_t *link_info = NULL; + gfdb_link_info_t *temp = NULL; - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); - list_for_each_entry_safe(link_info, temp, - &query_record->link_list, list) - { - gfdb_delete_linkinfo_from_list (&link_info); - link_info = NULL; - } + list_for_each_entry_safe(link_info, temp, &query_record->link_list, list) + { + gfdb_delete_linkinfo_from_list(&link_info); + link_info = NULL; + } out: - return; + return; } - - /* Function to add linkinfo to the query record */ int -gfdb_add_link_to_query_record (gfdb_query_record_t *query_record, - uuid_t pgfid, - char *base_name) +gfdb_add_link_to_query_record(gfdb_query_record_t *query_record, uuid_t pgfid, + char *base_name) { - int ret = -1; - gfdb_link_info_t *link_info = NULL; - int base_name_len = 0; + int ret = -1; + gfdb_link_info_t *link_info = NULL; + int base_name_len = 0; - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, pgfid, out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, base_name, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, pgfid, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, base_name, out); - link_info = gfdb_link_info_new (); - if (!link_info) { - goto out; - } + link_info = gfdb_link_info_new(); + if (!link_info) { + goto out; + } - gf_uuid_copy (link_info->pargfid, pgfid); - base_name_len = strlen (base_name); - memcpy (link_info->file_name, base_name, base_name_len); - link_info->file_name[base_name_len] = '\0'; + gf_uuid_copy(link_info->pargfid, pgfid); + base_name_len = strlen(base_name); + memcpy(link_info->file_name, base_name, base_name_len); + link_info->file_name[base_name_len] = '\0'; - list_add_tail (&link_info->list, - &query_record->link_list); + list_add_tail(&link_info->list, &query_record->link_list); - query_record->link_count++; + query_record->link_count++; - ret = 0; + ret = 0; out: - if (ret) { - gfdb_link_info_free (link_info); - link_info = NULL; - } - return ret; + if (ret) { + gfdb_link_info_free(link_info); + link_info = NULL; + } + return ret; } - - /*Function to destroy query record*/ void gfdb_query_record_free(gfdb_query_record_t *query_record) { - if (query_record) { - gfdb_free_link_info_list (query_record); - GF_FREE (query_record); - } + if (query_record) { + gfdb_free_link_info_list(query_record); + GF_FREE(query_record); + } } - /****************************************************************************** SERIALIZATION/DE-SERIALIZATION OF QUERY RECORD *******************************************************************************/ @@ -197,40 +185,39 @@ gfdb_query_record_free(gfdb_query_record_t *query_record) * ****************************************************************************/ #define GFDB_QUERY_RECORD_FOOTER 0xBAADF00D -#define UUID_LEN 16 +#define UUID_LEN 16 /*Function to get the potential length of the serialized buffer*/ static int32_t -gfdb_query_record_serialized_length (gfdb_query_record_t *query_record) +gfdb_query_record_serialized_length(gfdb_query_record_t *query_record) { - int32_t len = -1; - gfdb_link_info_t *link_info = NULL; - - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); + int32_t len = -1; + gfdb_link_info_t *link_info = NULL; - /* Length of GFID */ - len = UUID_LEN; + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); - /* length of number of links*/ - len += sizeof (int32_t); + /* Length of GFID */ + len = UUID_LEN; - list_for_each_entry (link_info, &query_record->link_list, list) { + /* length of number of links*/ + len += sizeof(int32_t); - /* length of PFID */ - len += UUID_LEN; + list_for_each_entry(link_info, &query_record->link_list, list) + { + /* length of PFID */ + len += UUID_LEN; - /* Add size of base name length*/ - len += sizeof (int32_t); + /* Add size of base name length*/ + len += sizeof(int32_t); - /* Length of base_name */ - len += strlen (link_info->file_name); - - } + /* Length of base_name */ + len += strlen(link_info->file_name); + } - /* length of footer */ - len += sizeof (int32_t); + /* length of footer */ + len += sizeof(int32_t); out: - return len; + return len; } /* Function for serializing query record. @@ -259,210 +246,200 @@ out: * * */ static int -gfdb_query_record_serialize (gfdb_query_record_t *query_record, - char **in_buffer) +gfdb_query_record_serialize(gfdb_query_record_t *query_record, char **in_buffer) { - gfdb_link_info_t *link_info = NULL; - int count = -1; - int base_name_len = 0; - int buffer_length = 0; - int footer = GFDB_QUERY_RECORD_FOOTER; - char *buffer = NULL; - char *ret_buffer = NULL; - - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, - (query_record->link_count > 0), out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, in_buffer, out); - - - /* Calculate the total length of the serialized buffer */ - buffer_length = gfdb_query_record_serialized_length (query_record); - if (buffer_length <= 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to calculate the length of " - "serialized buffer"); - goto out; - } - - /* Allocate memory to the serialized buffer */ - ret_buffer = GF_CALLOC (1, buffer_length, gf_common_mt_char); - if (!ret_buffer) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Memory allocation failed for " - "serialized buffer."); - goto out; - } - - buffer = ret_buffer; - - count = 0; - - /* Copying the GFID */ - memcpy (buffer, query_record->gfid, UUID_LEN); + gfdb_link_info_t *link_info = NULL; + int count = -1; + int base_name_len = 0; + int buffer_length = 0; + int footer = GFDB_QUERY_RECORD_FOOTER; + char *buffer = NULL; + char *ret_buffer = NULL; + + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, (query_record->link_count > 0), out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, in_buffer, out); + + /* Calculate the total length of the serialized buffer */ + buffer_length = gfdb_query_record_serialized_length(query_record); + if (buffer_length <= 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to calculate the length of " + "serialized buffer"); + goto out; + } + + /* Allocate memory to the serialized buffer */ + ret_buffer = GF_CALLOC(1, buffer_length, gf_common_mt_char); + if (!ret_buffer) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Memory allocation failed for " + "serialized buffer."); + goto out; + } + + buffer = ret_buffer; + + count = 0; + + /* Copying the GFID */ + memcpy(buffer, query_record->gfid, UUID_LEN); + buffer += UUID_LEN; + count += UUID_LEN; + + /* Copying the number of links */ + memcpy(buffer, &query_record->link_count, sizeof(int32_t)); + buffer += sizeof(int32_t); + count += sizeof(int32_t); + + list_for_each_entry(link_info, &query_record->link_list, list) + { + /* Copying the PFID */ + memcpy(buffer, link_info->pargfid, UUID_LEN); buffer += UUID_LEN; count += UUID_LEN; - /* Copying the number of links */ - memcpy (buffer, &query_record->link_count, sizeof (int32_t)); - buffer += sizeof (int32_t); - count += sizeof (int32_t); - - list_for_each_entry (link_info, &query_record->link_list, list) { - - /* Copying the PFID */ - memcpy(buffer, link_info->pargfid, UUID_LEN); - buffer += UUID_LEN; - count += UUID_LEN; - - /* Copying base name length*/ - base_name_len = strlen (link_info->file_name); - memcpy (buffer, &base_name_len, sizeof (int32_t)); - buffer += sizeof (int32_t); - count += sizeof (int32_t); + /* Copying base name length*/ + base_name_len = strlen(link_info->file_name); + memcpy(buffer, &base_name_len, sizeof(int32_t)); + buffer += sizeof(int32_t); + count += sizeof(int32_t); - /* Length of base_name */ - memcpy(buffer, link_info->file_name, base_name_len); - buffer += base_name_len; - count += base_name_len; + /* Length of base_name */ + memcpy(buffer, link_info->file_name, base_name_len); + buffer += base_name_len; + count += base_name_len; + } - } - - /* Copying the Footer of the record */ - memcpy (buffer, &footer, sizeof (int32_t)); - buffer += sizeof (int32_t); - count += sizeof (int32_t); + /* Copying the Footer of the record */ + memcpy(buffer, &footer, sizeof(int32_t)); + buffer += sizeof(int32_t); + count += sizeof(int32_t); out: - if (count < 0) { - GF_FREE (ret_buffer); - ret_buffer = NULL; - } - *in_buffer = ret_buffer; - return count; + if (count < 0) { + GF_FREE(ret_buffer); + ret_buffer = NULL; + } + *in_buffer = ret_buffer; + return count; } static gf_boolean_t -is_serialized_buffer_valid (char *in_buffer, int buffer_length) { - gf_boolean_t ret = _gf_false; - int footer = 0; - - /* Read the footer */ - in_buffer += (buffer_length - sizeof (int32_t)); - memcpy (&footer, in_buffer, sizeof (int32_t)); - - /* - * if the footer is not GFDB_QUERY_RECORD_FOOTER - * then the serialized record is invalid - * - * */ - if (footer != GFDB_QUERY_RECORD_FOOTER) { - goto out; - } - - ret = _gf_true; +is_serialized_buffer_valid(char *in_buffer, int buffer_length) +{ + gf_boolean_t ret = _gf_false; + int footer = 0; + + /* Read the footer */ + in_buffer += (buffer_length - sizeof(int32_t)); + memcpy(&footer, in_buffer, sizeof(int32_t)); + + /* + * if the footer is not GFDB_QUERY_RECORD_FOOTER + * then the serialized record is invalid + * + * */ + if (footer != GFDB_QUERY_RECORD_FOOTER) { + goto out; + } + + ret = _gf_true; out: - return ret; + return ret; } - static int -gfdb_query_record_deserialize (char *in_buffer, - int buffer_length, - gfdb_query_record_t **query_record) +gfdb_query_record_deserialize(char *in_buffer, int buffer_length, + gfdb_query_record_t **query_record) { - int ret = -1; - char *buffer = NULL; - int i = 0; - gfdb_link_info_t *link_info = NULL; - int count = 0; - int base_name_len = 0; - gfdb_query_record_t *ret_qrecord = NULL; - - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, in_buffer, out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, (buffer_length > 0), out); - - if (!is_serialized_buffer_valid (in_buffer, buffer_length)) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Invalid serialized query record"); - goto out; + int ret = -1; + char *buffer = NULL; + int i = 0; + gfdb_link_info_t *link_info = NULL; + int count = 0; + int base_name_len = 0; + gfdb_query_record_t *ret_qrecord = NULL; + + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, in_buffer, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, (buffer_length > 0), out); + + if (!is_serialized_buffer_valid(in_buffer, buffer_length)) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Invalid serialized query record"); + goto out; + } + + buffer = in_buffer; + + ret_qrecord = gfdb_query_record_new(); + if (!ret_qrecord) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to allocate space to " + "gfdb_query_record_t"); + goto out; + } + + /* READ GFID */ + memcpy((ret_qrecord)->gfid, buffer, UUID_LEN); + buffer += UUID_LEN; + count += UUID_LEN; + + /* Read the number of link */ + memcpy(&(ret_qrecord->link_count), buffer, sizeof(int32_t)); + buffer += sizeof(int32_t); + count += sizeof(int32_t); + + /* Read all the links */ + for (i = 0; i < ret_qrecord->link_count; i++) { + if (count >= buffer_length) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Invalid serialized " + "query record"); + ret = -1; + goto out; } - buffer = in_buffer; - - ret_qrecord = gfdb_query_record_new (); - if (!ret_qrecord) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to allocate space to " - "gfdb_query_record_t"); - goto out; + link_info = gfdb_link_info_new(); + if (!link_info) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to create link_info"); + goto out; } - /* READ GFID */ - memcpy ((ret_qrecord)->gfid, buffer, UUID_LEN); + /* READ PGFID */ + memcpy(link_info->pargfid, buffer, UUID_LEN); buffer += UUID_LEN; count += UUID_LEN; - /* Read the number of link */ - memcpy (&(ret_qrecord->link_count), buffer, sizeof (int32_t)); - buffer += sizeof (int32_t); - count += sizeof (int32_t); - - /* Read all the links */ - for (i = 0; i < ret_qrecord->link_count; i++) { - if (count >= buffer_length) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Invalid serialized " - "query record"); - ret = -1; - goto out; - } - - link_info = gfdb_link_info_new (); - if (!link_info) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to create link_info"); - goto out; - } - - /* READ PGFID */ - memcpy (link_info->pargfid, buffer, UUID_LEN); - buffer += UUID_LEN; - count += UUID_LEN; - - /* Read base name length */ - memcpy (&base_name_len, buffer, sizeof (int32_t)); - buffer += sizeof (int32_t); - count += sizeof (int32_t); - - /* READ basename */ - memcpy (link_info->file_name, buffer, base_name_len); - buffer += base_name_len; - count += base_name_len; - link_info->file_name[base_name_len] = '\0'; - - /* Add link_info to the list */ - list_add_tail (&link_info->list, - &(ret_qrecord->link_list)); - - /* Resetting link_info */ - link_info = NULL; - } - - ret = 0; -out: - if (ret) { - gfdb_query_record_free (ret_qrecord); - ret_qrecord = NULL; - } - *query_record = ret_qrecord; - return ret; -} + /* Read base name length */ + memcpy(&base_name_len, buffer, sizeof(int32_t)); + buffer += sizeof(int32_t); + count += sizeof(int32_t); + /* READ basename */ + memcpy(link_info->file_name, buffer, base_name_len); + buffer += base_name_len; + count += base_name_len; + link_info->file_name[base_name_len] = '\0'; + /* Add link_info to the list */ + list_add_tail(&link_info->list, &(ret_qrecord->link_list)); + /* Resetting link_info */ + link_info = NULL; + } + ret = 0; +out: + if (ret) { + gfdb_query_record_free(ret_qrecord); + ret_qrecord = NULL; + } + *query_record = ret_qrecord; + return ret; +} /* Function to write query record to file * @@ -477,57 +454,54 @@ out: * * */ int -gfdb_write_query_record (int fd, - gfdb_query_record_t *query_record) +gfdb_write_query_record(int fd, gfdb_query_record_t *query_record) { - int ret = -1; - int buffer_len = 0; - char *buffer = NULL; - int write_len = 0; - char *write_buffer = NULL; - - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, (fd >= 0), out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); - - buffer_len = gfdb_query_record_serialize (query_record, &buffer); - if (buffer_len < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to serialize query record"); - goto out; - } - - /* Serialize the buffer length and write to file */ - ret = write (fd, &buffer_len, sizeof (int32_t)); + int ret = -1; + int buffer_len = 0; + char *buffer = NULL; + int write_len = 0; + char *write_buffer = NULL; + + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, (fd >= 0), out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); + + buffer_len = gfdb_query_record_serialize(query_record, &buffer); + if (buffer_len < 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to serialize query record"); + goto out; + } + + /* Serialize the buffer length and write to file */ + ret = write(fd, &buffer_len, sizeof(int32_t)); + if (ret < 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to write buffer length" + " to file"); + goto out; + } + + /* Write the serialized query record to file */ + write_len = buffer_len; + write_buffer = buffer; + while ((ret = write(fd, write_buffer, write_len)) < write_len) { if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to write buffer length" - " to file"); - goto out; + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, errno, LG_MSG_DB_ERROR, + "Failed to write serialized " + "query record to file"); + goto out; } - /* Write the serialized query record to file */ - write_len = buffer_len; - write_buffer = buffer; - while ((ret = write (fd, write_buffer, write_len)) < write_len) { - if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, errno, - LG_MSG_DB_ERROR, "Failed to write serialized " - "query record to file"); - goto out; - } - - write_buffer += ret; - write_len -= ret; - } + write_buffer += ret; + write_len -= ret; + } - ret = 0; + ret = 0; out: - GF_FREE (buffer); - return ret; + GF_FREE(buffer); + return ret; } - - /* Function to read query record from file. * Allocates memory to query record and * returns length of serialized query record when successful @@ -535,86 +509,81 @@ out: * Return 0 when reached EOF. * */ int -gfdb_read_query_record (int fd, - gfdb_query_record_t **query_record) +gfdb_read_query_record(int fd, gfdb_query_record_t **query_record) { - int ret = -1; - int buffer_len = 0; - int read_len = 0; - char *buffer = NULL; - char *read_buffer = NULL; - - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, (fd >= 0), out); - GF_VALIDATE_OR_GOTO (GFDB_DATA_STORE, query_record, out); - - - /* Read serialized query record length from the file*/ - ret = sys_read (fd, &buffer_len, sizeof (int32_t)); + int ret = -1; + int buffer_len = 0; + int read_len = 0; + char *buffer = NULL; + char *read_buffer = NULL; + + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, (fd >= 0), out); + GF_VALIDATE_OR_GOTO(GFDB_DATA_STORE, query_record, out); + + /* Read serialized query record length from the file*/ + ret = sys_read(fd, &buffer_len, sizeof(int32_t)); + if (ret < 0) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed reading buffer length" + " from file"); + goto out; + } + /* EOF */ + else if (ret == 0) { + ret = 0; + goto out; + } + + /* Assumed sane range is 1B - 10MB */ + if ((buffer_len <= 0) || (buffer_len > (10 * 1024 * 1024))) { + ret = -1; + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "buffer length range is out of bound %d", buffer_len); + goto out; + } + + /* Allocating memory to the serialization buffer */ + buffer = GF_CALLOC(1, buffer_len, gf_common_mt_char); + if (!buffer) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to allocate space to " + "serialized buffer"); + goto out; + } + + /* Read the serialized query record from file */ + read_len = buffer_len; + read_buffer = buffer; + while ((ret = sys_read(fd, read_buffer, read_len)) < read_len) { + /*Any error */ if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed reading buffer length" - " from file"); - goto out; + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, errno, LG_MSG_DB_ERROR, + "Failed to read serialized " + "query record from file"); + goto out; } /* EOF */ else if (ret == 0) { - ret = 0; - goto out; + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Invalid query record or " + "corrupted query file"); + ret = -1; + goto out; } - /* Assumed sane range is 1B - 10MB */ - if ((buffer_len <= 0) || (buffer_len > (10 * 1024 * 1024))) { - ret = -1; - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, - "buffer length range is out of bound %d", buffer_len); - goto out; - } - - /* Allocating memory to the serialization buffer */ - buffer = GF_CALLOC (1, buffer_len, gf_common_mt_char); - if (!buffer) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to allocate space to " - "serialized buffer"); - goto out; - } + read_buffer += ret; + read_len -= ret; + } + ret = gfdb_query_record_deserialize(buffer, buffer_len, query_record); + if (ret) { + gf_msg(GFDB_DATA_STORE, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "Failed to de-serialize query record"); + goto out; + } - /* Read the serialized query record from file */ - read_len = buffer_len; - read_buffer = buffer; - while ((ret = sys_read (fd, read_buffer, read_len)) < read_len) { - - /*Any error */ - if (ret < 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, errno, - LG_MSG_DB_ERROR, "Failed to read serialized " - "query record from file"); - goto out; - } - /* EOF */ - else if (ret == 0) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Invalid query record or " - "corrupted query file"); - ret = -1; - goto out; - } - - read_buffer += ret; - read_len -= ret; - } - - ret = gfdb_query_record_deserialize (buffer, buffer_len, - query_record); - if (ret) { - gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0, - LG_MSG_DB_ERROR, "Failed to de-serialize query record"); - goto out; - } - - ret = buffer_len; + ret = buffer_len; out: - GF_FREE (buffer); - return ret; + GF_FREE(buffer); + return ret; } diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3.c b/libglusterfs/src/gfdb/gfdb_sqlite3.c index ad94d648369..63957278e8a 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3.c @@ -19,160 +19,158 @@ * * ***************************************************************************/ gf_sql_connection_t * -gf_sql_connection_init () +gf_sql_connection_init() { - gf_sql_connection_t *gf_sql_conn = NULL; - - gf_sql_conn = GF_CALLOC (1, sizeof(gf_sql_connection_t), - gf_mt_sql_connection_t); - if (gf_sql_conn == NULL) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, "Error allocating memory to " - "gf_sql_connection_t "); - } + gf_sql_connection_t *gf_sql_conn = NULL; + + gf_sql_conn = GF_CALLOC(1, sizeof(gf_sql_connection_t), + gf_mt_sql_connection_t); + if (gf_sql_conn == NULL) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "Error allocating memory to " + "gf_sql_connection_t "); + } - return gf_sql_conn; + return gf_sql_conn; } void -gf_sql_connection_fini (gf_sql_connection_t **sql_connection) +gf_sql_connection_fini(gf_sql_connection_t **sql_connection) { - if (!sql_connection) - return; - GF_FREE (*sql_connection); - *sql_connection = NULL; + if (!sql_connection) + return; + GF_FREE(*sql_connection); + *sql_connection = NULL; } const char * -gf_sql_jm2str (gf_sql_journal_mode_t jm) +gf_sql_jm2str(gf_sql_journal_mode_t jm) { - switch (jm) { + switch (jm) { case gf_sql_jm_delete: - return GF_SQL_JM_DELETE; + return GF_SQL_JM_DELETE; case gf_sql_jm_truncate: - return GF_SQL_JM_TRUNCATE; + return GF_SQL_JM_TRUNCATE; case gf_sql_jm_persist: - return GF_SQL_JM_PERSIST; + return GF_SQL_JM_PERSIST; case gf_sql_jm_memory: - return GF_SQL_JM_MEMORY; + return GF_SQL_JM_MEMORY; case gf_sql_jm_wal: - return GF_SQL_JM_WAL; + return GF_SQL_JM_WAL; case gf_sql_jm_off: - return GF_SQL_JM_OFF; + return GF_SQL_JM_OFF; case gf_sql_jm_invalid: - break; - } - return NULL; + break; + } + return NULL; } gf_sql_journal_mode_t -gf_sql_str2jm (const char *jm_str) +gf_sql_str2jm(const char *jm_str) { - if (!jm_str) { - return gf_sql_jm_invalid; - } else if (strcmp (jm_str, GF_SQL_JM_DELETE) == 0) { - return gf_sql_jm_delete; - } else if (strcmp (jm_str, GF_SQL_JM_TRUNCATE) == 0) { - return gf_sql_jm_truncate; - } else if (strcmp (jm_str, GF_SQL_JM_PERSIST) == 0) { - return gf_sql_jm_persist; - } else if (strcmp (jm_str, GF_SQL_JM_MEMORY) == 0) { - return gf_sql_jm_memory; - } else if (strcmp (jm_str, GF_SQL_JM_WAL) == 0) { - return gf_sql_jm_wal; - } else if (strcmp (jm_str, GF_SQL_JM_OFF) == 0) { - return gf_sql_jm_off; - } + if (!jm_str) { return gf_sql_jm_invalid; + } else if (strcmp(jm_str, GF_SQL_JM_DELETE) == 0) { + return gf_sql_jm_delete; + } else if (strcmp(jm_str, GF_SQL_JM_TRUNCATE) == 0) { + return gf_sql_jm_truncate; + } else if (strcmp(jm_str, GF_SQL_JM_PERSIST) == 0) { + return gf_sql_jm_persist; + } else if (strcmp(jm_str, GF_SQL_JM_MEMORY) == 0) { + return gf_sql_jm_memory; + } else if (strcmp(jm_str, GF_SQL_JM_WAL) == 0) { + return gf_sql_jm_wal; + } else if (strcmp(jm_str, GF_SQL_JM_OFF) == 0) { + return gf_sql_jm_off; + } + return gf_sql_jm_invalid; } const char * -gf_sql_av_t2str (gf_sql_auto_vacuum_t sql_av) +gf_sql_av_t2str(gf_sql_auto_vacuum_t sql_av) { - switch (sql_av) { + switch (sql_av) { case gf_sql_av_none: - return GF_SQL_AV_NONE; + return GF_SQL_AV_NONE; case gf_sql_av_full: - return GF_SQL_AV_FULL; + return GF_SQL_AV_FULL; case gf_sql_av_incr: - return GF_SQL_AV_INCR; + return GF_SQL_AV_INCR; case gf_sql_av_invalid: - break; - } - return NULL; + break; + } + return NULL; } gf_sql_auto_vacuum_t -gf_sql_str2av_t (const char *av_str) +gf_sql_str2av_t(const char *av_str) { - if (!av_str) { - return gf_sql_av_invalid; - } else if (strcmp (av_str, GF_SQL_AV_NONE) == 0) { - return gf_sql_av_none; - } else if (strcmp (av_str, GF_SQL_AV_FULL) == 0) { - return gf_sql_av_full; - } else if (strcmp (av_str, GF_SQL_AV_INCR) == 0) { - return gf_sql_av_incr; - } + if (!av_str) { return gf_sql_av_invalid; + } else if (strcmp(av_str, GF_SQL_AV_NONE) == 0) { + return gf_sql_av_none; + } else if (strcmp(av_str, GF_SQL_AV_FULL) == 0) { + return gf_sql_av_full; + } else if (strcmp(av_str, GF_SQL_AV_INCR) == 0) { + return gf_sql_av_incr; + } + return gf_sql_av_invalid; } const char * -gf_sync_t2str (gf_sql_sync_t sql_sync) +gf_sync_t2str(gf_sql_sync_t sql_sync) { - switch (sql_sync) { + switch (sql_sync) { case gf_sql_sync_off: - return GF_SQL_SYNC_OFF; + return GF_SQL_SYNC_OFF; case gf_sql_sync_normal: - return GF_SQL_SYNC_NORMAL; + return GF_SQL_SYNC_NORMAL; case gf_sql_sync_full: - return GF_SQL_SYNC_FULL; + return GF_SQL_SYNC_FULL; case gf_sql_sync_invalid: - break; - } - return NULL; + break; + } + return NULL; } gf_sql_sync_t -gf_sql_str2sync_t (const char *sync_str) +gf_sql_str2sync_t(const char *sync_str) { - if (!sync_str) { - return gf_sql_sync_invalid; - } else if (strcmp (sync_str, GF_SQL_SYNC_OFF) == 0) { - return gf_sql_sync_off; - } else if (strcmp (sync_str, GF_SQL_SYNC_NORMAL) == 0) { - return gf_sql_sync_normal; - } else if (strcmp (sync_str, GF_SQL_SYNC_FULL) == 0) { - return gf_sql_sync_full; - } + if (!sync_str) { return gf_sql_sync_invalid; + } else if (strcmp(sync_str, GF_SQL_SYNC_OFF) == 0) { + return gf_sql_sync_off; + } else if (strcmp(sync_str, GF_SQL_SYNC_NORMAL) == 0) { + return gf_sql_sync_normal; + } else if (strcmp(sync_str, GF_SQL_SYNC_FULL) == 0) { + return gf_sql_sync_full; + } + return gf_sql_sync_invalid; } - /*TODO replace GF_CALLOC by mem_pool or iobuff if required for performance */ static char * -sql_stmt_init () +sql_stmt_init() { - char *sql_stmt = NULL; + char *sql_stmt = NULL; - sql_stmt = GF_CALLOC (GF_STMT_SIZE_MAX, sizeof(char), - gf_common_mt_char); + sql_stmt = GF_CALLOC(GF_STMT_SIZE_MAX, sizeof(char), gf_common_mt_char); - if (!sql_stmt) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, ENOMEM, - LG_MSG_NO_MEMORY, "Error allocating memory to SQL " - "Statement "); - goto out; - } + if (!sql_stmt) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, ENOMEM, LG_MSG_NO_MEMORY, + "Error allocating memory to SQL " + "Statement "); + goto out; + } out: - return sql_stmt; + return sql_stmt; } /*TODO replace GF_FREE by mem_pool or iobuff if required for performance */ static void -sql_stmt_fini (char **sql_stmt) +sql_stmt_fini(char **sql_stmt) { - GF_FREE (*sql_stmt); + GF_FREE(*sql_stmt); } /****************************************************************************** @@ -183,334 +181,313 @@ sql_stmt_fini (char **sql_stmt) static sqlite3 * gf_open_sqlite3_conn(char *sqlite3_db_path, int flags) { - sqlite3 *sqlite3_db_conn = NULL; - int ret = -1; - - GF_ASSERT (sqlite3_db_path); - - /*Creates DB if not created*/ - ret = sqlite3_open_v2 (sqlite3_db_path, &sqlite3_db_conn, flags, NULL); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, - "FATAL: Could open %s : %s", - sqlite3_db_path, sqlite3_errmsg (sqlite3_db_conn)); - } - return sqlite3_db_conn; + sqlite3 *sqlite3_db_conn = NULL; + int ret = -1; + + GF_ASSERT(sqlite3_db_path); + + /*Creates DB if not created*/ + ret = sqlite3_open_v2(sqlite3_db_path, &sqlite3_db_conn, flags, NULL); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_DB_ERROR, + "FATAL: Could open %s : %s", sqlite3_db_path, + sqlite3_errmsg(sqlite3_db_conn)); + } + return sqlite3_db_conn; } static int gf_close_sqlite3_conn(sqlite3 *sqlite3_db_conn) { - int ret = 0; - - GF_ASSERT (sqlite3_db_conn); - - if (sqlite3_db_conn) { - ret = sqlite3_close (sqlite3_db_conn); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CONNECTION_ERROR, "FATAL: sqlite3 close" - " connection failed %s", - sqlite3_errmsg (sqlite3_db_conn)); - ret = -1; - goto out; - } - } - ret = 0; + int ret = 0; + + GF_ASSERT(sqlite3_db_conn); + + if (sqlite3_db_conn) { + ret = sqlite3_close(sqlite3_db_conn); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CONNECTION_ERROR, + "FATAL: sqlite3 close" + " connection failed %s", + sqlite3_errmsg(sqlite3_db_conn)); + ret = -1; + goto out; + } + } + ret = 0; out: - return ret; + return ret; } /****************************************************************************** -* -* Database init / fini / create table -* -* ***************************************************************************/ - + * + * Database init / fini / create table + * + * ***************************************************************************/ /*Function to fill db operations*/ void -gf_sqlite3_fill_db_operations(gfdb_db_operations_t *gfdb_db_ops) +gf_sqlite3_fill_db_operations(gfdb_db_operations_t *gfdb_db_ops) { - GF_ASSERT (gfdb_db_ops); + GF_ASSERT(gfdb_db_ops); - gfdb_db_ops->init_db_op = gf_sqlite3_init; - gfdb_db_ops->fini_db_op = gf_sqlite3_fini; + gfdb_db_ops->init_db_op = gf_sqlite3_init; + gfdb_db_ops->fini_db_op = gf_sqlite3_fini; - gfdb_db_ops->insert_record_op = gf_sqlite3_insert; - gfdb_db_ops->delete_record_op = gf_sqlite3_delete; - gfdb_db_ops->compact_db_op = gf_sqlite3_vacuum; + gfdb_db_ops->insert_record_op = gf_sqlite3_insert; + gfdb_db_ops->delete_record_op = gf_sqlite3_delete; + gfdb_db_ops->compact_db_op = gf_sqlite3_vacuum; - gfdb_db_ops->find_all_op = gf_sqlite3_find_all; - gfdb_db_ops->find_unchanged_for_time_op = - gf_sqlite3_find_unchanged_for_time; - gfdb_db_ops->find_recently_changed_files_op = - gf_sqlite3_find_recently_changed_files; - gfdb_db_ops->find_unchanged_for_time_freq_op = - gf_sqlite3_find_unchanged_for_time_freq; - gfdb_db_ops->find_recently_changed_files_freq_op = - gf_sqlite3_find_recently_changed_files_freq; + gfdb_db_ops->find_all_op = gf_sqlite3_find_all; + gfdb_db_ops + ->find_unchanged_for_time_op = gf_sqlite3_find_unchanged_for_time; + gfdb_db_ops->find_recently_changed_files_op = + gf_sqlite3_find_recently_changed_files; + gfdb_db_ops->find_unchanged_for_time_freq_op = + gf_sqlite3_find_unchanged_for_time_freq; + gfdb_db_ops->find_recently_changed_files_freq_op = + gf_sqlite3_find_recently_changed_files_freq; - gfdb_db_ops->clear_files_heat_op = gf_sqlite3_clear_files_heat; + gfdb_db_ops->clear_files_heat_op = gf_sqlite3_clear_files_heat; - gfdb_db_ops->get_db_version = gf_sqlite3_version; + gfdb_db_ops->get_db_version = gf_sqlite3_version; - gfdb_db_ops->get_db_params = gf_sqlite3_pragma; + gfdb_db_ops->get_db_params = gf_sqlite3_pragma; - gfdb_db_ops->set_db_params = gf_sqlite3_set_pragma; + gfdb_db_ops->set_db_params = gf_sqlite3_set_pragma; } - static int -create_filetable (sqlite3 *sqlite3_db_conn) +create_filetable(sqlite3 *sqlite3_db_conn) { - int ret = -1; - char *sql_stmt = NULL; - char *sql_strerror = NULL; - - GF_ASSERT(sqlite3_db_conn); - - sql_stmt = sql_stmt_init (); - if (!sql_stmt) { - ret = ENOMEM; - goto out; - } - - GF_CREATE_STMT(sql_stmt); - - ret = sqlite3_exec (sqlite3_db_conn, sql_stmt, NULL, NULL, - &sql_strerror); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_EXEC_FAILED, - "Failed executing: %s : %s", sql_stmt, sql_strerror); - sqlite3_free (sql_strerror); - ret = -1; - goto out; - } - - - ret = 0; + int ret = -1; + char *sql_stmt = NULL; + char *sql_strerror = NULL; + + GF_ASSERT(sqlite3_db_conn); + + sql_stmt = sql_stmt_init(); + if (!sql_stmt) { + ret = ENOMEM; + goto out; + } + + GF_CREATE_STMT(sql_stmt); + + ret = sqlite3_exec(sqlite3_db_conn, sql_stmt, NULL, NULL, &sql_strerror); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_EXEC_FAILED, + "Failed executing: %s : %s", sql_stmt, sql_strerror); + sqlite3_free(sql_strerror); + ret = -1; + goto out; + } + + ret = 0; out: - sql_stmt_fini (&sql_stmt); - return ret; + sql_stmt_fini(&sql_stmt); + return ret; } - - - static int apply_sql_params_db(gf_sql_connection_t *sql_conn, dict_t *param_dict) { - int ret = -1; - char *temp_str = NULL; - char sqlite3_config_str[GF_NAME_MAX] = ""; - - GF_ASSERT(sql_conn); - GF_ASSERT(param_dict); - - /*Extract sql page_size from param_dict, - * if not specified default value will be GF_SQL_DEFAULT_PAGE_SIZE*/ - temp_str = NULL; - GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, - GFDB_SQL_PARAM_PAGE_SIZE, temp_str, - GF_SQL_DEFAULT_PAGE_SIZE); - sql_conn->page_size = atoi (temp_str); - /*Apply page_size on the sqlite db*/ - GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "page_size", "%zd", - sql_conn->page_size, ret, out); - - - - /*Extract sql cache size from param_dict, + int ret = -1; + char *temp_str = NULL; + char sqlite3_config_str[GF_NAME_MAX] = ""; + + GF_ASSERT(sql_conn); + GF_ASSERT(param_dict); + + /*Extract sql page_size from param_dict, + * if not specified default value will be GF_SQL_DEFAULT_PAGE_SIZE*/ + temp_str = NULL; + GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, + GFDB_SQL_PARAM_PAGE_SIZE, temp_str, + GF_SQL_DEFAULT_PAGE_SIZE); + sql_conn->page_size = atoi(temp_str); + /*Apply page_size on the sqlite db*/ + GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "page_size", "%zd", + sql_conn->page_size, ret, out); + + /*Extract sql cache size from param_dict, + * if not specified default value will be + * GF_SQL_DEFAULT_CACHE_SIZE pages*/ + temp_str = NULL; + GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, + GFDB_SQL_PARAM_CACHE_SIZE, temp_str, + GF_SQL_DEFAULT_CACHE_SIZE); + sql_conn->cache_size = atoi(temp_str); + /*Apply cache size on the sqlite db*/ + GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "cache_size", "%zd", + sql_conn->cache_size, ret, out); + + /*Extract sql journal mode from param_dict, + * if not specified default value will be + * GF_SQL_DEFAULT_JOURNAL_MODE i.e "wal"*/ + temp_str = NULL; + GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, + GFDB_SQL_PARAM_JOURNAL_MODE, temp_str, + GF_SQL_DEFAULT_JOURNAL_MODE); + sql_conn->journal_mode = gf_sql_str2jm(temp_str); + /*Apply journal mode to the sqlite db*/ + GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "journal_mode", "%s", temp_str, + ret, out); + + /*Only when the journal mode is WAL, wal_autocheckpoint makes sense*/ + if (sql_conn->journal_mode == gf_sql_jm_wal) { + /*Extract sql wal auto check point from param_dict * if not specified default value will be - * GF_SQL_DEFAULT_CACHE_SIZE pages*/ + * GF_SQL_DEFAULT_WAL_AUTOCHECKPOINT pages*/ temp_str = NULL; GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, - GFDB_SQL_PARAM_CACHE_SIZE, temp_str, - GF_SQL_DEFAULT_CACHE_SIZE); - sql_conn->cache_size = atoi (temp_str); - /*Apply cache size on the sqlite db*/ - GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "cache_size", "%zd", - sql_conn->cache_size, ret, out); - - - - - /*Extract sql journal mode from param_dict, - * if not specified default value will be - * GF_SQL_DEFAULT_JOURNAL_MODE i.e "wal"*/ - temp_str = NULL; - GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, - GFDB_SQL_PARAM_JOURNAL_MODE, temp_str, - GF_SQL_DEFAULT_JOURNAL_MODE); - sql_conn->journal_mode = gf_sql_str2jm (temp_str); - /*Apply journal mode to the sqlite db*/ - GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "journal_mode", "%s", - temp_str, ret, out); - - - - /*Only when the journal mode is WAL, wal_autocheckpoint makes sense*/ - if (sql_conn->journal_mode == gf_sql_jm_wal) { - /*Extract sql wal auto check point from param_dict - * if not specified default value will be - * GF_SQL_DEFAULT_WAL_AUTOCHECKPOINT pages*/ - temp_str = NULL; - GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, - GFDB_SQL_PARAM_WAL_AUTOCHECK, temp_str, - GF_SQL_DEFAULT_WAL_AUTOCHECKPOINT); - sql_conn->wal_autocheckpoint = atoi(temp_str); - /*Apply wal auto check point to the sqlite db*/ - GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "wal_autocheckpoint", - "%zd", sql_conn->wal_autocheckpoint, ret, out); - } - - - - /*Extract sql synchronous from param_dict - * if not specified default value will be GF_SQL_DEFAULT_SYNC*/ - temp_str = NULL; - GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, - GFDB_SQL_PARAM_SYNC, temp_str, GF_SQL_DEFAULT_SYNC); - sql_conn->synchronous = gf_sql_str2sync_t (temp_str); - /*Apply synchronous to the sqlite db*/ - GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "synchronous", "%d", - sql_conn->synchronous, ret, out); - - - - /*Extract sql auto_vacuum from param_dict - * if not specified default value will be GF_SQL_DEFAULT_AUTO_VACUUM*/ - temp_str = NULL; - GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, - GFDB_SQL_PARAM_AUTO_VACUUM, temp_str, - GF_SQL_DEFAULT_AUTO_VACUUM); - sql_conn->auto_vacuum = gf_sql_str2av_t (temp_str); - /*Apply auto_vacuum to the sqlite db*/ - GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "auto_vacuum", "%d", - sql_conn->auto_vacuum, ret, out); - - ret = 0; + GFDB_SQL_PARAM_WAL_AUTOCHECK, temp_str, + GF_SQL_DEFAULT_WAL_AUTOCHECKPOINT); + sql_conn->wal_autocheckpoint = atoi(temp_str); + /*Apply wal auto check point to the sqlite db*/ + GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "wal_autocheckpoint", "%zd", + sql_conn->wal_autocheckpoint, ret, out); + } + + /*Extract sql synchronous from param_dict + * if not specified default value will be GF_SQL_DEFAULT_SYNC*/ + temp_str = NULL; + GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, + GFDB_SQL_PARAM_SYNC, temp_str, + GF_SQL_DEFAULT_SYNC); + sql_conn->synchronous = gf_sql_str2sync_t(temp_str); + /*Apply synchronous to the sqlite db*/ + GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "synchronous", "%d", + sql_conn->synchronous, ret, out); + + /*Extract sql auto_vacuum from param_dict + * if not specified default value will be GF_SQL_DEFAULT_AUTO_VACUUM*/ + temp_str = NULL; + GET_DB_PARAM_FROM_DICT_DEFAULT(GFDB_STR_SQLITE3, param_dict, + GFDB_SQL_PARAM_AUTO_VACUUM, temp_str, + GF_SQL_DEFAULT_AUTO_VACUUM); + sql_conn->auto_vacuum = gf_sql_str2av_t(temp_str); + /*Apply auto_vacuum to the sqlite db*/ + GF_SQLITE3_SET_PRAGMA(sqlite3_config_str, "auto_vacuum", "%d", + sql_conn->auto_vacuum, ret, out); + + ret = 0; out: - return ret; + return ret; } - - int -gf_sqlite3_init (dict_t *args, void **db_conn) { - int ret = -1; - gf_sql_connection_t *sql_conn = NULL; - struct stat stbuf = {0,}; - gf_boolean_t is_dbfile_exist = _gf_false; - char *temp_str = NULL; - - GF_ASSERT (args); - GF_ASSERT (db_conn); - - if (*db_conn != NULL) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CONNECTION_ERROR, "DB Connection is not " - "empty!"); - return 0; - } - - if (!sqlite3_threadsafe ()) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_NOT_MULTITHREAD_MODE, - "sqlite3 is not in multithreaded mode"); - goto out; - } - - sql_conn = gf_sql_connection_init (); - if (!sql_conn) { - goto out; - } - - /*Extract sql db path from args*/ - temp_str = NULL; - GET_DB_PARAM_FROM_DICT(GFDB_STR_SQLITE3, args, - GFDB_SQL_PARAM_DBPATH, temp_str, out); - strncpy(sql_conn->sqlite3_db_path, temp_str, PATH_MAX-1); - sql_conn->sqlite3_db_path[PATH_MAX-1] = 0; - - is_dbfile_exist = (sys_stat (sql_conn->sqlite3_db_path, &stbuf) == 0) ? - _gf_true : _gf_false; - - /*Creates DB if not created*/ - sql_conn->sqlite3_db_conn = gf_open_sqlite3_conn ( - sql_conn->sqlite3_db_path, - SQLITE_OPEN_READWRITE | - SQLITE_OPEN_CREATE); - if (!sql_conn->sqlite3_db_conn) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CONNECTION_ERROR, - "Failed creating db connection"); - goto out; - } - - /* If the file exist we skip the config part - * and creation of the schema */ - if (is_dbfile_exist) - goto db_exists; - - - /*Apply sqlite3 params to database*/ - ret = apply_sql_params_db (sql_conn, args); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_SET_PARAM_FAILED, "Failed applying sql params" - " to %s", sql_conn->sqlite3_db_path); - goto out; - } - - /*Create the schema if NOT present*/ - ret = create_filetable (sql_conn->sqlite3_db_conn); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CREATE_FAILED, "Failed Creating %s Table", - GF_FILE_TABLE); - goto out; - } +gf_sqlite3_init(dict_t *args, void **db_conn) +{ + int ret = -1; + gf_sql_connection_t *sql_conn = NULL; + struct stat stbuf = { + 0, + }; + gf_boolean_t is_dbfile_exist = _gf_false; + char *temp_str = NULL; + + GF_ASSERT(args); + GF_ASSERT(db_conn); + + if (*db_conn != NULL) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CONNECTION_ERROR, + "DB Connection is not " + "empty!"); + return 0; + } + + if (!sqlite3_threadsafe()) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_NOT_MULTITHREAD_MODE, + "sqlite3 is not in multithreaded mode"); + goto out; + } + + sql_conn = gf_sql_connection_init(); + if (!sql_conn) { + goto out; + } + + /*Extract sql db path from args*/ + temp_str = NULL; + GET_DB_PARAM_FROM_DICT(GFDB_STR_SQLITE3, args, GFDB_SQL_PARAM_DBPATH, + temp_str, out); + strncpy(sql_conn->sqlite3_db_path, temp_str, PATH_MAX - 1); + sql_conn->sqlite3_db_path[PATH_MAX - 1] = 0; + + is_dbfile_exist = (sys_stat(sql_conn->sqlite3_db_path, &stbuf) == 0) + ? _gf_true + : _gf_false; + + /*Creates DB if not created*/ + sql_conn->sqlite3_db_conn = gf_open_sqlite3_conn( + sql_conn->sqlite3_db_path, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); + if (!sql_conn->sqlite3_db_conn) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CONNECTION_ERROR, + "Failed creating db connection"); + goto out; + } + + /* If the file exist we skip the config part + * and creation of the schema */ + if (is_dbfile_exist) + goto db_exists; + + /*Apply sqlite3 params to database*/ + ret = apply_sql_params_db(sql_conn, args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_SET_PARAM_FAILED, + "Failed applying sql params" + " to %s", + sql_conn->sqlite3_db_path); + goto out; + } + + /*Create the schema if NOT present*/ + ret = create_filetable(sql_conn->sqlite3_db_conn); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Failed Creating %s Table", GF_FILE_TABLE); + goto out; + } db_exists: - ret = 0; + ret = 0; out: - if (ret) { - gf_sqlite3_fini ((void **)&sql_conn); - } + if (ret) { + gf_sqlite3_fini((void **)&sql_conn); + } - *db_conn = sql_conn; + *db_conn = sql_conn; - return ret; + return ret; } - int -gf_sqlite3_fini (void **db_conn) +gf_sqlite3_fini(void **db_conn) { - int ret = -1; - gf_sql_connection_t *sql_conn = NULL; - - GF_ASSERT (db_conn); - sql_conn = *db_conn; - - if (sql_conn) { - if (sql_conn->sqlite3_db_conn) { - ret = gf_close_sqlite3_conn (sql_conn->sqlite3_db_conn); - if (ret) { - /*Logging of error done in - * gf_close_sqlite3_conn()*/ - goto out; - } - sql_conn->sqlite3_db_conn = NULL; - } - gf_sql_connection_fini (&sql_conn); + int ret = -1; + gf_sql_connection_t *sql_conn = NULL; + + GF_ASSERT(db_conn); + sql_conn = *db_conn; + + if (sql_conn) { + if (sql_conn->sqlite3_db_conn) { + ret = gf_close_sqlite3_conn(sql_conn->sqlite3_db_conn); + if (ret) { + /*Logging of error done in + * gf_close_sqlite3_conn()*/ + goto out; + } + sql_conn->sqlite3_db_conn = NULL; } - *db_conn = sql_conn; - ret = 0; + gf_sql_connection_fini(&sql_conn); + } + *db_conn = sql_conn; + ret = 0; out: - return ret; + return ret; } /****************************************************************************** @@ -520,79 +497,84 @@ out: * * ***************************************************************************/ -int gf_sqlite3_insert(void *db_conn, gfdb_db_record_t *gfdb_db_record) +int +gf_sqlite3_insert(void *db_conn, gfdb_db_record_t *gfdb_db_record) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; - - CHECK_SQL_CONN(sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); - switch (gfdb_db_record->gfdb_fop_path) { + switch (gfdb_db_record->gfdb_fop_path) { case GFDB_FOP_WIND: - ret = gf_sql_insert_wind (sql_conn, gfdb_db_record); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), 0, - LG_MSG_INSERT_FAILED, "Failed wind insert"); - goto out; - } - break; + ret = gf_sql_insert_wind(sql_conn, gfdb_db_record); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_INSERT_FAILED, "Failed wind insert"); + goto out; + } + break; case GFDB_FOP_UNWIND: - ret = gf_sql_insert_unwind (sql_conn, gfdb_db_record); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), 0, - LG_MSG_INSERT_FAILED, "Failed unwind insert"); - goto out; - } - break; + ret = gf_sql_insert_unwind(sql_conn, gfdb_db_record); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_INSERT_FAILED, "Failed unwind insert"); + goto out; + } + break; case GFDB_FOP_WDEL: - ret = gf_sql_update_delete_wind (sql_conn, gfdb_db_record); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), 0, - LG_MSG_UPDATE_FAILED, "Failed updating delete " - "during wind"); - goto out; - } - break; + ret = gf_sql_update_delete_wind(sql_conn, gfdb_db_record); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed updating delete " + "during wind"); + goto out; + } + break; case GFDB_FOP_UNDEL: case GFDB_FOP_UNDEL_ALL: - ret = gf_sql_delete_unwind (sql_conn, gfdb_db_record); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), 0, - LG_MSG_DELETE_FAILED, "Failed deleting"); - goto out; - } - break; + ret = gf_sql_delete_unwind(sql_conn, gfdb_db_record); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_DELETE_FAILED, "Failed deleting"); + goto out; + } + break; case GFDB_FOP_INVALID: default: - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_INVALID_FOP, - "Cannot record to DB: Invalid FOP"); - goto out; - } + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_INVALID_FOP, + "Cannot record to DB: Invalid FOP"); + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } int gf_sqlite3_delete(void *db_conn, gfdb_db_record_t *gfdb_db_record) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; - CHECK_SQL_CONN(sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); - ret = 0; + ret = 0; out: - return ret; + return ret; } /****************************************************************************** @@ -603,27 +585,24 @@ out: * ***************************************************************************/ static int -gf_get_basic_query_stmt (char **out_stmt) +gf_get_basic_query_stmt(char **out_stmt) { - int ret = -1; - ret = gf_asprintf (out_stmt, "select GF_FILE_TB.GF_ID," - "GF_FLINK_TB.GF_PID ," - "GF_FLINK_TB.FNAME " - "from GF_FLINK_TB, GF_FILE_TB " - "where " - "GF_FILE_TB.GF_ID = GF_FLINK_TB.GF_ID "); - if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed to create base query statement"); - *out_stmt = NULL; - } - return ret; + int ret = -1; + ret = gf_asprintf(out_stmt, + "select GF_FILE_TB.GF_ID," + "GF_FLINK_TB.GF_PID ," + "GF_FLINK_TB.FNAME " + "from GF_FLINK_TB, GF_FILE_TB " + "where " + "GF_FILE_TB.GF_ID = GF_FLINK_TB.GF_ID "); + if (ret <= 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to create base query statement"); + *out_stmt = NULL; + } + return ret; } - - - - /* * Find All files recorded in the DB * Input: @@ -631,71 +610,65 @@ gf_get_basic_query_stmt (char **out_stmt) * result records from the query * */ int -gf_sqlite3_find_all (void *db_conn, gf_query_callback_t query_callback, - void *query_cbk_args, - int query_limit) +gf_sqlite3_find_all(void *db_conn, gf_query_callback_t query_callback, + void *query_cbk_args, int query_limit) { - int ret = -1; - char *query_str = NULL; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *prep_stmt = NULL; - char *limit_query = NULL; - char *query = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); + int ret = -1; + char *query_str = NULL; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *prep_stmt = NULL; + char *limit_query = NULL; + char *query = NULL; - ret = gf_get_basic_query_stmt (&query_str); - if (ret <= 0) { - goto out; - } + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); - query = query_str; - - if (query_limit > 0) { - ret = gf_asprintf (&limit_query, "%s LIMIT %d", - query, query_limit); - if (ret < 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_QUERY_FAILED, - "Failed creating limit query statement"); - limit_query = NULL; - goto out; - } + ret = gf_get_basic_query_stmt(&query_str); + if (ret <= 0) { + goto out; + } - query = limit_query; - } + query = query_str; - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, query, -1, - &prep_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, - "Failed to prepare statement %s: %s", query, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - ret = gf_sql_query_function (prep_stmt, query_callback, query_cbk_args); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed Query %s", query); - goto out; - } - - ret = 0; + if (query_limit > 0) { + ret = gf_asprintf(&limit_query, "%s LIMIT %d", query, query_limit); + if (ret < 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed creating limit query statement"); + limit_query = NULL; + goto out; + } + + query = limit_query; + } + + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, query, -1, &prep_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed to prepare statement %s: %s", query, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = gf_sql_query_function(prep_stmt, query_callback, query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed Query %s", query); + goto out; + } + + ret = 0; out: - sqlite3_finalize (prep_stmt); - GF_FREE (query_str); + sqlite3_finalize(prep_stmt); + GF_FREE(query_str); - if (limit_query) - GF_FREE (limit_query); + if (limit_query) + GF_FREE(limit_query); - return ret; + return ret; } - /* * Find recently changed files from the DB * Input: @@ -705,97 +678,101 @@ out: * */ int gf_sqlite3_find_recently_changed_files(void *db_conn, - gf_query_callback_t query_callback, - void *query_cbk_args, - gfdb_time_t *from_time) + gf_query_callback_t query_callback, + void *query_cbk_args, + gfdb_time_t *from_time) { - int ret = -1; - char *query_str = NULL; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *prep_stmt = NULL; - uint64_t from_time_usec = 0; - char *base_query_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); - - ret = gf_get_basic_query_stmt (&base_query_str); - if (ret <= 0) { - goto out; - } - - ret = gf_asprintf (&query_str, "%s AND" - /*First condition: For writes*/ - "( ((" GF_COL_TB_WSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_WMSEC ") >= ? )" - " OR " - /*Second condition: For reads*/ - "((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_RWMSEC ") >= ?) )" - /* Order by write wind time in a descending order - * i.e most hot files w.r.t to write */ - " ORDER BY GF_FILE_TB.W_SEC DESC", - base_query_str); - - if (ret < 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed creating query statement"); - query_str = NULL; - goto out; - } - - from_time_usec = gfdb_time_2_usec (from_time); - - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, query_str, -1, - &prep_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed to prepare statement %s :" - " %s", query_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 1, from_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind from_time_usec " - "%"PRIu64" : %s", from_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind read wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 2, from_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind from_time_usec " - "%"PRIu64" : %s ", from_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the query*/ - ret = gf_sql_query_function (prep_stmt, query_callback, query_cbk_args); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed Query %s", query_str); - goto out; - } - - ret = 0; + int ret = -1; + char *query_str = NULL; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *prep_stmt = NULL; + uint64_t from_time_usec = 0; + char *base_query_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); + + ret = gf_get_basic_query_stmt(&base_query_str); + if (ret <= 0) { + goto out; + } + + ret = gf_asprintf( + &query_str, + "%s AND" + /*First condition: For writes*/ + "( ((" GF_COL_TB_WSEC " * " TOSTRING( + GFDB_MICROSEC) " + " GF_COL_TB_WMSEC + ") >= ? )" + " OR " + /*Second condition: For reads*/ + "((" GF_COL_TB_RWSEC " * " TOSTRING( + GFDB_MICROSEC) " + " GF_COL_TB_RWMSEC + ") >= ?) )" + /* Order by write wind time in a + * descending order i.e most hot + * files w.r.t to write */ + " ORDER BY GF_FILE_TB.W_SEC DESC", + base_query_str); + + if (ret < 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed creating query statement"); + query_str = NULL; + goto out; + } + + from_time_usec = gfdb_time_2_usec(from_time); + + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, query_str, -1, &prep_stmt, + 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed to prepare statement %s :" + " %s", + query_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 1, from_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind from_time_usec " + "%" PRIu64 " : %s", + from_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 2, from_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind from_time_usec " + "%" PRIu64 " : %s ", + from_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the query*/ + ret = gf_sql_query_function(prep_stmt, query_callback, query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed Query %s", query_str); + goto out; + } + + ret = 0; out: - sqlite3_finalize (prep_stmt); - GF_FREE (base_query_str); - GF_FREE (query_str); - return ret; + sqlite3_finalize(prep_stmt); + GF_FREE(base_query_str); + GF_FREE(query_str); + return ret; } - /* * Find unchanged files from a specified time from the DB * Input: @@ -804,101 +781,101 @@ out: * for_time : Time from where the file/s are not changed * */ int -gf_sqlite3_find_unchanged_for_time (void *db_conn, - gf_query_callback_t query_callback, - void *query_cbk_args, - gfdb_time_t *for_time) +gf_sqlite3_find_unchanged_for_time(void *db_conn, + gf_query_callback_t query_callback, + void *query_cbk_args, gfdb_time_t *for_time) { - int ret = -1; - char *query_str = NULL; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *prep_stmt = NULL; - uint64_t for_time_usec = 0; - char *base_query_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); - - ret = gf_get_basic_query_stmt (&base_query_str); - if (ret <= 0) { - goto out; - } - - ret = gf_asprintf (&query_str, "%s AND " - /*First condition: For writes*/ - "( ((" GF_COL_TB_WSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_WMSEC ") <= ? )" - " AND " - /*Second condition: For reads*/ - "((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_RWMSEC ") <= ?) )" - /* Order by write wind time in a ascending order - * i.e most cold files w.r.t to write */ - " ORDER BY GF_FILE_TB.W_SEC ASC", - base_query_str); - - if (ret < 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed to create query statement"); - query_str = NULL; - goto out; - } - - for_time_usec = gfdb_time_2_usec (for_time); - - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, query_str, -1, - &prep_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed to prepare statement %s :" - " %s", query_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 1, for_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind for_time_usec " - "%"PRIu64" : %s", for_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind read wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 2, for_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind for_time_usec " - "%"PRIu64" : %s", for_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the query*/ - ret = gf_sql_query_function (prep_stmt, query_callback, query_cbk_args); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed Query %s", query_str); - goto out; - } - - ret = 0; + int ret = -1; + char *query_str = NULL; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *prep_stmt = NULL; + uint64_t for_time_usec = 0; + char *base_query_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); + + ret = gf_get_basic_query_stmt(&base_query_str); + if (ret <= 0) { + goto out; + } + + ret = gf_asprintf( + &query_str, + "%s AND " + /*First condition: For writes*/ + "( ((" GF_COL_TB_WSEC " * " TOSTRING( + GFDB_MICROSEC) " + " GF_COL_TB_WMSEC + ") <= ? )" + " AND " + /*Second condition: For reads*/ + "((" GF_COL_TB_RWSEC " * " TOSTRING( + GFDB_MICROSEC) " + " GF_COL_TB_RWMSEC + ") <= ?) )" + /* Order by write wind time in a + * ascending order i.e most cold + * files w.r.t to write */ + " ORDER BY GF_FILE_TB.W_SEC ASC", + base_query_str); + + if (ret < 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to create query statement"); + query_str = NULL; + goto out; + } + + for_time_usec = gfdb_time_2_usec(for_time); + + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, query_str, -1, &prep_stmt, + 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed to prepare statement %s :" + " %s", + query_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 1, for_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind for_time_usec " + "%" PRIu64 " : %s", + for_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 2, for_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind for_time_usec " + "%" PRIu64 " : %s", + for_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the query*/ + ret = gf_sql_query_function(prep_stmt, query_callback, query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed Query %s", query_str); + goto out; + } + + ret = 0; out: - sqlite3_finalize (prep_stmt); - GF_FREE (base_query_str); - GF_FREE (query_str); - return ret; + sqlite3_finalize(prep_stmt); + GF_FREE(base_query_str); + GF_FREE(query_str); + return ret; } - - - - /* * Find recently changed files with a specific frequency from the DB * Input: @@ -911,140 +888,144 @@ out: * clear_counters : Clear counters (r/w) for all inodes in DB * */ int -gf_sqlite3_find_recently_changed_files_freq (void *db_conn, - gf_query_callback_t query_callback, - void *query_cbk_args, - gfdb_time_t *from_time, - int freq_write_cnt, - int freq_read_cnt, - gf_boolean_t clear_counters) +gf_sqlite3_find_recently_changed_files_freq( + void *db_conn, gf_query_callback_t query_callback, void *query_cbk_args, + gfdb_time_t *from_time, int freq_write_cnt, int freq_read_cnt, + gf_boolean_t clear_counters) { - int ret = -1; - char *query_str = NULL; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *prep_stmt = NULL; - uint64_t from_time_usec = 0; - char *base_query_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); - - ret = gf_get_basic_query_stmt (&base_query_str); - if (ret <= 0) { - goto out; - } - ret = gf_asprintf (&query_str, "%s AND " - /*First condition: For Writes*/ - "( ( ((" GF_COL_TB_WSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_WMSEC ") >= ? )" - " AND "" (" GF_COL_TB_WFC " >= ? ) )" - " OR " - /*Second condition: For Reads */ - "( ((" GF_COL_TB_RWSEC " * " TOSTRING(GFDB_MICROSEC) " + " - GF_COL_TB_RWMSEC ") >= ?)" - " AND "" (" GF_COL_TB_RFC " >= ? ) ) )" - /* Order by write wind time and write freq in a descending order - * i.e most hot files w.r.t to write */ - " ORDER BY GF_FILE_TB.W_SEC DESC, " - "GF_FILE_TB.WRITE_FREQ_CNTR DESC", - base_query_str); - - if (ret < 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed to create query statement"); - query_str = NULL; - goto out; - } - - from_time_usec = gfdb_time_2_usec (from_time); - - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, query_str, -1, - &prep_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed to prepare statement %s :" - " %s", query_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 1, from_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind from_time_usec " - "%"PRIu64" : %s", from_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write frequency thresold*/ - ret = sqlite3_bind_int (prep_stmt, 2, freq_write_cnt); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind freq_write_cnt " - "%d : %s", freq_write_cnt, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - /*Bind read wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 3, from_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind from_time_usec " - "%"PRIu64" : %s", from_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind read frequency thresold*/ - ret = sqlite3_bind_int (prep_stmt, 4, freq_read_cnt); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind freq_read_cnt " - "%d : %s", freq_read_cnt, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the query*/ - ret = gf_sql_query_function (prep_stmt, query_callback, query_cbk_args); + int ret = -1; + char *query_str = NULL; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *prep_stmt = NULL; + uint64_t from_time_usec = 0; + char *base_query_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); + + ret = gf_get_basic_query_stmt(&base_query_str); + if (ret <= 0) { + goto out; + } + ret = gf_asprintf( + &query_str, + "%s AND " + /*First condition: For Writes*/ + "( ( ((" GF_COL_TB_WSEC " * " TOSTRING( + GFDB_MICROSEC) " + " GF_COL_TB_WMSEC + ") >= ? )" + " AND " + " (" GF_COL_TB_WFC + " >= ? ) )" + " OR " + /*Second condition: For Reads */ + "( ((" GF_COL_TB_RWSEC " * " TOSTRING( + GFDB_MICROSEC) " + " GF_COL_TB_RWMSEC + ") >= ?)" + " AND " + " (" GF_COL_TB_RFC + " >= ? ) ) )" + /* Order by write wind time and + * write freq in a descending + * order + * i.e most hot files w.r.t to + * write */ + " ORDER BY GF_FILE_TB.W_SEC " + "DESC, " + "GF_FILE_TB.WRITE_FREQ_CNTR DESC", + base_query_str); + + if (ret < 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to create query statement"); + query_str = NULL; + goto out; + } + + from_time_usec = gfdb_time_2_usec(from_time); + + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, query_str, -1, &prep_stmt, + 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed to prepare statement %s :" + " %s", + query_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 1, from_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind from_time_usec " + "%" PRIu64 " : %s", + from_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write frequency thresold*/ + ret = sqlite3_bind_int(prep_stmt, 2, freq_write_cnt); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind freq_write_cnt " + "%d : %s", + freq_write_cnt, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 3, from_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind from_time_usec " + "%" PRIu64 " : %s", + from_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read frequency thresold*/ + ret = sqlite3_bind_int(prep_stmt, 4, freq_read_cnt); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind freq_read_cnt " + "%d : %s", + freq_read_cnt, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the query*/ + ret = gf_sql_query_function(prep_stmt, query_callback, query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed Query %s", query_str); + goto out; + } + + /*Clear counters*/ + if (clear_counters) { + ret = gf_sql_clear_counters(sql_conn); if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed Query %s", query_str); - goto out; - } - - - - /*Clear counters*/ - if (clear_counters) { - ret = gf_sql_clear_counters (sql_conn); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CLEAR_COUNTER_FAILED, "Failed to clear" - " counters!"); - goto out; - } - } - ret = 0; + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_CLEAR_COUNTER_FAILED, + "Failed to clear" + " counters!"); + goto out; + } + } + ret = 0; out: - sqlite3_finalize (prep_stmt); - GF_FREE (base_query_str); - GF_FREE (query_str); - return ret; + sqlite3_finalize(prep_stmt); + GF_FREE(base_query_str); + GF_FREE(query_str); + return ret; } - - - /* * Find unchanged files from a specified time, w.r.t to frequency, from the DB * Input: @@ -1056,30 +1037,29 @@ out: * clear_counters : Clear counters (r/w) for all inodes in DB * */ int -gf_sqlite3_find_unchanged_for_time_freq (void *db_conn, +gf_sqlite3_find_unchanged_for_time_freq(void *db_conn, gf_query_callback_t query_callback, void *query_cbk_args, gfdb_time_t *for_time, - int freq_write_cnt, - int freq_read_cnt, + int freq_write_cnt, int freq_read_cnt, gf_boolean_t clear_counters) { - int ret = -1; - char *query_str = NULL; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *prep_stmt = NULL; - uint64_t for_time_usec = 0; - char *base_query_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); - - ret = gf_get_basic_query_stmt (&base_query_str); - if (ret <= 0) { - goto out; - } - - ret = gf_asprintf (&query_str, "%s AND " + int ret = -1; + char *query_str = NULL; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *prep_stmt = NULL; + uint64_t for_time_usec = 0; + char *base_query_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); + + ret = gf_get_basic_query_stmt(&base_query_str); + if (ret <= 0) { + goto out; + } + + ret = gf_asprintf (&query_str, "%s AND " /*First condition: For Writes * Files that have write wind time smaller than for_time * OR @@ -1109,145 +1089,141 @@ gf_sqlite3_find_unchanged_for_time_freq (void *db_conn, "GF_FILE_TB.WRITE_FREQ_CNTR ASC", base_query_str); - if (ret < 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed to create query statement"); - query_str = NULL; - goto out; - } - - for_time_usec = gfdb_time_2_usec (for_time); - - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, query_str, -1, - &prep_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed to prepare delete " - "statement %s : %s", query_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 1, for_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind for_time_usec " - "%"PRIu64" : %s", for_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write frequency thresold*/ - ret = sqlite3_bind_int (prep_stmt, 2, freq_write_cnt); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind freq_write_cnt" - " %d : %s", freq_write_cnt, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind write wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 3, for_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind for_time_usec " - "%"PRIu64" : %s", for_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - - /*Bind read wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 4, for_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind for_time_usec " - "%"PRIu64" : %s", for_time_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind read frequency thresold*/ - ret = sqlite3_bind_int (prep_stmt, 5, freq_read_cnt); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind freq_read_cnt " - "%d : %s", freq_read_cnt, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind read wind time*/ - ret = sqlite3_bind_int64 (prep_stmt, 6, for_time_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed to bind for_time_usec " - "%"PRIu64" : %s", for_time_usec, - sqlite3_errmsg(sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the query*/ - ret = gf_sql_query_function (prep_stmt, query_callback, query_cbk_args); + if (ret < 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to create query statement"); + query_str = NULL; + goto out; + } + + for_time_usec = gfdb_time_2_usec(for_time); + + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, query_str, -1, &prep_stmt, + 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed to prepare delete " + "statement %s : %s", + query_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 1, for_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind for_time_usec " + "%" PRIu64 " : %s", + for_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write frequency thresold*/ + ret = sqlite3_bind_int(prep_stmt, 2, freq_write_cnt); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind freq_write_cnt" + " %d : %s", + freq_write_cnt, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind write wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 3, for_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind for_time_usec " + "%" PRIu64 " : %s", + for_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 4, for_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind for_time_usec " + "%" PRIu64 " : %s", + for_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read frequency thresold*/ + ret = sqlite3_bind_int(prep_stmt, 5, freq_read_cnt); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind freq_read_cnt " + "%d : %s", + freq_read_cnt, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind read wind time*/ + ret = sqlite3_bind_int64(prep_stmt, 6, for_time_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed to bind for_time_usec " + "%" PRIu64 " : %s", + for_time_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the query*/ + ret = gf_sql_query_function(prep_stmt, query_callback, query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed Query %s", query_str); + goto out; + } + + /*Clear counters*/ + if (clear_counters) { + ret = gf_sql_clear_counters(sql_conn); if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed Query %s", query_str); - goto out; - } - - - /*Clear counters*/ - if (clear_counters) { - ret = gf_sql_clear_counters (sql_conn); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CLEAR_COUNTER_FAILED, "Failed to clear " - "counters!"); - goto out; - } + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_CLEAR_COUNTER_FAILED, + "Failed to clear " + "counters!"); + goto out; } + } - ret = 0; + ret = 0; out: - sqlite3_finalize (prep_stmt); - GF_FREE (base_query_str); - GF_FREE (query_str); - return ret; + sqlite3_finalize(prep_stmt); + GF_FREE(base_query_str); + GF_FREE(query_str); + return ret; } - int -gf_sqlite3_clear_files_heat (void *db_conn) +gf_sqlite3_clear_files_heat(void *db_conn) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; - CHECK_SQL_CONN (sql_conn, out); + CHECK_SQL_CONN(sql_conn, out); - ret = gf_sql_clear_counters (sql_conn); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CLEAR_COUNTER_FAILED, "Failed to clear " - "files heat"); - goto out; - } + ret = gf_sql_clear_counters(sql_conn); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CLEAR_COUNTER_FAILED, + "Failed to clear " + "files heat"); + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } - /* Function to extract version of sqlite db * Input: * void *db_conn : Sqlite connection @@ -1260,48 +1236,45 @@ out: * On failure return -1 * */ int -gf_sqlite3_version (void *db_conn, char **version) +gf_sqlite3_version(void *db_conn, char **version) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *pre_stmt = NULL; - - CHECK_SQL_CONN (sql_conn, out); - - ret = sqlite3_prepare_v2 (sql_conn->sqlite3_db_conn, - "SELECT SQLITE_VERSION()", - -1, &pre_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed init prepare stmt %s", - sqlite3_errmsg (db_conn)); - ret = -1; - goto out; - } - - ret = sqlite3_step(pre_stmt); - if (ret != SQLITE_ROW) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_RECORD_FAILED, "Failed to get records " - "from db : %s", sqlite3_errmsg (db_conn)); - ret = -1; - goto out; - } - - ret = gf_asprintf (version, "%s", sqlite3_column_text (pre_stmt, 0)); - if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed extracting version"); - } + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *pre_stmt = NULL; + + CHECK_SQL_CONN(sql_conn, out); + + ret = sqlite3_prepare_v2(sql_conn->sqlite3_db_conn, + "SELECT SQLITE_VERSION()", -1, &pre_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed init prepare stmt %s", sqlite3_errmsg(db_conn)); + ret = -1; + goto out; + } + + ret = sqlite3_step(pre_stmt); + if (ret != SQLITE_ROW) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_RECORD_FAILED, + "Failed to get records " + "from db : %s", + sqlite3_errmsg(db_conn)); + ret = -1; + goto out; + } + + ret = gf_asprintf(version, "%s", sqlite3_column_text(pre_stmt, 0)); + if (ret <= 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed extracting version"); + } out: - sqlite3_finalize (pre_stmt); + sqlite3_finalize(pre_stmt); - return ret; + return ret; } - - /* Function to extract PRAGMA from sqlite db * Input: * void *db_conn : Sqlite connection @@ -1315,59 +1288,57 @@ out: * On failure return -1 * */ int -gf_sqlite3_pragma (void *db_conn, char *pragma_key, char **pragma_value) +gf_sqlite3_pragma(void *db_conn, char *pragma_key, char **pragma_value) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; - sqlite3_stmt *pre_stmt = NULL; - char *sqlstring = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_key, out); - - ret = gf_asprintf (&sqlstring, "PRAGMA %s;", pragma_key); + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + sqlite3_stmt *pre_stmt = NULL; + char *sqlstring = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pragma_key, out); + + ret = gf_asprintf(&sqlstring, "PRAGMA %s;", pragma_key); + if (ret <= 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed allocating memory"); + goto out; + } + + ret = sqlite3_prepare_v2(sql_conn->sqlite3_db_conn, sqlstring, -1, + &pre_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed init prepare stmt %s", sqlite3_errmsg(db_conn)); + ret = -1; + goto out; + } + + ret = sqlite3_step(pre_stmt); + if (ret != SQLITE_ROW) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_RECORD_FAILED, + "Failed to get records " + "from db : %s", + sqlite3_errmsg(db_conn)); + ret = -1; + goto out; + } + + if (pragma_value) { + ret = gf_asprintf(pragma_value, "%s", sqlite3_column_text(pre_stmt, 0)); if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed allocating memory"); - goto out; + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to get %s from db", pragma_key); } + } - ret = sqlite3_prepare_v2 (sql_conn->sqlite3_db_conn, - sqlstring, -1, &pre_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed init prepare stmt %s", - sqlite3_errmsg (db_conn)); - ret = -1; - goto out; - } - - ret = sqlite3_step (pre_stmt); - if (ret != SQLITE_ROW) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_RECORD_FAILED, "Failed to get records " - "from db : %s", sqlite3_errmsg (db_conn)); - ret = -1; - goto out; - } - - if (pragma_value) { - ret = gf_asprintf (pragma_value, "%s", - sqlite3_column_text (pre_stmt, 0)); - if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_QUERY_FAILED, "Failed to get %s from db", - pragma_key); - } - } - - ret = 0; + ret = 0; out: - GF_FREE (sqlstring); + GF_FREE(sqlstring); - sqlite3_finalize (pre_stmt); + sqlite3_finalize(pre_stmt); - return ret; + return ret; } /* Function to set PRAGMA to sqlite db @@ -1380,35 +1351,34 @@ out: * On failure return -1 * */ int -gf_sqlite3_set_pragma (void *db_conn, char *pragma_key, char *pragma_value) +gf_sqlite3_set_pragma(void *db_conn, char *pragma_key, char *pragma_value) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; - char sqlstring[GF_NAME_MAX] = ""; - char *db_pragma_value = NULL; + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + char sqlstring[GF_NAME_MAX] = ""; + char *db_pragma_value = NULL; - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_key, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_value, out); + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pragma_key, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pragma_value, out); - GF_SQLITE3_SET_PRAGMA(sqlstring, pragma_key, "%s", - pragma_value, ret, out); + GF_SQLITE3_SET_PRAGMA(sqlstring, pragma_key, "%s", pragma_value, ret, out); - ret = gf_sqlite3_pragma (db_conn, pragma_key, &db_pragma_value); - if (ret < 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, - "Failed to get %s pragma", pragma_key); - } else { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, 0, - "Value set on DB %s : %s", pragma_key, db_pragma_value); - } - GF_FREE (db_pragma_value); + ret = gf_sqlite3_pragma(db_conn, pragma_key, &db_pragma_value); + if (ret < 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED, + "Failed to get %s pragma", pragma_key); + } else { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, 0, "Value set on DB %s : %s", + pragma_key, db_pragma_value); + } + GF_FREE(db_pragma_value); - ret = 0; + ret = 0; out: - return ret; + return ret; } /* Function to vacuum of sqlite db @@ -1421,167 +1391,152 @@ out: * On failure return -1 * */ int -gf_sqlite3_vacuum (void *db_conn, gf_boolean_t compact_active, - gf_boolean_t compact_mode_switched) +gf_sqlite3_vacuum(void *db_conn, gf_boolean_t compact_active, + gf_boolean_t compact_mode_switched) { - int ret = -1; - gf_sql_connection_t *sql_conn = db_conn; - char *sqlstring = NULL; - char *sql_strerror = NULL; - gf_boolean_t changing_pragma = _gf_true; - - CHECK_SQL_CONN (sql_conn, out); - - if (GF_SQL_COMPACT_DEF == GF_SQL_COMPACT_NONE) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_INFO, 0, - LG_MSG_COMPACT_STATUS, - "VACUUM type is off: no VACUUM to do"); - goto out; - } - - if (compact_mode_switched) { - if (compact_active) { /* Then it was OFF before. - So turn everything on */ - ret = 0; - switch (GF_SQL_COMPACT_DEF) { - case GF_SQL_COMPACT_FULL: - ret = gf_sqlite3_set_pragma (db_conn, - "auto_vacuum", - GF_SQL_AV_FULL); - break; - case GF_SQL_COMPACT_INCR: - ret = gf_sqlite3_set_pragma (db_conn, - "auto_vacuum", - GF_SQL_AV_INCR); - break; - case GF_SQL_COMPACT_MANUAL: - changing_pragma = _gf_false; - break; - default: - ret = -1; - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_COMPACT_FAILED, - "VACUUM type undefined"); - goto out; - break; - } - - } else { /* Then it was ON before, so turn it all off */ - if (GF_SQL_COMPACT_DEF == GF_SQL_COMPACT_FULL || - GF_SQL_COMPACT_DEF == GF_SQL_COMPACT_INCR) { - ret = gf_sqlite3_set_pragma (db_conn, - "auto_vacuum", - GF_SQL_AV_NONE); - } else { - changing_pragma = _gf_false; - } - } - - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, - LG_MSG_PREPARE_FAILED, - "Failed to set the pragma"); - goto out; - } + int ret = -1; + gf_sql_connection_t *sql_conn = db_conn; + char *sqlstring = NULL; + char *sql_strerror = NULL; + gf_boolean_t changing_pragma = _gf_true; - gf_msg (GFDB_STR_SQLITE3, GF_LOG_INFO, 0, - LG_MSG_COMPACT_STATUS, "Turning compaction %i", - GF_SQL_COMPACT_DEF); - - /* If we move from an auto_vacuum scheme to off, */ - /* or vice-versa, we must VACUUM to save the change. */ - /* In the case of a manual VACUUM scheme, we might as well */ - /* run a manual VACUUM now if we */ - if (changing_pragma || compact_active) { - ret = gf_asprintf (&sqlstring, "VACUUM;"); - if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, - "Failed allocating memory"); - goto out; - } - gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, - LG_MSG_COMPACT_STATUS, "Sealed with a VACUUM"); - } - } else { /* We are active, so it's time to VACUUM */ - if (!compact_active) { /* Did we somehow enter an inconsistent - state? */ - ret = -1; - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, - "Tried to VACUUM when compaction inactive"); - goto out; - } + CHECK_SQL_CONN(sql_conn, out); - gf_msg(GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, - LG_MSG_COMPACT_STATUS, - "Doing regular vacuum of type %i", GF_SQL_COMPACT_DEF); - - switch (GF_SQL_COMPACT_DEF) { - case GF_SQL_COMPACT_INCR: /* INCR auto_vacuum */ - ret = gf_asprintf(&sqlstring, - "PRAGMA incremental_vacuum;"); - if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, - "Failed allocating memory"); - goto out; - } - gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, - LG_MSG_COMPACT_STATUS, - "Will commence an incremental VACUUM"); - break; - /* (MANUAL) Invoke the VACUUM command */ - case GF_SQL_COMPACT_MANUAL: - ret = gf_asprintf(&sqlstring, "VACUUM;"); - if (ret <= 0) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, - "Failed allocating memory"); - goto out; - } - gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, - LG_MSG_COMPACT_STATUS, - "Will commence a VACUUM"); - break; - /* (FULL) The database does the compaction itself. */ - /* We cannot do anything else, so we can leave */ - /* without sending anything to the database */ + if (GF_SQL_COMPACT_DEF == GF_SQL_COMPACT_NONE) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, + "VACUUM type is off: no VACUUM to do"); + goto out; + } + + if (compact_mode_switched) { + if (compact_active) { /* Then it was OFF before. + So turn everything on */ + ret = 0; + switch (GF_SQL_COMPACT_DEF) { case GF_SQL_COMPACT_FULL: - ret = 0; - goto success; - /* Any other state must be an error. Note that OFF */ - /* cannot hit this statement since we immediately leave */ - /* in that case */ + ret = gf_sqlite3_set_pragma(db_conn, "auto_vacuum", + GF_SQL_AV_FULL); + break; + case GF_SQL_COMPACT_INCR: + ret = gf_sqlite3_set_pragma(db_conn, "auto_vacuum", + GF_SQL_AV_INCR); + break; + case GF_SQL_COMPACT_MANUAL: + changing_pragma = _gf_false; + break; default: - ret = -1; - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_COMPACT_FAILED, - "VACUUM type undefined"); - goto out; - break; - } + ret = -1; + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_COMPACT_FAILED, "VACUUM type undefined"); + goto out; + break; + } + + } else { /* Then it was ON before, so turn it all off */ + if (GF_SQL_COMPACT_DEF == GF_SQL_COMPACT_FULL || + GF_SQL_COMPACT_DEF == GF_SQL_COMPACT_INCR) { + ret = gf_sqlite3_set_pragma(db_conn, "auto_vacuum", + GF_SQL_AV_NONE); + } else { + changing_pragma = _gf_false; + } } - gf_msg(GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, LG_MSG_COMPACT_STATUS, - "SQLString == %s", sqlstring); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, LG_MSG_PREPARE_FAILED, + "Failed to set the pragma"); + goto out; + } - ret = sqlite3_exec(sql_conn->sqlite3_db_conn, sqlstring, NULL, NULL, - &sql_strerror); + gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, + "Turning compaction %i", GF_SQL_COMPACT_DEF); + + /* If we move from an auto_vacuum scheme to off, */ + /* or vice-versa, we must VACUUM to save the change. */ + /* In the case of a manual VACUUM scheme, we might as well */ + /* run a manual VACUUM now if we */ + if (changing_pragma || compact_active) { + ret = gf_asprintf(&sqlstring, "VACUUM;"); + if (ret <= 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed allocating memory"); + goto out; + } + gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, + "Sealed with a VACUUM"); + } + } else { /* We are active, so it's time to VACUUM */ + if (!compact_active) { /* Did we somehow enter an inconsistent + state? */ + ret = -1; + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Tried to VACUUM when compaction inactive"); + goto out; + } - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_RECORD_FAILED, "Failed to vacuum " - "the db : %s", sqlite3_errmsg (db_conn)); + gf_msg(GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, LG_MSG_COMPACT_STATUS, + "Doing regular vacuum of type %i", GF_SQL_COMPACT_DEF); + + switch (GF_SQL_COMPACT_DEF) { + case GF_SQL_COMPACT_INCR: /* INCR auto_vacuum */ + ret = gf_asprintf(&sqlstring, "PRAGMA incremental_vacuum;"); + if (ret <= 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_PREPARE_FAILED, "Failed allocating memory"); + goto out; + } + gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, + "Will commence an incremental VACUUM"); + break; + /* (MANUAL) Invoke the VACUUM command */ + case GF_SQL_COMPACT_MANUAL: + ret = gf_asprintf(&sqlstring, "VACUUM;"); + if (ret <= 0) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_PREPARE_FAILED, "Failed allocating memory"); + goto out; + } + gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, + "Will commence a VACUUM"); + break; + /* (FULL) The database does the compaction itself. */ + /* We cannot do anything else, so we can leave */ + /* without sending anything to the database */ + case GF_SQL_COMPACT_FULL: + ret = 0; + goto success; + /* Any other state must be an error. Note that OFF */ + /* cannot hit this statement since we immediately leave */ + /* in that case */ + default: ret = -1; + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_COMPACT_FAILED, + "VACUUM type undefined"); goto out; + break; } + } + + gf_msg(GFDB_STR_SQLITE3, GF_LOG_TRACE, 0, LG_MSG_COMPACT_STATUS, + "SQLString == %s", sqlstring); + + ret = sqlite3_exec(sql_conn->sqlite3_db_conn, sqlstring, NULL, NULL, + &sql_strerror); + + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_RECORD_FAILED, + "Failed to vacuum " + "the db : %s", + sqlite3_errmsg(db_conn)); + ret = -1; + goto out; + } success: - gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, - compact_mode_switched ? "Successfully changed VACUUM on/off" - : "DB successfully VACUUM"); + gf_msg(GFDB_STR_SQLITE3, GF_LOG_INFO, 0, LG_MSG_COMPACT_STATUS, + compact_mode_switched ? "Successfully changed VACUUM on/off" + : "DB successfully VACUUM"); out: - GF_FREE(sqlstring); + GF_FREE(sqlstring); - return ret; + return ret; } diff --git a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c index b2c3392f45a..60dd5e25e66 100644 --- a/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c +++ b/libglusterfs/src/gfdb/gfdb_sqlite3_helper.c @@ -10,7 +10,6 @@ #include "gfdb_sqlite3_helper.h" - #define GFDB_SQL_STMT_SIZE 256 /***************************************************************************** @@ -21,711 +20,653 @@ * ****************************************************************************/ static int -gf_sql_delete_all (gf_sql_connection_t *sql_conn, - char *gfid, - gf_boolean_t ignore_errors) +gf_sql_delete_all(gf_sql_connection_t *sql_conn, char *gfid, + gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *delete_file_stmt = NULL; - sqlite3_stmt *delete_link_stmt = NULL; - char *delete_link_str = "DELETE FROM " - GF_FILE_LINK_TABLE - " WHERE GF_ID = ? ;"; - char *delete_file_str = "DELETE FROM " - GF_FILE_TABLE - " WHERE GF_ID = ? ;"; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - - /* - * Delete all links associated with this GFID - * - * */ - /*Prepare statement for delete all links*/ - ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, delete_link_str, -1, - &delete_link_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing delete " - "statement %s : %s", delete_link_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (delete_link_stmt, 1, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - /*Execute the prepare statement*/ - if (sqlite3_step (delete_link_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt %s : %s", - delete_link_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - /* - * Delete entry from file table associated with this GFID - * - * */ - /*Prepare statement for delete all links*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, delete_file_str, -1, - &delete_file_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing delete " - "statement %s : %s", delete_file_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (delete_file_stmt, 1, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the prepare statement*/ - if (sqlite3_step (delete_file_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt %s : %s", - delete_file_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } + int ret = -1; + sqlite3_stmt *delete_file_stmt = NULL; + sqlite3_stmt *delete_link_stmt = NULL; + char *delete_link_str = "DELETE FROM " GF_FILE_LINK_TABLE + " WHERE GF_ID = ? ;"; + char *delete_file_str = "DELETE FROM " GF_FILE_TABLE " WHERE GF_ID = ? ;"; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + + /* + * Delete all links associated with this GFID + * + * */ + /*Prepare statement for delete all links*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, delete_link_str, -1, + &delete_link_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing delete " + "statement %s : %s", + delete_link_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(delete_link_stmt, 1, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(delete_link_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt %s : %s", delete_link_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /* + * Delete entry from file table associated with this GFID + * + * */ + /*Prepare statement for delete all links*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, delete_file_str, -1, + &delete_file_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing delete " + "statement %s : %s", + delete_file_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(delete_file_stmt, 1, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(delete_file_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt %s : %s", delete_file_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } out: - /*Free prepared statement*/ - sqlite3_finalize (delete_file_stmt); - sqlite3_finalize (delete_link_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(delete_file_stmt); + sqlite3_finalize(delete_link_stmt); + return ret; } static int -gf_sql_delete_link (gf_sql_connection_t *sql_conn, - char *gfid, - char *pargfid, - char *basename, - gf_boolean_t ignore_errors) +gf_sql_delete_link(gf_sql_connection_t *sql_conn, char *gfid, char *pargfid, + char *basename, gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *delete_stmt = NULL; - char *delete_str = "DELETE FROM " - GF_FILE_LINK_TABLE - " WHERE GF_ID = ? AND GF_PID = ?" - " AND FNAME = ?;"; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pargfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basename, out); - - /*Prepare statement*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, delete_str, -1, - &delete_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing delete " - "statement %s : %s", delete_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (delete_stmt, 1, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, - "Failed binding gfid %s : %s", gfid, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind pargfid*/ - ret = sqlite3_bind_text (delete_stmt, 2, pargfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent gfid %s " - ": %s", pargfid, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind basename*/ - ret = sqlite3_bind_text (delete_stmt, 3, basename, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding basename %s : " - "%s", basename, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the prepare statement*/ - if (sqlite3_step(delete_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt %s : %s", - delete_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - ret = 0; + int ret = -1; + sqlite3_stmt *delete_stmt = NULL; + char *delete_str = "DELETE FROM " GF_FILE_LINK_TABLE + " WHERE GF_ID = ? AND GF_PID = ?" + " AND FNAME = ?;"; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pargfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, basename, out); + + /*Prepare statement*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, delete_str, -1, + &delete_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing delete " + "statement %s : %s", + delete_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(delete_stmt, 1, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind pargfid*/ + ret = sqlite3_bind_text(delete_stmt, 2, pargfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent gfid %s " + ": %s", + pargfid, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind basename*/ + ret = sqlite3_bind_text(delete_stmt, 3, basename, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding basename %s : " + "%s", + basename, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(delete_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt %s : %s", delete_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = 0; out: - /*Free prepared statement*/ - sqlite3_finalize (delete_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(delete_stmt); + return ret; } - - static int -gf_sql_update_link_flags (gf_sql_connection_t *sql_conn, - char *gfid, - char *pargfid, - char *basename, - int update_flag, - gf_boolean_t is_update_or_delete, - gf_boolean_t ignore_errors) +gf_sql_update_link_flags(gf_sql_connection_t *sql_conn, char *gfid, + char *pargfid, char *basename, int update_flag, + gf_boolean_t is_update_or_delete, + gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *update_stmt = NULL; - char *update_column = NULL; - char update_str[1024] = ""; - - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pargfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basename, out); - - update_column = (is_update_or_delete) ? "LINK_UPDATE" : "W_DEL_FLAG"; - - sprintf (update_str, "UPDATE " - GF_FILE_LINK_TABLE - " SET %s = ?" - " WHERE GF_ID = ? AND GF_PID = ? AND FNAME = ?;", - update_column); - - /*Prepare statement*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, update_str, -1, - &update_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing update " - "statement %s : %s", update_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - /*Bind link_update*/ - ret = sqlite3_bind_int (update_stmt, 1, update_flag); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding update_flag %d " - ": %s", update_flag, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (update_stmt, 2, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind pargfid*/ - ret = sqlite3_bind_text (update_stmt, 3, pargfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent gfid %s " - ": %s", pargfid, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind basename*/ - ret = sqlite3_bind_text (update_stmt, 4, basename, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding basename %s : " - "%s", basename, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - /*Execute the prepare statement*/ - if (sqlite3_step(update_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt %s : %s", - update_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - ret = 0; + int ret = -1; + sqlite3_stmt *update_stmt = NULL; + char *update_column = NULL; + char update_str[1024] = ""; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pargfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, basename, out); + + update_column = (is_update_or_delete) ? "LINK_UPDATE" : "W_DEL_FLAG"; + + sprintf(update_str, + "UPDATE " GF_FILE_LINK_TABLE + " SET %s = ?" + " WHERE GF_ID = ? AND GF_PID = ? AND FNAME = ?;", + update_column); + + /*Prepare statement*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, update_str, -1, + &update_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing update " + "statement %s : %s", + update_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind link_update*/ + ret = sqlite3_bind_int(update_stmt, 1, update_flag); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding update_flag %d " + ": %s", + update_flag, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(update_stmt, 2, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind pargfid*/ + ret = sqlite3_bind_text(update_stmt, 3, pargfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent gfid %s " + ": %s", + pargfid, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind basename*/ + ret = sqlite3_bind_text(update_stmt, 4, basename, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding basename %s : " + "%s", + basename, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(update_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt %s : %s", update_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = 0; out: - /*Free prepared statement*/ - sqlite3_finalize (update_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(update_stmt); + return ret; } - static int -gf_sql_insert_link (gf_sql_connection_t *sql_conn, - char *gfid, - char *pargfid, - char *basename, - gf_boolean_t link_consistency, - gf_boolean_t ignore_errors) +gf_sql_insert_link(gf_sql_connection_t *sql_conn, char *gfid, char *pargfid, + char *basename, gf_boolean_t link_consistency, + gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *insert_stmt = NULL; - char insert_str[GFDB_SQL_STMT_SIZE] = ""; - - sprintf (insert_str, "INSERT INTO " - GF_FILE_LINK_TABLE - " (GF_ID, GF_PID, FNAME," - " W_DEL_FLAG, LINK_UPDATE) " - " VALUES (?, ?, ?, 0, %d);", - link_consistency); - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pargfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basename, out); - - /*Prepare statement*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, insert_str, -1, - &insert_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, - "Failed preparing insert " - "statement %s : %s", insert_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (insert_stmt, 1, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, - "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind pargfid*/ - ret = sqlite3_bind_text (insert_stmt, 2, pargfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_BINDING_FAILED, - "Failed binding parent gfid %s " - ": %s", pargfid, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind basename*/ - ret = sqlite3_bind_text (insert_stmt, 3, basename, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_BINDING_FAILED, - "Failed binding basename %s : %s", basename, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the prepare statement*/ - if (sqlite3_step (insert_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), - 0, LG_MSG_EXEC_FAILED, - "Failed executing the prepared " - "stmt %s %s %s %s : %s", - gfid, pargfid, basename, insert_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - ret = 0; + int ret = -1; + sqlite3_stmt *insert_stmt = NULL; + char insert_str[GFDB_SQL_STMT_SIZE] = ""; + + sprintf(insert_str, + "INSERT INTO " GF_FILE_LINK_TABLE + " (GF_ID, GF_PID, FNAME," + " W_DEL_FLAG, LINK_UPDATE) " + " VALUES (?, ?, ?, 0, %d);", + link_consistency); + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pargfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, basename, out); + + /*Prepare statement*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, insert_str, -1, + &insert_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing insert " + "statement %s : %s", + insert_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(insert_stmt, 1, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind pargfid*/ + ret = sqlite3_bind_text(insert_stmt, 2, pargfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent gfid %s " + ": %s", + pargfid, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind basename*/ + ret = sqlite3_bind_text(insert_stmt, 3, basename, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding basename %s : %s", basename, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(insert_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared " + "stmt %s %s %s %s : %s", + gfid, pargfid, basename, insert_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = 0; out: - /*Free prepared statement*/ - sqlite3_finalize (insert_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(insert_stmt); + return ret; } - static int -gf_sql_update_link (gf_sql_connection_t *sql_conn, - char *gfid, - char *pargfid, - char *basename, - char *old_pargfid, - char *old_basename, - gf_boolean_t link_consistency, - gf_boolean_t ignore_errors) +gf_sql_update_link(gf_sql_connection_t *sql_conn, char *gfid, char *pargfid, + char *basename, char *old_pargfid, char *old_basename, + gf_boolean_t link_consistency, gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *insert_stmt = NULL; - char insert_str[GFDB_SQL_STMT_SIZE] = ""; - - sprintf (insert_str, "INSERT INTO " - GF_FILE_LINK_TABLE - " (GF_ID, GF_PID, FNAME," - " W_DEL_FLAG, LINK_UPDATE) " - " VALUES (? , ?, ?, 0, %d);", - link_consistency); - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pargfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, basename, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, old_pargfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, old_basename, out); - - /* - * - * Delete the old link - * - * */ - ret = gf_sql_delete_link (sql_conn, gfid, old_pargfid, - old_basename, ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_DELETE_FAILED, "Failed deleting old link"); - goto out; - } - - /* - * - * insert new link - * - * */ - /*Prepare statement*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, insert_str, -1, - &insert_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing insert " - "statement %s : %s", insert_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (insert_stmt, 1, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind new pargfid*/ - ret = sqlite3_bind_text (insert_stmt, 2, pargfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent gfid %s " - ": %s", pargfid, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind new basename*/ - ret = sqlite3_bind_text (insert_stmt, 3, basename, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding basename %s : " - "%s", basename, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the prepare statement*/ - if (sqlite3_step (insert_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt %s : %s", - insert_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - - - ret = 0; + int ret = -1; + sqlite3_stmt *insert_stmt = NULL; + char insert_str[GFDB_SQL_STMT_SIZE] = ""; + + sprintf(insert_str, + "INSERT INTO " GF_FILE_LINK_TABLE + " (GF_ID, GF_PID, FNAME," + " W_DEL_FLAG, LINK_UPDATE) " + " VALUES (? , ?, ?, 0, %d);", + link_consistency); + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, pargfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, basename, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, old_pargfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, old_basename, out); + + /* + * + * Delete the old link + * + * */ + ret = gf_sql_delete_link(sql_conn, gfid, old_pargfid, old_basename, + ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_DELETE_FAILED, "Failed deleting old link"); + goto out; + } + + /* + * + * insert new link + * + * */ + /*Prepare statement*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, insert_str, -1, + &insert_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing insert " + "statement %s : %s", + insert_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(insert_stmt, 1, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind new pargfid*/ + ret = sqlite3_bind_text(insert_stmt, 2, pargfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent gfid %s " + ": %s", + pargfid, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind new basename*/ + ret = sqlite3_bind_text(insert_stmt, 3, basename, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding basename %s : " + "%s", + basename, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(insert_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt %s : %s", insert_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = 0; out: - /*Free prepared statement*/ - sqlite3_finalize (insert_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(insert_stmt); + return ret; } static int -gf_sql_insert_write_wind_time (gf_sql_connection_t *sql_conn, - char *gfid, - gfdb_time_t *wind_time, - gf_boolean_t ignore_errors) +gf_sql_insert_write_wind_time(gf_sql_connection_t *sql_conn, char *gfid, + gfdb_time_t *wind_time, + gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *insert_stmt = NULL; - char *insert_str = "INSERT INTO " - GF_FILE_TABLE - "(GF_ID, W_SEC, W_MSEC, UW_SEC, UW_MSEC)" - " VALUES (?, ?, ?, 0, 0);"; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, wind_time, out); - - - /*Prepare statement*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, insert_str, -1, - &insert_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing insert " - "statement %s : %s", insert_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind gfid*/ - ret = sqlite3_bind_text (insert_stmt, 1, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind wind secs*/ - ret = sqlite3_bind_int (insert_stmt, 2, wind_time->tv_sec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent wind " - "secs %ld : %s", wind_time->tv_sec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind wind msecs*/ - ret = sqlite3_bind_int (insert_stmt, 3, wind_time->tv_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent wind " - "msecs %ld : %s", wind_time->tv_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the prepare statement*/ - if (sqlite3_step (insert_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt GFID:%s %s : %s", - gfid, insert_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - ret = 0; + int ret = -1; + sqlite3_stmt *insert_stmt = NULL; + char *insert_str = "INSERT INTO " GF_FILE_TABLE + "(GF_ID, W_SEC, W_MSEC, UW_SEC, UW_MSEC)" + " VALUES (?, ?, ?, 0, 0);"; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, wind_time, out); + + /*Prepare statement*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, insert_str, -1, + &insert_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing insert " + "statement %s : %s", + insert_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(insert_stmt, 1, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind wind secs*/ + ret = sqlite3_bind_int(insert_stmt, 2, wind_time->tv_sec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent wind " + "secs %ld : %s", + wind_time->tv_sec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind wind msecs*/ + ret = sqlite3_bind_int(insert_stmt, 3, wind_time->tv_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent wind " + "msecs %ld : %s", + wind_time->tv_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(insert_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt GFID:%s %s : %s", gfid, + insert_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = 0; out: - /*Free prepared statement*/ - sqlite3_finalize (insert_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(insert_stmt); + return ret; } - - /*Update write/read times for both wind and unwind*/ static int -gf_update_time (gf_sql_connection_t *sql_conn, - char *gfid, - gfdb_time_t *update_time, - gf_boolean_t record_counter, - gf_boolean_t is_wind, - gf_boolean_t is_read, - gf_boolean_t ignore_errors) +gf_update_time(gf_sql_connection_t *sql_conn, char *gfid, + gfdb_time_t *update_time, gf_boolean_t record_counter, + gf_boolean_t is_wind, gf_boolean_t is_read, + gf_boolean_t ignore_errors) { - int ret = -1; - sqlite3_stmt *update_stmt = NULL; - char update_str[1024] = ""; - char *freq_cntr_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfid, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, update_time, out); - - /* - * Constructing the prepare statement string. - * - * */ - /*For write time*/ - if (!is_read) { - if (is_wind) { - /*if record counter is on*/ - freq_cntr_str = (record_counter) ? - ", WRITE_FREQ_CNTR = WRITE_FREQ_CNTR + 1" : ""; - - /*Perfectly safe as we will not go array of bound*/ - sprintf (update_str, "UPDATE " - GF_FILE_TABLE - " SET W_SEC = ?, W_MSEC = ? " - " %s"/*place for read freq counters*/ - " WHERE GF_ID = ? ;", freq_cntr_str); - } else { - /*Perfectly safe as we will not go array of bound*/ - sprintf (update_str, "UPDATE " - GF_FILE_TABLE - " SET UW_SEC = ?, UW_MSEC = ? ;"); - } + int ret = -1; + sqlite3_stmt *update_stmt = NULL; + char update_str[1024] = ""; + char *freq_cntr_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfid, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, update_time, out); + + /* + * Constructing the prepare statement string. + * + * */ + /*For write time*/ + if (!is_read) { + if (is_wind) { + /*if record counter is on*/ + freq_cntr_str = (record_counter) + ? ", WRITE_FREQ_CNTR = WRITE_FREQ_CNTR + 1" + : ""; + + /*Perfectly safe as we will not go array of bound*/ + sprintf(update_str, + "UPDATE " GF_FILE_TABLE + " SET W_SEC = ?, W_MSEC = ? " + " %s" /*place for read freq counters*/ + " WHERE GF_ID = ? ;", + freq_cntr_str); + } else { + /*Perfectly safe as we will not go array of bound*/ + sprintf(update_str, + "UPDATE " GF_FILE_TABLE " SET UW_SEC = ?, UW_MSEC = ? ;"); } - /*For Read Time update*/ - else { - if (is_wind) { - /*if record counter is on*/ - freq_cntr_str = (record_counter) ? - ", READ_FREQ_CNTR = READ_FREQ_CNTR + 1" : ""; - - /*Perfectly safe as we will not go array of bound*/ - sprintf (update_str, "UPDATE " - GF_FILE_TABLE - " SET W_READ_SEC = ?, W_READ_MSEC = ? " - " %s"/*place for read freq counters*/ - " WHERE GF_ID = ? ;", freq_cntr_str); - } else { - /*Perfectly safe as we will not go array of bound*/ - sprintf (update_str, "UPDATE " - GF_FILE_TABLE + } + /*For Read Time update*/ + else { + if (is_wind) { + /*if record counter is on*/ + freq_cntr_str = (record_counter) + ? ", READ_FREQ_CNTR = READ_FREQ_CNTR + 1" + : ""; + + /*Perfectly safe as we will not go array of bound*/ + sprintf(update_str, + "UPDATE " GF_FILE_TABLE + " SET W_READ_SEC = ?, W_READ_MSEC = ? " + " %s" /*place for read freq counters*/ + " WHERE GF_ID = ? ;", + freq_cntr_str); + } else { + /*Perfectly safe as we will not go array of bound*/ + sprintf(update_str, "UPDATE " GF_FILE_TABLE " SET UW_READ_SEC = ?, UW_READ_MSEC = ? ;"); - } - } - - /*Prepare statement*/ - ret = sqlite3_prepare (sql_conn->sqlite3_db_conn, update_str, -1, - &update_stmt, 0); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PREPARE_FAILED, "Failed preparing insert " - "statement %s : %s", update_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind time secs*/ - ret = sqlite3_bind_int (update_stmt, 1, update_time->tv_sec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent wind " - "secs %ld : %s", update_time->tv_sec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Bind time msecs*/ - ret = sqlite3_bind_int (update_stmt, 2, update_time->tv_usec); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding parent wind " - "msecs %ld : %s", update_time->tv_usec, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; } - - /*Bind gfid*/ - ret = sqlite3_bind_text (update_stmt, 3, gfid, -1, NULL); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_BINDING_FAILED, "Failed binding gfid %s : %s", - gfid, sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - /*Execute the prepare statement*/ - if (sqlite3_step (update_stmt) != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, ignore_errors), 0, - LG_MSG_EXEC_FAILED, - "Failed executing the prepared stmt %s : %s", - update_str, - sqlite3_errmsg (sql_conn->sqlite3_db_conn)); - ret = -1; - goto out; - } - - ret = 0; + } + + /*Prepare statement*/ + ret = sqlite3_prepare(sql_conn->sqlite3_db_conn, update_str, -1, + &update_stmt, 0); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PREPARE_FAILED, + "Failed preparing insert " + "statement %s : %s", + update_str, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind time secs*/ + ret = sqlite3_bind_int(update_stmt, 1, update_time->tv_sec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent wind " + "secs %ld : %s", + update_time->tv_sec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind time msecs*/ + ret = sqlite3_bind_int(update_stmt, 2, update_time->tv_usec); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding parent wind " + "msecs %ld : %s", + update_time->tv_usec, sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Bind gfid*/ + ret = sqlite3_bind_text(update_stmt, 3, gfid, -1, NULL); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_BINDING_FAILED, + "Failed binding gfid %s : %s", gfid, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + /*Execute the prepare statement*/ + if (sqlite3_step(update_stmt) != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, _gfdb_log_level(GF_LOG_ERROR, ignore_errors), + 0, LG_MSG_EXEC_FAILED, + "Failed executing the prepared stmt %s : %s", update_str, + sqlite3_errmsg(sql_conn->sqlite3_db_conn)); + ret = -1; + goto out; + } + + ret = 0; out: - /*Free prepared statement*/ - sqlite3_finalize (update_stmt); - return ret; + /*Free prepared statement*/ + sqlite3_finalize(update_stmt); + return ret; } /****************************************************************************** @@ -736,394 +677,364 @@ out: * ****************************************************************************/ int -gf_sql_insert_wind (gf_sql_connection_t *sql_conn, - gfdb_db_record_t *gfdb_db_record) +gf_sql_insert_wind(gf_sql_connection_t *sql_conn, + gfdb_db_record_t *gfdb_db_record) { - int ret = -1; - gfdb_time_t *modtime = NULL; - char *pargfid_str = NULL; - char *gfid_str = NULL; - char *old_pargfid_str = NULL; - gf_boolean_t its_wind = _gf_true;/*remains true for this function*/ - - - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfdb_db_record, out); - + int ret = -1; + gfdb_time_t *modtime = NULL; + char *pargfid_str = NULL; + char *gfid_str = NULL; + char *old_pargfid_str = NULL; + gf_boolean_t its_wind = _gf_true; /*remains true for this function*/ + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); + + gfid_str = gf_strdup(uuid_utoa(gfdb_db_record->gfid)); + if (!gfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating gfid string failed."); + goto out; + } + + modtime = &gfdb_db_record->gfdb_wind_change_time; + + /* handle all dentry based operations */ + if (isdentryfop(gfdb_db_record->gfdb_fop_type)) { + /*Parent GFID is always set*/ + pargfid_str = gf_strdup(uuid_utoa(gfdb_db_record->pargfid)); + if (!pargfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating gfid string " + "failed."); + goto out; + } - gfid_str = gf_strdup (uuid_utoa (gfdb_db_record->gfid)); - if (!gfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, - "Creating gfid string failed."); + /* handle create, mknod */ + if (isdentrycreatefop(gfdb_db_record->gfdb_fop_type)) { + /*insert link*/ + ret = gf_sql_insert_link( + sql_conn, gfid_str, pargfid_str, gfdb_db_record->file_name, + gfdb_db_record->link_consistency, _gf_true); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_WARNING, + gfdb_db_record->ignore_errors), + 0, LG_MSG_INSERT_FAILED, + "Failed " + "inserting link in DB"); + /* Even if link creation is failed we + * continue with the creation of file record. + * This covers to cases + * 1) Lookup heal: If the file record from + * gf_file_tb is deleted but the link record + * still exist. Lookup heal will attempt a heal + * with create_wind set. The link heal will fail + * as there is already a record and if we don't + * ignore the error we will not heal the + * gf_file_tb. + * 2) Rename file in cold tier: During a rename + * of a file that is there in cold tier. We get + * an link record created in hot tier for the + * linkto file. When the file gets heated and + * moves to hot tier there will be attempt from + * ctr lookup heal to create link and file + * record and If we don't ignore the error we + * will not heal the gf_file_tb. + * */ + } + gfdb_db_record->islinkupdate = gfdb_db_record->link_consistency; + + /* + * Only for create/mknod insert wind time + * for the first time + * */ + ret = gf_sql_insert_write_wind_time(sql_conn, gfid_str, modtime, + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_INSERT_FAILED, + "Failed inserting wind time in DB"); goto out; + } + goto out; } - - modtime = &gfdb_db_record->gfdb_wind_change_time; - - /* handle all dentry based operations */ - if (isdentryfop (gfdb_db_record->gfdb_fop_type)) { - /*Parent GFID is always set*/ - pargfid_str = gf_strdup (uuid_utoa (gfdb_db_record->pargfid)); - if (!pargfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_CREATE_FAILED, "Creating gfid string " - "failed."); - goto out; - } - - /* handle create, mknod */ - if (isdentrycreatefop (gfdb_db_record->gfdb_fop_type)) { - /*insert link*/ - ret = gf_sql_insert_link(sql_conn, - gfid_str, pargfid_str, - gfdb_db_record->file_name, - gfdb_db_record->link_consistency, - _gf_true); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_WARNING, - gfdb_db_record->ignore_errors), - 0, - LG_MSG_INSERT_FAILED, "Failed " - "inserting link in DB"); - /* Even if link creation is failed we - * continue with the creation of file record. - * This covers to cases - * 1) Lookup heal: If the file record from - * gf_file_tb is deleted but the link record - * still exist. Lookup heal will attempt a heal - * with create_wind set. The link heal will fail - * as there is already a record and if we don't - * ignore the error we will not heal the - * gf_file_tb. - * 2) Rename file in cold tier: During a rename - * of a file that is there in cold tier. We get - * an link record created in hot tier for the - * linkto file. When the file gets heated and - * moves to hot tier there will be attempt from - * ctr lookup heal to create link and file - * record and If we don't ignore the error we - * will not heal the gf_file_tb. - * */ - } - gfdb_db_record->islinkupdate = gfdb_db_record-> - link_consistency; - - /* - * Only for create/mknod insert wind time - * for the first time - * */ - ret = gf_sql_insert_write_wind_time (sql_conn, gfid_str, - modtime, gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_INSERT_FAILED, - "Failed inserting wind time in DB"); - goto out; - } - goto out; + /*handle rename, link */ + else { + /*rename*/ + if (strlen(gfdb_db_record->old_file_name) != 0) { + old_pargfid_str = gf_strdup( + uuid_utoa(gfdb_db_record->old_pargfid)); + if (!old_pargfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_CREATE_FAILED, + "Creating gfid string failed."); + goto out; } - /*handle rename, link */ - else { - /*rename*/ - if (strlen (gfdb_db_record->old_file_name) != 0) { - old_pargfid_str = gf_strdup (uuid_utoa ( - gfdb_db_record->old_pargfid)); - if (!old_pargfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_CREATE_FAILED, - "Creating gfid string failed."); - goto out; - } - ret = gf_sql_update_link (sql_conn, gfid_str, - pargfid_str, - gfdb_db_record->file_name, - old_pargfid_str, - gfdb_db_record->old_file_name, - gfdb_db_record-> - link_consistency, - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_UPDATE_FAILED, - "Failed updating link"); - goto out; - } - gfdb_db_record->islinkupdate = gfdb_db_record-> - link_consistency; - } - /*link*/ - else { - ret = gf_sql_insert_link (sql_conn, - gfid_str, pargfid_str, - gfdb_db_record->file_name, - gfdb_db_record-> - link_consistency, - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_INSERT_FAILED, - "Failed inserting link in DB"); - goto out; - } - gfdb_db_record->islinkupdate = gfdb_db_record-> - link_consistency; - } + ret = gf_sql_update_link( + sql_conn, gfid_str, pargfid_str, gfdb_db_record->file_name, + old_pargfid_str, gfdb_db_record->old_file_name, + gfdb_db_record->link_consistency, + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, "Failed updating link"); + goto out; } - } - - /* update times only when said!*/ - if (gfdb_db_record->do_record_times) { - /*All fops update times read or write*/ - ret = gf_update_time (sql_conn, gfid_str, modtime, - gfdb_db_record->do_record_counters, - its_wind, - isreadfop (gfdb_db_record->gfdb_fop_type), - gfdb_db_record->ignore_errors); + gfdb_db_record->islinkupdate = gfdb_db_record->link_consistency; + } + /*link*/ + else { + ret = gf_sql_insert_link(sql_conn, gfid_str, pargfid_str, + gfdb_db_record->file_name, + gfdb_db_record->link_consistency, + gfdb_db_record->ignore_errors); if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), 0, - LG_MSG_UPDATE_FAILED, "Failed update wind time" - " in DB"); - goto out; + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_INSERT_FAILED, + "Failed inserting link in DB"); + goto out; } + gfdb_db_record->islinkupdate = gfdb_db_record->link_consistency; + } + } + } + + /* update times only when said!*/ + if (gfdb_db_record->do_record_times) { + /*All fops update times read or write*/ + ret = gf_update_time(sql_conn, gfid_str, modtime, + gfdb_db_record->do_record_counters, its_wind, + isreadfop(gfdb_db_record->gfdb_fop_type), + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed update wind time" + " in DB"); + goto out; } + } - ret = 0; + ret = 0; out: - GF_FREE (gfid_str); - GF_FREE (pargfid_str); - GF_FREE (old_pargfid_str); - return ret; + GF_FREE(gfid_str); + GF_FREE(pargfid_str); + GF_FREE(old_pargfid_str); + return ret; } - - - int -gf_sql_insert_unwind (gf_sql_connection_t *sql_conn, - gfdb_db_record_t *gfdb_db_record) +gf_sql_insert_unwind(gf_sql_connection_t *sql_conn, + gfdb_db_record_t *gfdb_db_record) { - - int ret = -1; - gfdb_time_t *modtime = NULL; - gf_boolean_t its_wind = _gf_true;/*remains true for this function*/ - char *gfid_str = NULL; - char *pargfid_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfdb_db_record, out); - - gfid_str = gf_strdup (uuid_utoa(gfdb_db_record->gfid)); - if (!gfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_CREATE_FAILED, "Creating gfid string failed."); - goto out; + int ret = -1; + gfdb_time_t *modtime = NULL; + gf_boolean_t its_wind = _gf_true; /*remains true for this function*/ + char *gfid_str = NULL; + char *pargfid_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); + + gfid_str = gf_strdup(uuid_utoa(gfdb_db_record->gfid)); + if (!gfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating gfid string failed."); + goto out; + } + + /*Only update if recording unwind is set*/ + if (gfdb_db_record->do_record_times && + gfdb_db_record->do_record_uwind_time) { + modtime = &gfdb_db_record->gfdb_unwind_change_time; + ret = gf_update_time(sql_conn, gfid_str, modtime, + gfdb_db_record->do_record_counters, (!its_wind), + isreadfop(gfdb_db_record->gfdb_fop_type), + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed update unwind " + "time in DB"); + goto out; } + } - /*Only update if recording unwind is set*/ - if (gfdb_db_record->do_record_times && - gfdb_db_record->do_record_uwind_time) { - modtime = &gfdb_db_record->gfdb_unwind_change_time; - ret = gf_update_time (sql_conn, gfid_str, modtime, - gfdb_db_record->do_record_counters, - (!its_wind), - isreadfop (gfdb_db_record->gfdb_fop_type), - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_UPDATE_FAILED, "Failed update unwind " - "time in DB"); - goto out; - } + /*For link creation and changes we use link updated*/ + if (gfdb_db_record->islinkupdate && + isdentryfop(gfdb_db_record->gfdb_fop_type)) { + pargfid_str = gf_strdup(uuid_utoa(gfdb_db_record->pargfid)); + if (!pargfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating pargfid_str string failed."); + goto out; } - /*For link creation and changes we use link updated*/ - if (gfdb_db_record->islinkupdate && - isdentryfop(gfdb_db_record->gfdb_fop_type)) { - - pargfid_str = gf_strdup(uuid_utoa(gfdb_db_record->pargfid)); - if (!pargfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_CREATE_FAILED, - "Creating pargfid_str string failed."); - goto out; - } - - ret = gf_sql_update_link_flags (sql_conn, gfid_str, pargfid_str, - gfdb_db_record->file_name, 0, _gf_true, - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_UPDATE_FAILED, - "Failed updating link flags in unwind"); - goto out; - } + ret = gf_sql_update_link_flags(sql_conn, gfid_str, pargfid_str, + gfdb_db_record->file_name, 0, _gf_true, + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed updating link flags in unwind"); + goto out; } + } - ret = 0; + ret = 0; out: - GF_FREE (gfid_str); - GF_FREE (pargfid_str); - return ret; + GF_FREE(gfid_str); + GF_FREE(pargfid_str); + return ret; } - int -gf_sql_update_delete_wind (gf_sql_connection_t *sql_conn, - gfdb_db_record_t *gfdb_db_record) +gf_sql_update_delete_wind(gf_sql_connection_t *sql_conn, + gfdb_db_record_t *gfdb_db_record) { - int ret = -1; - char *gfid_str = NULL; - char *pargfid_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfdb_db_record, out); - - gfid_str = gf_strdup (uuid_utoa(gfdb_db_record->gfid)); - if (!gfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, - "Creating gfid string failed."); - goto out; - } - - pargfid_str = gf_strdup (uuid_utoa(gfdb_db_record->pargfid)); - if (!pargfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_CREATE_FAILED, "Creating pargfid_str " - "string failed."); - goto out; - } - - if (gfdb_db_record->link_consistency) { - ret = gf_sql_update_link_flags (sql_conn, gfid_str, pargfid_str, - gfdb_db_record->file_name, 1, - _gf_false, - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_UPDATE_FAILED, - "Failed updating link flags in wind"); - goto out; - } + int ret = -1; + char *gfid_str = NULL; + char *pargfid_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); + + gfid_str = gf_strdup(uuid_utoa(gfdb_db_record->gfid)); + if (!gfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating gfid string failed."); + goto out; + } + + pargfid_str = gf_strdup(uuid_utoa(gfdb_db_record->pargfid)); + if (!pargfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating pargfid_str " + "string failed."); + goto out; + } + + if (gfdb_db_record->link_consistency) { + ret = gf_sql_update_link_flags(sql_conn, gfid_str, pargfid_str, + gfdb_db_record->file_name, 1, _gf_false, + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed updating link flags in wind"); + goto out; } + } - ret = 0; + ret = 0; out: - GF_FREE (gfid_str); - GF_FREE (pargfid_str); - return ret; + GF_FREE(gfid_str); + GF_FREE(pargfid_str); + return ret; } int -gf_sql_delete_unwind (gf_sql_connection_t *sql_conn, - gfdb_db_record_t *gfdb_db_record) +gf_sql_delete_unwind(gf_sql_connection_t *sql_conn, + gfdb_db_record_t *gfdb_db_record) { - int ret = -1; - char *gfid_str = NULL; - char *pargfid_str = NULL; - gfdb_time_t *modtime = NULL; - - CHECK_SQL_CONN (sql_conn, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, gfdb_db_record, out); - - gfid_str = gf_strdup (uuid_utoa(gfdb_db_record->gfid)); - if (!gfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, - "Creating gfid string failed."); - goto out; + int ret = -1; + char *gfid_str = NULL; + char *pargfid_str = NULL; + gfdb_time_t *modtime = NULL; + + CHECK_SQL_CONN(sql_conn, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out); + + gfid_str = gf_strdup(uuid_utoa(gfdb_db_record->gfid)); + if (!gfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating gfid string failed."); + goto out; + } + + /*Nuke all the entries for this GFID from DB*/ + if (gfdb_db_record->gfdb_fop_path == GFDB_FOP_UNDEL_ALL) { + gf_sql_delete_all(sql_conn, gfid_str, gfdb_db_record->ignore_errors); + } + /*Remove link entries only*/ + else if (gfdb_db_record->gfdb_fop_path == GFDB_FOP_UNDEL) { + pargfid_str = gf_strdup(uuid_utoa(gfdb_db_record->pargfid)); + if (!pargfid_str) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_CREATE_FAILED, + "Creating pargfid_str " + "string failed."); + goto out; } - /*Nuke all the entries for this GFID from DB*/ - if (gfdb_db_record->gfdb_fop_path == GFDB_FOP_UNDEL_ALL) { - gf_sql_delete_all (sql_conn, gfid_str, - gfdb_db_record->ignore_errors); + /* Special performance case: + * Updating wind time in unwind for delete. This is done here + * as in the wind path we will not know whether its the last + * link or not. For a last link there is not use to update any + * wind or unwind time!*/ + if (gfdb_db_record->do_record_times) { + /*Update the wind write times*/ + modtime = &gfdb_db_record->gfdb_wind_change_time; + ret = gf_update_time(sql_conn, gfid_str, modtime, + gfdb_db_record->do_record_counters, _gf_true, + isreadfop(gfdb_db_record->gfdb_fop_type), + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed update wind time in DB"); + goto out; + } } - /*Remove link entries only*/ - else if (gfdb_db_record->gfdb_fop_path == GFDB_FOP_UNDEL) { - - pargfid_str = gf_strdup(uuid_utoa(gfdb_db_record->pargfid)); - if (!pargfid_str) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_CREATE_FAILED, "Creating pargfid_str " - "string failed."); - goto out; - } - - /* Special performance case: - * Updating wind time in unwind for delete. This is done here - * as in the wind path we will not know whether its the last - * link or not. For a last link there is not use to update any - * wind or unwind time!*/ - if (gfdb_db_record->do_record_times) { - /*Update the wind write times*/ - modtime = &gfdb_db_record->gfdb_wind_change_time; - ret = gf_update_time (sql_conn, gfid_str, modtime, - gfdb_db_record->do_record_counters, - _gf_true, - isreadfop (gfdb_db_record->gfdb_fop_type), - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_UPDATE_FAILED, - "Failed update wind time in DB"); - goto out; - } - } - modtime = &gfdb_db_record->gfdb_unwind_change_time; + modtime = &gfdb_db_record->gfdb_unwind_change_time; - ret = gf_sql_delete_link(sql_conn, gfid_str, pargfid_str, - gfdb_db_record->file_name, - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_DELETE_FAILED, "Failed deleting link"); - goto out; - } + ret = gf_sql_delete_link(sql_conn, gfid_str, pargfid_str, + gfdb_db_record->file_name, + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_DELETE_FAILED, + "Failed deleting link"); + goto out; + } - if (gfdb_db_record->do_record_times && - gfdb_db_record->do_record_uwind_time) { - ret = gf_update_time (sql_conn, gfid_str, modtime, - gfdb_db_record->do_record_counters, - _gf_false, - isreadfop(gfdb_db_record->gfdb_fop_type), - gfdb_db_record->ignore_errors); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - _gfdb_log_level (GF_LOG_ERROR, - gfdb_db_record->ignore_errors), - 0, LG_MSG_UPDATE_FAILED, - "Failed update unwind time in DB"); - goto out; - } - } - } else { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_INVALID_UPLINK, "Invalid unlink option"); + if (gfdb_db_record->do_record_times && + gfdb_db_record->do_record_uwind_time) { + ret = gf_update_time(sql_conn, gfid_str, modtime, + gfdb_db_record->do_record_counters, _gf_false, + isreadfop(gfdb_db_record->gfdb_fop_type), + gfdb_db_record->ignore_errors); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, + _gfdb_log_level(GF_LOG_ERROR, + gfdb_db_record->ignore_errors), + 0, LG_MSG_UPDATE_FAILED, + "Failed update unwind time in DB"); goto out; + } } - ret = 0; + } else { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_INVALID_UPLINK, + "Invalid unlink option"); + goto out; + } + ret = 0; out: - GF_FREE (gfid_str); - GF_FREE (pargfid_str); - return ret; + GF_FREE(gfid_str); + GF_FREE(pargfid_str); + return ret; } /****************************************************************************** @@ -1132,240 +1043,218 @@ out: * * ****************************************************************************/ int -gf_sql_query_function (sqlite3_stmt *prep_stmt, - gf_query_callback_t query_callback, - void *_query_cbk_args) +gf_sql_query_function(sqlite3_stmt *prep_stmt, + gf_query_callback_t query_callback, void *_query_cbk_args) { - int ret = -1; - gfdb_query_record_t *query_record = NULL; - char *text_column = NULL; - sqlite3 *db_conn = NULL; - uuid_t prev_gfid = {0}; - uuid_t curr_gfid = {0}; - uuid_t pgfid = {0}; - char *base_name = NULL; - gf_boolean_t is_first_record = _gf_true; - gf_boolean_t is_query_empty = _gf_true; - - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, prep_stmt, out); - GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, query_callback, out); - - db_conn = sqlite3_db_handle(prep_stmt); - - /* - * Loop to access queried rows - * Each db record will have 3 columns - * GFID, PGFID, FILE_NAME - * - * For file with multiple hard links we will get multiple query rows - * with the same GFID, but different PGID and FILE_NAME Combination - * For Example if a file with - * GFID = 00000000-0000-0000-0000-000000000006 - * has 3 hardlinks file1, file2 and file3 in 3 different folder - * with GFID's - * 00000000-0000-0000-0000-0000EFC00001, - * 00000000-0000-0000-0000-00000ABC0001 and - * 00000000-0000-0000-0000-00000ABC00CD - * Then there will be 3 records - * GFID : 00000000-0000-0000-0000-000000000006 - * PGFID : 00000000-0000-0000-0000-0000EFC00001 - * FILE_NAME : file1 - * - * GFID : 00000000-0000-0000-0000-000000000006 - * PGFID : 00000000-0000-0000-0000-00000ABC0001 - * FILE_NAME : file2 - * - * GFID : 00000000-0000-0000-0000-000000000006 - * PGFID : 00000000-0000-0000-0000-00000ABC00CD - * FILE_NAME : file3 - * - * This is retrieved and added to a single query_record - * - * query_record->gfid = 00000000-0000-0000-0000-000000000006 - * ->link_info = {00000000-0000-0000-0000-0000EFC00001, - * "file1"} - * | - * V - * link_info = {00000000-0000-0000-0000-00000ABC0001, - * "file2"} - * | - * V - * link_info = {00000000-0000-0000-0000-00000ABC0001, - * "file3", - * list} - * - * This query record is sent to the registered query_callback() - * - * */ - while ((ret = sqlite3_step (prep_stmt)) == SQLITE_ROW) { - - if (sqlite3_column_count(prep_stmt) > 0) { - - is_query_empty = _gf_false; - - /*Retrieving GFID - column index is 0*/ - text_column = (char *)sqlite3_column_text - (prep_stmt, 0); - if (!text_column) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_ID_FAILED, "Failed to" - "retrieve GFID"); - goto out; - } - ret = gf_uuid_parse (text_column, curr_gfid); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PARSE_FAILED, "Failed to parse " - "GFID"); - goto out; - } - - /* - * if the previous record was not of the current gfid - * call the call_back function and send the - * query record, which will have all the link_info - * objects associated with this gfid - * - * */ - if (gf_uuid_compare (curr_gfid, prev_gfid) != 0) { - - /* If this is not the first record */ - if (!is_first_record) { - /*Call the call_back function provided*/ - ret = query_callback (query_record, - _query_cbk_args); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, - GF_LOG_ERROR, 0, - LG_MSG_QUERY_CALL_BACK_FAILED, - "Query call back " - "failed"); - goto out; - } - - } - - /*Clear the query record*/ - gfdb_query_record_free (query_record); - query_record = NULL; - query_record = gfdb_query_record_new (); - if (!query_record) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, - 0, LG_MSG_CREATE_FAILED, - "Failed to create " - "query_record"); - goto out; - } - - gf_uuid_copy(query_record->gfid, - curr_gfid); - gf_uuid_copy(prev_gfid, curr_gfid); - - } - - /* Get PGFID */ - text_column = (char *)sqlite3_column_text - (prep_stmt, 1); - if (!text_column) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_ID_FAILED, "Failed to" - " retrieve GF_ID"); - goto out; - } - ret = gf_uuid_parse (text_column, pgfid); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_PARSE_FAILED, "Failed to parse " - "GF_ID"); - goto out; - } - - /* Get Base name */ - text_column = (char *)sqlite3_column_text - (prep_stmt, 2); - if (!text_column) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_ID_FAILED, "Failed to" - " retrieve GF_ID"); - goto out; - } - base_name = text_column; - - - /* Add link info to the list */ - ret = gfdb_add_link_to_query_record (query_record, - pgfid, base_name); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_ID_FAILED, "Failed to" - " add link info to query record"); - goto out; - } - - is_first_record = _gf_false; + int ret = -1; + gfdb_query_record_t *query_record = NULL; + char *text_column = NULL; + sqlite3 *db_conn = NULL; + uuid_t prev_gfid = {0}; + uuid_t curr_gfid = {0}; + uuid_t pgfid = {0}; + char *base_name = NULL; + gf_boolean_t is_first_record = _gf_true; + gf_boolean_t is_query_empty = _gf_true; + + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, prep_stmt, out); + GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, query_callback, out); + + db_conn = sqlite3_db_handle(prep_stmt); + + /* + * Loop to access queried rows + * Each db record will have 3 columns + * GFID, PGFID, FILE_NAME + * + * For file with multiple hard links we will get multiple query rows + * with the same GFID, but different PGID and FILE_NAME Combination + * For Example if a file with + * GFID = 00000000-0000-0000-0000-000000000006 + * has 3 hardlinks file1, file2 and file3 in 3 different folder + * with GFID's + * 00000000-0000-0000-0000-0000EFC00001, + * 00000000-0000-0000-0000-00000ABC0001 and + * 00000000-0000-0000-0000-00000ABC00CD + * Then there will be 3 records + * GFID : 00000000-0000-0000-0000-000000000006 + * PGFID : 00000000-0000-0000-0000-0000EFC00001 + * FILE_NAME : file1 + * + * GFID : 00000000-0000-0000-0000-000000000006 + * PGFID : 00000000-0000-0000-0000-00000ABC0001 + * FILE_NAME : file2 + * + * GFID : 00000000-0000-0000-0000-000000000006 + * PGFID : 00000000-0000-0000-0000-00000ABC00CD + * FILE_NAME : file3 + * + * This is retrieved and added to a single query_record + * + * query_record->gfid = 00000000-0000-0000-0000-000000000006 + * ->link_info = {00000000-0000-0000-0000-0000EFC00001, + * "file1"} + * | + * V + * link_info = {00000000-0000-0000-0000-00000ABC0001, + * "file2"} + * | + * V + * link_info = {00000000-0000-0000-0000-00000ABC0001, + * "file3", + * list} + * + * This query record is sent to the registered query_callback() + * + * */ + while ((ret = sqlite3_step(prep_stmt)) == SQLITE_ROW) { + if (sqlite3_column_count(prep_stmt) > 0) { + is_query_empty = _gf_false; + + /*Retrieving GFID - column index is 0*/ + text_column = (char *)sqlite3_column_text(prep_stmt, 0); + if (!text_column) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_ID_FAILED, + "Failed to" + "retrieve GFID"); + goto out; + } + ret = gf_uuid_parse(text_column, curr_gfid); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PARSE_FAILED, + "Failed to parse " + "GFID"); + goto out; + } + + /* + * if the previous record was not of the current gfid + * call the call_back function and send the + * query record, which will have all the link_info + * objects associated with this gfid + * + * */ + if (gf_uuid_compare(curr_gfid, prev_gfid) != 0) { + /* If this is not the first record */ + if (!is_first_record) { + /*Call the call_back function provided*/ + ret = query_callback(query_record, _query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_QUERY_CALL_BACK_FAILED, + "Query call back " + "failed"); + goto out; + } + } + /*Clear the query record*/ + gfdb_query_record_free(query_record); + query_record = NULL; + query_record = gfdb_query_record_new(); + if (!query_record) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_CREATE_FAILED, + "Failed to create " + "query_record"); + goto out; } - } + gf_uuid_copy(query_record->gfid, curr_gfid); + gf_uuid_copy(prev_gfid, curr_gfid); + } - if (ret != SQLITE_DONE) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_GET_RECORD_FAILED, "Failed to retrieve records " - "from db : %s", sqlite3_errmsg (db_conn)); - ret = -1; + /* Get PGFID */ + text_column = (char *)sqlite3_column_text(prep_stmt, 1); + if (!text_column) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_ID_FAILED, + "Failed to" + " retrieve GF_ID"); goto out; - } - + } + ret = gf_uuid_parse(text_column, pgfid); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_PARSE_FAILED, + "Failed to parse " + "GF_ID"); + goto out; + } + + /* Get Base name */ + text_column = (char *)sqlite3_column_text(prep_stmt, 2); + if (!text_column) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_ID_FAILED, + "Failed to" + " retrieve GF_ID"); + goto out; + } + base_name = text_column; + + /* Add link info to the list */ + ret = gfdb_add_link_to_query_record(query_record, pgfid, base_name); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_ID_FAILED, + "Failed to" + " add link info to query record"); + goto out; + } - if (!is_query_empty) { - /* - * Call the call_back function for the last record from the - * Database - * */ - ret = query_callback (query_record, _query_cbk_args); - if (ret) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, - LG_MSG_QUERY_CALL_BACK_FAILED, - "Query call back failed"); - goto out; - } + is_first_record = _gf_false; } + } + + if (ret != SQLITE_DONE) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_GET_RECORD_FAILED, + "Failed to retrieve records " + "from db : %s", + sqlite3_errmsg(db_conn)); + ret = -1; + goto out; + } + + if (!is_query_empty) { + /* + * Call the call_back function for the last record from the + * Database + * */ + ret = query_callback(query_record, _query_cbk_args); + if (ret) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, + LG_MSG_QUERY_CALL_BACK_FAILED, "Query call back failed"); + goto out; + } + } - ret = 0; + ret = 0; out: - gfdb_query_record_free (query_record); - query_record = NULL; - return ret; + gfdb_query_record_free(query_record); + query_record = NULL; + return ret; } - - int -gf_sql_clear_counters (gf_sql_connection_t *sql_conn) +gf_sql_clear_counters(gf_sql_connection_t *sql_conn) { - int ret = -1; - char *sql_strerror = NULL; - char *query_str = NULL; - - CHECK_SQL_CONN (sql_conn, out); - - query_str = "UPDATE " - GF_FILE_TABLE - " SET " GF_COL_READ_FREQ_CNTR " = 0 , " - GF_COL_WRITE_FREQ_CNTR " = 0 ;"; - - ret = sqlite3_exec (sql_conn->sqlite3_db_conn, query_str, NULL, NULL, - &sql_strerror); - if (ret != SQLITE_OK) { - gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_EXEC_FAILED, - "Failed to execute: %s : %s", - query_str, sql_strerror); - sqlite3_free (sql_strerror); - ret = -1; - goto out; - } - - ret = 0; + int ret = -1; + char *sql_strerror = NULL; + char *query_str = NULL; + + CHECK_SQL_CONN(sql_conn, out); + + query_str = "UPDATE " GF_FILE_TABLE " SET " GF_COL_READ_FREQ_CNTR + " = 0 , " GF_COL_WRITE_FREQ_CNTR " = 0 ;"; + + ret = sqlite3_exec(sql_conn->sqlite3_db_conn, query_str, NULL, NULL, + &sql_strerror); + if (ret != SQLITE_OK) { + gf_msg(GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_EXEC_FAILED, + "Failed to execute: %s : %s", query_str, sql_strerror); + sqlite3_free(sql_strerror); + ret = -1; + goto out; + } + + ret = 0; out: - return ret; + return ret; } diff --git a/libglusterfs/src/gidcache.c b/libglusterfs/src/gidcache.c index f2d98abefc3..b9fdb9a39be 100644 --- a/libglusterfs/src/gidcache.c +++ b/libglusterfs/src/gidcache.c @@ -16,37 +16,39 @@ * out after a configurable interval. Hardly rocket science, but lots of * details to worry about. */ -#define BUCKET_START(p,n) ((p) + ((n) * AUX_GID_CACHE_ASSOC)) +#define BUCKET_START(p, n) ((p) + ((n)*AUX_GID_CACHE_ASSOC)) /* * Initialize the cache. */ -int gid_cache_init(gid_cache_t *cache, uint32_t timeout) +int +gid_cache_init(gid_cache_t *cache, uint32_t timeout) { - if (!cache) - return -1; + if (!cache) + return -1; - LOCK_INIT(&cache->gc_lock); - cache->gc_max_age = timeout; - cache->gc_nbuckets = AUX_GID_CACHE_BUCKETS; - memset(cache->gc_cache, 0, sizeof(gid_list_t) * AUX_GID_CACHE_SIZE); + LOCK_INIT(&cache->gc_lock); + cache->gc_max_age = timeout; + cache->gc_nbuckets = AUX_GID_CACHE_BUCKETS; + memset(cache->gc_cache, 0, sizeof(gid_list_t) * AUX_GID_CACHE_SIZE); - return 0; + return 0; } /* * Reconfigure the cache timeout. */ -int gid_cache_reconf(gid_cache_t *cache, uint32_t timeout) +int +gid_cache_reconf(gid_cache_t *cache, uint32_t timeout) { - if (!cache) - return -1; + if (!cache) + return -1; - LOCK(&cache->gc_lock); - cache->gc_max_age = timeout; - UNLOCK(&cache->gc_lock); + LOCK(&cache->gc_lock); + cache->gc_max_age = timeout; + UNLOCK(&cache->gc_lock); - return 0; + return 0; } /* @@ -54,153 +56,155 @@ int gid_cache_reconf(gid_cache_t *cache, uint32_t timeout) * an additional allocation and memory copy. The caller should copy the data and * release (unlock) the cache as soon as possible. */ -const gid_list_t *gid_cache_lookup(gid_cache_t *cache, uint64_t id, - uint64_t uid, uint64_t gid) +const gid_list_t * +gid_cache_lookup(gid_cache_t *cache, uint64_t id, uint64_t uid, uint64_t gid) { - int bucket; - int i; - time_t now; - const gid_list_t *agl; - - LOCK(&cache->gc_lock); - now = time(NULL); - bucket = id % cache->gc_nbuckets; - agl = BUCKET_START(cache->gc_cache, bucket); - for (i = 0; i < AUX_GID_CACHE_ASSOC; i++, agl++) { - if (!agl->gl_list) - continue; - if (agl->gl_id != id) - continue; - - /* - @uid and @gid reflect the latest UID/GID of the - process performing the syscall (taken from frame->root). - - If the UID and GID has changed for the PID since the - time we cached it, we should treat the cache as having - stale values and query them freshly. - */ - if (agl->gl_uid != uid || agl->gl_gid != gid) - break; - - /* - * We don't put new entries in the cache when expiration=0, but - * there might be entries still in there if expiration was - * changed very recently. Writing the check this way ensures - * that they're not used. - */ - if (now < agl->gl_deadline) { - return agl; - } - - /* - * We're not going to find any more UID matches, and reaping - * is handled further down to maintain LRU order. - */ - break; - } - UNLOCK(&cache->gc_lock); - return NULL; + int bucket; + int i; + time_t now; + const gid_list_t *agl; + + LOCK(&cache->gc_lock); + now = time(NULL); + bucket = id % cache->gc_nbuckets; + agl = BUCKET_START(cache->gc_cache, bucket); + for (i = 0; i < AUX_GID_CACHE_ASSOC; i++, agl++) { + if (!agl->gl_list) + continue; + if (agl->gl_id != id) + continue; + + /* + @uid and @gid reflect the latest UID/GID of the + process performing the syscall (taken from frame->root). + + If the UID and GID has changed for the PID since the + time we cached it, we should treat the cache as having + stale values and query them freshly. + */ + if (agl->gl_uid != uid || agl->gl_gid != gid) + break; + + /* + * We don't put new entries in the cache when expiration=0, but + * there might be entries still in there if expiration was + * changed very recently. Writing the check this way ensures + * that they're not used. + */ + if (now < agl->gl_deadline) { + return agl; + } + + /* + * We're not going to find any more UID matches, and reaping + * is handled further down to maintain LRU order. + */ + break; + } + UNLOCK(&cache->gc_lock); + return NULL; } /* * Release an entry found via lookup. */ -void gid_cache_release(gid_cache_t *cache, const gid_list_t *agl) +void +gid_cache_release(gid_cache_t *cache, const gid_list_t *agl) { - UNLOCK(&cache->gc_lock); + UNLOCK(&cache->gc_lock); } /* * Add a new list entry to the cache. If an entry for this ID already exists, * update it. */ -int gid_cache_add(gid_cache_t *cache, gid_list_t *gl) +int +gid_cache_add(gid_cache_t *cache, gid_list_t *gl) { - gid_list_t *agl; - int bucket; - int i; - time_t now; - - if (!gl || !gl->gl_list) - return -1; - - if (!cache->gc_max_age) - return 0; - - LOCK(&cache->gc_lock); - now = time(NULL); - - /* - * Scan for the first free entry or one that matches this id. The id - * check is added to address a bug where the cache might contain an - * expired entry for this id. Since lookup occurs in LRU order and - * does not reclaim entries, it will always return failure on discovery - * of an expired entry. This leads to duplicate entries being added, - * which still do not satisfy lookups until the expired entry (and - * everything before it) is reclaimed. - * - * We address this through reuse of an entry already allocated to this - * id, whether expired or not, since we have obviously already received - * more recent data. The entry is repopulated with the new data and a new - * deadline and is pushed forward to reside as the last populated entry in - * the bucket. - */ - bucket = gl->gl_id % cache->gc_nbuckets; - agl = BUCKET_START(cache->gc_cache, bucket); - for (i = 0; i < AUX_GID_CACHE_ASSOC; ++i, ++agl) { - if (agl->gl_id == gl->gl_id) - break; - if (!agl->gl_list) - break; - } - - /* - * The way we allocate free entries naturally places the newest - * ones at the highest indices, so evicting the lowest makes - * sense, but that also means we can't just replace it with the - * one that caused the eviction. That would cause us to thrash - * the first entry while others remain idle. Therefore, we - * need to slide the other entries down and add the new one at - * the end just as if the *last* slot had been free. - * - * Deadline expiration is also handled here, since the oldest - * expired entry will be in the first position. This does mean - * the bucket can stay full of expired entries if we're idle - * but, if the small amount of extra memory or scan time before - * we decide to evict someone ever become issues, we could - * easily add a reaper thread. - */ - - if (i >= AUX_GID_CACHE_ASSOC) { - /* cache full, evict the first (LRU) entry */ - i = 0; - agl = BUCKET_START(cache->gc_cache, bucket); - GF_FREE(agl->gl_list); - } else if (agl->gl_list) { - /* evict the old entry we plan to reuse */ - GF_FREE(agl->gl_list); - } - - /* - * If we have evicted an entry, slide the subsequent populated entries - * back and populate the last entry. - */ - for (; i < AUX_GID_CACHE_ASSOC - 1; i++) { - if (!agl[1].gl_list) - break; - agl[0] = agl[1]; - agl++; - } - - agl->gl_id = gl->gl_id; - agl->gl_uid = gl->gl_uid; - agl->gl_gid = gl->gl_gid; - agl->gl_count = gl->gl_count; - agl->gl_list = gl->gl_list; - agl->gl_deadline = now + cache->gc_max_age; - - UNLOCK(&cache->gc_lock); - - return 1; + gid_list_t *agl; + int bucket; + int i; + time_t now; + + if (!gl || !gl->gl_list) + return -1; + + if (!cache->gc_max_age) + return 0; + + LOCK(&cache->gc_lock); + now = time(NULL); + + /* + * Scan for the first free entry or one that matches this id. The id + * check is added to address a bug where the cache might contain an + * expired entry for this id. Since lookup occurs in LRU order and + * does not reclaim entries, it will always return failure on discovery + * of an expired entry. This leads to duplicate entries being added, + * which still do not satisfy lookups until the expired entry (and + * everything before it) is reclaimed. + * + * We address this through reuse of an entry already allocated to this + * id, whether expired or not, since we have obviously already received + * more recent data. The entry is repopulated with the new data and a new + * deadline and is pushed forward to reside as the last populated entry in + * the bucket. + */ + bucket = gl->gl_id % cache->gc_nbuckets; + agl = BUCKET_START(cache->gc_cache, bucket); + for (i = 0; i < AUX_GID_CACHE_ASSOC; ++i, ++agl) { + if (agl->gl_id == gl->gl_id) + break; + if (!agl->gl_list) + break; + } + + /* + * The way we allocate free entries naturally places the newest + * ones at the highest indices, so evicting the lowest makes + * sense, but that also means we can't just replace it with the + * one that caused the eviction. That would cause us to thrash + * the first entry while others remain idle. Therefore, we + * need to slide the other entries down and add the new one at + * the end just as if the *last* slot had been free. + * + * Deadline expiration is also handled here, since the oldest + * expired entry will be in the first position. This does mean + * the bucket can stay full of expired entries if we're idle + * but, if the small amount of extra memory or scan time before + * we decide to evict someone ever become issues, we could + * easily add a reaper thread. + */ + + if (i >= AUX_GID_CACHE_ASSOC) { + /* cache full, evict the first (LRU) entry */ + i = 0; + agl = BUCKET_START(cache->gc_cache, bucket); + GF_FREE(agl->gl_list); + } else if (agl->gl_list) { + /* evict the old entry we plan to reuse */ + GF_FREE(agl->gl_list); + } + + /* + * If we have evicted an entry, slide the subsequent populated entries + * back and populate the last entry. + */ + for (; i < AUX_GID_CACHE_ASSOC - 1; i++) { + if (!agl[1].gl_list) + break; + agl[0] = agl[1]; + agl++; + } + + agl->gl_id = gl->gl_id; + agl->gl_uid = gl->gl_uid; + agl->gl_gid = gl->gl_gid; + agl->gl_count = gl->gl_count; + agl->gl_list = gl->gl_list; + agl->gl_deadline = now + cache->gc_max_age; + + UNLOCK(&cache->gc_lock); + + return 1; } diff --git a/libglusterfs/src/globals.c b/libglusterfs/src/globals.c index 3506d482bda..98990460c86 100644 --- a/libglusterfs/src/globals.c +++ b/libglusterfs/src/globals.c @@ -19,75 +19,75 @@ #include "upcall-utils.h" const char *gf_fop_list[GF_FOP_MAXVALUE] = { - [GF_FOP_NULL] = "NULL", - [GF_FOP_STAT] = "STAT", - [GF_FOP_READLINK] = "READLINK", - [GF_FOP_MKNOD] = "MKNOD", - [GF_FOP_MKDIR] = "MKDIR", - [GF_FOP_UNLINK] = "UNLINK", - [GF_FOP_RMDIR] = "RMDIR", - [GF_FOP_SYMLINK] = "SYMLINK", - [GF_FOP_RENAME] = "RENAME", - [GF_FOP_LINK] = "LINK", - [GF_FOP_TRUNCATE] = "TRUNCATE", - [GF_FOP_OPEN] = "OPEN", - [GF_FOP_READ] = "READ", - [GF_FOP_WRITE] = "WRITE", - [GF_FOP_STATFS] = "STATFS", - [GF_FOP_FLUSH] = "FLUSH", - [GF_FOP_FSYNC] = "FSYNC", - [GF_FOP_SETXATTR] = "SETXATTR", - [GF_FOP_GETXATTR] = "GETXATTR", - [GF_FOP_REMOVEXATTR] = "REMOVEXATTR", - [GF_FOP_OPENDIR] = "OPENDIR", - [GF_FOP_FSYNCDIR] = "FSYNCDIR", - [GF_FOP_ACCESS] = "ACCESS", - [GF_FOP_CREATE] = "CREATE", - [GF_FOP_FTRUNCATE] = "FTRUNCATE", - [GF_FOP_FSTAT] = "FSTAT", - [GF_FOP_LK] = "LK", - [GF_FOP_LOOKUP] = "LOOKUP", - [GF_FOP_READDIR] = "READDIR", - [GF_FOP_INODELK] = "INODELK", - [GF_FOP_FINODELK] = "FINODELK", - [GF_FOP_ENTRYLK] = "ENTRYLK", - [GF_FOP_FENTRYLK] = "FENTRYLK", - [GF_FOP_XATTROP] = "XATTROP", - [GF_FOP_FXATTROP] = "FXATTROP", - [GF_FOP_FSETXATTR] = "FSETXATTR", - [GF_FOP_FGETXATTR] = "FGETXATTR", - [GF_FOP_RCHECKSUM] = "RCHECKSUM", - [GF_FOP_SETATTR] = "SETATTR", - [GF_FOP_FSETATTR] = "FSETATTR", - [GF_FOP_READDIRP] = "READDIRP", - [GF_FOP_GETSPEC] = "GETSPEC", - [GF_FOP_FORGET] = "FORGET", - [GF_FOP_RELEASE] = "RELEASE", - [GF_FOP_RELEASEDIR] = "RELEASEDIR", - [GF_FOP_FREMOVEXATTR]= "FREMOVEXATTR", - [GF_FOP_FALLOCATE] = "FALLOCATE", - [GF_FOP_DISCARD] = "DISCARD", - [GF_FOP_ZEROFILL] = "ZEROFILL", - [GF_FOP_IPC] = "IPC", - [GF_FOP_SEEK] = "SEEK", - [GF_FOP_LEASE] = "LEASE", - [GF_FOP_COMPOUND] = "COMPOUND", - [GF_FOP_GETACTIVELK] = "GETACTIVELK", - [GF_FOP_SETACTIVELK] = "SETACTIVELK", - [GF_FOP_PUT] = "PUT", - [GF_FOP_ICREATE] = "ICREATE", - [GF_FOP_NAMELINK] = "NAMELINK", + [GF_FOP_NULL] = "NULL", + [GF_FOP_STAT] = "STAT", + [GF_FOP_READLINK] = "READLINK", + [GF_FOP_MKNOD] = "MKNOD", + [GF_FOP_MKDIR] = "MKDIR", + [GF_FOP_UNLINK] = "UNLINK", + [GF_FOP_RMDIR] = "RMDIR", + [GF_FOP_SYMLINK] = "SYMLINK", + [GF_FOP_RENAME] = "RENAME", + [GF_FOP_LINK] = "LINK", + [GF_FOP_TRUNCATE] = "TRUNCATE", + [GF_FOP_OPEN] = "OPEN", + [GF_FOP_READ] = "READ", + [GF_FOP_WRITE] = "WRITE", + [GF_FOP_STATFS] = "STATFS", + [GF_FOP_FLUSH] = "FLUSH", + [GF_FOP_FSYNC] = "FSYNC", + [GF_FOP_SETXATTR] = "SETXATTR", + [GF_FOP_GETXATTR] = "GETXATTR", + [GF_FOP_REMOVEXATTR] = "REMOVEXATTR", + [GF_FOP_OPENDIR] = "OPENDIR", + [GF_FOP_FSYNCDIR] = "FSYNCDIR", + [GF_FOP_ACCESS] = "ACCESS", + [GF_FOP_CREATE] = "CREATE", + [GF_FOP_FTRUNCATE] = "FTRUNCATE", + [GF_FOP_FSTAT] = "FSTAT", + [GF_FOP_LK] = "LK", + [GF_FOP_LOOKUP] = "LOOKUP", + [GF_FOP_READDIR] = "READDIR", + [GF_FOP_INODELK] = "INODELK", + [GF_FOP_FINODELK] = "FINODELK", + [GF_FOP_ENTRYLK] = "ENTRYLK", + [GF_FOP_FENTRYLK] = "FENTRYLK", + [GF_FOP_XATTROP] = "XATTROP", + [GF_FOP_FXATTROP] = "FXATTROP", + [GF_FOP_FSETXATTR] = "FSETXATTR", + [GF_FOP_FGETXATTR] = "FGETXATTR", + [GF_FOP_RCHECKSUM] = "RCHECKSUM", + [GF_FOP_SETATTR] = "SETATTR", + [GF_FOP_FSETATTR] = "FSETATTR", + [GF_FOP_READDIRP] = "READDIRP", + [GF_FOP_GETSPEC] = "GETSPEC", + [GF_FOP_FORGET] = "FORGET", + [GF_FOP_RELEASE] = "RELEASE", + [GF_FOP_RELEASEDIR] = "RELEASEDIR", + [GF_FOP_FREMOVEXATTR] = "FREMOVEXATTR", + [GF_FOP_FALLOCATE] = "FALLOCATE", + [GF_FOP_DISCARD] = "DISCARD", + [GF_FOP_ZEROFILL] = "ZEROFILL", + [GF_FOP_IPC] = "IPC", + [GF_FOP_SEEK] = "SEEK", + [GF_FOP_LEASE] = "LEASE", + [GF_FOP_COMPOUND] = "COMPOUND", + [GF_FOP_GETACTIVELK] = "GETACTIVELK", + [GF_FOP_SETACTIVELK] = "SETACTIVELK", + [GF_FOP_PUT] = "PUT", + [GF_FOP_ICREATE] = "ICREATE", + [GF_FOP_NAMELINK] = "NAMELINK", }; const char *gf_upcall_list[GF_UPCALL_FLAGS_MAXVALUE] = { - [GF_UPCALL_NULL] = "NULL", - [GF_UPCALL] = "UPCALL", - [GF_UPCALL_CI_STAT] = "CI_IATT", - [GF_UPCALL_CI_XATTR] = "CI_XATTR", - [GF_UPCALL_CI_RENAME] = "CI_RENAME", - [GF_UPCALL_CI_NLINK] = "CI_UNLINK", - [GF_UPCALL_CI_FORGET] = "CI_FORGET", - [GF_UPCALL_LEASE_RECALL] = "LEASE_RECALL", + [GF_UPCALL_NULL] = "NULL", + [GF_UPCALL] = "UPCALL", + [GF_UPCALL_CI_STAT] = "CI_IATT", + [GF_UPCALL_CI_XATTR] = "CI_XATTR", + [GF_UPCALL_CI_RENAME] = "CI_RENAME", + [GF_UPCALL_CI_NLINK] = "CI_UNLINK", + [GF_UPCALL_CI_FORGET] = "CI_FORGET", + [GF_UPCALL_LEASE_RECALL] = "LEASE_RECALL", }; /* THIS */ @@ -101,461 +101,452 @@ xlator_t global_xlator; static pthread_key_t this_xlator_key; static pthread_key_t synctask_key; static pthread_key_t uuid_buf_key; -static char global_uuid_buf[GF_UUID_BUF_SIZE]; +static char global_uuid_buf[GF_UUID_BUF_SIZE]; static pthread_key_t lkowner_buf_key; -static char global_lkowner_buf[GF_LKOWNER_BUF_SIZE]; +static char global_lkowner_buf[GF_LKOWNER_BUF_SIZE]; static pthread_key_t leaseid_buf_key; static int gf_global_mem_acct_enable = 1; static pthread_once_t globals_inited = PTHREAD_ONCE_INIT; - int -gf_global_mem_acct_enable_get (void) +gf_global_mem_acct_enable_get(void) { - return gf_global_mem_acct_enable; + return gf_global_mem_acct_enable; } int -gf_global_mem_acct_enable_set (int val) +gf_global_mem_acct_enable_set(int val) { - gf_global_mem_acct_enable = val; - return 0; + gf_global_mem_acct_enable = val; + return 0; } void -glusterfs_this_destroy (void *ptr) +glusterfs_this_destroy(void *ptr) { - FREE (ptr); + FREE(ptr); } static struct xlator_cbks global_cbks = { - .forget = NULL, - .release = NULL, - .releasedir = NULL, - .invalidate = NULL, - .client_destroy = NULL, - .client_disconnect = NULL, - .ictxmerge = NULL, - .ictxsize = NULL, - .fdctxsize = NULL, + .forget = NULL, + .release = NULL, + .releasedir = NULL, + .invalidate = NULL, + .client_destroy = NULL, + .client_disconnect = NULL, + .ictxmerge = NULL, + .ictxsize = NULL, + .fdctxsize = NULL, }; /* This is required to get through the check in graph.c */ -static struct xlator_fops global_fops = { -}; +static struct xlator_fops global_fops = {}; static int -global_xl_reconfigure (xlator_t *this, dict_t *options) +global_xl_reconfigure(xlator_t *this, dict_t *options) { - int ret = -1; - gf_boolean_t bool_opt = _gf_false; + int ret = -1; + gf_boolean_t bool_opt = _gf_false; - /* This is not added in volume dump, hence adding the options in log - would be helpful for debugging later */ - dict_dump_to_log (options); + /* This is not added in volume dump, hence adding the options in log + would be helpful for debugging later */ + dict_dump_to_log(options); - GF_OPTION_RECONF ("measure-latency", bool_opt, options, bool, out); - this->ctx->measure_latency = bool_opt; + GF_OPTION_RECONF("measure-latency", bool_opt, options, bool, out); + this->ctx->measure_latency = bool_opt; - GF_OPTION_RECONF ("metrics-dump-path", this->ctx->config.metrics_dumppath, - options, str, out); + GF_OPTION_RECONF("metrics-dump-path", this->ctx->config.metrics_dumppath, + options, str, out); - /* TODO: add more things here */ - ret = 0; + /* TODO: add more things here */ + ret = 0; out: - return ret; + return ret; } static int -global_xl_init (xlator_t *this) +global_xl_init(xlator_t *this) { - int ret = -1; - gf_boolean_t bool_opt = false; + int ret = -1; + gf_boolean_t bool_opt = false; - GF_OPTION_INIT ("measure-latency", bool_opt, bool, out); - this->ctx->measure_latency = bool_opt; + GF_OPTION_INIT("measure-latency", bool_opt, bool, out); + this->ctx->measure_latency = bool_opt; - GF_OPTION_INIT ("metrics-dump-path", this->ctx->config.metrics_dumppath, - str, out); + GF_OPTION_INIT("metrics-dump-path", this->ctx->config.metrics_dumppath, str, + out); - ret = 0; + ret = 0; out: - return ret; + return ret; } static void -global_xl_fini (xlator_t *this) +global_xl_fini(xlator_t *this) { - return; + return; } struct volume_options global_xl_options[] = { - { .key = {"measure-latency"}, - .type = GF_OPTION_TYPE_BOOL, - .default_value = "no", - .op_version = {GD_OP_VERSION_4_0_0}, - .flags = OPT_FLAG_SETTABLE, - .tags = {"global", "context"}, - .description = "Use this option to toggle measuring latency" - }, - { .key = {"metrics-dump-path"}, - .type = GF_OPTION_TYPE_STR, - .default_value = "{{gluster_workdir}}/metrics", - .op_version = {GD_OP_VERSION_4_0_0}, - .flags = OPT_FLAG_SETTABLE, - .tags = {"global", "context"}, - .description = "Use this option to set the metrics dump path" - }, - - { .key = {NULL},}, + {.key = {"measure-latency"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "no", + .op_version = {GD_OP_VERSION_4_0_0}, + .flags = OPT_FLAG_SETTABLE, + .tags = {"global", "context"}, + .description = "Use this option to toggle measuring latency"}, + {.key = {"metrics-dump-path"}, + .type = GF_OPTION_TYPE_STR, + .default_value = "{{gluster_workdir}}/metrics", + .op_version = {GD_OP_VERSION_4_0_0}, + .flags = OPT_FLAG_SETTABLE, + .tags = {"global", "context"}, + .description = "Use this option to set the metrics dump path"}, + + { + .key = {NULL}, + }, }; static volume_opt_list_t global_xl_opt_list; int -glusterfs_this_init () +glusterfs_this_init() { - int ret = 0; - ret = pthread_key_create (&this_xlator_key, glusterfs_this_destroy); - if (ret != 0) { - gf_msg ("", GF_LOG_WARNING, ret, - LG_MSG_PTHREAD_KEY_CREATE_FAILED, "failed to create " - "the pthread key"); - return ret; - } + int ret = 0; + ret = pthread_key_create(&this_xlator_key, glusterfs_this_destroy); + if (ret != 0) { + gf_msg("", GF_LOG_WARNING, ret, LG_MSG_PTHREAD_KEY_CREATE_FAILED, + "failed to create " + "the pthread key"); + return ret; + } - global_xlator.name = "glusterfs"; - global_xlator.type = GF_GLOBAL_XLATOR_NAME; - global_xlator.cbks = &global_cbks; - global_xlator.fops = &global_fops; - global_xlator.reconfigure = global_xl_reconfigure; - global_xlator.init = global_xl_init; - global_xlator.fini = global_xl_fini; + global_xlator.name = "glusterfs"; + global_xlator.type = GF_GLOBAL_XLATOR_NAME; + global_xlator.cbks = &global_cbks; + global_xlator.fops = &global_fops; + global_xlator.reconfigure = global_xl_reconfigure; + global_xlator.init = global_xl_init; + global_xlator.fini = global_xl_fini; - INIT_LIST_HEAD (&global_xlator.volume_options); - INIT_LIST_HEAD (&global_xl_opt_list.list); - global_xl_opt_list.given_opt = global_xl_options; + INIT_LIST_HEAD(&global_xlator.volume_options); + INIT_LIST_HEAD(&global_xl_opt_list.list); + global_xl_opt_list.given_opt = global_xl_options; - list_add_tail (&global_xl_opt_list.list, &global_xlator.volume_options); + list_add_tail(&global_xl_opt_list.list, &global_xlator.volume_options); - return ret; + return ret; } - xlator_t ** -__glusterfs_this_location () +__glusterfs_this_location() { - xlator_t **this_location = NULL; - int ret = 0; - - this_location = pthread_getspecific (this_xlator_key); - - if (!this_location) { - this_location = CALLOC (1, sizeof (*this_location)); - if (!this_location) - goto out; - - ret = pthread_setspecific (this_xlator_key, this_location); - if (ret != 0) { - FREE (this_location); - this_location = NULL; - goto out; - } + xlator_t **this_location = NULL; + int ret = 0; + + this_location = pthread_getspecific(this_xlator_key); + + if (!this_location) { + this_location = CALLOC(1, sizeof(*this_location)); + if (!this_location) + goto out; + + ret = pthread_setspecific(this_xlator_key, this_location); + if (ret != 0) { + FREE(this_location); + this_location = NULL; + goto out; } + } out: - if (this_location) { - if (!*this_location) - *this_location = &global_xlator; - } - return this_location; + if (this_location) { + if (!*this_location) + *this_location = &global_xlator; + } + return this_location; } - xlator_t * -glusterfs_this_get () +glusterfs_this_get() { - xlator_t **this_location = NULL; + xlator_t **this_location = NULL; - this_location = __glusterfs_this_location (); - if (!this_location) - return &global_xlator; + this_location = __glusterfs_this_location(); + if (!this_location) + return &global_xlator; - return *this_location; + return *this_location; } - int -glusterfs_this_set (xlator_t *this) +glusterfs_this_set(xlator_t *this) { - xlator_t **this_location = NULL; + xlator_t **this_location = NULL; - this_location = __glusterfs_this_location (); - if (!this_location) - return -ENOMEM; + this_location = __glusterfs_this_location(); + if (!this_location) + return -ENOMEM; - *this_location = this; + *this_location = this; - return 0; + return 0; } /* SYNCOPCTX */ static pthread_key_t syncopctx_key; static void -syncopctx_key_destroy (void *ptr) +syncopctx_key_destroy(void *ptr) { - struct syncopctx *opctx = ptr; + struct syncopctx *opctx = ptr; - if (opctx) { - if (opctx->groups) - GF_FREE (opctx->groups); + if (opctx) { + if (opctx->groups) + GF_FREE(opctx->groups); - GF_FREE (opctx); - } + GF_FREE(opctx); + } - return; + return; } void * -syncopctx_getctx () +syncopctx_getctx() { - void *opctx = NULL; + void *opctx = NULL; - opctx = pthread_getspecific (syncopctx_key); + opctx = pthread_getspecific(syncopctx_key); - return opctx; + return opctx; } int -syncopctx_setctx (void *ctx) +syncopctx_setctx(void *ctx) { - int ret = 0; + int ret = 0; - ret = pthread_setspecific (syncopctx_key, ctx); + ret = pthread_setspecific(syncopctx_key, ctx); - return ret; + return ret; } static int -syncopctx_init (void) +syncopctx_init(void) { - int ret; + int ret; - ret = pthread_key_create (&syncopctx_key, syncopctx_key_destroy); + ret = pthread_key_create(&syncopctx_key, syncopctx_key_destroy); - return ret; + return ret; } /* SYNCTASK */ int -synctask_init () +synctask_init() { - int ret = 0; + int ret = 0; - ret = pthread_key_create (&synctask_key, NULL); + ret = pthread_key_create(&synctask_key, NULL); - return ret; + return ret; } void * -synctask_get () +synctask_get() { - void *synctask = NULL; + void *synctask = NULL; - synctask = pthread_getspecific (synctask_key); + synctask = pthread_getspecific(synctask_key); - return synctask; + return synctask; } - int -synctask_set (void *synctask) +synctask_set(void *synctask) { - int ret = 0; + int ret = 0; - pthread_setspecific (synctask_key, synctask); + pthread_setspecific(synctask_key, synctask); - return ret; + return ret; } -//UUID_BUFFER +// UUID_BUFFER void -glusterfs_uuid_buf_destroy (void *ptr) +glusterfs_uuid_buf_destroy(void *ptr) { - FREE (ptr); + FREE(ptr); } int -glusterfs_uuid_buf_init () +glusterfs_uuid_buf_init() { - int ret = 0; + int ret = 0; - ret = pthread_key_create (&uuid_buf_key, - glusterfs_uuid_buf_destroy); - return ret; + ret = pthread_key_create(&uuid_buf_key, glusterfs_uuid_buf_destroy); + return ret; } char * -glusterfs_uuid_buf_get () +glusterfs_uuid_buf_get() { - char *buf; - int ret = 0; - - buf = pthread_getspecific (uuid_buf_key); - if(!buf) { - buf = MALLOC (GF_UUID_BUF_SIZE); - ret = pthread_setspecific (uuid_buf_key, (void *) buf); - if (ret) - buf = global_uuid_buf; - } - return buf; + char *buf; + int ret = 0; + + buf = pthread_getspecific(uuid_buf_key); + if (!buf) { + buf = MALLOC(GF_UUID_BUF_SIZE); + ret = pthread_setspecific(uuid_buf_key, (void *)buf); + if (ret) + buf = global_uuid_buf; + } + return buf; } /* LKOWNER_BUFFER */ void -glusterfs_lkowner_buf_destroy (void *ptr) +glusterfs_lkowner_buf_destroy(void *ptr) { - FREE (ptr); + FREE(ptr); } int -glusterfs_lkowner_buf_init () +glusterfs_lkowner_buf_init() { - int ret = 0; + int ret = 0; - ret = pthread_key_create (&lkowner_buf_key, - glusterfs_lkowner_buf_destroy); - return ret; + ret = pthread_key_create(&lkowner_buf_key, glusterfs_lkowner_buf_destroy); + return ret; } char * -glusterfs_lkowner_buf_get () +glusterfs_lkowner_buf_get() { - char *buf; - int ret = 0; - - buf = pthread_getspecific (lkowner_buf_key); - if(!buf) { - buf = MALLOC (GF_LKOWNER_BUF_SIZE); - ret = pthread_setspecific (lkowner_buf_key, (void *) buf); - if (ret) - buf = global_lkowner_buf; - } - return buf; + char *buf; + int ret = 0; + + buf = pthread_getspecific(lkowner_buf_key); + if (!buf) { + buf = MALLOC(GF_LKOWNER_BUF_SIZE); + ret = pthread_setspecific(lkowner_buf_key, (void *)buf); + if (ret) + buf = global_lkowner_buf; + } + return buf; } /* Leaseid buffer */ void -glusterfs_leaseid_buf_destroy (void *ptr) +glusterfs_leaseid_buf_destroy(void *ptr) { - FREE (ptr); + FREE(ptr); } int -glusterfs_leaseid_buf_init () +glusterfs_leaseid_buf_init() { - int ret = 0; + int ret = 0; - ret = pthread_key_create (&leaseid_buf_key, - glusterfs_leaseid_buf_destroy); - return ret; + ret = pthread_key_create(&leaseid_buf_key, glusterfs_leaseid_buf_destroy); + return ret; } char * -glusterfs_leaseid_buf_get () +glusterfs_leaseid_buf_get() { - char *buf = NULL; - int ret = 0; - - buf = pthread_getspecific (leaseid_buf_key); - if (!buf) { - buf = CALLOC (1, GF_LEASE_ID_BUF_SIZE); - ret = pthread_setspecific (leaseid_buf_key, (void *) buf); - if (ret) { - FREE (buf); - buf = NULL; - } + char *buf = NULL; + int ret = 0; + + buf = pthread_getspecific(leaseid_buf_key); + if (!buf) { + buf = CALLOC(1, GF_LEASE_ID_BUF_SIZE); + ret = pthread_setspecific(leaseid_buf_key, (void *)buf); + if (ret) { + FREE(buf); + buf = NULL; } - return buf; + } + return buf; } char * -glusterfs_leaseid_exist () +glusterfs_leaseid_exist() { - return pthread_getspecific (leaseid_buf_key); + return pthread_getspecific(leaseid_buf_key); } static void -gf_globals_init_once () +gf_globals_init_once() { - int ret = 0; - - ret = glusterfs_this_init (); - if (ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_TRANSLATOR_INIT_FAILED, - "ERROR: glusterfs-translator init failed"); - goto out; - } - - ret = glusterfs_uuid_buf_init (); - if(ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_UUID_BUF_INIT_FAILED, - "ERROR: glusterfs uuid buffer init failed"); - goto out; - } - - ret = glusterfs_lkowner_buf_init (); - if(ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_LKOWNER_BUF_INIT_FAILED, - "ERROR: glusterfs lkowner buffer init failed"); - goto out; - } - - ret = glusterfs_leaseid_buf_init (); - if (ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_LEASEID_BUF_INIT_FAILED, - "ERROR: glusterfs leaseid buffer init failed"); - goto out; - } - - ret = synctask_init (); - if (ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_SYNCTASK_INIT_FAILED, - "ERROR: glusterfs synctask init failed"); - goto out; - } - - ret = syncopctx_init (); - if (ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_SYNCOPCTX_INIT_FAILED, - "ERROR: glusterfs syncopctx init failed"); - goto out; - } + int ret = 0; + + ret = glusterfs_this_init(); + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_TRANSLATOR_INIT_FAILED, + "ERROR: glusterfs-translator init failed"); + goto out; + } + + ret = glusterfs_uuid_buf_init(); + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_UUID_BUF_INIT_FAILED, + "ERROR: glusterfs uuid buffer init failed"); + goto out; + } + + ret = glusterfs_lkowner_buf_init(); + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_LKOWNER_BUF_INIT_FAILED, + "ERROR: glusterfs lkowner buffer init failed"); + goto out; + } + + ret = glusterfs_leaseid_buf_init(); + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_LEASEID_BUF_INIT_FAILED, + "ERROR: glusterfs leaseid buffer init failed"); + goto out; + } + + ret = synctask_init(); + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_SYNCTASK_INIT_FAILED, + "ERROR: glusterfs synctask init failed"); + goto out; + } + + ret = syncopctx_init(); + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_SYNCOPCTX_INIT_FAILED, + "ERROR: glusterfs syncopctx init failed"); + goto out; + } out: - if (ret) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_GLOBAL_INIT_FAILED, - "Exiting as global initialization failed"); - exit (ret); - } + if (ret) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_GLOBAL_INIT_FAILED, + "Exiting as global initialization failed"); + exit(ret); + } } int -glusterfs_globals_init (glusterfs_ctx_t *ctx) +glusterfs_globals_init(glusterfs_ctx_t *ctx) { - int ret = 0; + int ret = 0; - gf_log_globals_init (ctx, GF_LOG_INFO); + gf_log_globals_init(ctx, GF_LOG_INFO); - ret = pthread_once (&globals_inited, gf_globals_init_once); + ret = pthread_once(&globals_inited, gf_globals_init_once); - if (ret) - gf_msg ("", GF_LOG_CRITICAL, ret, LG_MSG_PTHREAD_FAILED, - "pthread_once failed"); + if (ret) + gf_msg("", GF_LOG_CRITICAL, ret, LG_MSG_PTHREAD_FAILED, + "pthread_once failed"); - return ret; + return ret; } diff --git a/libglusterfs/src/graph-print.c b/libglusterfs/src/graph-print.c index 676167b17d2..3b984b64508 100644 --- a/libglusterfs/src/graph-print.c +++ b/libglusterfs/src/graph-print.c @@ -15,183 +15,180 @@ #include "graph-utils.h" #include "libglusterfs-messages.h" - struct gf_printer { - ssize_t (*write) (struct gf_printer *gp, char *buf, size_t len); - void *priv; - int len; + ssize_t (*write)(struct gf_printer *gp, char *buf, size_t len); + void *priv; + int len; }; static ssize_t -gp_write_file (struct gf_printer *gp, char *buf, size_t len) +gp_write_file(struct gf_printer *gp, char *buf, size_t len) { - FILE *f = gp->priv; + FILE *f = gp->priv; - if (fwrite (buf, len, 1, f) != 1) { - gf_msg ("graph-print", GF_LOG_ERROR, errno, - LG_MSG_FWRITE_FAILED, "fwrite failed"); + if (fwrite(buf, len, 1, f) != 1) { + gf_msg("graph-print", GF_LOG_ERROR, errno, LG_MSG_FWRITE_FAILED, + "fwrite failed"); - return -1; - } + return -1; + } - return len; + return len; } static ssize_t -gp_write_buf (struct gf_printer *gp, char *buf, size_t len) +gp_write_buf(struct gf_printer *gp, char *buf, size_t len) { - struct iovec *iov = gp->priv; + struct iovec *iov = gp->priv; - if (iov->iov_len < len) { - gf_msg ("graph-print", GF_LOG_ERROR, 0, LG_MSG_BUFFER_FULL, - "buffer full"); + if (iov->iov_len < len) { + gf_msg("graph-print", GF_LOG_ERROR, 0, LG_MSG_BUFFER_FULL, + "buffer full"); - return -1; - } + return -1; + } - memcpy (iov->iov_base, buf, len); - iov->iov_base += len; - iov->iov_len -= len; + memcpy(iov->iov_base, buf, len); + iov->iov_base += len; + iov->iov_len -= len; - return len; + return len; } static int -gpprintf (struct gf_printer *gp, const char *format, ...) +gpprintf(struct gf_printer *gp, const char *format, ...) { - va_list arg; - char *str = NULL; - int ret = 0; + va_list arg; + char *str = NULL; + int ret = 0; - va_start (arg, format); - ret = gf_vasprintf (&str, format, arg); - va_end (arg); + va_start(arg, format); + ret = gf_vasprintf(&str, format, arg); + va_end(arg); - if (ret < 0) - return ret; + if (ret < 0) + return ret; - ret = gp->write (gp, str, ret); + ret = gp->write(gp, str, ret); - GF_FREE (str); + GF_FREE(str); - return ret; + return ret; } -#define GPPRINTF(gp, fmt, ...) do { \ - ret = gpprintf (gp, fmt, ## __VA_ARGS__); \ - if (ret == -1) \ - goto out; \ - else \ - gp->len += ret; \ - } while (0) +#define GPPRINTF(gp, fmt, ...) \ + do { \ + ret = gpprintf(gp, fmt, ##__VA_ARGS__); \ + if (ret == -1) \ + goto out; \ + else \ + gp->len += ret; \ + } while (0) static int -_print_volume_options (dict_t *d, char *k, data_t *v, - void *tmp) +_print_volume_options(dict_t *d, char *k, data_t *v, void *tmp) { - struct gf_printer *gp = tmp; - int ret = 0; - GPPRINTF (gp, " option %s %s\n", k, v->data); - return 0; + struct gf_printer *gp = tmp; + int ret = 0; + GPPRINTF(gp, " option %s %s\n", k, v->data); + return 0; out: - /* means, it is a failure */ - return -1; + /* means, it is a failure */ + return -1; } static int -glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph) +glusterfs_graph_print(struct gf_printer *gp, glusterfs_graph_t *graph) { - xlator_t *trav = NULL; - xlator_list_t *xch = NULL; - int ret = 0; - ssize_t len = 0; - - if (!graph->first) - return 0; + xlator_t *trav = NULL; + xlator_list_t *xch = NULL; + int ret = 0; + ssize_t len = 0; - for (trav = graph->first; trav->next; trav = trav->next); - for (; trav; trav = trav->prev) { - GPPRINTF (gp, "volume %s\n type %s\n", trav->name, - trav->type); + if (!graph->first) + return 0; - ret = dict_foreach (trav->options, _print_volume_options, gp); - if (ret) - goto out; + for (trav = graph->first; trav->next; trav = trav->next) + ; + for (; trav; trav = trav->prev) { + GPPRINTF(gp, "volume %s\n type %s\n", trav->name, trav->type); - if (trav->children) { - GPPRINTF (gp, " subvolumes"); + ret = dict_foreach(trav->options, _print_volume_options, gp); + if (ret) + goto out; - for (xch = trav->children; xch; xch = xch->next) - GPPRINTF (gp, " %s", xch->xlator->name); + if (trav->children) { + GPPRINTF(gp, " subvolumes"); - GPPRINTF (gp, "\n"); - } + for (xch = trav->children; xch; xch = xch->next) + GPPRINTF(gp, " %s", xch->xlator->name); - GPPRINTF (gp, "end-volume\n"); - if (trav != graph->first) - GPPRINTF (gp, "\n"); + GPPRINTF(gp, "\n"); } + GPPRINTF(gp, "end-volume\n"); + if (trav != graph->first) + GPPRINTF(gp, "\n"); + } + out: - len = gp->len; - if (ret == -1) { - gf_msg ("graph-print", GF_LOG_ERROR, 0, LG_MSG_PRINT_FAILED, - "printing failed"); + len = gp->len; + if (ret == -1) { + gf_msg("graph-print", GF_LOG_ERROR, 0, LG_MSG_PRINT_FAILED, + "printing failed"); - return -1; - } + return -1; + } - return len; + return len; #undef GPPRINTF } int -glusterfs_graph_print_file (FILE *file, glusterfs_graph_t *graph) +glusterfs_graph_print_file(FILE *file, glusterfs_graph_t *graph) { - struct gf_printer gp = { .write = gp_write_file, - .priv = file - }; + struct gf_printer gp = {.write = gp_write_file, .priv = file}; - return glusterfs_graph_print (&gp, graph); + return glusterfs_graph_print(&gp, graph); } char * -glusterfs_graph_print_buf (glusterfs_graph_t *graph) +glusterfs_graph_print_buf(glusterfs_graph_t *graph) { - FILE *f = NULL; - struct iovec iov = {0,}; - int len = 0; - char *buf = NULL; - struct gf_printer gp = { .write = gp_write_buf, - .priv = &iov - }; - - f = fopen ("/dev/null", "a"); - if (!f) { - gf_msg ("graph-print", GF_LOG_ERROR, errno, - LG_MSG_DIR_OP_FAILED, "cannot open /dev/null"); - - return NULL; - } - len = glusterfs_graph_print_file (f, graph); - fclose (f); - if (len == -1) - return NULL; - - buf = GF_CALLOC (1, len + 1, gf_common_mt_graph_buf); - if (!buf) { - return NULL; - } - iov.iov_base = buf; - iov.iov_len = len; - - len = glusterfs_graph_print (&gp, graph); - if (len == -1) { - GF_FREE (buf); - - return NULL; - } - - return buf; + FILE *f = NULL; + struct iovec iov = { + 0, + }; + int len = 0; + char *buf = NULL; + struct gf_printer gp = {.write = gp_write_buf, .priv = &iov}; + + f = fopen("/dev/null", "a"); + if (!f) { + gf_msg("graph-print", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "cannot open /dev/null"); + + return NULL; + } + len = glusterfs_graph_print_file(f, graph); + fclose(f); + if (len == -1) + return NULL; + + buf = GF_CALLOC(1, len + 1, gf_common_mt_graph_buf); + if (!buf) { + return NULL; + } + iov.iov_base = buf; + iov.iov_len = len; + + len = glusterfs_graph_print(&gp, graph); + if (len == -1) { + GF_FREE(buf); + + return NULL; + } + + return buf; } diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index 03ef55c5892..2a213d2c48e 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -69,623 +69,611 @@ _gf_dump_details (int argc, char **argv) #endif int -glusterfs_read_secure_access_file (void) +glusterfs_read_secure_access_file(void) { - FILE *fp = NULL; - char line[100] = {0,}; - int cert_depth = 1; /* Default SSL CERT DEPTH */ - regex_t regcmpl; - char *key = {"^option transport.socket.ssl-cert-depth"}; - char keyval[50] = {0,}; - int start = 0, end = 0, copy_len = 0; - regmatch_t result[1] = {{0} }; - - fp = fopen (SECURE_ACCESS_FILE, "r"); - if (!fp) - goto out; - - /* Check if any line matches with key */ - while (fgets(line, sizeof(line), fp) != NULL) { - if (regcomp (®cmpl, key, REG_EXTENDED)) { - goto out; - } - if (!regexec (®cmpl, line, 1, result, 0)) { - start = result[0].rm_so; - end = result[0].rm_eo; - copy_len = end - start; - gf_strncpy (keyval, line+copy_len, sizeof (keyval)); - if (keyval[0]) { - cert_depth = atoi(keyval); - if (cert_depth == 0) - cert_depth = 1; /* Default SSL CERT DEPTH */ - break; - } - } - regfree(®cmpl); + FILE *fp = NULL; + char line[100] = { + 0, + }; + int cert_depth = 1; /* Default SSL CERT DEPTH */ + regex_t regcmpl; + char *key = {"^option transport.socket.ssl-cert-depth"}; + char keyval[50] = { + 0, + }; + int start = 0, end = 0, copy_len = 0; + regmatch_t result[1] = {{0}}; + + fp = fopen(SECURE_ACCESS_FILE, "r"); + if (!fp) + goto out; + + /* Check if any line matches with key */ + while (fgets(line, sizeof(line), fp) != NULL) { + if (regcomp(®cmpl, key, REG_EXTENDED)) { + goto out; } + if (!regexec(®cmpl, line, 1, result, 0)) { + start = result[0].rm_so; + end = result[0].rm_eo; + copy_len = end - start; + gf_strncpy(keyval, line + copy_len, sizeof(keyval)); + if (keyval[0]) { + cert_depth = atoi(keyval); + if (cert_depth == 0) + cert_depth = 1; /* Default SSL CERT DEPTH */ + break; + } + } + regfree(®cmpl); + } out: - if (fp) - fclose (fp); - return cert_depth; + if (fp) + fclose(fp); + return cert_depth; } int -glusterfs_xlator_link (xlator_t *pxl, xlator_t *cxl) +glusterfs_xlator_link(xlator_t *pxl, xlator_t *cxl) { - xlator_list_t *xlchild = NULL; - xlator_list_t *xlparent = NULL; - xlator_list_t **tmp = NULL; + xlator_list_t *xlchild = NULL; + xlator_list_t *xlparent = NULL; + xlator_list_t **tmp = NULL; - xlparent = (void *) GF_CALLOC (1, sizeof (*xlparent), - gf_common_mt_xlator_list_t); - if (!xlparent) - return -1; + xlparent = (void *)GF_CALLOC(1, sizeof(*xlparent), + gf_common_mt_xlator_list_t); + if (!xlparent) + return -1; - xlchild = (void *) GF_CALLOC (1, sizeof (*xlchild), - gf_common_mt_xlator_list_t); - if (!xlchild) { - GF_FREE (xlparent); + xlchild = (void *)GF_CALLOC(1, sizeof(*xlchild), + gf_common_mt_xlator_list_t); + if (!xlchild) { + GF_FREE(xlparent); - return -1; - } + return -1; + } - xlparent->xlator = pxl; - for (tmp = &cxl->parents; *tmp; tmp = &(*tmp)->next); - *tmp = xlparent; + xlparent->xlator = pxl; + for (tmp = &cxl->parents; *tmp; tmp = &(*tmp)->next) + ; + *tmp = xlparent; - xlchild->xlator = cxl; - for (tmp = &pxl->children; *tmp; tmp = &(*tmp)->next); - *tmp = xlchild; + xlchild->xlator = cxl; + for (tmp = &pxl->children; *tmp; tmp = &(*tmp)->next) + ; + *tmp = xlchild; - return 0; + return 0; } - void -glusterfs_graph_set_first (glusterfs_graph_t *graph, xlator_t *xl) +glusterfs_graph_set_first(glusterfs_graph_t *graph, xlator_t *xl) { - xl->next = graph->first; - if (graph->first) - ((xlator_t *)graph->first)->prev = xl; - graph->first = xl; + xl->next = graph->first; + if (graph->first) + ((xlator_t *)graph->first)->prev = xl; + graph->first = xl; - graph->xl_count++; - xl->xl_id = graph->xl_count; + graph->xl_count++; + xl->xl_id = graph->xl_count; } - int -glusterfs_graph_insert (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx, - const char *type, const char *name, - gf_boolean_t autoload) +glusterfs_graph_insert(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx, + const char *type, const char *name, + gf_boolean_t autoload) { - xlator_t *ixl = NULL; + xlator_t *ixl = NULL; - if (!ctx->master) { - gf_msg ("glusterfs", GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, - "volume \"%s\" can be added from command line only " - "on client side", type); + if (!ctx->master) { + gf_msg("glusterfs", GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, + "volume \"%s\" can be added from command line only " + "on client side", + type); - return -1; - } + return -1; + } - ixl = GF_CALLOC (1, sizeof (*ixl), gf_common_mt_xlator_t); - if (!ixl) - return -1; + ixl = GF_CALLOC(1, sizeof(*ixl), gf_common_mt_xlator_t); + if (!ixl) + return -1; - ixl->ctx = ctx; - ixl->graph = graph; - ixl->options = get_new_dict (); - if (!ixl->options) - goto err; + ixl->ctx = ctx; + ixl->graph = graph; + ixl->options = get_new_dict(); + if (!ixl->options) + goto err; - ixl->name = gf_strdup (name); - if (!ixl->name) - goto err; + ixl->name = gf_strdup(name); + if (!ixl->name) + goto err; - ixl->is_autoloaded = autoload; + ixl->is_autoloaded = autoload; - if (xlator_set_type (ixl, type) == -1) { - gf_msg ("glusterfs", GF_LOG_ERROR, 0, LG_MSG_INIT_FAILED, - "%s (%s) initialization failed", - name, type); - return -1; - } + if (xlator_set_type(ixl, type) == -1) { + gf_msg("glusterfs", GF_LOG_ERROR, 0, LG_MSG_INIT_FAILED, + "%s (%s) initialization failed", name, type); + return -1; + } - if (glusterfs_xlator_link (ixl, graph->top) == -1) - goto err; - glusterfs_graph_set_first (graph, ixl); - graph->top = ixl; + if (glusterfs_xlator_link(ixl, graph->top) == -1) + goto err; + glusterfs_graph_set_first(graph, ixl); + graph->top = ixl; - return 0; + return 0; err: - xlator_destroy (ixl); - return -1; + xlator_destroy(ixl); + return -1; } int -glusterfs_graph_acl (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +glusterfs_graph_acl(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { - int ret = 0; - cmd_args_t *cmd_args = NULL; + int ret = 0; + cmd_args_t *cmd_args = NULL; - cmd_args = &ctx->cmd_args; + cmd_args = &ctx->cmd_args; - if (!cmd_args->acl) - return 0; + if (!cmd_args->acl) + return 0; - ret = glusterfs_graph_insert (graph, ctx, "system/posix-acl", - "posix-acl-autoload", 1); - return ret; + ret = glusterfs_graph_insert(graph, ctx, "system/posix-acl", + "posix-acl-autoload", 1); + return ret; } int -glusterfs_graph_worm (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +glusterfs_graph_worm(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { - int ret = 0; - cmd_args_t *cmd_args = NULL; + int ret = 0; + cmd_args_t *cmd_args = NULL; - cmd_args = &ctx->cmd_args; + cmd_args = &ctx->cmd_args; - if (!cmd_args->worm) - return 0; + if (!cmd_args->worm) + return 0; - ret = glusterfs_graph_insert (graph, ctx, "features/worm", - "worm-autoload", 1); - return ret; + ret = glusterfs_graph_insert(graph, ctx, "features/worm", "worm-autoload", + 1); + return ret; } - int -glusterfs_graph_meta (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +glusterfs_graph_meta(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { - int ret = 0; + int ret = 0; - if (!ctx->master) - return 0; + if (!ctx->master) + return 0; - ret = glusterfs_graph_insert (graph, ctx, "meta", - "meta-autoload", 1); - return ret; + ret = glusterfs_graph_insert(graph, ctx, "meta", "meta-autoload", 1); + return ret; } - int -glusterfs_graph_mac_compat (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +glusterfs_graph_mac_compat(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { - int ret = 0; - cmd_args_t *cmd_args = NULL; + int ret = 0; + cmd_args_t *cmd_args = NULL; - cmd_args = &ctx->cmd_args; + cmd_args = &ctx->cmd_args; - if (cmd_args->mac_compat == GF_OPTION_DISABLE) - return 0; + if (cmd_args->mac_compat == GF_OPTION_DISABLE) + return 0; - ret = glusterfs_graph_insert (graph, ctx, "features/mac-compat", - "mac-compat-autoload", 1); + ret = glusterfs_graph_insert(graph, ctx, "features/mac-compat", + "mac-compat-autoload", 1); - return ret; + return ret; } int -glusterfs_graph_gfid_access (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +glusterfs_graph_gfid_access(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { - int ret = 0; - cmd_args_t *cmd_args = NULL; + int ret = 0; + cmd_args_t *cmd_args = NULL; - cmd_args = &ctx->cmd_args; + cmd_args = &ctx->cmd_args; - if (!cmd_args->aux_gfid_mount) - return 0; + if (!cmd_args->aux_gfid_mount) + return 0; - ret = glusterfs_graph_insert (graph, ctx, "features/gfid-access", - "gfid-access-autoload", 1); - return ret; + ret = glusterfs_graph_insert(graph, ctx, "features/gfid-access", + "gfid-access-autoload", 1); + return ret; } static void -gf_add_cmdline_options (glusterfs_graph_t *graph, cmd_args_t *cmd_args) +gf_add_cmdline_options(glusterfs_graph_t *graph, cmd_args_t *cmd_args) { - int ret = 0; - xlator_t *trav = NULL; - xlator_cmdline_option_t *cmd_option = NULL; - - trav = graph->first; - - while (trav) { - list_for_each_entry (cmd_option, - &cmd_args->xlator_options, cmd_args) { - if (!fnmatch (cmd_option->volume, - trav->name, FNM_NOESCAPE)) { - ret = dict_set_str (trav->options, - cmd_option->key, - cmd_option->value); - if (ret == 0) { - gf_msg (trav->name, GF_LOG_TRACE, 0, - LG_MSG_VOL_OPTION_ADD, - "adding option '%s' for " - "volume '%s' with value '%s'", - cmd_option->key, trav->name, - cmd_option->value); - } else { - gf_msg (trav->name, GF_LOG_WARNING, - -ret, LG_MSG_VOL_OPTION_ADD, - "adding option '%s' for " - "volume '%s' failed", - cmd_option->key, trav->name); - } - } + int ret = 0; + xlator_t *trav = NULL; + xlator_cmdline_option_t *cmd_option = NULL; + + trav = graph->first; + + while (trav) { + list_for_each_entry(cmd_option, &cmd_args->xlator_options, cmd_args) + { + if (!fnmatch(cmd_option->volume, trav->name, FNM_NOESCAPE)) { + ret = dict_set_str(trav->options, cmd_option->key, + cmd_option->value); + if (ret == 0) { + gf_msg(trav->name, GF_LOG_TRACE, 0, LG_MSG_VOL_OPTION_ADD, + "adding option '%s' for " + "volume '%s' with value '%s'", + cmd_option->key, trav->name, cmd_option->value); + } else { + gf_msg(trav->name, GF_LOG_WARNING, -ret, + LG_MSG_VOL_OPTION_ADD, + "adding option '%s' for " + "volume '%s' failed", + cmd_option->key, trav->name); } - trav = trav->next; + } } + trav = trav->next; + } } - int -glusterfs_graph_validate_options (glusterfs_graph_t *graph) +glusterfs_graph_validate_options(glusterfs_graph_t *graph) { - xlator_t *trav = NULL; - int ret = -1; - char *errstr = NULL; + xlator_t *trav = NULL; + int ret = -1; + char *errstr = NULL; - trav = graph->first; + trav = graph->first; - while (trav) { - if (list_empty (&trav->volume_options)) { - trav = trav->next; - continue; - } + while (trav) { + if (list_empty(&trav->volume_options)) { + trav = trav->next; + continue; + } - ret = xlator_options_validate (trav, trav->options, &errstr); - if (ret) { - gf_msg (trav->name, GF_LOG_ERROR, 0, - LG_MSG_VALIDATION_FAILED, "validation failed: " - "%s", errstr); - return ret; - } - trav = trav->next; + ret = xlator_options_validate(trav, trav->options, &errstr); + if (ret) { + gf_msg(trav->name, GF_LOG_ERROR, 0, LG_MSG_VALIDATION_FAILED, + "validation failed: " + "%s", + errstr); + return ret; } + trav = trav->next; + } - return 0; + return 0; } - int -glusterfs_graph_init (glusterfs_graph_t *graph) +glusterfs_graph_init(glusterfs_graph_t *graph) { - xlator_t *trav = NULL; - int ret = -1; - - trav = graph->first; - - while (trav) { - ret = xlator_init (trav); - if (ret) { - gf_msg (trav->name, GF_LOG_ERROR, 0, - LG_MSG_TRANSLATOR_INIT_FAILED, - "initializing translator failed"); - return ret; - } - trav = trav->next; + xlator_t *trav = NULL; + int ret = -1; + + trav = graph->first; + + while (trav) { + ret = xlator_init(trav); + if (ret) { + gf_msg(trav->name, GF_LOG_ERROR, 0, LG_MSG_TRANSLATOR_INIT_FAILED, + "initializing translator failed"); + return ret; } + trav = trav->next; + } - return 0; + return 0; } int -glusterfs_graph_deactivate (glusterfs_graph_t *graph) +glusterfs_graph_deactivate(glusterfs_graph_t *graph) { - xlator_t *top = NULL; + xlator_t *top = NULL; - if (graph == NULL) - goto out; + if (graph == NULL) + goto out; - top = graph->top; - xlator_tree_fini (top); - out: - return 0; + top = graph->top; + xlator_tree_fini(top); +out: + return 0; } static int -_log_if_unknown_option (dict_t *dict, char *key, data_t *value, void *data) +_log_if_unknown_option(dict_t *dict, char *key, data_t *value, void *data) { - volume_option_t *found = NULL; - xlator_t *xl = NULL; + volume_option_t *found = NULL; + xlator_t *xl = NULL; - xl = data; + xl = data; - found = xlator_volume_option_get (xl, key); + found = xlator_volume_option_get(xl, key); - if (!found) { - gf_msg (xl->name, GF_LOG_WARNING, 0, - LG_MSG_XLATOR_OPTION_INVALID, - "option '%s' is not recognized", key); - } + if (!found) { + gf_msg(xl->name, GF_LOG_WARNING, 0, LG_MSG_XLATOR_OPTION_INVALID, + "option '%s' is not recognized", key); + } - return 0; + return 0; } - static void -_xlator_check_unknown_options (xlator_t *xl, void *data) +_xlator_check_unknown_options(xlator_t *xl, void *data) { - dict_foreach (xl->options, _log_if_unknown_option, xl); + dict_foreach(xl->options, _log_if_unknown_option, xl); } - int -glusterfs_graph_unknown_options (glusterfs_graph_t *graph) +glusterfs_graph_unknown_options(glusterfs_graph_t *graph) { - xlator_foreach (graph->first, _xlator_check_unknown_options, NULL); - return 0; + xlator_foreach(graph->first, _xlator_check_unknown_options, NULL); + return 0; } - void -fill_uuid (char *uuid, int size) +fill_uuid(char *uuid, int size) { - char hostname[256] = {0,}; - struct timeval tv = {0,}; - char now_str[64]; - - if (gettimeofday (&tv, NULL) == -1) { - gf_msg ("graph", GF_LOG_ERROR, errno, - LG_MSG_GETTIMEOFDAY_FAILED, "gettimeofday: " - "failed"); - } - - if (gethostname (hostname, 256) == -1) { - gf_msg ("graph", GF_LOG_ERROR, errno, - LG_MSG_GETHOSTNAME_FAILED, "gethostname: " - "failed"); - } - - gf_time_fmt (now_str, sizeof now_str, tv.tv_sec, gf_timefmt_dirent); - snprintf (uuid, size, "%s-%d-%s:%"GF_PRI_SUSECONDS, - hostname, getpid(), now_str, tv.tv_usec); - - return; + char hostname[256] = { + 0, + }; + struct timeval tv = { + 0, + }; + char now_str[64]; + + if (gettimeofday(&tv, NULL) == -1) { + gf_msg("graph", GF_LOG_ERROR, errno, LG_MSG_GETTIMEOFDAY_FAILED, + "gettimeofday: " + "failed"); + } + + if (gethostname(hostname, 256) == -1) { + gf_msg("graph", GF_LOG_ERROR, errno, LG_MSG_GETHOSTNAME_FAILED, + "gethostname: " + "failed"); + } + + gf_time_fmt(now_str, sizeof now_str, tv.tv_sec, gf_timefmt_dirent); + snprintf(uuid, size, "%s-%d-%s:%" GF_PRI_SUSECONDS, hostname, getpid(), + now_str, tv.tv_usec); + + return; } - static int -glusterfs_graph_settop (glusterfs_graph_t *graph, char *volume_name, - gf_boolean_t exact_match) +glusterfs_graph_settop(glusterfs_graph_t *graph, char *volume_name, + gf_boolean_t exact_match) { - int ret = -1; - xlator_t *trav = NULL; + int ret = -1; + xlator_t *trav = NULL; - if (!volume_name || !exact_match) { - graph->top = graph->first; + if (!volume_name || !exact_match) { + graph->top = graph->first; + ret = 0; + } else { + for (trav = graph->first; trav; trav = trav->next) { + if (strcmp(trav->name, volume_name) == 0) { + graph->top = trav; ret = 0; - } else { - for (trav = graph->first; trav; trav = trav->next) { - if (strcmp (trav->name, volume_name) == 0) { - graph->top = trav; - ret = 0; - break; - } - } + break; + } } + } - return ret; + return ret; } - int -glusterfs_graph_parent_up (glusterfs_graph_t *graph) +glusterfs_graph_parent_up(glusterfs_graph_t *graph) { - xlator_t *trav = NULL; - int ret = -1; + xlator_t *trav = NULL; + int ret = -1; - trav = graph->first; + trav = graph->first; - while (trav) { - if (!xlator_has_parent (trav)) { - ret = xlator_notify (trav, GF_EVENT_PARENT_UP, trav); - } + while (trav) { + if (!xlator_has_parent(trav)) { + ret = xlator_notify(trav, GF_EVENT_PARENT_UP, trav); + } - if (ret) - break; + if (ret) + break; - trav = trav->next; - } + trav = trav->next; + } - return ret; + return ret; } - int -glusterfs_graph_prepare (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx, - char *volume_name) +glusterfs_graph_prepare(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx, + char *volume_name) { - xlator_t *trav = NULL; - int ret = 0; - - /* XXX: CHECKSUM */ - - /* XXX: attach to -n volname */ - /* A '/' in the volume name suggests brick multiplexing is used, find - * the top of the (sub)graph. The volname MUST match the subvol in this - * case. In other cases (like for gfapi) the default top for the - * (sub)graph is ok. */ - if (!volume_name) { - /* GlusterD does not pass a volume_name */ - ret = glusterfs_graph_settop (graph, volume_name, _gf_false); - } else if (strncmp (volume_name, "/snaps/", 7) == 0) { - /* snap shots have their top xlator named like "/snaps/..." */ - ret = glusterfs_graph_settop (graph, volume_name, - _gf_false); - } else if (volume_name[0] == '/') { - /* brick multiplexing passes the brick path */ - ret = glusterfs_graph_settop (graph, volume_name, - _gf_true); - } else { - ret = glusterfs_graph_settop (graph, volume_name, - _gf_false); - } - if (!ret) { - goto ok; - } - - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, - "glusterfs graph settop failed"); - return -1; + xlator_t *trav = NULL; + int ret = 0; + + /* XXX: CHECKSUM */ + + /* XXX: attach to -n volname */ + /* A '/' in the volume name suggests brick multiplexing is used, find + * the top of the (sub)graph. The volname MUST match the subvol in this + * case. In other cases (like for gfapi) the default top for the + * (sub)graph is ok. */ + if (!volume_name) { + /* GlusterD does not pass a volume_name */ + ret = glusterfs_graph_settop(graph, volume_name, _gf_false); + } else if (strncmp(volume_name, "/snaps/", 7) == 0) { + /* snap shots have their top xlator named like "/snaps/..." */ + ret = glusterfs_graph_settop(graph, volume_name, _gf_false); + } else if (volume_name[0] == '/') { + /* brick multiplexing passes the brick path */ + ret = glusterfs_graph_settop(graph, volume_name, _gf_true); + } else { + ret = glusterfs_graph_settop(graph, volume_name, _gf_false); + } + if (!ret) { + goto ok; + } + + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, + "glusterfs graph settop failed"); + return -1; ok: - /* XXX: WORM VOLUME */ - ret = glusterfs_graph_worm (graph, ctx); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, - "glusterfs graph worm failed"); - return -1; - } - ret = glusterfs_graph_acl (graph, ctx); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, - "glusterfs graph ACL failed"); - return -1; - } + /* XXX: WORM VOLUME */ + ret = glusterfs_graph_worm(graph, ctx); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, + "glusterfs graph worm failed"); + return -1; + } + ret = glusterfs_graph_acl(graph, ctx); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, + "glusterfs graph ACL failed"); + return -1; + } - /* XXX: MAC COMPAT */ - ret = glusterfs_graph_mac_compat (graph, ctx); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, - "glusterfs graph mac compat failed"); - return -1; - } + /* XXX: MAC COMPAT */ + ret = glusterfs_graph_mac_compat(graph, ctx); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, + "glusterfs graph mac compat failed"); + return -1; + } - /* XXX: gfid-access */ - ret = glusterfs_graph_gfid_access (graph, ctx); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, - "glusterfs graph 'gfid-access' failed"); - return -1; - } + /* XXX: gfid-access */ + ret = glusterfs_graph_gfid_access(graph, ctx); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, + "glusterfs graph 'gfid-access' failed"); + return -1; + } - /* XXX: topmost xlator */ - ret = glusterfs_graph_meta (graph, ctx); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, - "glusterfs graph meta failed"); - return -1; - } + /* XXX: topmost xlator */ + ret = glusterfs_graph_meta(graph, ctx); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_ERROR, + "glusterfs graph meta failed"); + return -1; + } - /* XXX: this->ctx setting */ - for (trav = graph->first; trav; trav = trav->next) { - trav->ctx = ctx; - } + /* XXX: this->ctx setting */ + for (trav = graph->first; trav; trav = trav->next) { + trav->ctx = ctx; + } - /* XXX: DOB setting */ - gettimeofday (&graph->dob, NULL); + /* XXX: DOB setting */ + gettimeofday(&graph->dob, NULL); - fill_uuid (graph->graph_uuid, 128); + fill_uuid(graph->graph_uuid, 128); - graph->id = ctx->graph_id++; + graph->id = ctx->graph_id++; - /* XXX: --xlator-option additions */ - gf_add_cmdline_options (graph, &ctx->cmd_args); + /* XXX: --xlator-option additions */ + gf_add_cmdline_options(graph, &ctx->cmd_args); - return 0; + return 0; } -static -xlator_t *glusterfs_root(glusterfs_graph_t *graph) +static xlator_t * +glusterfs_root(glusterfs_graph_t *graph) { - return graph->first; + return graph->first; } -static -int glusterfs_is_leaf(xlator_t *xl) +static int +glusterfs_is_leaf(xlator_t *xl) { - int ret = 0; + int ret = 0; - if (!xl->children) - ret = 1; + if (!xl->children) + ret = 1; - return ret; + return ret; } -static -uint32_t glusterfs_count_leaves(xlator_t *xl) +static uint32_t +glusterfs_count_leaves(xlator_t *xl) { - int n = 0; - xlator_list_t *list = NULL; + int n = 0; + xlator_list_t *list = NULL; - if (glusterfs_is_leaf(xl)) - n = 1; - else - for (list = xl->children; list; list = list->next) - n += glusterfs_count_leaves(list->xlator); + if (glusterfs_is_leaf(xl)) + n = 1; + else + for (list = xl->children; list; list = list->next) + n += glusterfs_count_leaves(list->xlator); - return n; + return n; } -int glusterfs_get_leaf_count(glusterfs_graph_t *graph) +int +glusterfs_get_leaf_count(glusterfs_graph_t *graph) { - return graph->leaf_count; + return graph->leaf_count; } -static -int _glusterfs_leaf_position(xlator_t *tgt, int *id, xlator_t *xl) +static int +_glusterfs_leaf_position(xlator_t *tgt, int *id, xlator_t *xl) { - xlator_list_t *list = NULL; - int found = 0; - - if (xl == tgt) - found = 1; - else if (glusterfs_is_leaf(xl)) - *id += 1; - else - for (list = xl->children; !found && list; list = list->next) - found = _glusterfs_leaf_position(tgt, id, list->xlator); - - return found; + xlator_list_t *list = NULL; + int found = 0; + + if (xl == tgt) + found = 1; + else if (glusterfs_is_leaf(xl)) + *id += 1; + else + for (list = xl->children; !found && list; list = list->next) + found = _glusterfs_leaf_position(tgt, id, list->xlator); + + return found; } -int glusterfs_leaf_position(xlator_t *tgt) +int +glusterfs_leaf_position(xlator_t *tgt) { - xlator_t *root = NULL; - int pos = 0; + xlator_t *root = NULL; + int pos = 0; - root = glusterfs_root(tgt->graph); + root = glusterfs_root(tgt->graph); - if (!_glusterfs_leaf_position(tgt, &pos, root)) - pos = -1; + if (!_glusterfs_leaf_position(tgt, &pos, root)) + pos = -1; - return pos; + return pos; } static int _glusterfs_reachable_leaves(xlator_t *base, xlator_t *xl, dict_t *leaves) { - xlator_list_t *list = NULL; - int err = 1; - int pos = 0; - char *strpos = NULL; + xlator_list_t *list = NULL; + int err = 1; + int pos = 0; + char *strpos = NULL; - if (glusterfs_is_leaf(xl)) { - pos = glusterfs_leaf_position(xl); - if (pos < 0) - goto out; + if (glusterfs_is_leaf(xl)) { + pos = glusterfs_leaf_position(xl); + if (pos < 0) + goto out; - err = gf_asprintf(&strpos, "%d", pos); + err = gf_asprintf(&strpos, "%d", pos); - if (err >= 0) { - err = dict_set_static_ptr(leaves, strpos, base); - GF_FREE (strpos); - } - } else { - for (err = 0, list = xl->children; - !err && list; - list = list->next) - err = _glusterfs_reachable_leaves(base, list->xlator, - leaves); + if (err >= 0) { + err = dict_set_static_ptr(leaves, strpos, base); + GF_FREE(strpos); } + } else { + for (err = 0, list = xl->children; !err && list; list = list->next) + err = _glusterfs_reachable_leaves(base, list->xlator, leaves); + } out: - return err; + return err; } /* @@ -703,230 +691,226 @@ out: int glusterfs_reachable_leaves(xlator_t *base, dict_t *leaves) { - xlator_list_t *list = NULL; - int err = 0; + xlator_list_t *list = NULL; + int err = 0; - for (list = base->children; !err && list; list = list->next) - err = _glusterfs_reachable_leaves(list->xlator, - list->xlator, leaves); + for (list = base->children; !err && list; list = list->next) + err = _glusterfs_reachable_leaves(list->xlator, list->xlator, leaves); - return err; + return err; } int -glusterfs_graph_activate (glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) +glusterfs_graph_activate(glusterfs_graph_t *graph, glusterfs_ctx_t *ctx) { - int ret = 0; - xlator_t *root = NULL; + int ret = 0; + xlator_t *root = NULL; - root = glusterfs_root(graph); + root = glusterfs_root(graph); - graph->leaf_count = glusterfs_count_leaves(root); + graph->leaf_count = glusterfs_count_leaves(root); - /* XXX: all xlator options validation */ - ret = glusterfs_graph_validate_options (graph); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_VALIDATION_FAILED, - "validate options failed"); - return ret; - } - - /* XXX: perform init () */ - ret = glusterfs_graph_init (graph); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_INIT_FAILED, - "init failed"); - return ret; - } + /* XXX: all xlator options validation */ + ret = glusterfs_graph_validate_options(graph); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_VALIDATION_FAILED, + "validate options failed"); + return ret; + } - ret = glusterfs_graph_unknown_options (graph); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, - LG_MSG_UNKNOWN_OPTIONS_FAILED, "unknown options " - "failed"); - return ret; - } + /* XXX: perform init () */ + ret = glusterfs_graph_init(graph); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_GRAPH_INIT_FAILED, + "init failed"); + return ret; + } - /* XXX: log full graph (_gf_dump_details) */ + ret = glusterfs_graph_unknown_options(graph); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_UNKNOWN_OPTIONS_FAILED, + "unknown options " + "failed"); + return ret; + } - list_add (&graph->list, &ctx->graphs); - ctx->active = graph; + /* XXX: log full graph (_gf_dump_details) */ - /* XXX: attach to master and set active pointer */ - if (ctx->master) { - ret = xlator_notify (ctx->master, GF_EVENT_GRAPH_NEW, graph); - if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, - LG_MSG_EVENT_NOTIFY_FAILED, - "graph new notification failed"); - return ret; - } - ((xlator_t *)ctx->master)->next = graph->top; - } + list_add(&graph->list, &ctx->graphs); + ctx->active = graph; - /* XXX: perform parent up */ - ret = glusterfs_graph_parent_up (graph); + /* XXX: attach to master and set active pointer */ + if (ctx->master) { + ret = xlator_notify(ctx->master, GF_EVENT_GRAPH_NEW, graph); if (ret) { - gf_msg ("graph", GF_LOG_ERROR, 0, LG_MSG_EVENT_NOTIFY_FAILED, - "parent up notification failed"); - return ret; + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_EVENT_NOTIFY_FAILED, + "graph new notification failed"); + return ret; } + ((xlator_t *)ctx->master)->next = graph->top; + } + + /* XXX: perform parent up */ + ret = glusterfs_graph_parent_up(graph); + if (ret) { + gf_msg("graph", GF_LOG_ERROR, 0, LG_MSG_EVENT_NOTIFY_FAILED, + "parent up notification failed"); + return ret; + } - return 0; + return 0; } - int -xlator_equal_rec (xlator_t *xl1, xlator_t *xl2) +xlator_equal_rec(xlator_t *xl1, xlator_t *xl2) { - xlator_list_t *trav1 = NULL; - xlator_list_t *trav2 = NULL; - int ret = 0; + xlator_list_t *trav1 = NULL; + xlator_list_t *trav2 = NULL; + int ret = 0; - if (xl1 == NULL || xl2 == NULL) { - gf_msg_debug ("xlator", 0, "invalid argument"); - return -1; - } - - trav1 = xl1->children; - trav2 = xl2->children; - - while (trav1 && trav2) { - ret = xlator_equal_rec (trav1->xlator, trav2->xlator); - if (ret) { - gf_msg_debug ("glusterfsd-mgmt", 0, "xlators children " - "not equal"); - goto out; - } - - trav1 = trav1->next; - trav2 = trav2->next; - } + if (xl1 == NULL || xl2 == NULL) { + gf_msg_debug("xlator", 0, "invalid argument"); + return -1; + } - if (trav1 || trav2) { - ret = -1; - goto out; - } + trav1 = xl1->children; + trav2 = xl2->children; - if (strcmp (xl1->name, xl2->name)) { - ret = -1; - goto out; + while (trav1 && trav2) { + ret = xlator_equal_rec(trav1->xlator, trav2->xlator); + if (ret) { + gf_msg_debug("glusterfsd-mgmt", 0, + "xlators children " + "not equal"); + goto out; } - /* type could have changed even if xlator names match, - e.g cluster/distribute and cluster/nufa share the same - xlator name - */ - if (strcmp (xl1->type, xl2->type)) { - ret = -1; - goto out; - } -out : - return ret; + trav1 = trav1->next; + trav2 = trav2->next; + } + + if (trav1 || trav2) { + ret = -1; + goto out; + } + + if (strcmp(xl1->name, xl2->name)) { + ret = -1; + goto out; + } + + /* type could have changed even if xlator names match, + e.g cluster/distribute and cluster/nufa share the same + xlator name + */ + if (strcmp(xl1->type, xl2->type)) { + ret = -1; + goto out; + } +out: + return ret; } - gf_boolean_t -is_graph_topology_equal (glusterfs_graph_t *graph1, glusterfs_graph_t *graph2) +is_graph_topology_equal(glusterfs_graph_t *graph1, glusterfs_graph_t *graph2) { - xlator_t *trav1 = NULL; - xlator_t *trav2 = NULL; - gf_boolean_t ret = _gf_true; - xlator_list_t *ltrav; - - trav1 = graph1->first; - trav2 = graph2->first; - - if (strcmp (trav2->type, "protocol/server") == 0) { - trav2 = trav2->children->xlator; - for (ltrav = trav1->children; ltrav; ltrav = ltrav->next) { - trav1 = ltrav->xlator; - if (!trav1->cleanup_starting && !strcmp (trav1->name, trav2->name)) { - break; - } - } - if (!ltrav) { - return _gf_false; - } + xlator_t *trav1 = NULL; + xlator_t *trav2 = NULL; + gf_boolean_t ret = _gf_true; + xlator_list_t *ltrav; + + trav1 = graph1->first; + trav2 = graph2->first; + + if (strcmp(trav2->type, "protocol/server") == 0) { + trav2 = trav2->children->xlator; + for (ltrav = trav1->children; ltrav; ltrav = ltrav->next) { + trav1 = ltrav->xlator; + if (!trav1->cleanup_starting && !strcmp(trav1->name, trav2->name)) { + break; + } + } + if (!ltrav) { + return _gf_false; } + } - ret = xlator_equal_rec (trav1, trav2); + ret = xlator_equal_rec(trav1, trav2); - if (ret) { - gf_msg_debug ("glusterfsd-mgmt", 0, "graphs are not equal"); - ret = _gf_false; - goto out; - } + if (ret) { + gf_msg_debug("glusterfsd-mgmt", 0, "graphs are not equal"); + ret = _gf_false; + goto out; + } - ret = _gf_true; - gf_msg_debug ("glusterfsd-mgmt", 0, "graphs are equal"); + ret = _gf_true; + gf_msg_debug("glusterfsd-mgmt", 0, "graphs are equal"); out: - return ret; + return ret; } - /* Function has 3types of return value 0, -ve , 1 * return 0 =======> reconfiguration of options has succeeded - * return 1 =======> the graph has to be reconstructed and all the xlators should be inited - * return -1(or -ve) =======> Some Internal Error occurred during the operation + * return 1 =======> the graph has to be reconstructed and all the + * xlators should be inited return -1(or -ve) =======> Some Internal Error + * occurred during the operation */ int -glusterfs_volfile_reconfigure (FILE *newvolfile_fp, glusterfs_ctx_t *ctx) +glusterfs_volfile_reconfigure(FILE *newvolfile_fp, glusterfs_ctx_t *ctx) { - glusterfs_graph_t *oldvolfile_graph = NULL; - glusterfs_graph_t *newvolfile_graph = NULL; - - int ret = -1; - - if (!ctx) { - gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL, - "ctx is NULL"); - goto out; - } - - oldvolfile_graph = ctx->active; - if (!oldvolfile_graph) { - ret = 1; - goto out; - } - - newvolfile_graph = glusterfs_graph_construct (newvolfile_fp); - - if (!newvolfile_graph) { - goto out; - } - - glusterfs_graph_prepare (newvolfile_graph, ctx, - ctx->cmd_args.volume_name); - - if (!is_graph_topology_equal (oldvolfile_graph, - newvolfile_graph)) { - - ret = 1; - gf_msg_debug ("glusterfsd-mgmt", 0, "Graph topology not " - "equal(should call INIT)"); - goto out; - } - - gf_msg_debug ("glusterfsd-mgmt", 0, "Only options have changed in the" - " new graph"); - - ret = glusterfs_graph_reconfigure (oldvolfile_graph, - newvolfile_graph); - if (ret) { - gf_msg_debug ("glusterfsd-mgmt", 0, "Could not reconfigure " - "new options in old graph"); - goto out; - } - - ret = 0; + glusterfs_graph_t *oldvolfile_graph = NULL; + glusterfs_graph_t *newvolfile_graph = NULL; + + int ret = -1; + + if (!ctx) { + gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL, + "ctx is NULL"); + goto out; + } + + oldvolfile_graph = ctx->active; + if (!oldvolfile_graph) { + ret = 1; + goto out; + } + + newvolfile_graph = glusterfs_graph_construct(newvolfile_fp); + + if (!newvolfile_graph) { + goto out; + } + + glusterfs_graph_prepare(newvolfile_graph, ctx, ctx->cmd_args.volume_name); + + if (!is_graph_topology_equal(oldvolfile_graph, newvolfile_graph)) { + ret = 1; + gf_msg_debug("glusterfsd-mgmt", 0, + "Graph topology not " + "equal(should call INIT)"); + goto out; + } + + gf_msg_debug("glusterfsd-mgmt", 0, + "Only options have changed in the" + " new graph"); + + ret = glusterfs_graph_reconfigure(oldvolfile_graph, newvolfile_graph); + if (ret) { + gf_msg_debug("glusterfsd-mgmt", 0, + "Could not reconfigure " + "new options in old graph"); + goto out; + } + + ret = 0; out: - if (newvolfile_graph) - glusterfs_graph_destroy (newvolfile_graph); + if (newvolfile_graph) + glusterfs_graph_destroy(newvolfile_graph); - return ret; + return ret; } /* This function need to remove. This added to support gfapi volfile @@ -934,183 +918,183 @@ out: */ int -gf_volfile_reconfigure (int oldvollen, FILE *newvolfile_fp, - glusterfs_ctx_t *ctx, const char *oldvolfile) +gf_volfile_reconfigure(int oldvollen, FILE *newvolfile_fp, glusterfs_ctx_t *ctx, + const char *oldvolfile) { - glusterfs_graph_t *oldvolfile_graph = NULL; - glusterfs_graph_t *newvolfile_graph = NULL; - FILE *oldvolfile_fp = NULL; - /*Since the function mkstemp() replaces XXXXXX, - * assigning it to a variable - */ - char temp_file[] = "/tmp/temp_vol_file_XXXXXX"; - gf_boolean_t active_graph_found = _gf_true; - - int ret = -1; - int u_ret = -1; - int file_desc = -1; - - if (!oldvollen) { - ret = 1; // Has to call INIT for the whole graph - goto out; - } - - if (!ctx) { - gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL, - "ctx is NULL"); - goto out; - } - - oldvolfile_graph = ctx->active; - if (!oldvolfile_graph) { - active_graph_found = _gf_false; - gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, 0, - LG_MSG_ACTIVE_GRAPH_NULL, - "glusterfs_ctx->active is NULL"); + glusterfs_graph_t *oldvolfile_graph = NULL; + glusterfs_graph_t *newvolfile_graph = NULL; + FILE *oldvolfile_fp = NULL; + /*Since the function mkstemp() replaces XXXXXX, + * assigning it to a variable + */ + char temp_file[] = "/tmp/temp_vol_file_XXXXXX"; + gf_boolean_t active_graph_found = _gf_true; + + int ret = -1; + int u_ret = -1; + int file_desc = -1; + + if (!oldvollen) { + ret = 1; // Has to call INIT for the whole graph + goto out; + } + + if (!ctx) { + gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_CTX_NULL, + "ctx is NULL"); + goto out; + } + + oldvolfile_graph = ctx->active; + if (!oldvolfile_graph) { + active_graph_found = _gf_false; + gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, 0, LG_MSG_ACTIVE_GRAPH_NULL, + "glusterfs_ctx->active is NULL"); /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ - file_desc = mkstemp(temp_file); - if (file_desc < 0) { - gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, errno, - LG_MSG_TMPFILE_CREATE_FAILED, "Unable to " - "create temporary volfile"); - goto out; - } - - /*Calling unlink so that when the file is closed or program - *terminates the tempfile is deleted. - */ - u_ret = sys_unlink(temp_file); - - if (u_ret < 0) { - gf_msg ("glusterfsd-mgmt", GF_LOG_ERROR, errno, - LG_MSG_TMPFILE_DELETE_FAILED, "Temporary file" - " delete failed."); - sys_close (file_desc); - goto out; - } - - - oldvolfile_fp = fdopen (file_desc, "w+b"); - if (!oldvolfile_fp) - goto out; - - fwrite (oldvolfile, oldvollen, 1, oldvolfile_fp); - fflush (oldvolfile_fp); - if (ferror (oldvolfile_fp)) { - goto out; - } - - oldvolfile_graph = glusterfs_graph_construct (oldvolfile_fp); - if (!oldvolfile_graph) - goto out; - } - - newvolfile_graph = glusterfs_graph_construct (newvolfile_fp); - if (!newvolfile_graph) { - goto out; + file_desc = mkstemp(temp_file); + if (file_desc < 0) { + gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, errno, + LG_MSG_TMPFILE_CREATE_FAILED, + "Unable to " + "create temporary volfile"); + goto out; } - glusterfs_graph_prepare (newvolfile_graph, ctx, - ctx->cmd_args.volume_name); - - if (!is_graph_topology_equal (oldvolfile_graph, - newvolfile_graph)) { - - ret = 1; - gf_msg_debug ("glusterfsd-mgmt", 0, "Graph topology not " - "equal(should call INIT)"); - goto out; + /*Calling unlink so that when the file is closed or program + *terminates the tempfile is deleted. + */ + u_ret = sys_unlink(temp_file); + + if (u_ret < 0) { + gf_msg("glusterfsd-mgmt", GF_LOG_ERROR, errno, + LG_MSG_TMPFILE_DELETE_FAILED, + "Temporary file" + " delete failed."); + sys_close(file_desc); + goto out; } - gf_msg_debug ("glusterfsd-mgmt", 0, "Only options have changed in the" - " new graph"); + oldvolfile_fp = fdopen(file_desc, "w+b"); + if (!oldvolfile_fp) + goto out; - /* */ - ret = glusterfs_graph_reconfigure (oldvolfile_graph, - newvolfile_graph); - if (ret) { - gf_msg_debug ("glusterfsd-mgmt", 0, "Could not reconfigure " - "new options in old graph"); - goto out; + fwrite(oldvolfile, oldvollen, 1, oldvolfile_fp); + fflush(oldvolfile_fp); + if (ferror(oldvolfile_fp)) { + goto out; } - ret = 0; + oldvolfile_graph = glusterfs_graph_construct(oldvolfile_fp); + if (!oldvolfile_graph) + goto out; + } + + newvolfile_graph = glusterfs_graph_construct(newvolfile_fp); + if (!newvolfile_graph) { + goto out; + } + + glusterfs_graph_prepare(newvolfile_graph, ctx, ctx->cmd_args.volume_name); + + if (!is_graph_topology_equal(oldvolfile_graph, newvolfile_graph)) { + ret = 1; + gf_msg_debug("glusterfsd-mgmt", 0, + "Graph topology not " + "equal(should call INIT)"); + goto out; + } + + gf_msg_debug("glusterfsd-mgmt", 0, + "Only options have changed in the" + " new graph"); + + /* */ + ret = glusterfs_graph_reconfigure(oldvolfile_graph, newvolfile_graph); + if (ret) { + gf_msg_debug("glusterfsd-mgmt", 0, + "Could not reconfigure " + "new options in old graph"); + goto out; + } + + ret = 0; out: - if (oldvolfile_fp) - fclose (oldvolfile_fp); - - /* Do not simply destroy the old graph here. If the oldgraph - is constructed here in this function itself instead of getting - it from ctx->active (which happens only of ctx->active is NULL), - then destroy the old graph. If some i/o is still happening in - the old graph and the old graph is obtained from ctx->active, - then destroying the graph will cause problems. - */ - if (!active_graph_found && oldvolfile_graph) - glusterfs_graph_destroy (oldvolfile_graph); - if (newvolfile_graph) - glusterfs_graph_destroy (newvolfile_graph); - - return ret; + if (oldvolfile_fp) + fclose(oldvolfile_fp); + + /* Do not simply destroy the old graph here. If the oldgraph + is constructed here in this function itself instead of getting + it from ctx->active (which happens only of ctx->active is NULL), + then destroy the old graph. If some i/o is still happening in + the old graph and the old graph is obtained from ctx->active, + then destroying the graph will cause problems. + */ + if (!active_graph_found && oldvolfile_graph) + glusterfs_graph_destroy(oldvolfile_graph); + if (newvolfile_graph) + glusterfs_graph_destroy(newvolfile_graph); + + return ret; } int -glusterfs_graph_reconfigure (glusterfs_graph_t *oldgraph, - glusterfs_graph_t *newgraph) +glusterfs_graph_reconfigure(glusterfs_graph_t *oldgraph, + glusterfs_graph_t *newgraph) { - xlator_t *old_xl = NULL; - xlator_t *new_xl = NULL; - xlator_list_t *trav; - - GF_ASSERT (oldgraph); - GF_ASSERT (newgraph); - - old_xl = oldgraph->first; - while (old_xl->is_autoloaded) { - old_xl = old_xl->children->xlator; - } - - new_xl = newgraph->first; - while (new_xl->is_autoloaded) { - new_xl = new_xl->children->xlator; - } - - if (strcmp (old_xl->type, "protocol/server") != 0) { - return xlator_tree_reconfigure (old_xl, new_xl); - } - - /* Some options still need to be handled by the server translator. */ - if (old_xl->reconfigure) { - old_xl->reconfigure (old_xl, new_xl->options); - } - - (void) copy_opts_to_child (new_xl, FIRST_CHILD (new_xl), "*auth*"); - new_xl = FIRST_CHILD (new_xl); - - for (trav = old_xl->children; trav; trav = trav->next) { - if (!trav->xlator->cleanup_starting && !strcmp (trav->xlator->name, new_xl->name)) { - return xlator_tree_reconfigure (trav->xlator, new_xl); - } + xlator_t *old_xl = NULL; + xlator_t *new_xl = NULL; + xlator_list_t *trav; + + GF_ASSERT(oldgraph); + GF_ASSERT(newgraph); + + old_xl = oldgraph->first; + while (old_xl->is_autoloaded) { + old_xl = old_xl->children->xlator; + } + + new_xl = newgraph->first; + while (new_xl->is_autoloaded) { + new_xl = new_xl->children->xlator; + } + + if (strcmp(old_xl->type, "protocol/server") != 0) { + return xlator_tree_reconfigure(old_xl, new_xl); + } + + /* Some options still need to be handled by the server translator. */ + if (old_xl->reconfigure) { + old_xl->reconfigure(old_xl, new_xl->options); + } + + (void)copy_opts_to_child(new_xl, FIRST_CHILD(new_xl), "*auth*"); + new_xl = FIRST_CHILD(new_xl); + + for (trav = old_xl->children; trav; trav = trav->next) { + if (!trav->xlator->cleanup_starting && + !strcmp(trav->xlator->name, new_xl->name)) { + return xlator_tree_reconfigure(trav->xlator, new_xl); } + } - return -1; + return -1; } int -glusterfs_graph_destroy_residual (glusterfs_graph_t *graph) +glusterfs_graph_destroy_residual(glusterfs_graph_t *graph) { - int ret = -1; + int ret = -1; - if (graph == NULL) - return ret; + if (graph == NULL) + return ret; - ret = xlator_tree_free_memacct (graph->first); + ret = xlator_tree_free_memacct(graph->first); - list_del_init (&graph->list); - GF_FREE (graph); + list_del_init(&graph->list); + GF_FREE(graph); - return ret; + return ret; } /* This function destroys all the xlator members except for the @@ -1136,137 +1120,139 @@ glusterfs_graph_destroy_residual (glusterfs_graph_t *graph) * object itself. */ int -glusterfs_graph_destroy (glusterfs_graph_t *graph) +glusterfs_graph_destroy(glusterfs_graph_t *graph) { - int ret = 0; + int ret = 0; - GF_VALIDATE_OR_GOTO ("graph", graph, out); + GF_VALIDATE_OR_GOTO("graph", graph, out); - ret = xlator_tree_free_members (graph->first); + ret = xlator_tree_free_members(graph->first); - ret = glusterfs_graph_destroy_residual (graph); + ret = glusterfs_graph_destroy_residual(graph); out: - return ret; + return ret; } - int -glusterfs_graph_attach (glusterfs_graph_t *orig_graph, char *path, - glusterfs_graph_t **newgraph) +glusterfs_graph_attach(glusterfs_graph_t *orig_graph, char *path, + glusterfs_graph_t **newgraph) { - xlator_t *this = THIS; - FILE *fp; - glusterfs_graph_t *graph; - xlator_t *xl; - char *volfile_id = NULL; - char *volfile_content = NULL; - struct stat stbuf = {0,}; - size_t file_len = -1; - gf_volfile_t *volfile_obj = NULL; - int ret = -1; - char sha256_hash[SHA256_DIGEST_LENGTH] = {0, }; - - if (!orig_graph) { - return -EINVAL; - } - - ret = sys_stat (path, &stbuf); - if (ret < 0) { - gf_log (THIS->name, GF_LOG_ERROR, "Unable to stat %s (%s)", - path, strerror (errno)); - return -EINVAL; - } - - file_len = stbuf.st_size; - volfile_content = GF_MALLOC (file_len+1, gf_common_mt_char); - if (!volfile_content) - return -ENOMEM; - - fp = fopen (path, "r"); - if (!fp) { - gf_log (THIS->name, GF_LOG_WARNING, - "oops, %s disappeared on us", path); - GF_FREE (volfile_content); - return -EIO; - } - - ret = fread (volfile_content, sizeof (char), file_len, fp); - if (ret == file_len) { - glusterfs_compute_sha256 ((const unsigned char *) volfile_content, - file_len, sha256_hash); - } else { - gf_log (THIS->name, GF_LOG_ERROR, - "read failed on path %s. File size=%"GF_PRI_SIZET - "read size=%d", path, file_len, ret); - GF_FREE (volfile_content); - fclose (fp); - return -EIO; - } - - GF_FREE (volfile_content); - - graph = glusterfs_graph_construct (fp); + xlator_t *this = THIS; + FILE *fp; + glusterfs_graph_t *graph; + xlator_t *xl; + char *volfile_id = NULL; + char *volfile_content = NULL; + struct stat stbuf = { + 0, + }; + size_t file_len = -1; + gf_volfile_t *volfile_obj = NULL; + int ret = -1; + char sha256_hash[SHA256_DIGEST_LENGTH] = { + 0, + }; + + if (!orig_graph) { + return -EINVAL; + } + + ret = sys_stat(path, &stbuf); + if (ret < 0) { + gf_log(THIS->name, GF_LOG_ERROR, "Unable to stat %s (%s)", path, + strerror(errno)); + return -EINVAL; + } + + file_len = stbuf.st_size; + volfile_content = GF_MALLOC(file_len + 1, gf_common_mt_char); + if (!volfile_content) + return -ENOMEM; + + fp = fopen(path, "r"); + if (!fp) { + gf_log(THIS->name, GF_LOG_WARNING, "oops, %s disappeared on us", path); + GF_FREE(volfile_content); + return -EIO; + } + + ret = fread(volfile_content, sizeof(char), file_len, fp); + if (ret == file_len) { + glusterfs_compute_sha256((const unsigned char *)volfile_content, + file_len, sha256_hash); + } else { + gf_log(THIS->name, GF_LOG_ERROR, + "read failed on path %s. File size=%" GF_PRI_SIZET + "read size=%d", + path, file_len, ret); + GF_FREE(volfile_content); fclose(fp); - if (!graph) { - gf_log (this->name, GF_LOG_WARNING, - "could not create graph from %s", path); - return -EIO; - } - - /* - * If there's a server translator on top, we want whatever's below - * that. - */ - xl = graph->first; - if (strcmp(xl->type, "protocol/server") == 0) { - (void) copy_opts_to_child (xl, FIRST_CHILD (xl), "*auth*"); - xl = FIRST_CHILD(xl); - } - graph->first = xl; - *newgraph = graph; - - volfile_id = strstr (path, "/snaps/"); - if (!volfile_id) { - volfile_id = rindex (path, '/'); - if (volfile_id) { - ++volfile_id; - } - } + return -EIO; + } + + GF_FREE(volfile_content); + + graph = glusterfs_graph_construct(fp); + fclose(fp); + if (!graph) { + gf_log(this->name, GF_LOG_WARNING, "could not create graph from %s", + path); + return -EIO; + } + + /* + * If there's a server translator on top, we want whatever's below + * that. + */ + xl = graph->first; + if (strcmp(xl->type, "protocol/server") == 0) { + (void)copy_opts_to_child(xl, FIRST_CHILD(xl), "*auth*"); + xl = FIRST_CHILD(xl); + } + graph->first = xl; + *newgraph = graph; + + volfile_id = strstr(path, "/snaps/"); + if (!volfile_id) { + volfile_id = rindex(path, '/'); if (volfile_id) { - xl->volfile_id = gf_strdup (volfile_id); - /* There's a stray ".vol" at the end. */ - xl->volfile_id[strlen(xl->volfile_id)-4] = '\0'; - } - - /* TODO memory leaks everywhere need to free graph in case of error */ - if (glusterfs_graph_prepare (graph, this->ctx, xl->name)) { - gf_log (this->name, GF_LOG_WARNING, - "failed to prepare graph for xlator %s", xl->name); - return -EIO; - } else if (glusterfs_graph_init (graph)) { - gf_log (this->name, GF_LOG_WARNING, - "failed to initialize graph for xlator %s", xl->name); - return -EIO; - } else if (glusterfs_xlator_link (orig_graph->top, graph->top)) { - gf_log (this->name, GF_LOG_WARNING, - "failed to link the graphs for xlator %s ", xl->name); - return -EIO; + ++volfile_id; } - + } + if (volfile_id) { + xl->volfile_id = gf_strdup(volfile_id); + /* There's a stray ".vol" at the end. */ + xl->volfile_id[strlen(xl->volfile_id) - 4] = '\0'; + } + + /* TODO memory leaks everywhere need to free graph in case of error */ + if (glusterfs_graph_prepare(graph, this->ctx, xl->name)) { + gf_log(this->name, GF_LOG_WARNING, + "failed to prepare graph for xlator %s", xl->name); + return -EIO; + } else if (glusterfs_graph_init(graph)) { + gf_log(this->name, GF_LOG_WARNING, + "failed to initialize graph for xlator %s", xl->name); + return -EIO; + } else if (glusterfs_xlator_link(orig_graph->top, graph->top)) { + gf_log(this->name, GF_LOG_WARNING, + "failed to link the graphs for xlator %s ", xl->name); + return -EIO; + } + + if (!volfile_obj) { + volfile_obj = GF_CALLOC(1, sizeof(gf_volfile_t), gf_common_volfile_t); if (!volfile_obj) { - volfile_obj = GF_CALLOC (1, sizeof (gf_volfile_t), - gf_common_volfile_t); - if (!volfile_obj) { - return -EIO; - } + return -EIO; } + } - INIT_LIST_HEAD (&volfile_obj->volfile_list); - snprintf (volfile_obj->vol_id, sizeof (volfile_obj->vol_id), - "%s", xl->volfile_id); - memcpy (volfile_obj->volfile_checksum, sha256_hash, - sizeof (volfile_obj->volfile_checksum)); - list_add (&volfile_obj->volfile_list, &this->ctx->volfile_list); + INIT_LIST_HEAD(&volfile_obj->volfile_list); + snprintf(volfile_obj->vol_id, sizeof(volfile_obj->vol_id), "%s", + xl->volfile_id); + memcpy(volfile_obj->volfile_checksum, sha256_hash, + sizeof(volfile_obj->volfile_checksum)); + list_add(&volfile_obj->volfile_list, &this->ctx->volfile_list); - return 0; + return 0; } diff --git a/libglusterfs/src/hashfn.c b/libglusterfs/src/hashfn.c index 62f7ab87800..5c4561f1ee8 100644 --- a/libglusterfs/src/hashfn.c +++ b/libglusterfs/src/hashfn.c @@ -13,21 +13,20 @@ #include "hashfn.h" -#define get16bits(d) (*((const uint16_t *) (d))) +#define get16bits(d) (*((const uint16_t *)(d))) #define DM_DELTA 0x9E3779B9 -#define DM_FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */ -#define DM_PARTROUNDS 6 /* 6 gets complete mixing */ - +#define DM_FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */ +#define DM_PARTROUNDS 6 /* 6 gets complete mixing */ uint32_t -ReallySimpleHash (char *path, int len) +ReallySimpleHash(char *path, int len) { - uint32_t hash = 0; - for (;len > 0; len--) - hash ^= (char)path[len]; + uint32_t hash = 0; + for (; len > 0; len--) + hash ^= (char)path[len]; - return hash; + return hash; } /* @@ -37,146 +36,145 @@ ReallySimpleHash (char *path, int len) /* In any case make sure, you return 1 */ -uint32_t SuperFastHash (const char * data, int32_t len) { - uint32_t hash = len, tmp; - int32_t rem; - - if (len <= 1 || data == NULL) return 1; - - rem = len & 3; - len >>= 2; - - /* Main loop */ - for (;len > 0; len--) { - hash += get16bits (data); - tmp = (get16bits (data+2) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2*sizeof (uint16_t); - hash += hash >> 11; - } - - /* Handle end cases */ - switch (rem) { - case 3: hash += get16bits (data); - hash ^= hash << 16; - hash ^= data[sizeof (uint16_t)] << 18; - hash += hash >> 11; - break; - case 2: hash += get16bits (data); - hash ^= hash << 11; - hash += hash >> 17; - break; - case 1: hash += *data; - hash ^= hash << 10; - hash += hash >> 1; - } - - /* Force "avalanching" of final 127 bits */ - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 4; - hash += hash >> 17; - hash ^= hash << 25; - hash += hash >> 6; - - return hash; +uint32_t +SuperFastHash(const char *data, int32_t len) +{ + uint32_t hash = len, tmp; + int32_t rem; + + if (len <= 1 || data == NULL) + return 1; + + rem = len & 3; + len >>= 2; + + /* Main loop */ + for (; len > 0; len--) { + hash += get16bits(data); + tmp = (get16bits(data + 2) << 11) ^ hash; + hash = (hash << 16) ^ tmp; + data += 2 * sizeof(uint16_t); + hash += hash >> 11; + } + + /* Handle end cases */ + switch (rem) { + case 3: + hash += get16bits(data); + hash ^= hash << 16; + hash ^= data[sizeof(uint16_t)] << 18; + hash += hash >> 11; + break; + case 2: + hash += get16bits(data); + hash ^= hash << 11; + hash += hash >> 17; + break; + case 1: + hash += *data; + hash ^= hash << 10; + hash += hash >> 1; + } + + /* Force "avalanching" of final 127 bits */ + hash ^= hash << 3; + hash += hash >> 5; + hash ^= hash << 4; + hash += hash >> 17; + hash ^= hash << 25; + hash += hash >> 6; + + return hash; } - /* Davies-Meyer hashing function implementation */ static int -dm_round (int rounds, uint32_t *array, uint32_t *h0, uint32_t *h1) +dm_round(int rounds, uint32_t *array, uint32_t *h0, uint32_t *h1) { - uint32_t sum = 0; - int n = 0; - uint32_t b0 = 0; - uint32_t b1 = 0; - - b0 = *h0; - b1 = *h1; - - n = rounds; - - do { - sum += DM_DELTA; - b0 += ((b1 << 4) + array[0]) - ^ (b1 + sum) - ^ ((b1 >> 5) + array[1]); - b1 += ((b0 << 4) + array[2]) - ^ (b0 + sum) - ^ ((b0 >> 5) + array[3]); - } while (--n); - - *h0 += b0; - *h1 += b1; - - return 0; -} + uint32_t sum = 0; + int n = 0; + uint32_t b0 = 0; + uint32_t b1 = 0; + + b0 = *h0; + b1 = *h1; + + n = rounds; + + do { + sum += DM_DELTA; + b0 += ((b1 << 4) + array[0]) ^ (b1 + sum) ^ ((b1 >> 5) + array[1]); + b1 += ((b0 << 4) + array[2]) ^ (b0 + sum) ^ ((b0 >> 5) + array[3]); + } while (--n); + *h0 += b0; + *h1 += b1; + + return 0; +} uint32_t -__pad (int len) +__pad(int len) { - uint32_t pad = 0; + uint32_t pad = 0; - pad = (uint32_t) len | ((uint32_t) len << 8); - pad |= pad << 16; + pad = (uint32_t)len | ((uint32_t)len << 8); + pad |= pad << 16; - return pad; + return pad; } uint32_t -gf_dm_hashfn (const char *msg, int len) +gf_dm_hashfn(const char *msg, int len) { - uint32_t h0 = 0x9464a485; - uint32_t h1 = 0x542e1a94; - uint32_t array[4]; - uint32_t pad = 0; - int i = 0; - int j = 0; - int full_quads = 0; - int full_words = 0; - int full_bytes = 0; - uint32_t *intmsg = NULL; - int word = 0; - - - intmsg = (uint32_t *) msg; - pad = __pad (len); - - full_bytes = len; - full_words = len / 4; - full_quads = len / 16; - - for (i = 0; i < full_quads; i++) { - for (j = 0; j < 4; j++) { - word = *intmsg; - array[j] = word; - intmsg++; - full_words--; - full_bytes -= 4; - } - dm_round (DM_PARTROUNDS, &array[0], &h0, &h1); - } - + uint32_t h0 = 0x9464a485; + uint32_t h1 = 0x542e1a94; + uint32_t array[4]; + uint32_t pad = 0; + int i = 0; + int j = 0; + int full_quads = 0; + int full_words = 0; + int full_bytes = 0; + uint32_t *intmsg = NULL; + int word = 0; + + intmsg = (uint32_t *)msg; + pad = __pad(len); + + full_bytes = len; + full_words = len / 4; + full_quads = len / 16; + + for (i = 0; i < full_quads; i++) { for (j = 0; j < 4; j++) { - if (full_words) { - word = *intmsg; - array[j] = word; - intmsg++; - full_words--; - full_bytes -= 4; - } else { - array[j] = pad; - while (full_bytes) { - array[j] <<= 8; - array[j] |= msg[len - full_bytes]; - full_bytes--; - } - } + word = *intmsg; + array[j] = word; + intmsg++; + full_words--; + full_bytes -= 4; + } + dm_round(DM_PARTROUNDS, &array[0], &h0, &h1); + } + + for (j = 0; j < 4; j++) { + if (full_words) { + word = *intmsg; + array[j] = word; + intmsg++; + full_words--; + full_bytes -= 4; + } else { + array[j] = pad; + while (full_bytes) { + array[j] <<= 8; + array[j] |= msg[len - full_bytes]; + full_bytes--; + } } - dm_round (DM_FULLROUNDS, &array[0], &h0, &h1); + } + dm_round(DM_FULLROUNDS, &array[0], &h0, &h1); - return h0 ^ h1; + return h0 ^ h1; } diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index 70909bf596f..ee85c0e793c 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -23,676 +23,651 @@ move latest accessed dentry to list_head of inode */ -#define INODE_DUMP_LIST(head, key_buf, key_prefix, list_type) \ - { \ - int i = 1; \ - inode_t *inode = NULL; \ - list_for_each_entry (inode, head, list) { \ - gf_proc_dump_build_key(key_buf, key_prefix, \ - "%s.%d",list_type, i++); \ - gf_proc_dump_add_section(key_buf); \ - inode_dump(inode, key); \ - } \ - } +#define INODE_DUMP_LIST(head, key_buf, key_prefix, list_type) \ + { \ + int i = 1; \ + inode_t *inode = NULL; \ + list_for_each_entry(inode, head, list) \ + { \ + gf_proc_dump_build_key(key_buf, key_prefix, "%s.%d", list_type, \ + i++); \ + gf_proc_dump_add_section(key_buf); \ + inode_dump(inode, key); \ + } \ + } static inode_t * -__inode_unref (inode_t *inode); +__inode_unref(inode_t *inode); static int -inode_table_prune (inode_table_t *table); +inode_table_prune(inode_table_t *table); void -fd_dump (struct list_head *head, char *prefix); +fd_dump(struct list_head *head, char *prefix); static int -hash_dentry (inode_t *parent, const char *name, int mod) +hash_dentry(inode_t *parent, const char *name, int mod) { - int hash = 0; - int ret = 0; + int hash = 0; + int ret = 0; - hash = *name; - if (hash) { - for (name += 1; *name != '\0'; name++) { - hash = (hash << 5) - hash + *name; - } + hash = *name; + if (hash) { + for (name += 1; *name != '\0'; name++) { + hash = (hash << 5) - hash + *name; } - ret = (hash + (unsigned long)parent) % mod; + } + ret = (hash + (unsigned long)parent) % mod; - return ret; + return ret; } - static int -hash_gfid (uuid_t uuid, int mod) +hash_gfid(uuid_t uuid, int mod) { - int ret = 0; + int ret = 0; - ret = uuid[15] + (uuid[14] << 8); + ret = uuid[15] + (uuid[14] << 8); - return ret; + return ret; } - static void -__dentry_hash (dentry_t *dentry) +__dentry_hash(dentry_t *dentry) { - inode_table_t *table = NULL; - int hash = 0; + inode_table_t *table = NULL; + int hash = 0; - if (!dentry) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_DENTRY_NOT_FOUND, "dentry not found"); - return; - } + if (!dentry) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, + "dentry not found"); + return; + } - table = dentry->inode->table; - hash = hash_dentry (dentry->parent, dentry->name, - table->hashsize); + table = dentry->inode->table; + hash = hash_dentry(dentry->parent, dentry->name, table->hashsize); - list_del_init (&dentry->hash); - list_add (&dentry->hash, &table->name_hash[hash]); + list_del_init(&dentry->hash); + list_add(&dentry->hash, &table->name_hash[hash]); } - static int -__is_dentry_hashed (dentry_t *dentry) +__is_dentry_hashed(dentry_t *dentry) { - if (!dentry) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_DENTRY_NOT_FOUND, "dentry not found"); - return 0; - } + if (!dentry) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, + "dentry not found"); + return 0; + } - return !list_empty (&dentry->hash); + return !list_empty(&dentry->hash); } - static void -__dentry_unhash (dentry_t *dentry) +__dentry_unhash(dentry_t *dentry) { - if (!dentry) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_DENTRY_NOT_FOUND, "dentry not found"); - return; - } + if (!dentry) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, + "dentry not found"); + return; + } - list_del_init (&dentry->hash); + list_del_init(&dentry->hash); } - static void -__dentry_unset (dentry_t *dentry) +__dentry_unset(dentry_t *dentry) { - if (!dentry) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_DENTRY_NOT_FOUND, "dentry not found"); - return; - } + if (!dentry) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, + "dentry not found"); + return; + } - __dentry_unhash (dentry); + __dentry_unhash(dentry); - list_del_init (&dentry->inode_list); + list_del_init(&dentry->inode_list); - GF_FREE (dentry->name); - dentry->name = NULL; + GF_FREE(dentry->name); + dentry->name = NULL; - if (dentry->parent) { - __inode_unref (dentry->parent); - dentry->parent = NULL; - } + if (dentry->parent) { + __inode_unref(dentry->parent); + dentry->parent = NULL; + } - mem_put (dentry); + mem_put(dentry); } - static int -__foreach_ancestor_dentry (dentry_t *dentry, - int (per_dentry_fn) (dentry_t *dentry, - void *data), - void *data) -{ - inode_t *parent = NULL; - dentry_t *each = NULL; - int ret = 0; - - if (!dentry) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_DENTRY_NOT_FOUND, "dentry not found"); - return 0; - } - - ret = per_dentry_fn (dentry, data); - if (ret) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_PER_DENTRY_FAILED, "per dentry fn returned %d", - ret); - goto out; - } - - parent = dentry->parent; - if (!parent) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_PARENT_DENTRY_NOT_FOUND, - "parent not found"); - goto out; - } +__foreach_ancestor_dentry(dentry_t *dentry, + int(per_dentry_fn)(dentry_t *dentry, void *data), + void *data) +{ + inode_t *parent = NULL; + dentry_t *each = NULL; + int ret = 0; - list_for_each_entry (each, &parent->dentry_list, inode_list) { - ret = __foreach_ancestor_dentry (each, per_dentry_fn, data); - if (ret) - goto out; - } + if (!dentry) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, + "dentry not found"); + return 0; + } + + ret = per_dentry_fn(dentry, data); + if (ret) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_PER_DENTRY_FAILED, + "per dentry fn returned %d", ret); + goto out; + } + + parent = dentry->parent; + if (!parent) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_PARENT_DENTRY_NOT_FOUND, + "parent not found"); + goto out; + } + + list_for_each_entry(each, &parent->dentry_list, inode_list) + { + ret = __foreach_ancestor_dentry(each, per_dentry_fn, data); + if (ret) + goto out; + } out: - return ret; + return ret; } - static int -__check_cycle (dentry_t *a_dentry, void *data) +__check_cycle(dentry_t *a_dentry, void *data) { - inode_t *link_inode = NULL; + inode_t *link_inode = NULL; - link_inode = data; + link_inode = data; - if (a_dentry->parent == link_inode) - return 1; + if (a_dentry->parent == link_inode) + return 1; - return 0; + return 0; } - static int -__is_dentry_cyclic (dentry_t *dentry) +__is_dentry_cyclic(dentry_t *dentry) { - int ret = 0; - inode_t *inode = NULL; - char *name = "<nul>"; + int ret = 0; + inode_t *inode = NULL; + char *name = "<nul>"; - ret = __foreach_ancestor_dentry (dentry, __check_cycle, - dentry->inode); - if (ret) { - inode = dentry->inode; + ret = __foreach_ancestor_dentry(dentry, __check_cycle, dentry->inode); + if (ret) { + inode = dentry->inode; - if (dentry->name) - name = dentry->name; + if (dentry->name) + name = dentry->name; - gf_msg (dentry->inode->table->name, GF_LOG_CRITICAL, 0, - LG_MSG_DENTRY_CYCLIC_LOOP, "detected cyclic loop " - "formation during inode linkage. inode (%s) linking " - "under itself as %s", uuid_utoa (inode->gfid), name); - } + gf_msg(dentry->inode->table->name, GF_LOG_CRITICAL, 0, + LG_MSG_DENTRY_CYCLIC_LOOP, + "detected cyclic loop " + "formation during inode linkage. inode (%s) linking " + "under itself as %s", + uuid_utoa(inode->gfid), name); + } - return ret; + return ret; } - static void -__inode_unhash (inode_t *inode) +__inode_unhash(inode_t *inode) { - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - list_del_init (&inode->hash); + list_del_init(&inode->hash); } - static int -__is_inode_hashed (inode_t *inode) +__is_inode_hashed(inode_t *inode) { - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return 0; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return 0; + } - return !list_empty (&inode->hash); + return !list_empty(&inode->hash); } - static void -__inode_hash (inode_t *inode) +__inode_hash(inode_t *inode) { - inode_table_t *table = NULL; - int hash = 0; + inode_table_t *table = NULL; + int hash = 0; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - table = inode->table; - hash = hash_gfid (inode->gfid, 65536); + table = inode->table; + hash = hash_gfid(inode->gfid, 65536); - list_del_init (&inode->hash); - list_add (&inode->hash, &table->inode_hash[hash]); + list_del_init(&inode->hash); + list_add(&inode->hash, &table->inode_hash[hash]); } - static dentry_t * -__dentry_search_for_inode (inode_t *inode, uuid_t pargfid, const char *name) +__dentry_search_for_inode(inode_t *inode, uuid_t pargfid, const char *name) { - dentry_t *dentry = NULL; - dentry_t *tmp = NULL; + dentry_t *dentry = NULL; + dentry_t *tmp = NULL; - if (!inode || !name) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "inode || name not found"); - return NULL; - } + if (!inode || !name) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "inode || name not found"); + return NULL; + } - /* earlier, just the ino was sent, which could have been 0, now - we deal with gfid, and if sent gfid is null or 0, no need to - continue with the check */ - if (!pargfid || gf_uuid_is_null (pargfid)) - return NULL; + /* earlier, just the ino was sent, which could have been 0, now + we deal with gfid, and if sent gfid is null or 0, no need to + continue with the check */ + if (!pargfid || gf_uuid_is_null(pargfid)) + return NULL; - list_for_each_entry (tmp, &inode->dentry_list, inode_list) { - if ((gf_uuid_compare (tmp->parent->gfid, pargfid) == 0) && - !strcmp (tmp->name, name)) { - dentry = tmp; - break; - } + list_for_each_entry(tmp, &inode->dentry_list, inode_list) + { + if ((gf_uuid_compare(tmp->parent->gfid, pargfid) == 0) && + !strcmp(tmp->name, name)) { + dentry = tmp; + break; } + } - return dentry; + return dentry; } - static void -__inode_ctx_free (inode_t *inode) +__inode_ctx_free(inode_t *inode) { - int index = 0; - xlator_t *xl = NULL; - xlator_t *old_THIS = NULL; + int index = 0; + xlator_t *xl = NULL; + xlator_t *old_THIS = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - if (!inode->_ctx) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_CTX_NULL, - "_ctx not found"); - goto noctx; - } + if (!inode->_ctx) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_CTX_NULL, + "_ctx not found"); + goto noctx; + } - for (index = 0; index < inode->table->xl->graph->xl_count; index++) { - if (inode->_ctx[index].value1 || inode->_ctx[index].value2) { - xl = (xlator_t *)(long)inode->_ctx[index].xl_key; - old_THIS = THIS; - THIS = xl; - if (!xl->call_cleanup && xl->cbks->forget) - xl->cbks->forget (xl, inode); - THIS = old_THIS; - } + for (index = 0; index < inode->table->xl->graph->xl_count; index++) { + if (inode->_ctx[index].value1 || inode->_ctx[index].value2) { + xl = (xlator_t *)(long)inode->_ctx[index].xl_key; + old_THIS = THIS; + THIS = xl; + if (!xl->call_cleanup && xl->cbks->forget) + xl->cbks->forget(xl, inode); + THIS = old_THIS; } + } - GF_FREE (inode->_ctx); - inode->_ctx = NULL; + GF_FREE(inode->_ctx); + inode->_ctx = NULL; noctx: - return; + return; } static void -__inode_destroy (inode_t *inode) +__inode_destroy(inode_t *inode) { - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - __inode_ctx_free (inode); + __inode_ctx_free(inode); - LOCK_DESTROY (&inode->lock); - // memset (inode, 0xb, sizeof (*inode)); - mem_put (inode); + LOCK_DESTROY(&inode->lock); + // memset (inode, 0xb, sizeof (*inode)); + mem_put(inode); } void -inode_ctx_merge (fd_t *fd, inode_t *inode, inode_t *linked_inode) +inode_ctx_merge(fd_t *fd, inode_t *inode, inode_t *linked_inode) { - int index = 0; - xlator_t *xl = NULL; - xlator_t *old_THIS = NULL; + int index = 0; + xlator_t *xl = NULL; + xlator_t *old_THIS = NULL; - if (!fd || !inode || !linked_inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "invalid inode"); - return; - } + if (!fd || !inode || !linked_inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "invalid inode"); + return; + } - if (!inode->_ctx || !linked_inode->_ctx) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "invalid inode context"); - return; - } + if (!inode->_ctx || !linked_inode->_ctx) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "invalid inode context"); + return; + } - for (; index < inode->table->ctxcount; index++) { - if (inode->_ctx[index].xl_key) { - xl = (xlator_t *)(long) inode->_ctx[index].xl_key; + for (; index < inode->table->ctxcount; index++) { + if (inode->_ctx[index].xl_key) { + xl = (xlator_t *)(long)inode->_ctx[index].xl_key; - old_THIS = THIS; - THIS = xl; - if (xl->cbks->ictxmerge) - xl->cbks->ictxmerge (xl, fd, - inode, linked_inode); - THIS = old_THIS; - } + old_THIS = THIS; + THIS = xl; + if (xl->cbks->ictxmerge) + xl->cbks->ictxmerge(xl, fd, inode, linked_inode); + THIS = old_THIS; } + } } static void -__inode_activate (inode_t *inode) +__inode_activate(inode_t *inode) { - if (!inode) - return; + if (!inode) + return; - list_move (&inode->list, &inode->table->active); - inode->table->active_size++; + list_move(&inode->list, &inode->table->active); + inode->table->active_size++; } - static void -__inode_passivate (inode_t *inode) +__inode_passivate(inode_t *inode) { - dentry_t *dentry = NULL; - dentry_t *t = NULL; + dentry_t *dentry = NULL; + dentry_t *t = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - list_move_tail (&inode->list, &inode->table->lru); - inode->table->lru_size++; + list_move_tail(&inode->list, &inode->table->lru); + inode->table->lru_size++; - list_for_each_entry_safe (dentry, t, &inode->dentry_list, inode_list) { - if (!__is_dentry_hashed (dentry)) - __dentry_unset (dentry); - } + list_for_each_entry_safe(dentry, t, &inode->dentry_list, inode_list) + { + if (!__is_dentry_hashed(dentry)) + __dentry_unset(dentry); + } } - static void -__inode_retire (inode_t *inode) +__inode_retire(inode_t *inode) { - dentry_t *dentry = NULL; - dentry_t *t = NULL; + dentry_t *dentry = NULL; + dentry_t *t = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - list_move_tail (&inode->list, &inode->table->purge); - inode->table->purge_size++; + list_move_tail(&inode->list, &inode->table->purge); + inode->table->purge_size++; - __inode_unhash (inode); + __inode_unhash(inode); - list_for_each_entry_safe (dentry, t, &inode->dentry_list, inode_list) { - __dentry_unset (dentry); - } + list_for_each_entry_safe(dentry, t, &inode->dentry_list, inode_list) + { + __dentry_unset(dentry); + } } - static int -__inode_get_xl_index (inode_t *inode, xlator_t *xlator) +__inode_get_xl_index(inode_t *inode, xlator_t *xlator) { - int set_idx = -1; + int set_idx = -1; - if ((inode->_ctx[xlator->xl_id].xl_key != NULL) && - (inode->_ctx[xlator->xl_id].xl_key != xlator)) - goto out; + if ((inode->_ctx[xlator->xl_id].xl_key != NULL) && + (inode->_ctx[xlator->xl_id].xl_key != xlator)) + goto out; - set_idx = xlator->xl_id; - inode->_ctx[set_idx].xl_key = xlator; + set_idx = xlator->xl_id; + inode->_ctx[set_idx].xl_key = xlator; out: - return set_idx; + return set_idx; } - static inode_t * -__inode_unref (inode_t *inode) +__inode_unref(inode_t *inode) { - int index = 0; - xlator_t *this = NULL; + int index = 0; + xlator_t *this = NULL; - if (!inode) - return NULL; + if (!inode) + return NULL; - this = THIS; + this = THIS; - /* - * Root inode should always be in active list of inode table. So unrefs - * on root inode are no-ops. - */ - if (__is_root_gfid(inode->gfid)) - return inode; + /* + * Root inode should always be in active list of inode table. So unrefs + * on root inode are no-ops. + */ + if (__is_root_gfid(inode->gfid)) + return inode; - GF_ASSERT (inode->ref); + GF_ASSERT(inode->ref); - --inode->ref; + --inode->ref; - index = __inode_get_xl_index (inode, this); - if (index >= 0) { - inode->_ctx[index].xl_key = this; - inode->_ctx[index].ref--; - } + index = __inode_get_xl_index(inode, this); + if (index >= 0) { + inode->_ctx[index].xl_key = this; + inode->_ctx[index].ref--; + } - if (!inode->ref) { - inode->table->active_size--; + if (!inode->ref) { + inode->table->active_size--; - if (inode->nlookup) - __inode_passivate (inode); - else - __inode_retire (inode); - } + if (inode->nlookup) + __inode_passivate(inode); + else + __inode_retire(inode); + } - return inode; + return inode; } - static inode_t * -__inode_ref (inode_t *inode) -{ - int index = 0; - xlator_t *this = NULL; - - if (!inode) - return NULL; - - this = THIS; - - if (!inode->ref) { - inode->table->lru_size--; - __inode_activate (inode); - } - - /* - * Root inode should always be in active list of inode table. So unrefs - * on root inode are no-ops. If we do not allow unrefs but allow refs, - * it leads to refcount overflows and deleting and adding the inode - * to active-list, which is ugly. active_size (check __inode_activate) - * in inode table increases which is wrong. So just keep the ref - * count as 1 always - */ - if (__is_root_gfid(inode->gfid) && inode->ref) - return inode; +__inode_ref(inode_t *inode) +{ + int index = 0; + xlator_t *this = NULL; + + if (!inode) + return NULL; + + this = THIS; + + if (!inode->ref) { + inode->table->lru_size--; + __inode_activate(inode); + } + + /* + * Root inode should always be in active list of inode table. So unrefs + * on root inode are no-ops. If we do not allow unrefs but allow refs, + * it leads to refcount overflows and deleting and adding the inode + * to active-list, which is ugly. active_size (check __inode_activate) + * in inode table increases which is wrong. So just keep the ref + * count as 1 always + */ + if (__is_root_gfid(inode->gfid) && inode->ref) + return inode; - inode->ref++; + inode->ref++; - index = __inode_get_xl_index (inode, this); - if (index >= 0) { - inode->_ctx[index].xl_key = this; - inode->_ctx[index].ref++; - } + index = __inode_get_xl_index(inode, this); + if (index >= 0) { + inode->_ctx[index].xl_key = this; + inode->_ctx[index].ref++; + } - return inode; + return inode; } - inode_t * -inode_unref (inode_t *inode) +inode_unref(inode_t *inode) { - inode_table_t *table = NULL; + inode_table_t *table = NULL; - if (!inode) - return NULL; + if (!inode) + return NULL; - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - inode = __inode_unref (inode); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + inode = __inode_unref(inode); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); - return inode; + return inode; } - inode_t * -inode_ref (inode_t *inode) +inode_ref(inode_t *inode) { - inode_table_t *table = NULL; + inode_table_t *table = NULL; - if (!inode) - return NULL; + if (!inode) + return NULL; - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - inode = __inode_ref (inode); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + inode = __inode_ref(inode); + } + pthread_mutex_unlock(&table->lock); - return inode; + return inode; } - static dentry_t * -__dentry_create (inode_t *inode, inode_t *parent, const char *name) +__dentry_create(inode_t *inode, inode_t *parent, const char *name) { - dentry_t *newd = NULL; + dentry_t *newd = NULL; - if (!inode || !parent || !name) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, - "inode || parent || name not found"); - return NULL; - } + if (!inode || !parent || !name) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "inode || parent || name not found"); + return NULL; + } - newd = mem_get0 (parent->table->dentry_pool); - if (newd == NULL) { - goto out; - } + newd = mem_get0(parent->table->dentry_pool); + if (newd == NULL) { + goto out; + } - INIT_LIST_HEAD (&newd->inode_list); - INIT_LIST_HEAD (&newd->hash); + INIT_LIST_HEAD(&newd->inode_list); + INIT_LIST_HEAD(&newd->hash); - newd->name = gf_strdup (name); - if (newd->name == NULL) { - mem_put (newd); - newd = NULL; - goto out; - } + newd->name = gf_strdup(name); + if (newd->name == NULL) { + mem_put(newd); + newd = NULL; + goto out; + } - if (parent) - newd->parent = __inode_ref (parent); + if (parent) + newd->parent = __inode_ref(parent); - list_add (&newd->inode_list, &inode->dentry_list); - newd->inode = inode; + list_add(&newd->inode_list, &inode->dentry_list); + newd->inode = inode; out: - return newd; + return newd; } - static inode_t * -__inode_create (inode_table_t *table) +__inode_create(inode_table_t *table) { - inode_t *newi = NULL; + inode_t *newi = NULL; - if (!table) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_TABLE_NOT_FOUND, "table not " - "found"); - return NULL; - } + if (!table) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INODE_TABLE_NOT_FOUND, + "table not " + "found"); + return NULL; + } - newi = mem_get0 (table->inode_pool); - if (!newi) { - goto out; - } + newi = mem_get0(table->inode_pool); + if (!newi) { + goto out; + } - newi->table = table; + newi->table = table; - LOCK_INIT (&newi->lock); + LOCK_INIT(&newi->lock); - INIT_LIST_HEAD (&newi->fd_list); - INIT_LIST_HEAD (&newi->list); - INIT_LIST_HEAD (&newi->hash); - INIT_LIST_HEAD (&newi->dentry_list); + INIT_LIST_HEAD(&newi->fd_list); + INIT_LIST_HEAD(&newi->list); + INIT_LIST_HEAD(&newi->hash); + INIT_LIST_HEAD(&newi->dentry_list); - newi->_ctx = GF_CALLOC (1, - (sizeof (struct _inode_ctx) * table->ctxcount), - gf_common_mt_inode_ctx); - if (newi->_ctx == NULL) { - LOCK_DESTROY (&newi->lock); - mem_put (newi); - newi = NULL; - goto out; - } + newi->_ctx = GF_CALLOC(1, (sizeof(struct _inode_ctx) * table->ctxcount), + gf_common_mt_inode_ctx); + if (newi->_ctx == NULL) { + LOCK_DESTROY(&newi->lock); + mem_put(newi); + newi = NULL; + goto out; + } - list_add (&newi->list, &table->lru); - table->lru_size++; + list_add(&newi->list, &table->lru); + table->lru_size++; out: - return newi; + return newi; } - inode_t * -inode_new (inode_table_t *table) +inode_new(inode_table_t *table) { - inode_t *inode = NULL; + inode_t *inode = NULL; - if (!table) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_TABLE_NOT_FOUND, "inode not " - "found"); - return NULL; - } + if (!table) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INODE_TABLE_NOT_FOUND, + "inode not " + "found"); + return NULL; + } - pthread_mutex_lock (&table->lock); - { - inode = __inode_create (table); - if (inode != NULL) { - __inode_ref (inode); - } + pthread_mutex_lock(&table->lock); + { + inode = __inode_create(table); + if (inode != NULL) { + __inode_ref(inode); } - pthread_mutex_unlock (&table->lock); + } + pthread_mutex_unlock(&table->lock); - return inode; + return inode; } - /* Reduce the ref count by value 'nref' * Args: * inode - address of the inode to operate on @@ -703,1240 +678,1221 @@ inode_new (inode_table_t *table) * hence to be used only in destructor functions and not otherwise. */ static inode_t * -__inode_ref_reduce_by_n (inode_t *inode, uint64_t nref) +__inode_ref_reduce_by_n(inode_t *inode, uint64_t nref) { - if (!inode) - return NULL; + if (!inode) + return NULL; - GF_ASSERT (inode->ref >= nref); + GF_ASSERT(inode->ref >= nref); - inode->ref -= nref; + inode->ref -= nref; - if (!nref) - inode->ref = 0; + if (!nref) + inode->ref = 0; - if (!inode->ref) { - inode->table->active_size--; + if (!inode->ref) { + inode->table->active_size--; - if (inode->nlookup) - __inode_passivate (inode); - else - __inode_retire (inode); - } + if (inode->nlookup) + __inode_passivate(inode); + else + __inode_retire(inode); + } - return inode; + return inode; } - static inode_t * -__inode_lookup (inode_t *inode) +__inode_lookup(inode_t *inode) { - if (!inode) - return NULL; + if (!inode) + return NULL; - inode->nlookup++; + inode->nlookup++; - return inode; + return inode; } - static inode_t * -__inode_forget (inode_t *inode, uint64_t nlookup) +__inode_forget(inode_t *inode, uint64_t nlookup) { - if (!inode) - return NULL; + if (!inode) + return NULL; - GF_ASSERT (inode->nlookup >= nlookup); + GF_ASSERT(inode->nlookup >= nlookup); - inode->nlookup -= nlookup; + inode->nlookup -= nlookup; - if (!nlookup) - inode->nlookup = 0; + if (!nlookup) + inode->nlookup = 0; - return inode; + return inode; } - dentry_t * -__dentry_grep (inode_table_t *table, inode_t *parent, const char *name) +__dentry_grep(inode_table_t *table, inode_t *parent, const char *name) { - int hash = 0; - dentry_t *dentry = NULL; - dentry_t *tmp = NULL; + int hash = 0; + dentry_t *dentry = NULL; + dentry_t *tmp = NULL; - if (!table || !name || !parent) - return NULL; + if (!table || !name || !parent) + return NULL; - hash = hash_dentry (parent, name, table->hashsize); + hash = hash_dentry(parent, name, table->hashsize); - list_for_each_entry (tmp, &table->name_hash[hash], hash) { - if (tmp->parent == parent && !strcmp (tmp->name, name)) { - dentry = tmp; - break; - } + list_for_each_entry(tmp, &table->name_hash[hash], hash) + { + if (tmp->parent == parent && !strcmp(tmp->name, name)) { + dentry = tmp; + break; } + } - return dentry; + return dentry; } - inode_t * -inode_grep (inode_table_t *table, inode_t *parent, const char *name) +inode_grep(inode_table_t *table, inode_t *parent, const char *name) { - inode_t *inode = NULL; - dentry_t *dentry = NULL; + inode_t *inode = NULL; + dentry_t *dentry = NULL; - if (!table || !parent || !name) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "table || parent || name" - " not found"); - return NULL; - } + if (!table || !parent || !name) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "table || parent || name" + " not found"); + return NULL; + } - pthread_mutex_lock (&table->lock); - { - dentry = __dentry_grep (table, parent, name); + pthread_mutex_lock(&table->lock); + { + dentry = __dentry_grep(table, parent, name); - if (dentry) - inode = dentry->inode; + if (dentry) + inode = dentry->inode; - if (inode) - __inode_ref (inode); - } - pthread_mutex_unlock (&table->lock); + if (inode) + __inode_ref(inode); + } + pthread_mutex_unlock(&table->lock); - return inode; + return inode; } - inode_t * -inode_resolve (inode_table_t *table, char *path) +inode_resolve(inode_table_t *table, char *path) { - char *tmp = NULL, *bname = NULL, *str = NULL, *saveptr = NULL; - inode_t *inode = NULL, *parent = NULL; - - if ((path == NULL) || (table == NULL)) { - goto out; - } + char *tmp = NULL, *bname = NULL, *str = NULL, *saveptr = NULL; + inode_t *inode = NULL, *parent = NULL; - parent = inode_ref (table->root); - str = tmp = gf_strdup (path); + if ((path == NULL) || (table == NULL)) { + goto out; + } - while (1) { - bname = strtok_r (str, "/", &saveptr); - if (bname == NULL) { - break; - } + parent = inode_ref(table->root); + str = tmp = gf_strdup(path); - if (inode != NULL) { - inode_unref (inode); - } + while (1) { + bname = strtok_r(str, "/", &saveptr); + if (bname == NULL) { + break; + } - inode = inode_grep (table, parent, bname); - if (inode == NULL) { - break; - } + if (inode != NULL) { + inode_unref(inode); + } - if (parent != NULL) { - inode_unref (parent); - } + inode = inode_grep(table, parent, bname); + if (inode == NULL) { + break; + } - parent = inode_ref (inode); - str = NULL; + if (parent != NULL) { + inode_unref(parent); } - inode_unref (parent); - GF_FREE (tmp); + parent = inode_ref(inode); + str = NULL; + } + + inode_unref(parent); + GF_FREE(tmp); out: - return inode; + return inode; } - int -inode_grep_for_gfid (inode_table_t *table, inode_t *parent, const char *name, - uuid_t gfid, ia_type_t *type) -{ - inode_t *inode = NULL; - dentry_t *dentry = NULL; - int ret = -1; - - if (!table || !parent || !name) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "table || parent || name" - " not found"); - return ret; - } +inode_grep_for_gfid(inode_table_t *table, inode_t *parent, const char *name, + uuid_t gfid, ia_type_t *type) +{ + inode_t *inode = NULL; + dentry_t *dentry = NULL; + int ret = -1; - pthread_mutex_lock (&table->lock); - { - dentry = __dentry_grep (table, parent, name); + if (!table || !parent || !name) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "table || parent || name" + " not found"); + return ret; + } - if (dentry) - inode = dentry->inode; + pthread_mutex_lock(&table->lock); + { + dentry = __dentry_grep(table, parent, name); - if (inode) { - gf_uuid_copy (gfid, inode->gfid); - *type = inode->ia_type; - ret = 0; - } + if (dentry) + inode = dentry->inode; + + if (inode) { + gf_uuid_copy(gfid, inode->gfid); + *type = inode->ia_type; + ret = 0; } - pthread_mutex_unlock (&table->lock); + } + pthread_mutex_unlock(&table->lock); - return ret; + return ret; } - /* return 1 if gfid is of root, 0 if not */ gf_boolean_t -__is_root_gfid (uuid_t gfid) +__is_root_gfid(uuid_t gfid) { - static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - if (gf_uuid_compare (gfid, root) == 0) - return _gf_true; + if (gf_uuid_compare(gfid, root) == 0) + return _gf_true; - return _gf_false; + return _gf_false; } - inode_t * -__inode_find (inode_table_t *table, uuid_t gfid) +__inode_find(inode_table_t *table, uuid_t gfid) { - inode_t *inode = NULL; - inode_t *tmp = NULL; - int hash = 0; + inode_t *inode = NULL; + inode_t *tmp = NULL; + int hash = 0; - if (!table) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_TABLE_NOT_FOUND, "table not " - "found"); - goto out; - } + if (!table) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INODE_TABLE_NOT_FOUND, + "table not " + "found"); + goto out; + } - if (__is_root_gfid (gfid)) - return table->root; + if (__is_root_gfid(gfid)) + return table->root; - hash = hash_gfid (gfid, 65536); + hash = hash_gfid(gfid, 65536); - list_for_each_entry (tmp, &table->inode_hash[hash], hash) { - if (gf_uuid_compare (tmp->gfid, gfid) == 0) { - inode = tmp; - break; - } + list_for_each_entry(tmp, &table->inode_hash[hash], hash) + { + if (gf_uuid_compare(tmp->gfid, gfid) == 0) { + inode = tmp; + break; } + } out: - return inode; + return inode; } - inode_t * -inode_find (inode_table_t *table, uuid_t gfid) +inode_find(inode_table_t *table, uuid_t gfid) { - inode_t *inode = NULL; + inode_t *inode = NULL; - if (!table) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_TABLE_NOT_FOUND, "table not " - "found"); - return NULL; - } + if (!table) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INODE_TABLE_NOT_FOUND, + "table not " + "found"); + return NULL; + } - pthread_mutex_lock (&table->lock); - { - inode = __inode_find (table, gfid); - if (inode) - __inode_ref (inode); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + inode = __inode_find(table, gfid); + if (inode) + __inode_ref(inode); + } + pthread_mutex_unlock(&table->lock); - return inode; + return inode; } - static inode_t * -__inode_link (inode_t *inode, inode_t *parent, const char *name, - struct iatt *iatt) -{ - dentry_t *dentry = NULL; - dentry_t *old_dentry = NULL; - inode_t *old_inode = NULL; - inode_table_t *table = NULL; - inode_t *link_inode = NULL; - - if (!inode) { - errno = EINVAL; - return NULL; - } - - table = inode->table; - if (!table) { - errno = EINVAL; - return NULL; - } - - if (parent) { - /* We should prevent inode linking between different - inode tables. This can cause errors which is very - hard to catch/debug. */ - if (inode->table != parent->table) { - errno = EINVAL; - GF_ASSERT (!"link attempted b/w inodes of diff table"); - } - - if (parent->ia_type != IA_IFDIR) { - errno = EINVAL; - GF_ASSERT (!"link attempted on non-directory parent"); - return NULL; - } - - if (!name || strlen (name) == 0) { - errno = EINVAL; - GF_ASSERT (!"link attempted with no basename on " +__inode_link(inode_t *inode, inode_t *parent, const char *name, + struct iatt *iatt) +{ + dentry_t *dentry = NULL; + dentry_t *old_dentry = NULL; + inode_t *old_inode = NULL; + inode_table_t *table = NULL; + inode_t *link_inode = NULL; + + if (!inode) { + errno = EINVAL; + return NULL; + } + + table = inode->table; + if (!table) { + errno = EINVAL; + return NULL; + } + + if (parent) { + /* We should prevent inode linking between different + inode tables. This can cause errors which is very + hard to catch/debug. */ + if (inode->table != parent->table) { + errno = EINVAL; + GF_ASSERT(!"link attempted b/w inodes of diff table"); + } + + if (parent->ia_type != IA_IFDIR) { + errno = EINVAL; + GF_ASSERT(!"link attempted on non-directory parent"); + return NULL; + } + + if (!name || strlen(name) == 0) { + errno = EINVAL; + GF_ASSERT (!"link attempted with no basename on " "parent"); - return NULL; - } + return NULL; } + } - link_inode = inode; + link_inode = inode; - if (!__is_inode_hashed (inode)) { - if (!iatt) { - errno = EINVAL; - return NULL; - } + if (!__is_inode_hashed(inode)) { + if (!iatt) { + errno = EINVAL; + return NULL; + } - if (gf_uuid_is_null (iatt->ia_gfid)) { - errno = EINVAL; - return NULL; - } + if (gf_uuid_is_null(iatt->ia_gfid)) { + errno = EINVAL; + return NULL; + } - old_inode = __inode_find (table, iatt->ia_gfid); + old_inode = __inode_find(table, iatt->ia_gfid); - if (old_inode) { - link_inode = old_inode; - } else { - gf_uuid_copy (inode->gfid, iatt->ia_gfid); - inode->ia_type = iatt->ia_type; - __inode_hash (inode); - } + if (old_inode) { + link_inode = old_inode; } else { - /* @old_inode serves another important purpose - it indicates - to the code further below whether a dentry cycle check is - required or not (a new inode linkage can never result in - creation of a loop.) - - if the given @inode is already hashed, it actually means - it is an "old" inode and deserves to undergo the cyclic - check. - */ - old_inode = inode; - } - - if (name) { - if (!strcmp(name, ".") || !strcmp(name, "..")) - return link_inode; - - if (strchr (name, '/')) { - GF_ASSERT (!"inode link attempted with '/' in name"); - return NULL; - } - } + gf_uuid_copy(inode->gfid, iatt->ia_gfid); + inode->ia_type = iatt->ia_type; + __inode_hash(inode); + } + } else { + /* @old_inode serves another important purpose - it indicates + to the code further below whether a dentry cycle check is + required or not (a new inode linkage can never result in + creation of a loop.) + + if the given @inode is already hashed, it actually means + it is an "old" inode and deserves to undergo the cyclic + check. + */ + old_inode = inode; + } + + if (name) { + if (!strcmp(name, ".") || !strcmp(name, "..")) + return link_inode; + + if (strchr(name, '/')) { + GF_ASSERT(!"inode link attempted with '/' in name"); + return NULL; + } + } + + /* use only link_inode beyond this point */ + if (parent) { + old_dentry = __dentry_grep(table, parent, name); + + if (!old_dentry || old_dentry->inode != link_inode) { + dentry = __dentry_create(link_inode, parent, name); + if (!dentry) { + gf_msg_callingfn( + THIS->name, GF_LOG_ERROR, 0, LG_MSG_DENTRY_CREATE_FAILED, + "dentry create failed on " + "inode %s with parent %s", + uuid_utoa(link_inode->gfid), uuid_utoa(parent->gfid)); + errno = ENOMEM; + return NULL; + } + if (old_inode && __is_dentry_cyclic(dentry)) { + errno = ELOOP; + __dentry_unset(dentry); + return NULL; + } + __dentry_hash(dentry); - /* use only link_inode beyond this point */ - if (parent) { - old_dentry = __dentry_grep (table, parent, name); - - if (!old_dentry || old_dentry->inode != link_inode) { - dentry = __dentry_create (link_inode, parent, name); - if (!dentry) { - gf_msg_callingfn (THIS->name, GF_LOG_ERROR, 0, - LG_MSG_DENTRY_CREATE_FAILED, - "dentry create failed on " - "inode %s with parent %s", - uuid_utoa (link_inode->gfid), - uuid_utoa (parent->gfid)); - errno = ENOMEM; - return NULL; - } - if (old_inode && __is_dentry_cyclic (dentry)) { - errno = ELOOP; - __dentry_unset (dentry); - return NULL; - } - __dentry_hash (dentry); - - if (old_dentry) - __dentry_unset (old_dentry); - } + if (old_dentry) + __dentry_unset(old_dentry); } + } - return link_inode; + return link_inode; } - inode_t * -inode_link (inode_t *inode, inode_t *parent, const char *name, - struct iatt *iatt) +inode_link(inode_t *inode, inode_t *parent, const char *name, struct iatt *iatt) { - inode_table_t *table = NULL; - inode_t *linked_inode = NULL; + inode_table_t *table = NULL; + inode_t *linked_inode = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return NULL; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return NULL; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - linked_inode = __inode_link (inode, parent, name, iatt); + pthread_mutex_lock(&table->lock); + { + linked_inode = __inode_link(inode, parent, name, iatt); - if (linked_inode) - __inode_ref (linked_inode); - } - pthread_mutex_unlock (&table->lock); + if (linked_inode) + __inode_ref(linked_inode); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); - return linked_inode; + return linked_inode; } - int -inode_lookup (inode_t *inode) +inode_lookup(inode_t *inode) { - inode_table_t *table = NULL; + inode_table_t *table = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return -1; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return -1; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - __inode_lookup (inode); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + __inode_lookup(inode); + } + pthread_mutex_unlock(&table->lock); - return 0; + return 0; } - int -inode_ref_reduce_by_n (inode_t *inode, uint64_t nref) +inode_ref_reduce_by_n(inode_t *inode, uint64_t nref) { - inode_table_t *table = NULL; + inode_table_t *table = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return -1; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return -1; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - __inode_ref_reduce_by_n (inode, nref); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + __inode_ref_reduce_by_n(inode, nref); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); - return 0; + return 0; } - int -inode_forget (inode_t *inode, uint64_t nlookup) +inode_forget(inode_t *inode, uint64_t nlookup) { - inode_table_t *table = NULL; + inode_table_t *table = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return -1; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return -1; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - __inode_forget (inode, nlookup); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + __inode_forget(inode, nlookup); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); - return 0; + return 0; } /* - * Invalidate an inode. This is invoked when a translator decides that an inode's - * cache is no longer valid. Any translator interested in taking action in this - * situation can define the invalidate callback. + * Invalidate an inode. This is invoked when a translator decides that an + * inode's cache is no longer valid. Any translator interested in taking action + * in this situation can define the invalidate callback. */ int inode_invalidate(inode_t *inode) { - int ret = 0; - xlator_t *xl = NULL; - xlator_t *old_THIS = NULL; - - if (!inode) { - gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return -1; - } - - /* - * The master xlator is not in the graph but it can define an invalidate - * handler. - */ - xl = inode->table->xl->ctx->master; - if (xl && xl->cbks->invalidate) { - old_THIS = THIS; - THIS = xl; - ret = xl->cbks->invalidate(xl, inode); - THIS = old_THIS; - if (ret) - return ret; - } + int ret = 0; + xlator_t *xl = NULL; + xlator_t *old_THIS = NULL; + + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return -1; + } + + /* + * The master xlator is not in the graph but it can define an invalidate + * handler. + */ + xl = inode->table->xl->ctx->master; + if (xl && xl->cbks->invalidate) { + old_THIS = THIS; + THIS = xl; + ret = xl->cbks->invalidate(xl, inode); + THIS = old_THIS; + if (ret) + return ret; + } - xl = inode->table->xl->graph->first; - while (xl) { - old_THIS = THIS; - THIS = xl; - if (xl->cbks->invalidate) - ret = xl->cbks->invalidate(xl, inode); - THIS = old_THIS; + xl = inode->table->xl->graph->first; + while (xl) { + old_THIS = THIS; + THIS = xl; + if (xl->cbks->invalidate) + ret = xl->cbks->invalidate(xl, inode); + THIS = old_THIS; - if (ret) - break; + if (ret) + break; - xl = xl->next; - } + xl = xl->next; + } - return ret; + return ret; } - static void -__inode_unlink (inode_t *inode, inode_t *parent, const char *name) +__inode_unlink(inode_t *inode, inode_t *parent, const char *name) { - dentry_t *dentry = NULL; - char pgfid[64] = {0}; - char gfid[64] = {0}; + dentry_t *dentry = NULL; + char pgfid[64] = {0}; + char gfid[64] = {0}; - if (!inode || !parent || !name) - return; + if (!inode || !parent || !name) + return; - dentry = __dentry_search_for_inode (inode, parent->gfid, name); - - /* dentry NULL for corrupted backend */ - if (dentry) { - __dentry_unset (dentry); - } else { - gf_msg ("inode", GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, - "%s/%s: dentry not found in %s", - uuid_utoa_r (parent->gfid, pgfid), name, - uuid_utoa_r (inode->gfid, gfid)); - } + dentry = __dentry_search_for_inode(inode, parent->gfid, name); + /* dentry NULL for corrupted backend */ + if (dentry) { + __dentry_unset(dentry); + } else { + gf_msg("inode", GF_LOG_WARNING, 0, LG_MSG_DENTRY_NOT_FOUND, + "%s/%s: dentry not found in %s", + uuid_utoa_r(parent->gfid, pgfid), name, + uuid_utoa_r(inode->gfid, gfid)); + } } - void -inode_unlink (inode_t *inode, inode_t *parent, const char *name) +inode_unlink(inode_t *inode, inode_t *parent, const char *name) { - inode_table_t *table = NULL; + inode_table_t *table = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - __inode_unlink (inode, parent, name); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + __inode_unlink(inode, parent, name); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); } - int -inode_rename (inode_table_t *table, inode_t *srcdir, const char *srcname, - inode_t *dstdir, const char *dstname, inode_t *inode, - struct iatt *iatt) -{ - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return -1; - } +inode_rename(inode_table_t *table, inode_t *srcdir, const char *srcname, + inode_t *dstdir, const char *dstname, inode_t *inode, + struct iatt *iatt) +{ + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return -1; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - __inode_link (inode, dstdir, dstname, iatt); - __inode_unlink (inode, srcdir, srcname); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + __inode_link(inode, dstdir, dstname, iatt); + __inode_unlink(inode, srcdir, srcname); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); - return 0; + return 0; } - static dentry_t * -__dentry_search_arbit (inode_t *inode) +__dentry_search_arbit(inode_t *inode) { - dentry_t *dentry = NULL; - dentry_t *trav = NULL; + dentry_t *dentry = NULL; + dentry_t *trav = NULL; - if (!inode) - return NULL; + if (!inode) + return NULL; - list_for_each_entry (trav, &inode->dentry_list, inode_list) { - if (__is_dentry_hashed (trav)) { - dentry = trav; - break; - } + list_for_each_entry(trav, &inode->dentry_list, inode_list) + { + if (__is_dentry_hashed(trav)) { + dentry = trav; + break; } + } - if (!dentry) { - list_for_each_entry (trav, &inode->dentry_list, inode_list) { - dentry = trav; - break; - } + if (!dentry) { + list_for_each_entry(trav, &inode->dentry_list, inode_list) + { + dentry = trav; + break; } + } - return dentry; + return dentry; } - inode_t * -inode_parent (inode_t *inode, uuid_t pargfid, const char *name) +inode_parent(inode_t *inode, uuid_t pargfid, const char *name) { - inode_t *parent = NULL; - inode_table_t *table = NULL; - dentry_t *dentry = NULL; + inode_t *parent = NULL; + inode_table_t *table = NULL; + dentry_t *dentry = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return NULL; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return NULL; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - if (pargfid && !gf_uuid_is_null (pargfid) && name) { - dentry = __dentry_search_for_inode (inode, pargfid, name); - } else { - dentry = __dentry_search_arbit (inode); - } + pthread_mutex_lock(&table->lock); + { + if (pargfid && !gf_uuid_is_null(pargfid) && name) { + dentry = __dentry_search_for_inode(inode, pargfid, name); + } else { + dentry = __dentry_search_arbit(inode); + } - if (dentry) - parent = dentry->parent; + if (dentry) + parent = dentry->parent; - if (parent) - __inode_ref (parent); - } - pthread_mutex_unlock (&table->lock); + if (parent) + __inode_ref(parent); + } + pthread_mutex_unlock(&table->lock); - return parent; + return parent; } static int -__inode_has_dentry (inode_t *inode) +__inode_has_dentry(inode_t *inode) { - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return 0; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return 0; + } - return !list_empty (&inode->dentry_list); + return !list_empty(&inode->dentry_list); } int -inode_has_dentry (inode_t *inode) +inode_has_dentry(inode_t *inode) { + int dentry_present = 0; - int dentry_present = 0; - - LOCK (&inode->lock); - { - dentry_present = __inode_has_dentry (inode); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + dentry_present = __inode_has_dentry(inode); + } + UNLOCK(&inode->lock); - return dentry_present; + return dentry_present; } int -__inode_path (inode_t *inode, const char *name, char **bufp) -{ - inode_table_t *table = NULL; - inode_t *itrav = NULL; - dentry_t *trav = NULL; - size_t i = 0, size = 0; - int64_t ret = 0; - int len = 0; - char *buf = NULL; - - if (!inode || gf_uuid_is_null (inode->gfid)) { - GF_ASSERT (0); - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "invalid inode"); - return -EINVAL; - } +__inode_path(inode_t *inode, const char *name, char **bufp) +{ + inode_table_t *table = NULL; + inode_t *itrav = NULL; + dentry_t *trav = NULL; + size_t i = 0, size = 0; + int64_t ret = 0; + int len = 0; + char *buf = NULL; + + if (!inode || gf_uuid_is_null(inode->gfid)) { + GF_ASSERT(0); + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "invalid inode"); + return -EINVAL; + } + + table = inode->table; + + itrav = inode; + for (trav = __dentry_search_arbit(itrav); trav; + trav = __dentry_search_arbit(itrav)) { + itrav = trav->parent; + i++; /* "/" */ + i += strlen(trav->name); + if (i > PATH_MAX) { + gf_msg(table->name, GF_LOG_CRITICAL, 0, LG_MSG_DENTRY_CYCLIC_LOOP, + "possible infinite " + "loop detected, forcing break. name=(%s)", + name); + ret = -ENOENT; + goto out; + } + } + + if (!__is_root_gfid(itrav->gfid)) { + /* "<gfid:00000000-0000-0000-0000-000000000000>"/path */ + i += GFID_STR_PFX_LEN; + } + + if (name) { + i++; + i += strlen(name); + } + + ret = i; + size = i + 1; + buf = GF_CALLOC(size, sizeof(char), gf_common_mt_char); + if (buf) { + buf[size - 1] = 0; - table = inode->table; + if (name) { + len = strlen(name); + strncpy(buf + (i - len), name, len); + buf[i - len - 1] = '/'; + i -= (len + 1); + } itrav = inode; - for (trav = __dentry_search_arbit (itrav); trav; - trav = __dentry_search_arbit (itrav)) { - itrav = trav->parent; - i ++; /* "/" */ - i += strlen (trav->name); - if (i > PATH_MAX) { - gf_msg (table->name, GF_LOG_CRITICAL, 0, - LG_MSG_DENTRY_CYCLIC_LOOP, "possible infinite " - "loop detected, forcing break. name=(%s)", - name); - ret = -ENOENT; - goto out; - } + for (trav = __dentry_search_arbit(itrav); trav; + trav = __dentry_search_arbit(itrav)) { + itrav = trav->parent; + len = strlen(trav->name); + strncpy(buf + (i - len), trav->name, len); + buf[i - len - 1] = '/'; + i -= (len + 1); } - if (!__is_root_gfid (itrav->gfid)) { - /* "<gfid:00000000-0000-0000-0000-000000000000>"/path */ - i += GFID_STR_PFX_LEN; + if (!__is_root_gfid(itrav->gfid)) { + snprintf(&buf[i - GFID_STR_PFX_LEN], GFID_STR_PFX_LEN, + INODE_PATH_FMT, uuid_utoa(itrav->gfid)); + buf[i - 1] = '>'; } - if (name) { - i++; - i += strlen (name); - } + *bufp = buf; + } else { + ret = -ENOMEM; + } - ret = i; - size = i + 1; - buf = GF_CALLOC (size, sizeof (char), gf_common_mt_char); +out: + if (__is_root_gfid(inode->gfid) && !name) { + ret = 1; + GF_FREE(buf); + buf = GF_CALLOC(ret + 1, sizeof(char), gf_common_mt_char); if (buf) { - - buf[size - 1] = 0; - - if (name) { - len = strlen (name); - strncpy (buf + (i - len), name, len); - buf[i-len-1] = '/'; - i -= (len + 1); - } - - itrav = inode; - for (trav = __dentry_search_arbit (itrav); trav; - trav = __dentry_search_arbit (itrav)) { - itrav = trav->parent; - len = strlen (trav->name); - strncpy (buf + (i - len), trav->name, len); - buf[i-len-1] = '/'; - i -= (len + 1); - } - - if (!__is_root_gfid (itrav->gfid)) { - snprintf (&buf[i-GFID_STR_PFX_LEN], GFID_STR_PFX_LEN, - INODE_PATH_FMT, uuid_utoa (itrav->gfid)); - buf[i-1] = '>'; - } - - *bufp = buf; + strcpy(buf, "/"); + *bufp = buf; } else { - ret = -ENOMEM; + ret = -ENOMEM; } + } -out: - if (__is_root_gfid (inode->gfid) && !name) { - ret = 1; - GF_FREE (buf); - buf = GF_CALLOC (ret + 1, sizeof (char), gf_common_mt_char); - if (buf) { - strcpy (buf, "/"); - *bufp = buf; - } else { - ret = -ENOMEM; - } - } - - if (ret < 0) - *bufp = NULL; - return ret; + if (ret < 0) + *bufp = NULL; + return ret; } - int -inode_path (inode_t *inode, const char *name, char **bufp) +inode_path(inode_t *inode, const char *name, char **bufp) { - inode_table_t *table = NULL; - int ret = -1; + inode_table_t *table = NULL; + int ret = -1; - if (!inode) - return -EINVAL; + if (!inode) + return -EINVAL; - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - ret = __inode_path (inode, name, bufp); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + ret = __inode_path(inode, name, bufp); + } + pthread_mutex_unlock(&table->lock); - return ret; + return ret; } void -__inode_table_set_lru_limit (inode_table_t *table, uint32_t lru_limit) +__inode_table_set_lru_limit(inode_table_t *table, uint32_t lru_limit) { - table->lru_limit = lru_limit; - return; + table->lru_limit = lru_limit; + return; } - void -inode_table_set_lru_limit (inode_table_t *table, uint32_t lru_limit) +inode_table_set_lru_limit(inode_table_t *table, uint32_t lru_limit) { - pthread_mutex_lock (&table->lock); - { - __inode_table_set_lru_limit (table, lru_limit); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + __inode_table_set_lru_limit(table, lru_limit); + } + pthread_mutex_unlock(&table->lock); - inode_table_prune (table); + inode_table_prune(table); - return; + return; } static int -inode_table_prune (inode_table_t *table) +inode_table_prune(inode_table_t *table) { - int ret = 0; - struct list_head purge = {0, }; - inode_t *del = NULL; - inode_t *tmp = NULL; - inode_t *entry = NULL; + int ret = 0; + struct list_head purge = { + 0, + }; + inode_t *del = NULL; + inode_t *tmp = NULL; + inode_t *entry = NULL; - if (!table) - return -1; + if (!table) + return -1; - INIT_LIST_HEAD (&purge); + INIT_LIST_HEAD(&purge); - pthread_mutex_lock (&table->lock); - { - while (table->lru_limit - && table->lru_size > (table->lru_limit)) { - if (list_empty (&table->lru)) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_INODE_LIST, - "Empty inode lru list found" - " but with (%d) lru_size", - table->lru_size); - break; - } - - entry = list_entry (table->lru.next, inode_t, list); - - table->lru_size--; - __inode_retire (entry); - - ret++; - } + pthread_mutex_lock(&table->lock); + { + while (table->lru_limit && table->lru_size > (table->lru_limit)) { + if (list_empty(&table->lru)) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_INVALID_INODE_LIST, + "Empty inode lru list found" + " but with (%d) lru_size", + table->lru_size); + break; + } + + entry = list_entry(table->lru.next, inode_t, list); + + table->lru_size--; + __inode_retire(entry); - list_splice_init (&table->purge, &purge); - table->purge_size = 0; + ret++; } - pthread_mutex_unlock (&table->lock); + list_splice_init(&table->purge, &purge); + table->purge_size = 0; + } + pthread_mutex_unlock(&table->lock); + + { + list_for_each_entry_safe(del, tmp, &purge, list) { - list_for_each_entry_safe (del, tmp, &purge, list) { - list_del_init (&del->list); - __inode_forget (del, 0); - __inode_destroy (del); - } + list_del_init(&del->list); + __inode_forget(del, 0); + __inode_destroy(del); } + } - return ret; + return ret; } - static void -__inode_table_init_root (inode_table_t *table) +__inode_table_init_root(inode_table_t *table) { - inode_t *root = NULL; - struct iatt iatt = {0, }; + inode_t *root = NULL; + struct iatt iatt = { + 0, + }; - if (!table) - return; + if (!table) + return; - root = __inode_create (table); + root = __inode_create(table); - iatt.ia_gfid[15] = 1; - iatt.ia_ino = 1; - iatt.ia_type = IA_IFDIR; + iatt.ia_gfid[15] = 1; + iatt.ia_ino = 1; + iatt.ia_type = IA_IFDIR; - __inode_link (root, NULL, NULL, &iatt); - table->root = root; + __inode_link(root, NULL, NULL, &iatt); + table->root = root; } - inode_table_t * -inode_table_new (size_t lru_limit, xlator_t *xl) +inode_table_new(size_t lru_limit, xlator_t *xl) { - inode_table_t *new = NULL; - int ret = -1; - int i = 0; - - new = (void *)GF_CALLOC(1, sizeof (*new), gf_common_mt_inode_table_t); - if (!new) - return NULL; + inode_table_t *new = NULL; + int ret = -1; + int i = 0; - new->xl = xl; - new->ctxcount = xl->graph->xl_count + 1; + new = (void *)GF_CALLOC(1, sizeof(*new), gf_common_mt_inode_table_t); + if (!new) + return NULL; - new->lru_limit = lru_limit; + new->xl = xl; + new->ctxcount = xl->graph->xl_count + 1; - new->hashsize = 14057; /* TODO: Random Number?? */ + new->lru_limit = lru_limit; - /* In case FUSE is initing the inode table. */ - if (lru_limit == 0) - lru_limit = DEFAULT_INODE_MEMPOOL_ENTRIES; + new->hashsize = 14057; /* TODO: Random Number?? */ - new->inode_pool = mem_pool_new (inode_t, lru_limit); + /* In case FUSE is initing the inode table. */ + if (lru_limit == 0) + lru_limit = DEFAULT_INODE_MEMPOOL_ENTRIES; - if (!new->inode_pool) - goto out; + new->inode_pool = mem_pool_new(inode_t, lru_limit); - new->dentry_pool = mem_pool_new (dentry_t, lru_limit); + if (!new->inode_pool) + goto out; - if (!new->dentry_pool) - goto out; + new->dentry_pool = mem_pool_new(dentry_t, lru_limit); - new->inode_hash = (void *)GF_CALLOC (65536, - sizeof (struct list_head), - gf_common_mt_list_head); - if (!new->inode_hash) - goto out; + if (!new->dentry_pool) + goto out; - new->name_hash = (void *)GF_CALLOC (new->hashsize, - sizeof (struct list_head), - gf_common_mt_list_head); - if (!new->name_hash) - goto out; + new->inode_hash = (void *)GF_CALLOC(65536, sizeof(struct list_head), + gf_common_mt_list_head); + if (!new->inode_hash) + goto out; - /* if number of fd open in one process is more than this, - we may hit perf issues */ - new->fd_mem_pool = mem_pool_new (fd_t, 1024); + new->name_hash = (void *)GF_CALLOC(new->hashsize, sizeof(struct list_head), + gf_common_mt_list_head); + if (!new->name_hash) + goto out; - if (!new->fd_mem_pool) - goto out; + /* if number of fd open in one process is more than this, + we may hit perf issues */ + new->fd_mem_pool = mem_pool_new(fd_t, 1024); - for (i = 0; i < 65536; i++) { - INIT_LIST_HEAD (&new->inode_hash[i]); - } + if (!new->fd_mem_pool) + goto out; + for (i = 0; i < 65536; i++) { + INIT_LIST_HEAD(&new->inode_hash[i]); + } - for (i = 0; i < new->hashsize; i++) { - INIT_LIST_HEAD (&new->name_hash[i]); - } + for (i = 0; i < new->hashsize; i++) { + INIT_LIST_HEAD(&new->name_hash[i]); + } - INIT_LIST_HEAD (&new->active); - INIT_LIST_HEAD (&new->lru); - INIT_LIST_HEAD (&new->purge); + INIT_LIST_HEAD(&new->active); + INIT_LIST_HEAD(&new->lru); + INIT_LIST_HEAD(&new->purge); - ret = gf_asprintf (&new->name, "%s/inode", xl->name); - if (-1 == ret) { - /* TODO: This should be ok to continue, check with avati */ - ; - } + ret = gf_asprintf(&new->name, "%s/inode", xl->name); + if (-1 == ret) { + /* TODO: This should be ok to continue, check with avati */ + ; + } - __inode_table_init_root (new); + __inode_table_init_root(new); - pthread_mutex_init (&new->lock, NULL); + pthread_mutex_init(&new->lock, NULL); - ret = 0; + ret = 0; out: - if (ret) { - if (new) { - GF_FREE (new->inode_hash); - GF_FREE (new->name_hash); - if (new->dentry_pool) - mem_pool_destroy (new->dentry_pool); - if (new->inode_pool) - mem_pool_destroy (new->inode_pool); - GF_FREE (new); - new = NULL; - } + if (ret) { + if (new) { + GF_FREE(new->inode_hash); + GF_FREE(new->name_hash); + if (new->dentry_pool) + mem_pool_destroy(new->dentry_pool); + if (new->inode_pool) + mem_pool_destroy(new->inode_pool); + GF_FREE(new); + new = NULL; } + } - return new; + return new; } int -inode_table_ctx_free (inode_table_t *table) +inode_table_ctx_free(inode_table_t *table) { - int ret = 0; - inode_t *del = NULL; - inode_t *tmp = NULL; - int purge_count = 0; - int lru_count = 0; - int active_count = 0; - xlator_t *this = NULL; - int itable_size = 0; + int ret = 0; + inode_t *del = NULL; + inode_t *tmp = NULL; + int purge_count = 0; + int lru_count = 0; + int active_count = 0; + xlator_t *this = NULL; + int itable_size = 0; - if (!table) - return -1; + if (!table) + return -1; - this = THIS; + this = THIS; - pthread_mutex_lock (&table->lock); + pthread_mutex_lock(&table->lock); + { + list_for_each_entry_safe(del, tmp, &table->purge, list) { - list_for_each_entry_safe (del, tmp, &table->purge, list) { - if (del->_ctx) { - __inode_ctx_free (del); - purge_count++; - } - } - - list_for_each_entry_safe (del, tmp, &table->lru, list) { - if (del->_ctx) { - __inode_ctx_free (del); - lru_count++; - } - } + if (del->_ctx) { + __inode_ctx_free(del); + purge_count++; + } + } - /* should the contexts of active inodes be freed? - * Since before this function being called fds would have - * been migrated and would have held the ref on the new - * inode from the new inode table, the older inode would not - * be used. - */ - list_for_each_entry_safe (del, tmp, &table->active, list) { - if (del->_ctx) { - __inode_ctx_free (del); - active_count++; - } - } + list_for_each_entry_safe(del, tmp, &table->lru, list) + { + if (del->_ctx) { + __inode_ctx_free(del); + lru_count++; + } } - pthread_mutex_unlock (&table->lock); - - ret = purge_count + lru_count + active_count; - itable_size = table->active_size + table->lru_size + table->purge_size; - gf_msg_callingfn (this->name, GF_LOG_INFO, 0, - LG_MSG_INODE_CONTEXT_FREED, "total %d (itable size: " - "%d) inode contexts have been freed (active: %d, (" - "active size: %d), lru: %d, (lru size: %d), purge: " - "%d, (purge size: %d))", ret, itable_size, - active_count, table->active_size, lru_count, - table->lru_size, purge_count, table->purge_size); - return ret; + + /* should the contexts of active inodes be freed? + * Since before this function being called fds would have + * been migrated and would have held the ref on the new + * inode from the new inode table, the older inode would not + * be used. + */ + list_for_each_entry_safe(del, tmp, &table->active, list) + { + if (del->_ctx) { + __inode_ctx_free(del); + active_count++; + } + } + } + pthread_mutex_unlock(&table->lock); + + ret = purge_count + lru_count + active_count; + itable_size = table->active_size + table->lru_size + table->purge_size; + gf_msg_callingfn(this->name, GF_LOG_INFO, 0, LG_MSG_INODE_CONTEXT_FREED, + "total %d (itable size: " + "%d) inode contexts have been freed (active: %d, (" + "active size: %d), lru: %d, (lru size: %d), purge: " + "%d, (purge size: %d))", + ret, itable_size, active_count, table->active_size, + lru_count, table->lru_size, purge_count, + table->purge_size); + return ret; } void -inode_table_destroy_all (glusterfs_ctx_t *ctx) { - - glusterfs_graph_t *trav_graph = NULL, *tmp = NULL; - xlator_t *tree = NULL; - inode_table_t *inode_table = NULL; +inode_table_destroy_all(glusterfs_ctx_t *ctx) +{ + glusterfs_graph_t *trav_graph = NULL, *tmp = NULL; + xlator_t *tree = NULL; + inode_table_t *inode_table = NULL; + + if (ctx == NULL) + goto out; + + /* TODO: Traverse ctx->graphs with in ctx->lock and also the other + * graph additions and traversals in ctx->lock. + */ + list_for_each_entry_safe(trav_graph, tmp, &ctx->graphs, list) + { + tree = trav_graph->first; + inode_table = tree->itable; + tree->itable = NULL; + if (inode_table) + inode_table_destroy(inode_table); + } +out: + return; +} - if (ctx == NULL) - goto out; +void +inode_table_destroy(inode_table_t *inode_table) +{ + inode_t *trav = NULL; - /* TODO: Traverse ctx->graphs with in ctx->lock and also the other - * graph additions and traversals in ctx->lock. - */ - list_for_each_entry_safe (trav_graph, tmp, &ctx->graphs, list) { - tree = trav_graph->first; - inode_table = tree->itable; - tree->itable = NULL; - if (inode_table) - inode_table_destroy (inode_table); - } - out: + if (inode_table == NULL) return; -} -void -inode_table_destroy (inode_table_t *inode_table) { - - inode_t *trav = NULL; - - if (inode_table == NULL) - return; - - /* Ideally at this point in time, there should be no inodes with - * refs remaining. But there are quite a few chances where the inodes - * leak. So we can take three approaches for cleaning up the inode table: - * 1. Assume there are no leaks and then send a forget on all the inodes - * in lru list.(If no leaks there should be no inodes in active list) - * 2. Knowing there could be leaks and not freeing those inodes will - * also not free its inode context and this could leak a lot of - * memory, force free the inodes by changing the ref to 0. - * The problem with this is that any reference to inode after this - * calling this function will lead to a crash. - * 3. Knowing there could be leakes, just free the inode contexts of - * all the inodes. and let the inodes be alive. This way the major - * memory consumed by the inode contexts are freed, but there can - * be errors when any inode contexts are accessed after destroying - * this table. + /* Ideally at this point in time, there should be no inodes with + * refs remaining. But there are quite a few chances where the inodes + * leak. So we can take three approaches for cleaning up the inode table: + * 1. Assume there are no leaks and then send a forget on all the inodes + * in lru list.(If no leaks there should be no inodes in active list) + * 2. Knowing there could be leaks and not freeing those inodes will + * also not free its inode context and this could leak a lot of + * memory, force free the inodes by changing the ref to 0. + * The problem with this is that any reference to inode after this + * calling this function will lead to a crash. + * 3. Knowing there could be leakes, just free the inode contexts of + * all the inodes. and let the inodes be alive. This way the major + * memory consumed by the inode contexts are freed, but there can + * be errors when any inode contexts are accessed after destroying + * this table. + * + * Not sure which is the approach to be taken, going by approach 2. + */ + + /* Approach 3: + * ret = inode_table_ctx_free (inode_table); + */ + pthread_mutex_lock(&inode_table->lock); + { + /* Process lru list first as we need to unset their dentry + * entries (the ones which may not be unset during + * '__inode_passivate' as they were hashed) which in turn + * shall unref their parent * - * Not sure which is the approach to be taken, going by approach 2. - */ - - /* Approach 3: - * ret = inode_table_ctx_free (inode_table); + * These parent inodes when unref'ed may well again fall + * into lru list and if we are at the end of traversing + * the list, we may miss to delete/retire that entry. Hence + * traverse the lru list till it gets empty. */ - pthread_mutex_lock (&inode_table->lock); - { - /* Process lru list first as we need to unset their dentry - * entries (the ones which may not be unset during - * '__inode_passivate' as they were hashed) which in turn - * shall unref their parent - * - * These parent inodes when unref'ed may well again fall - * into lru list and if we are at the end of traversing - * the list, we may miss to delete/retire that entry. Hence - * traverse the lru list till it gets empty. - */ - while (!list_empty (&inode_table->lru)) { - trav = list_first_entry (&inode_table->lru, - inode_t, list); - __inode_forget (trav, 0); - __inode_retire (trav); - inode_table->lru_size--; - } - - while (!list_empty (&inode_table->active)) { - trav = list_first_entry (&inode_table->active, - inode_t, list); - /* forget and unref the inode to retire and add it to - * purge list. By this time there should not be any - * inodes present in the active list except for root - * inode. Its a ref_leak otherwise. */ - if (trav != inode_table->root) - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_REF_COUNT, - "Active inode(%p) with refcount" - "(%d) found during cleanup", - trav, trav->ref); - __inode_forget (trav, 0); - __inode_ref_reduce_by_n (trav, 0); - } - - } - pthread_mutex_unlock (&inode_table->lock); - - inode_table_prune (inode_table); - - GF_FREE (inode_table->inode_hash); - GF_FREE (inode_table->name_hash); - if (inode_table->dentry_pool) - mem_pool_destroy (inode_table->dentry_pool); - if (inode_table->inode_pool) - mem_pool_destroy (inode_table->inode_pool); - if (inode_table->fd_mem_pool) - mem_pool_destroy (inode_table->fd_mem_pool); - - pthread_mutex_destroy (&inode_table->lock); - - GF_FREE (inode_table->name); - GF_FREE (inode_table); - - return; + while (!list_empty(&inode_table->lru)) { + trav = list_first_entry(&inode_table->lru, inode_t, list); + __inode_forget(trav, 0); + __inode_retire(trav); + inode_table->lru_size--; + } + + while (!list_empty(&inode_table->active)) { + trav = list_first_entry(&inode_table->active, inode_t, list); + /* forget and unref the inode to retire and add it to + * purge list. By this time there should not be any + * inodes present in the active list except for root + * inode. Its a ref_leak otherwise. */ + if (trav != inode_table->root) + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, + LG_MSG_REF_COUNT, + "Active inode(%p) with refcount" + "(%d) found during cleanup", + trav, trav->ref); + __inode_forget(trav, 0); + __inode_ref_reduce_by_n(trav, 0); + } + } + pthread_mutex_unlock(&inode_table->lock); + + inode_table_prune(inode_table); + + GF_FREE(inode_table->inode_hash); + GF_FREE(inode_table->name_hash); + if (inode_table->dentry_pool) + mem_pool_destroy(inode_table->dentry_pool); + if (inode_table->inode_pool) + mem_pool_destroy(inode_table->inode_pool); + if (inode_table->fd_mem_pool) + mem_pool_destroy(inode_table->fd_mem_pool); + + pthread_mutex_destroy(&inode_table->lock); + + GF_FREE(inode_table->name); + GF_FREE(inode_table); + + return; } inode_t * -inode_from_path (inode_table_t *itable, const char *path) +inode_from_path(inode_table_t *itable, const char *path) { - inode_t *inode = NULL; - inode_t *parent = NULL; - inode_t *root = NULL; - inode_t *curr = NULL; - char *pathname = NULL; - char *component = NULL, *next_component = NULL; - char *strtokptr = NULL; + inode_t *inode = NULL; + inode_t *parent = NULL; + inode_t *root = NULL; + inode_t *curr = NULL; + char *pathname = NULL; + char *component = NULL, *next_component = NULL; + char *strtokptr = NULL; - if (!itable || !path) - return NULL; + if (!itable || !path) + return NULL; - /* top-down approach */ - pathname = gf_strdup (path); - if (pathname == NULL) { - goto out; - } + /* top-down approach */ + pathname = gf_strdup(path); + if (pathname == NULL) { + goto out; + } - root = itable->root; - parent = inode_ref (root); - component = strtok_r (pathname, "/", &strtokptr); + root = itable->root; + parent = inode_ref(root); + component = strtok_r(pathname, "/", &strtokptr); - if (component == NULL) - /* root inode */ - inode = inode_ref (parent); + if (component == NULL) + /* root inode */ + inode = inode_ref(parent); - while (component) { - curr = inode_grep (itable, parent, component); + while (component) { + curr = inode_grep(itable, parent, component); - if (curr == NULL) { - strtok_r (NULL, "/", &strtokptr); - break; - } - - next_component = strtok_r (NULL, "/", &strtokptr); + if (curr == NULL) { + strtok_r(NULL, "/", &strtokptr); + break; + } - if (next_component) { - inode_unref (parent); - parent = curr; - curr = NULL; - } else { - inode = curr; - } + next_component = strtok_r(NULL, "/", &strtokptr); - component = next_component; + if (next_component) { + inode_unref(parent); + parent = curr; + curr = NULL; + } else { + inode = curr; } - if (parent) - inode_unref (parent); + component = next_component; + } + + if (parent) + inode_unref(parent); - GF_FREE (pathname); + GF_FREE(pathname); out: - return inode; + return inode; } void -inode_set_need_lookup (inode_t *inode, xlator_t *this) +inode_set_need_lookup(inode_t *inode, xlator_t *this) { - uint64_t need_lookup = LOOKUP_NEEDED; + uint64_t need_lookup = LOOKUP_NEEDED; - if (!inode || !this) - return; + if (!inode || !this) + return; - inode_ctx_set (inode, this, &need_lookup); + inode_ctx_set(inode, this, &need_lookup); - return; + return; } /* Function behaviour: @@ -1947,264 +1903,259 @@ inode_set_need_lookup (inode_t *inode, xlator_t *this) * needed. */ gf_boolean_t -inode_needs_lookup (inode_t *inode, xlator_t *this) -{ - uint64_t need_lookup = 0; - gf_boolean_t ret = _gf_false; - int op_ret = -1; - - if (!inode || !this) - return ret; - - op_ret = inode_ctx_get (inode, this, &need_lookup); - if (op_ret == -1) { - ret = _gf_true; - } else if (need_lookup == LOOKUP_NEEDED) { - ret = _gf_true; - need_lookup = LOOKUP_NOT_NEEDED; - inode_ctx_set (inode, this, &need_lookup); - } +inode_needs_lookup(inode_t *inode, xlator_t *this) +{ + uint64_t need_lookup = 0; + gf_boolean_t ret = _gf_false; + int op_ret = -1; + if (!inode || !this) return ret; -} - -int -__inode_ctx_set2 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p, - uint64_t *value2_p) -{ - int ret = 0; - int set_idx = -1; - if (!inode || !xlator || !inode->_ctx) - return -1; + op_ret = inode_ctx_get(inode, this, &need_lookup); + if (op_ret == -1) { + ret = _gf_true; + } else if (need_lookup == LOOKUP_NEEDED) { + ret = _gf_true; + need_lookup = LOOKUP_NOT_NEEDED; + inode_ctx_set(inode, this, &need_lookup); + } - set_idx = __inode_get_xl_index (inode, xlator); - if (set_idx == -1) { - ret = -1; - goto out;; - } + return ret; +} - inode->_ctx[set_idx].xl_key = xlator; - if (value1_p) - inode->_ctx[set_idx].value1 = *value1_p; - if (value2_p) - inode->_ctx[set_idx].value2 = *value2_p; +int +__inode_ctx_set2(inode_t *inode, xlator_t *xlator, uint64_t *value1_p, + uint64_t *value2_p) +{ + int ret = 0; + int set_idx = -1; + + if (!inode || !xlator || !inode->_ctx) + return -1; + + set_idx = __inode_get_xl_index(inode, xlator); + if (set_idx == -1) { + ret = -1; + goto out; + ; + } + + inode->_ctx[set_idx].xl_key = xlator; + if (value1_p) + inode->_ctx[set_idx].value1 = *value1_p; + if (value2_p) + inode->_ctx[set_idx].value2 = *value2_p; out: - return ret; + return ret; } int -__inode_ctx_set0 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p) +__inode_ctx_set0(inode_t *inode, xlator_t *xlator, uint64_t *value1_p) { - return __inode_ctx_set2 (inode, xlator, value1_p, NULL); + return __inode_ctx_set2(inode, xlator, value1_p, NULL); } int -__inode_ctx_set1 (inode_t *inode, xlator_t *xlator, uint64_t *value2_p) +__inode_ctx_set1(inode_t *inode, xlator_t *xlator, uint64_t *value2_p) { - return __inode_ctx_set2 (inode, xlator, NULL, value2_p); + return __inode_ctx_set2(inode, xlator, NULL, value2_p); } - int -inode_ctx_set2 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p, - uint64_t *value2_p) +inode_ctx_set2(inode_t *inode, xlator_t *xlator, uint64_t *value1_p, + uint64_t *value2_p) { - int ret = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - ret = __inode_ctx_set2 (inode, xlator, value1_p, value2_p); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ret = __inode_ctx_set2(inode, xlator, value1_p, value2_p); + } + UNLOCK(&inode->lock); - return ret; + return ret; } int -inode_ctx_set1 (inode_t *inode, xlator_t *xlator, uint64_t *value2_p) +inode_ctx_set1(inode_t *inode, xlator_t *xlator, uint64_t *value2_p) { - int ret = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - ret = __inode_ctx_set1 (inode, xlator, value2_p); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ret = __inode_ctx_set1(inode, xlator, value2_p); + } + UNLOCK(&inode->lock); - return ret; + return ret; } int -inode_ctx_set0 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p) +inode_ctx_set0(inode_t *inode, xlator_t *xlator, uint64_t *value1_p) { - int ret = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - ret = __inode_ctx_set0 (inode, xlator, value1_p); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ret = __inode_ctx_set0(inode, xlator, value1_p); + } + UNLOCK(&inode->lock); - return ret; + return ret; } - int -__inode_ctx_get2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, - uint64_t *value2) +__inode_ctx_get2(inode_t *inode, xlator_t *xlator, uint64_t *value1, + uint64_t *value2) { - int index = 0; - int ret = -1; + int index = 0; + int ret = -1; - if (!inode || !xlator || !inode->_ctx) - goto out; + if (!inode || !xlator || !inode->_ctx) + goto out; - index = xlator->xl_id; - if (inode->_ctx[index].xl_key != xlator) - goto out; + index = xlator->xl_id; + if (inode->_ctx[index].xl_key != xlator) + goto out; - if (inode->_ctx[index].value1) { - if (value1) { - *value1 = inode->_ctx[index].value1; - ret = 0; - } + if (inode->_ctx[index].value1) { + if (value1) { + *value1 = inode->_ctx[index].value1; + ret = 0; } - if (inode->_ctx[index].value2) { - if (value2) { - *value2 = inode->_ctx[index].value2; - ret = 0; - } + } + if (inode->_ctx[index].value2) { + if (value2) { + *value2 = inode->_ctx[index].value2; + ret = 0; } + } out: - return ret; + return ret; } - - int -__inode_ctx_get0 (inode_t *inode, xlator_t *xlator, uint64_t *value1) +__inode_ctx_get0(inode_t *inode, xlator_t *xlator, uint64_t *value1) { - uint64_t tmp_value = 0; - int ret = 0; + uint64_t tmp_value = 0; + int ret = 0; - ret = __inode_ctx_get2 (inode, xlator, &tmp_value, NULL); - if (!ret && value1) - *value1 = tmp_value; + ret = __inode_ctx_get2(inode, xlator, &tmp_value, NULL); + if (!ret && value1) + *value1 = tmp_value; - return ret; + return ret; } int -__inode_ctx_get1 (inode_t *inode, xlator_t *xlator, uint64_t *value2) +__inode_ctx_get1(inode_t *inode, xlator_t *xlator, uint64_t *value2) { - uint64_t tmp_value = 0; - int ret = 0; + uint64_t tmp_value = 0; + int ret = 0; - ret = __inode_ctx_get2 (inode, xlator, NULL, &tmp_value); - if (!ret && value2) - *value2 = tmp_value; + ret = __inode_ctx_get2(inode, xlator, NULL, &tmp_value); + if (!ret && value2) + *value2 = tmp_value; - return ret; + return ret; } - int -inode_ctx_get2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, - uint64_t *value2) +inode_ctx_get2(inode_t *inode, xlator_t *xlator, uint64_t *value1, + uint64_t *value2) { - int ret = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - ret = __inode_ctx_get2 (inode, xlator, value1, value2); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ret = __inode_ctx_get2(inode, xlator, value1, value2); + } + UNLOCK(&inode->lock); - return ret; + return ret; } int -inode_ctx_get1 (inode_t *inode, xlator_t *xlator, uint64_t *value2) +inode_ctx_get1(inode_t *inode, xlator_t *xlator, uint64_t *value2) { - int ret = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - ret = __inode_ctx_get1 (inode, xlator, value2); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ret = __inode_ctx_get1(inode, xlator, value2); + } + UNLOCK(&inode->lock); - return ret; + return ret; } int -inode_ctx_get0 (inode_t *inode, xlator_t *xlator, uint64_t *value1) +inode_ctx_get0(inode_t *inode, xlator_t *xlator, uint64_t *value1) { - int ret = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - ret = __inode_ctx_get0 (inode, xlator, value1); - } - UNLOCK (&inode->lock); + LOCK(&inode->lock); + { + ret = __inode_ctx_get0(inode, xlator, value1); + } + UNLOCK(&inode->lock); - return ret; + return ret; } - int -inode_ctx_del2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, - uint64_t *value2) +inode_ctx_del2(inode_t *inode, xlator_t *xlator, uint64_t *value1, + uint64_t *value2) { - int index = 0; - int ret = 0; + int index = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - if (!inode->_ctx) - goto unlock; + LOCK(&inode->lock); + { + if (!inode->_ctx) + goto unlock; - index = xlator->xl_id; - if (inode->_ctx[index].xl_key != xlator) { - ret = -1; - goto unlock; - } + index = xlator->xl_id; + if (inode->_ctx[index].xl_key != xlator) { + ret = -1; + goto unlock; + } - if (inode->_ctx[index].value1 && value1) - *value1 = inode->_ctx[index].value1; - if (inode->_ctx[index].value2 && value2) - *value2 = inode->_ctx[index].value2; + if (inode->_ctx[index].value1 && value1) + *value1 = inode->_ctx[index].value1; + if (inode->_ctx[index].value2 && value2) + *value2 = inode->_ctx[index].value2; - inode->_ctx[index].key = 0; - inode->_ctx[index].xl_key = NULL; - inode->_ctx[index].value1 = 0; - inode->_ctx[index].value2 = 0; - } + inode->_ctx[index].key = 0; + inode->_ctx[index].xl_key = NULL; + inode->_ctx[index].value1 = 0; + inode->_ctx[index].value2 = 0; + } unlock: - UNLOCK (&inode->lock); + UNLOCK(&inode->lock); - return ret; + return ret; } /* function behavior: @@ -2215,348 +2166,344 @@ unlock: - if both are set, both fields are reset. */ static int -__inode_ctx_reset2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, - uint64_t *value2) +__inode_ctx_reset2(inode_t *inode, xlator_t *xlator, uint64_t *value1, + uint64_t *value2) { - int index = 0; - int ret = 0; + int index = 0; + int ret = 0; - if (!inode || !xlator) - return -1; + if (!inode || !xlator) + return -1; - LOCK (&inode->lock); - { - index = xlator->xl_id; - if (inode->_ctx[index].xl_key != xlator) { - ret = -1; - goto unlock; - } + LOCK(&inode->lock); + { + index = xlator->xl_id; + if (inode->_ctx[index].xl_key != xlator) { + ret = -1; + goto unlock; + } - if (inode->_ctx[index].value1 && value1) { - *value1 = inode->_ctx[index].value1; - inode->_ctx[index].value1 = 0; - } - if (inode->_ctx[index].value2 && value2) { - *value2 = inode->_ctx[index].value2; - inode->_ctx[index].value2 = 0; - } + if (inode->_ctx[index].value1 && value1) { + *value1 = inode->_ctx[index].value1; + inode->_ctx[index].value1 = 0; + } + if (inode->_ctx[index].value2 && value2) { + *value2 = inode->_ctx[index].value2; + inode->_ctx[index].value2 = 0; } + } unlock: - UNLOCK (&inode->lock); + UNLOCK(&inode->lock); - return ret; + return ret; } int -inode_ctx_reset2 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p, - uint64_t *value2_p) -{ - uint64_t tmp_value1 = 0; - uint64_t tmp_value2 = 0; - int ret = 0; - - ret = __inode_ctx_reset2 (inode, xlator, &tmp_value1, &tmp_value2); - if (!ret) { - if (value1_p) - *value1_p = tmp_value1; - if (value2_p) - *value2_p = tmp_value2; - } - return ret; +inode_ctx_reset2(inode_t *inode, xlator_t *xlator, uint64_t *value1_p, + uint64_t *value2_p) +{ + uint64_t tmp_value1 = 0; + uint64_t tmp_value2 = 0; + int ret = 0; + + ret = __inode_ctx_reset2(inode, xlator, &tmp_value1, &tmp_value2); + if (!ret) { + if (value1_p) + *value1_p = tmp_value1; + if (value2_p) + *value2_p = tmp_value2; + } + return ret; } int -inode_ctx_reset1 (inode_t *inode, xlator_t *xlator, uint64_t *value2_p) +inode_ctx_reset1(inode_t *inode, xlator_t *xlator, uint64_t *value2_p) { - uint64_t tmp_value2 = 0; - int ret = 0; + uint64_t tmp_value2 = 0; + int ret = 0; - ret = __inode_ctx_reset2 (inode, xlator, NULL, &tmp_value2); + ret = __inode_ctx_reset2(inode, xlator, NULL, &tmp_value2); - if (!ret && value2_p) - *value2_p = tmp_value2; - - return ret; + if (!ret && value2_p) + *value2_p = tmp_value2; + return ret; } int -inode_ctx_reset0 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p) +inode_ctx_reset0(inode_t *inode, xlator_t *xlator, uint64_t *value1_p) { - uint64_t tmp_value1 = 0; - int ret = 0; + uint64_t tmp_value1 = 0; + int ret = 0; - ret = __inode_ctx_reset2 (inode, xlator, &tmp_value1, NULL); + ret = __inode_ctx_reset2(inode, xlator, &tmp_value1, NULL); - if (!ret && value1_p) - *value1_p = tmp_value1; + if (!ret && value1_p) + *value1_p = tmp_value1; - return ret; + return ret; } int -inode_is_linked (inode_t *inode) +inode_is_linked(inode_t *inode) { - int ret = 0; - inode_table_t *table = NULL; + int ret = 0; + inode_table_t *table = NULL; - if (!inode) { - gf_msg_callingfn (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INODE_NOT_FOUND, "inode not found"); - return 0; - } + if (!inode) { + gf_msg_callingfn(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INODE_NOT_FOUND, + "inode not found"); + return 0; + } - table = inode->table; + table = inode->table; - pthread_mutex_lock (&table->lock); - { - ret = __is_inode_hashed (inode); - } - pthread_mutex_unlock (&table->lock); + pthread_mutex_lock(&table->lock); + { + ret = __is_inode_hashed(inode); + } + pthread_mutex_unlock(&table->lock); - return ret; + return ret; } void -inode_dump (inode_t *inode, char *prefix) -{ - int ret = -1; - xlator_t *xl = NULL; - int i = 0; - fd_t *fd = NULL; - struct _inode_ctx *inode_ctx = NULL; - struct list_head fd_list; - int ref = 0; - char key[GF_DUMP_MAX_BUF_LEN]; - - if (!inode) - return; +inode_dump(inode_t *inode, char *prefix) +{ + int ret = -1; + xlator_t *xl = NULL; + int i = 0; + fd_t *fd = NULL; + struct _inode_ctx *inode_ctx = NULL; + struct list_head fd_list; + int ref = 0; + char key[GF_DUMP_MAX_BUF_LEN]; + + if (!inode) + return; - INIT_LIST_HEAD (&fd_list); + INIT_LIST_HEAD(&fd_list); - ret = TRY_LOCK(&inode->lock); - if (ret != 0) { - return; - } - - { - gf_proc_dump_write("gfid", "%s", uuid_utoa (inode->gfid)); - gf_proc_dump_write("nlookup", "%ld", inode->nlookup); - gf_proc_dump_write("fd-count", "%u", inode->fd_count); - gf_proc_dump_write("active-fd-count", "%u", - inode->active_fd_count); - gf_proc_dump_write("ref", "%u", inode->ref); - gf_proc_dump_write("ia_type", "%d", inode->ia_type); - if (inode->_ctx) { - inode_ctx = GF_CALLOC (inode->table->ctxcount, - sizeof (*inode_ctx), - gf_common_mt_inode_ctx); - if (inode_ctx == NULL) { - goto unlock; - } - - for (i = 0; i < inode->table->ctxcount; - i++) { - inode_ctx[i] = inode->_ctx[i]; - xl = inode_ctx[i].xl_key; - ref = inode_ctx[i].ref; - if (ref != 0 && xl) { - gf_proc_dump_build_key (key, - "ref_by_xl:", - "%s", - xl->name); - gf_proc_dump_write (key, "%d", ref); - } - } + ret = TRY_LOCK(&inode->lock); + if (ret != 0) { + return; + } + + { + gf_proc_dump_write("gfid", "%s", uuid_utoa(inode->gfid)); + gf_proc_dump_write("nlookup", "%ld", inode->nlookup); + gf_proc_dump_write("fd-count", "%u", inode->fd_count); + gf_proc_dump_write("active-fd-count", "%u", inode->active_fd_count); + gf_proc_dump_write("ref", "%u", inode->ref); + gf_proc_dump_write("ia_type", "%d", inode->ia_type); + if (inode->_ctx) { + inode_ctx = GF_CALLOC(inode->table->ctxcount, sizeof(*inode_ctx), + gf_common_mt_inode_ctx); + if (inode_ctx == NULL) { + goto unlock; + } + + for (i = 0; i < inode->table->ctxcount; i++) { + inode_ctx[i] = inode->_ctx[i]; + xl = inode_ctx[i].xl_key; + ref = inode_ctx[i].ref; + if (ref != 0 && xl) { + gf_proc_dump_build_key(key, "ref_by_xl:", "%s", xl->name); + gf_proc_dump_write(key, "%d", ref); } + } + } - if (dump_options.xl_options.dump_fdctx != _gf_true) - goto unlock; - + if (dump_options.xl_options.dump_fdctx != _gf_true) + goto unlock; - list_for_each_entry (fd, &inode->fd_list, inode_list) { - fd_ctx_dump (fd, prefix); - } + list_for_each_entry(fd, &inode->fd_list, inode_list) + { + fd_ctx_dump(fd, prefix); } + } unlock: - UNLOCK(&inode->lock); - - if (inode_ctx && (dump_options.xl_options.dump_inodectx == _gf_true)) { - for (i = 0; i < inode->table->ctxcount; i++) { - if (inode_ctx[i].xl_key) { - xl = (xlator_t *)(long)inode_ctx[i].xl_key; - if (xl->dumpops && xl->dumpops->inodectx) - xl->dumpops->inodectx (xl, inode); - } - } + UNLOCK(&inode->lock); + + if (inode_ctx && (dump_options.xl_options.dump_inodectx == _gf_true)) { + for (i = 0; i < inode->table->ctxcount; i++) { + if (inode_ctx[i].xl_key) { + xl = (xlator_t *)(long)inode_ctx[i].xl_key; + if (xl->dumpops && xl->dumpops->inodectx) + xl->dumpops->inodectx(xl, inode); + } } + } - GF_FREE (inode_ctx); + GF_FREE(inode_ctx); - return; + return; } void -inode_table_dump (inode_table_t *itable, char *prefix) +inode_table_dump(inode_table_t *itable, char *prefix) { + char key[GF_DUMP_MAX_BUF_LEN]; + int ret = 0; - char key[GF_DUMP_MAX_BUF_LEN]; - int ret = 0; - - if (!itable) - return; + if (!itable) + return; - ret = pthread_mutex_trylock(&itable->lock); + ret = pthread_mutex_trylock(&itable->lock); - if (ret != 0) { - return; - } + if (ret != 0) { + return; + } - gf_proc_dump_build_key(key, prefix, "hashsize"); - gf_proc_dump_write(key, "%d", itable->hashsize); - gf_proc_dump_build_key(key, prefix, "name"); - gf_proc_dump_write(key, "%s", itable->name); + gf_proc_dump_build_key(key, prefix, "hashsize"); + gf_proc_dump_write(key, "%d", itable->hashsize); + gf_proc_dump_build_key(key, prefix, "name"); + gf_proc_dump_write(key, "%s", itable->name); - gf_proc_dump_build_key(key, prefix, "lru_limit"); - gf_proc_dump_write(key, "%d", itable->lru_limit); - gf_proc_dump_build_key(key, prefix, "active_size"); - gf_proc_dump_write(key, "%d", itable->active_size); - gf_proc_dump_build_key(key, prefix, "lru_size"); - gf_proc_dump_write(key, "%d", itable->lru_size); - gf_proc_dump_build_key(key, prefix, "purge_size"); - gf_proc_dump_write(key, "%d", itable->purge_size); + gf_proc_dump_build_key(key, prefix, "lru_limit"); + gf_proc_dump_write(key, "%d", itable->lru_limit); + gf_proc_dump_build_key(key, prefix, "active_size"); + gf_proc_dump_write(key, "%d", itable->active_size); + gf_proc_dump_build_key(key, prefix, "lru_size"); + gf_proc_dump_write(key, "%d", itable->lru_size); + gf_proc_dump_build_key(key, prefix, "purge_size"); + gf_proc_dump_write(key, "%d", itable->purge_size); - INODE_DUMP_LIST(&itable->active, key, prefix, "active"); - INODE_DUMP_LIST(&itable->lru, key, prefix, "lru"); - INODE_DUMP_LIST(&itable->purge, key, prefix, "purge"); + INODE_DUMP_LIST(&itable->active, key, prefix, "active"); + INODE_DUMP_LIST(&itable->lru, key, prefix, "lru"); + INODE_DUMP_LIST(&itable->purge, key, prefix, "purge"); - pthread_mutex_unlock(&itable->lock); + pthread_mutex_unlock(&itable->lock); } void -inode_dump_to_dict (inode_t *inode, char *prefix, dict_t *dict) +inode_dump_to_dict(inode_t *inode, char *prefix, dict_t *dict) { - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; - ret = TRY_LOCK (&inode->lock); - if (ret) - return; + ret = TRY_LOCK(&inode->lock); + if (ret) + return; - snprintf (key, sizeof (key), "%s.gfid", prefix); - ret = dict_set_dynstr (dict, key, gf_strdup (uuid_utoa (inode->gfid))); - if (ret) - goto out; + snprintf(key, sizeof(key), "%s.gfid", prefix); + ret = dict_set_dynstr(dict, key, gf_strdup(uuid_utoa(inode->gfid))); + if (ret) + goto out; - snprintf (key, sizeof (key), "%s.nlookup", prefix); - ret = dict_set_uint64 (dict, key, inode->nlookup); - if (ret) - goto out; + snprintf(key, sizeof(key), "%s.nlookup", prefix); + ret = dict_set_uint64(dict, key, inode->nlookup); + if (ret) + goto out; - snprintf (key, sizeof (key), "%s.ref", prefix); - ret = dict_set_uint32 (dict, key, inode->ref); - if (ret) - goto out; + snprintf(key, sizeof(key), "%s.ref", prefix); + ret = dict_set_uint32(dict, key, inode->ref); + if (ret) + goto out; - snprintf (key, sizeof (key), "%s.ia_type", prefix); - ret = dict_set_int32 (dict, key, inode->ia_type); + snprintf(key, sizeof(key), "%s.ia_type", prefix); + ret = dict_set_int32(dict, key, inode->ia_type); out: - UNLOCK (&inode->lock); - return; + UNLOCK(&inode->lock); + return; } void -inode_table_dump_to_dict (inode_table_t *itable, char *prefix, dict_t *dict) +inode_table_dump_to_dict(inode_table_t *itable, char *prefix, dict_t *dict) { - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - int ret = 0; - inode_t *inode = NULL; - int count = 0; - - ret = pthread_mutex_trylock (&itable->lock); - if (ret) - return; - - snprintf (key, sizeof (key), "%s.itable.active_size", prefix); - ret = dict_set_uint32 (dict, key, itable->active_size); - if (ret) - goto out; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + int ret = 0; + inode_t *inode = NULL; + int count = 0; - snprintf (key, sizeof (key), "%s.itable.lru_size", prefix); - ret = dict_set_uint32 (dict, key, itable->lru_size); - if (ret) - goto out; - - snprintf (key, sizeof (key), "%s.itable.purge_size", prefix); - ret = dict_set_uint32 (dict, key, itable->purge_size); - if (ret) - goto out; - - list_for_each_entry (inode, &itable->active, list) { - snprintf (key, sizeof (key), "%s.itable.active%d", prefix, - count++); - inode_dump_to_dict (inode, key, dict); - } - count = 0; + ret = pthread_mutex_trylock(&itable->lock); + if (ret) + return; - list_for_each_entry (inode, &itable->lru, list) { - snprintf (key, sizeof (key), "%s.itable.lru%d", prefix, - count++); - inode_dump_to_dict (inode, key, dict); - } - count = 0; - - list_for_each_entry (inode, &itable->purge, list) { - snprintf (key, sizeof (key), "%s.itable.purge%d", prefix, - count++); - inode_dump_to_dict (inode, key, dict); - } + snprintf(key, sizeof(key), "%s.itable.active_size", prefix); + ret = dict_set_uint32(dict, key, itable->active_size); + if (ret) + goto out; + + snprintf(key, sizeof(key), "%s.itable.lru_size", prefix); + ret = dict_set_uint32(dict, key, itable->lru_size); + if (ret) + goto out; + + snprintf(key, sizeof(key), "%s.itable.purge_size", prefix); + ret = dict_set_uint32(dict, key, itable->purge_size); + if (ret) + goto out; + + list_for_each_entry(inode, &itable->active, list) + { + snprintf(key, sizeof(key), "%s.itable.active%d", prefix, count++); + inode_dump_to_dict(inode, key, dict); + } + count = 0; + + list_for_each_entry(inode, &itable->lru, list) + { + snprintf(key, sizeof(key), "%s.itable.lru%d", prefix, count++); + inode_dump_to_dict(inode, key, dict); + } + count = 0; + + list_for_each_entry(inode, &itable->purge, list) + { + snprintf(key, sizeof(key), "%s.itable.purge%d", prefix, count++); + inode_dump_to_dict(inode, key, dict); + } out: - pthread_mutex_unlock (&itable->lock); + pthread_mutex_unlock(&itable->lock); - return; + return; } size_t -inode_ctx_size (inode_t *inode) +inode_ctx_size(inode_t *inode) { - int i = 0; - size_t size = 0; - xlator_t *xl = NULL, *old_THIS = NULL; + int i = 0; + size_t size = 0; + xlator_t *xl = NULL, *old_THIS = NULL; - if (!inode) - goto out; + if (!inode) + goto out; - LOCK (&inode->lock); - { - for (i = 0; i < inode->table->ctxcount; i++) { - if (!inode->_ctx[i].xl_key) - continue; - - xl = (xlator_t *)(long)inode->_ctx[i].xl_key; - old_THIS = THIS; - THIS = xl; - - /* If inode ref is taken when THIS is global xlator, - * the ctx xl_key is set, but the value is NULL. - * For global xlator the cbks can be NULL, hence check - * for the same */ - if (!xl->cbks) { - THIS = old_THIS; - continue; - } - - if (xl->cbks->ictxsize) - size += xl->cbks->ictxsize (xl, inode); - - THIS = old_THIS; - } + LOCK(&inode->lock); + { + for (i = 0; i < inode->table->ctxcount; i++) { + if (!inode->_ctx[i].xl_key) + continue; + + xl = (xlator_t *)(long)inode->_ctx[i].xl_key; + old_THIS = THIS; + THIS = xl; + + /* If inode ref is taken when THIS is global xlator, + * the ctx xl_key is set, but the value is NULL. + * For global xlator the cbks can be NULL, hence check + * for the same */ + if (!xl->cbks) { + THIS = old_THIS; + continue; + } + + if (xl->cbks->ictxsize) + size += xl->cbks->ictxsize(xl, inode); + + THIS = old_THIS; } - UNLOCK (&inode->lock); + } + UNLOCK(&inode->lock); out: - return size; + return size; } /* * @@ -2566,23 +2513,24 @@ out: * not possible(no hardlinks) * */ void -inode_find_directory_name (inode_t *inode, const char **name) { - dentry_t *dentry = NULL; +inode_find_directory_name(inode_t *inode, const char **name) +{ + dentry_t *dentry = NULL; - GF_VALIDATE_OR_GOTO ("inode", inode, out); - GF_VALIDATE_OR_GOTO ("inode", name, out); + GF_VALIDATE_OR_GOTO("inode", inode, out); + GF_VALIDATE_OR_GOTO("inode", name, out); - if (!IA_ISDIR (inode->ia_type)) - return; + if (!IA_ISDIR(inode->ia_type)) + return; - pthread_mutex_lock (&inode->table->lock); - { - dentry = __dentry_search_arbit (inode); - if (dentry) { - *name = dentry->name; - } + pthread_mutex_lock(&inode->table->lock); + { + dentry = __dentry_search_arbit(inode); + if (dentry) { + *name = dentry->name; } - pthread_mutex_unlock (&inode->table->lock); + } + pthread_mutex_unlock(&inode->table->lock); out: - return; + return; } diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index b2b4da1c111..8682420d8f8 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - #include "iobuf.h" #include "statedump.h" #include <stdio.h> @@ -18,1240 +17,1204 @@ TODO: implement destroy margins and prefetching of arenas */ -#define IOBUF_ARENA_MAX_INDEX (sizeof (gf_iobuf_init_config) / \ - (sizeof (struct iobuf_init_config))) +#define IOBUF_ARENA_MAX_INDEX \ + (sizeof(gf_iobuf_init_config) / (sizeof(struct iobuf_init_config))) /* Make sure this array is sorted based on pagesize */ struct iobuf_init_config gf_iobuf_init_config[] = { - /* { pagesize, num_pages }, */ - {128, 1024}, - {512, 512}, - {2 * 1024, 512}, - {8 * 1024, 128}, - {32 * 1024, 64}, - {128 * 1024, 32}, - {256 * 1024, 8}, - {1 * 1024 * 1024, 2}, + /* { pagesize, num_pages }, */ + {128, 1024}, {512, 512}, {2 * 1024, 512}, {8 * 1024, 128}, + {32 * 1024, 64}, {128 * 1024, 32}, {256 * 1024, 8}, {1 * 1024 * 1024, 2}, }; int -gf_iobuf_get_arena_index (size_t page_size) +gf_iobuf_get_arena_index(size_t page_size) { - int i = -1; + int i = -1; - for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { - if (page_size <= gf_iobuf_init_config[i].pagesize) - break; - } + for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { + if (page_size <= gf_iobuf_init_config[i].pagesize) + break; + } - if (i >= IOBUF_ARENA_MAX_INDEX) - i = -1; + if (i >= IOBUF_ARENA_MAX_INDEX) + i = -1; - return i; + return i; } - size_t -gf_iobuf_get_pagesize (size_t page_size) +gf_iobuf_get_pagesize(size_t page_size) { - int i = 0; - size_t size = 0; + int i = 0; + size_t size = 0; - for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { - size = gf_iobuf_init_config[i].pagesize; - if (page_size <= size) - break; - } + for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { + size = gf_iobuf_init_config[i].pagesize; + if (page_size <= size) + break; + } - if (i >= IOBUF_ARENA_MAX_INDEX) - size = -1; + if (i >= IOBUF_ARENA_MAX_INDEX) + size = -1; - return size; + return size; } void -__iobuf_arena_init_iobufs (struct iobuf_arena *iobuf_arena) +__iobuf_arena_init_iobufs(struct iobuf_arena *iobuf_arena) { - int iobuf_cnt = 0; - struct iobuf *iobuf = NULL; - int offset = 0; - int i = 0; + int iobuf_cnt = 0; + struct iobuf *iobuf = NULL; + int offset = 0; + int i = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_arena, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_arena, out); - iobuf_cnt = iobuf_arena->page_count; + iobuf_cnt = iobuf_arena->page_count; - iobuf_arena->iobufs = GF_CALLOC (sizeof (*iobuf), iobuf_cnt, - gf_common_mt_iobuf); - if (!iobuf_arena->iobufs) - return; + iobuf_arena->iobufs = GF_CALLOC(sizeof(*iobuf), iobuf_cnt, + gf_common_mt_iobuf); + if (!iobuf_arena->iobufs) + return; - iobuf = iobuf_arena->iobufs; - for (i = 0; i < iobuf_cnt; i++) { - INIT_LIST_HEAD (&iobuf->list); - LOCK_INIT (&iobuf->lock); + iobuf = iobuf_arena->iobufs; + for (i = 0; i < iobuf_cnt; i++) { + INIT_LIST_HEAD(&iobuf->list); + LOCK_INIT(&iobuf->lock); - iobuf->iobuf_arena = iobuf_arena; + iobuf->iobuf_arena = iobuf_arena; - iobuf->ptr = iobuf_arena->mem_base + offset; + iobuf->ptr = iobuf_arena->mem_base + offset; - list_add (&iobuf->list, &iobuf_arena->passive.list); - iobuf_arena->passive_cnt++; + list_add(&iobuf->list, &iobuf_arena->passive.list); + iobuf_arena->passive_cnt++; - offset += iobuf_arena->page_size; - iobuf++; - } + offset += iobuf_arena->page_size; + iobuf++; + } out: - return; + return; } - void -__iobuf_arena_destroy_iobufs (struct iobuf_arena *iobuf_arena) +__iobuf_arena_destroy_iobufs(struct iobuf_arena *iobuf_arena) { - int iobuf_cnt = 0; - struct iobuf *iobuf = NULL; - int i = 0; + int iobuf_cnt = 0; + struct iobuf *iobuf = NULL; + int i = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_arena, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_arena, out); - iobuf_cnt = iobuf_arena->page_count; + iobuf_cnt = iobuf_arena->page_count; - if (!iobuf_arena->iobufs) { - gf_msg_callingfn (THIS->name, GF_LOG_ERROR, 0, - LG_MSG_IOBUFS_NOT_FOUND, "iobufs not found"); - return; - } + if (!iobuf_arena->iobufs) { + gf_msg_callingfn(THIS->name, GF_LOG_ERROR, 0, LG_MSG_IOBUFS_NOT_FOUND, + "iobufs not found"); + return; + } - iobuf = iobuf_arena->iobufs; - for (i = 0; i < iobuf_cnt; i++) { - GF_ASSERT (GF_ATOMIC_GET(iobuf->ref) == 0); + iobuf = iobuf_arena->iobufs; + for (i = 0; i < iobuf_cnt; i++) { + GF_ASSERT(GF_ATOMIC_GET(iobuf->ref) == 0); - LOCK_DESTROY (&iobuf->lock); - list_del_init (&iobuf->list); - iobuf++; - } + LOCK_DESTROY(&iobuf->lock); + list_del_init(&iobuf->list); + iobuf++; + } - GF_FREE (iobuf_arena->iobufs); + GF_FREE(iobuf_arena->iobufs); out: - return; + return; } - void -__iobuf_arena_destroy (struct iobuf_pool *iobuf_pool, - struct iobuf_arena *iobuf_arena) +__iobuf_arena_destroy(struct iobuf_pool *iobuf_pool, + struct iobuf_arena *iobuf_arena) { - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_arena, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_arena, out); - if (iobuf_pool->rdma_deregistration) - iobuf_pool->rdma_deregistration (iobuf_pool->mr_list, - iobuf_arena); + if (iobuf_pool->rdma_deregistration) + iobuf_pool->rdma_deregistration(iobuf_pool->mr_list, iobuf_arena); - __iobuf_arena_destroy_iobufs (iobuf_arena); + __iobuf_arena_destroy_iobufs(iobuf_arena); - if (iobuf_arena->mem_base - && iobuf_arena->mem_base != MAP_FAILED) - munmap (iobuf_arena->mem_base, iobuf_arena->arena_size); + if (iobuf_arena->mem_base && iobuf_arena->mem_base != MAP_FAILED) + munmap(iobuf_arena->mem_base, iobuf_arena->arena_size); - GF_FREE (iobuf_arena); + GF_FREE(iobuf_arena); out: - return; + return; } - struct iobuf_arena * -__iobuf_arena_alloc (struct iobuf_pool *iobuf_pool, size_t page_size, - int32_t num_iobufs) +__iobuf_arena_alloc(struct iobuf_pool *iobuf_pool, size_t page_size, + int32_t num_iobufs) { - struct iobuf_arena *iobuf_arena = NULL; - size_t rounded_size = 0; + struct iobuf_arena *iobuf_arena = NULL; + size_t rounded_size = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - iobuf_arena = GF_CALLOC (sizeof (*iobuf_arena), 1, - gf_common_mt_iobuf_arena); - if (!iobuf_arena) - goto err; + iobuf_arena = GF_CALLOC(sizeof(*iobuf_arena), 1, gf_common_mt_iobuf_arena); + if (!iobuf_arena) + goto err; - INIT_LIST_HEAD (&iobuf_arena->list); - INIT_LIST_HEAD (&iobuf_arena->all_list); - INIT_LIST_HEAD (&iobuf_arena->active.list); - INIT_LIST_HEAD (&iobuf_arena->passive.list); - iobuf_arena->iobuf_pool = iobuf_pool; + INIT_LIST_HEAD(&iobuf_arena->list); + INIT_LIST_HEAD(&iobuf_arena->all_list); + INIT_LIST_HEAD(&iobuf_arena->active.list); + INIT_LIST_HEAD(&iobuf_arena->passive.list); + iobuf_arena->iobuf_pool = iobuf_pool; - rounded_size = gf_iobuf_get_pagesize (page_size); + rounded_size = gf_iobuf_get_pagesize(page_size); - iobuf_arena->page_size = rounded_size; - iobuf_arena->page_count = num_iobufs; + iobuf_arena->page_size = rounded_size; + iobuf_arena->page_count = num_iobufs; - iobuf_arena->arena_size = rounded_size * num_iobufs; + iobuf_arena->arena_size = rounded_size * num_iobufs; - iobuf_arena->mem_base = mmap (NULL, iobuf_arena->arena_size, - PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if (iobuf_arena->mem_base == MAP_FAILED) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_MAPPING_FAILED, - "mapping failed"); - goto err; - } + iobuf_arena->mem_base = mmap(NULL, iobuf_arena->arena_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (iobuf_arena->mem_base == MAP_FAILED) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_MAPPING_FAILED, + "mapping failed"); + goto err; + } - if (iobuf_pool->rdma_registration) { - iobuf_pool->rdma_registration (iobuf_pool->device, - iobuf_arena); - } + if (iobuf_pool->rdma_registration) { + iobuf_pool->rdma_registration(iobuf_pool->device, iobuf_arena); + } - list_add_tail (&iobuf_arena->all_list, &iobuf_pool->all_arenas); + list_add_tail(&iobuf_arena->all_list, &iobuf_pool->all_arenas); - __iobuf_arena_init_iobufs (iobuf_arena); - if (!iobuf_arena->iobufs) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, LG_MSG_INIT_IOBUF_FAILED, - "init failed"); - goto err; - } + __iobuf_arena_init_iobufs(iobuf_arena); + if (!iobuf_arena->iobufs) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, LG_MSG_INIT_IOBUF_FAILED, + "init failed"); + goto err; + } - iobuf_pool->arena_cnt++; + iobuf_pool->arena_cnt++; - return iobuf_arena; + return iobuf_arena; err: - __iobuf_arena_destroy (iobuf_pool, iobuf_arena); + __iobuf_arena_destroy(iobuf_pool, iobuf_arena); out: - return NULL; + return NULL; } - struct iobuf_arena * -__iobuf_arena_unprune (struct iobuf_pool *iobuf_pool, size_t page_size) +__iobuf_arena_unprune(struct iobuf_pool *iobuf_pool, size_t page_size) { - struct iobuf_arena *iobuf_arena = NULL; - struct iobuf_arena *tmp = NULL; - int index = 0; - - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); - - index = gf_iobuf_get_arena_index (page_size); - if (index == -1) { - gf_msg ("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, - "page_size (%zu) of iobufs in arena being added is " - "greater than max available", page_size); - return NULL; - } - - list_for_each_entry (tmp, &iobuf_pool->purge[index], list) { - list_del_init (&tmp->list); - iobuf_arena = tmp; - break; - } + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *tmp = NULL; + int index = 0; + + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); + + index = gf_iobuf_get_arena_index(page_size); + if (index == -1) { + gf_msg("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, + "page_size (%zu) of iobufs in arena being added is " + "greater than max available", + page_size); + return NULL; + } + + list_for_each_entry(tmp, &iobuf_pool->purge[index], list) + { + list_del_init(&tmp->list); + iobuf_arena = tmp; + break; + } out: - return iobuf_arena; + return iobuf_arena; } - struct iobuf_arena * -__iobuf_pool_add_arena (struct iobuf_pool *iobuf_pool, size_t page_size, - int32_t num_pages) +__iobuf_pool_add_arena(struct iobuf_pool *iobuf_pool, size_t page_size, + int32_t num_pages) { - struct iobuf_arena *iobuf_arena = NULL; - int index = 0; - - index = gf_iobuf_get_arena_index (page_size); - if (index == -1) { - gf_msg ("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, - "page_size (%zu) of iobufs in arena being added is " - "greater than max available", page_size); - return NULL; - } - - iobuf_arena = __iobuf_arena_unprune (iobuf_pool, page_size); + struct iobuf_arena *iobuf_arena = NULL; + int index = 0; + + index = gf_iobuf_get_arena_index(page_size); + if (index == -1) { + gf_msg("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, + "page_size (%zu) of iobufs in arena being added is " + "greater than max available", + page_size); + return NULL; + } - if (!iobuf_arena) - iobuf_arena = __iobuf_arena_alloc (iobuf_pool, page_size, - num_pages); + iobuf_arena = __iobuf_arena_unprune(iobuf_pool, page_size); - if (!iobuf_arena) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, - "arena not found"); - return NULL; - } - list_add (&iobuf_arena->list, &iobuf_pool->arenas[index]); + if (!iobuf_arena) + iobuf_arena = __iobuf_arena_alloc(iobuf_pool, page_size, num_pages); + if (!iobuf_arena) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, + "arena not found"); + return NULL; + } + list_add(&iobuf_arena->list, &iobuf_pool->arenas[index]); - return iobuf_arena; + return iobuf_arena; } - struct iobuf_arena * -iobuf_pool_add_arena (struct iobuf_pool *iobuf_pool, size_t page_size, - int32_t num_pages) +iobuf_pool_add_arena(struct iobuf_pool *iobuf_pool, size_t page_size, + int32_t num_pages) { - struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *iobuf_arena = NULL; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - pthread_mutex_lock (&iobuf_pool->mutex); - { - iobuf_arena = __iobuf_pool_add_arena (iobuf_pool, page_size, - num_pages); - } - pthread_mutex_unlock (&iobuf_pool->mutex); + pthread_mutex_lock(&iobuf_pool->mutex); + { + iobuf_arena = __iobuf_pool_add_arena(iobuf_pool, page_size, num_pages); + } + pthread_mutex_unlock(&iobuf_pool->mutex); out: - return iobuf_arena; + return iobuf_arena; } - /* This function destroys all the iobufs and the iobuf_pool */ void -iobuf_pool_destroy (struct iobuf_pool *iobuf_pool) +iobuf_pool_destroy(struct iobuf_pool *iobuf_pool) { - struct iobuf_arena *iobuf_arena = NULL; - struct iobuf_arena *tmp = NULL; - int i = 0; + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *tmp = NULL; + int i = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - pthread_mutex_lock (&iobuf_pool->mutex); - { - for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { - list_for_each_entry_safe (iobuf_arena, tmp, - &iobuf_pool->arenas[i], list) { - list_del_init (&iobuf_arena->list); - iobuf_pool->arena_cnt--; - - __iobuf_arena_destroy (iobuf_pool, iobuf_arena); - } - list_for_each_entry_safe (iobuf_arena, tmp, - &iobuf_pool->purge[i], list) { - list_del_init (&iobuf_arena->list); - iobuf_pool->arena_cnt--; - __iobuf_arena_destroy (iobuf_pool, iobuf_arena); - } - /* If there are no iobuf leaks, there should be no - * arenas in the filled list. If at all there are any - * arenas in the filled list, the below function will - * assert. - */ - list_for_each_entry_safe (iobuf_arena, tmp, - &iobuf_pool->filled[i], list) { - list_del_init (&iobuf_arena->list); - iobuf_pool->arena_cnt--; - __iobuf_arena_destroy (iobuf_pool, iobuf_arena); - } - /* If there are no iobuf leaks, there shoould be - * no standard allocated arenas, iobuf_put will free - * such arenas. - * TODO: Free the stdalloc arenas forcefully if present? - */ - } + pthread_mutex_lock(&iobuf_pool->mutex); + { + for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { + list_for_each_entry_safe(iobuf_arena, tmp, &iobuf_pool->arenas[i], + list) + { + list_del_init(&iobuf_arena->list); + iobuf_pool->arena_cnt--; + + __iobuf_arena_destroy(iobuf_pool, iobuf_arena); + } + list_for_each_entry_safe(iobuf_arena, tmp, &iobuf_pool->purge[i], + list) + { + list_del_init(&iobuf_arena->list); + iobuf_pool->arena_cnt--; + __iobuf_arena_destroy(iobuf_pool, iobuf_arena); + } + /* If there are no iobuf leaks, there should be no + * arenas in the filled list. If at all there are any + * arenas in the filled list, the below function will + * assert. + */ + list_for_each_entry_safe(iobuf_arena, tmp, &iobuf_pool->filled[i], + list) + { + list_del_init(&iobuf_arena->list); + iobuf_pool->arena_cnt--; + __iobuf_arena_destroy(iobuf_pool, iobuf_arena); + } + /* If there are no iobuf leaks, there shoould be + * no standard allocated arenas, iobuf_put will free + * such arenas. + * TODO: Free the stdalloc arenas forcefully if present? + */ } - pthread_mutex_unlock (&iobuf_pool->mutex); + } + pthread_mutex_unlock(&iobuf_pool->mutex); - pthread_mutex_destroy (&iobuf_pool->mutex); + pthread_mutex_destroy(&iobuf_pool->mutex); - GF_FREE (iobuf_pool); + GF_FREE(iobuf_pool); out: - return; + return; } static void -iobuf_create_stdalloc_arena (struct iobuf_pool *iobuf_pool) +iobuf_create_stdalloc_arena(struct iobuf_pool *iobuf_pool) { - struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *iobuf_arena = NULL; - /* No locking required here as its called only once during init */ - iobuf_arena = GF_CALLOC (sizeof (*iobuf_arena), 1, - gf_common_mt_iobuf_arena); - if (!iobuf_arena) - goto err; + /* No locking required here as its called only once during init */ + iobuf_arena = GF_CALLOC(sizeof(*iobuf_arena), 1, gf_common_mt_iobuf_arena); + if (!iobuf_arena) + goto err; - INIT_LIST_HEAD (&iobuf_arena->list); - INIT_LIST_HEAD (&iobuf_arena->active.list); - INIT_LIST_HEAD (&iobuf_arena->passive.list); + INIT_LIST_HEAD(&iobuf_arena->list); + INIT_LIST_HEAD(&iobuf_arena->active.list); + INIT_LIST_HEAD(&iobuf_arena->passive.list); - iobuf_arena->iobuf_pool = iobuf_pool; + iobuf_arena->iobuf_pool = iobuf_pool; - iobuf_arena->page_size = 0x7fffffff; + iobuf_arena->page_size = 0x7fffffff; - list_add_tail (&iobuf_arena->list, - &iobuf_pool->arenas[IOBUF_ARENA_MAX_INDEX]); + list_add_tail(&iobuf_arena->list, + &iobuf_pool->arenas[IOBUF_ARENA_MAX_INDEX]); err: - return; + return; } struct iobuf_pool * -iobuf_pool_new (void) +iobuf_pool_new(void) { - struct iobuf_pool *iobuf_pool = NULL; - int i = 0; - size_t page_size = 0; - size_t arena_size = 0; - int32_t num_pages = 0; - - iobuf_pool = GF_CALLOC (sizeof (*iobuf_pool), 1, - gf_common_mt_iobuf_pool); - if (!iobuf_pool) - goto out; - INIT_LIST_HEAD (&iobuf_pool->all_arenas); - pthread_mutex_init (&iobuf_pool->mutex, NULL); - for (i = 0; i <= IOBUF_ARENA_MAX_INDEX; i++) { - INIT_LIST_HEAD (&iobuf_pool->arenas[i]); - INIT_LIST_HEAD (&iobuf_pool->filled[i]); - INIT_LIST_HEAD (&iobuf_pool->purge[i]); - } - - iobuf_pool->default_page_size = 128 * GF_UNIT_KB; - - iobuf_pool->rdma_registration = NULL; - iobuf_pool->rdma_deregistration = NULL; - - for (i = 0; i < GF_RDMA_DEVICE_COUNT; i++) { - - iobuf_pool->device[i] = NULL; - iobuf_pool->mr_list[i] = NULL; - - } - - arena_size = 0; - for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { - page_size = gf_iobuf_init_config[i].pagesize; - num_pages = gf_iobuf_init_config[i].num_pages; - - iobuf_pool_add_arena (iobuf_pool, page_size, num_pages); - - arena_size += page_size * num_pages; - } - - /* Need an arena to handle all the bigger iobuf requests */ - iobuf_create_stdalloc_arena (iobuf_pool); - - iobuf_pool->arena_size = arena_size; + struct iobuf_pool *iobuf_pool = NULL; + int i = 0; + size_t page_size = 0; + size_t arena_size = 0; + int32_t num_pages = 0; + + iobuf_pool = GF_CALLOC(sizeof(*iobuf_pool), 1, gf_common_mt_iobuf_pool); + if (!iobuf_pool) + goto out; + INIT_LIST_HEAD(&iobuf_pool->all_arenas); + pthread_mutex_init(&iobuf_pool->mutex, NULL); + for (i = 0; i <= IOBUF_ARENA_MAX_INDEX; i++) { + INIT_LIST_HEAD(&iobuf_pool->arenas[i]); + INIT_LIST_HEAD(&iobuf_pool->filled[i]); + INIT_LIST_HEAD(&iobuf_pool->purge[i]); + } + + iobuf_pool->default_page_size = 128 * GF_UNIT_KB; + + iobuf_pool->rdma_registration = NULL; + iobuf_pool->rdma_deregistration = NULL; + + for (i = 0; i < GF_RDMA_DEVICE_COUNT; i++) { + iobuf_pool->device[i] = NULL; + iobuf_pool->mr_list[i] = NULL; + } + + arena_size = 0; + for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { + page_size = gf_iobuf_init_config[i].pagesize; + num_pages = gf_iobuf_init_config[i].num_pages; + + iobuf_pool_add_arena(iobuf_pool, page_size, num_pages); + + arena_size += page_size * num_pages; + } + + /* Need an arena to handle all the bigger iobuf requests */ + iobuf_create_stdalloc_arena(iobuf_pool); + + iobuf_pool->arena_size = arena_size; out: - return iobuf_pool; + return iobuf_pool; } - void -__iobuf_arena_prune (struct iobuf_pool *iobuf_pool, - struct iobuf_arena *iobuf_arena, int index) +__iobuf_arena_prune(struct iobuf_pool *iobuf_pool, + struct iobuf_arena *iobuf_arena, int index) { - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - /* code flow comes here only if the arena is in purge list and we can - * free the arena only if we have at least one arena in 'arenas' list - * (ie, at least few iobufs free in arena), that way, there won't - * be spurious mmap/unmap of buffers - */ - if (list_empty (&iobuf_pool->arenas[index])) - goto out; + /* code flow comes here only if the arena is in purge list and we can + * free the arena only if we have at least one arena in 'arenas' list + * (ie, at least few iobufs free in arena), that way, there won't + * be spurious mmap/unmap of buffers + */ + if (list_empty(&iobuf_pool->arenas[index])) + goto out; - /* All cases matched, destroy */ - list_del_init (&iobuf_arena->list); - list_del_init (&iobuf_arena->all_list); - iobuf_pool->arena_cnt--; + /* All cases matched, destroy */ + list_del_init(&iobuf_arena->list); + list_del_init(&iobuf_arena->all_list); + iobuf_pool->arena_cnt--; - __iobuf_arena_destroy (iobuf_pool, iobuf_arena); + __iobuf_arena_destroy(iobuf_pool, iobuf_arena); out: - return; + return; } - void -iobuf_pool_prune (struct iobuf_pool *iobuf_pool) +iobuf_pool_prune(struct iobuf_pool *iobuf_pool) { - struct iobuf_arena *iobuf_arena = NULL; - struct iobuf_arena *tmp = NULL; - int i = 0; + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *tmp = NULL; + int i = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - pthread_mutex_lock (&iobuf_pool->mutex); - { - for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { - if (list_empty (&iobuf_pool->arenas[i])) { - continue; - } - - list_for_each_entry_safe (iobuf_arena, tmp, - &iobuf_pool->purge[i], list) { - __iobuf_arena_prune (iobuf_pool, iobuf_arena, i); - } - } + pthread_mutex_lock(&iobuf_pool->mutex); + { + for (i = 0; i < IOBUF_ARENA_MAX_INDEX; i++) { + if (list_empty(&iobuf_pool->arenas[i])) { + continue; + } + + list_for_each_entry_safe(iobuf_arena, tmp, &iobuf_pool->purge[i], + list) + { + __iobuf_arena_prune(iobuf_pool, iobuf_arena, i); + } } - pthread_mutex_unlock (&iobuf_pool->mutex); + } + pthread_mutex_unlock(&iobuf_pool->mutex); out: - return; + return; } - struct iobuf_arena * -__iobuf_select_arena (struct iobuf_pool *iobuf_pool, size_t page_size) +__iobuf_select_arena(struct iobuf_pool *iobuf_pool, size_t page_size) { - struct iobuf_arena *iobuf_arena = NULL; - struct iobuf_arena *trav = NULL; - int index = 0; - - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); - - index = gf_iobuf_get_arena_index (page_size); - if (index == -1) { - gf_msg ("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, - "page_size (%zu) of iobufs in arena being added is " - "greater than max available", page_size); - return NULL; - } - - /* look for unused iobuf from the head-most arena */ - list_for_each_entry (trav, &iobuf_pool->arenas[index], list) { - if (trav->passive_cnt) { - iobuf_arena = trav; - break; - } + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *trav = NULL; + int index = 0; + + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); + + index = gf_iobuf_get_arena_index(page_size); + if (index == -1) { + gf_msg("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, + "page_size (%zu) of iobufs in arena being added is " + "greater than max available", + page_size); + return NULL; + } + + /* look for unused iobuf from the head-most arena */ + list_for_each_entry(trav, &iobuf_pool->arenas[index], list) + { + if (trav->passive_cnt) { + iobuf_arena = trav; + break; } + } - if (!iobuf_arena) { - /* all arenas were full, find the right count to add */ - iobuf_arena = __iobuf_pool_add_arena (iobuf_pool, page_size, - gf_iobuf_init_config[index].num_pages); - } + if (!iobuf_arena) { + /* all arenas were full, find the right count to add */ + iobuf_arena = __iobuf_pool_add_arena( + iobuf_pool, page_size, gf_iobuf_init_config[index].num_pages); + } out: - return iobuf_arena; + return iobuf_arena; } - struct iobuf * -__iobuf_get (struct iobuf_arena *iobuf_arena, size_t page_size) +__iobuf_get(struct iobuf_arena *iobuf_arena, size_t page_size) { - struct iobuf *iobuf = NULL; - struct iobuf_pool *iobuf_pool = NULL; - int index = 0; - - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_arena, out); + struct iobuf *iobuf = NULL; + struct iobuf_pool *iobuf_pool = NULL; + int index = 0; - iobuf_pool = iobuf_arena->iobuf_pool; + GF_VALIDATE_OR_GOTO("iobuf", iobuf_arena, out); - list_for_each_entry (iobuf, &iobuf_arena->passive.list, list) - break; + iobuf_pool = iobuf_arena->iobuf_pool; - list_del (&iobuf->list); - iobuf_arena->passive_cnt--; + list_for_each_entry(iobuf, &iobuf_arena->passive.list, list) break; - list_add (&iobuf->list, &iobuf_arena->active.list); - iobuf_arena->active_cnt++; + list_del(&iobuf->list); + iobuf_arena->passive_cnt--; - /* no resetting requied for this element */ - iobuf_arena->alloc_cnt++; + list_add(&iobuf->list, &iobuf_arena->active.list); + iobuf_arena->active_cnt++; - if (iobuf_arena->max_active < iobuf_arena->active_cnt) - iobuf_arena->max_active = iobuf_arena->active_cnt; + /* no resetting requied for this element */ + iobuf_arena->alloc_cnt++; - if (iobuf_arena->passive_cnt == 0) { - index = gf_iobuf_get_arena_index (page_size); - if (index == -1) { - gf_msg ("iobuf", GF_LOG_ERROR, 0, - LG_MSG_PAGE_SIZE_EXCEEDED, "page_size (%zu) of" - " iobufs in arena being added is greater " - "than max available", page_size); - goto out; - } + if (iobuf_arena->max_active < iobuf_arena->active_cnt) + iobuf_arena->max_active = iobuf_arena->active_cnt; - list_del (&iobuf_arena->list); - list_add (&iobuf_arena->list, &iobuf_pool->filled[index]); + if (iobuf_arena->passive_cnt == 0) { + index = gf_iobuf_get_arena_index(page_size); + if (index == -1) { + gf_msg("iobuf", GF_LOG_ERROR, 0, LG_MSG_PAGE_SIZE_EXCEEDED, + "page_size (%zu) of" + " iobufs in arena being added is greater " + "than max available", + page_size); + goto out; } + list_del(&iobuf_arena->list); + list_add(&iobuf_arena->list, &iobuf_pool->filled[index]); + } + out: - return iobuf; + return iobuf; } struct iobuf * -iobuf_get_from_stdalloc (struct iobuf_pool *iobuf_pool, size_t page_size) +iobuf_get_from_stdalloc(struct iobuf_pool *iobuf_pool, size_t page_size) { - struct iobuf *iobuf = NULL; - struct iobuf_arena *iobuf_arena = NULL; - struct iobuf_arena *trav = NULL; - int ret = -1; - - /* The first arena in the 'MAX-INDEX' will always be used for misc */ - list_for_each_entry (trav, &iobuf_pool->arenas[IOBUF_ARENA_MAX_INDEX], - list) { - iobuf_arena = trav; - break; - } - - iobuf = GF_CALLOC (1, sizeof (*iobuf), gf_common_mt_iobuf); - if (!iobuf) - goto out; - - /* 4096 is the alignment */ - iobuf->free_ptr = GF_CALLOC (1, ((page_size + GF_IOBUF_ALIGN_SIZE) - 1), - gf_common_mt_char); - if (!iobuf->free_ptr) - goto out; - - iobuf->ptr = GF_ALIGN_BUF (iobuf->free_ptr, GF_IOBUF_ALIGN_SIZE); - iobuf->iobuf_arena = iobuf_arena; - LOCK_INIT (&iobuf->lock); - - /* Hold a ref because you are allocating and using it */ - GF_ATOMIC_INIT (iobuf->ref, 1); - - ret = 0; + struct iobuf *iobuf = NULL; + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_arena *trav = NULL; + int ret = -1; + + /* The first arena in the 'MAX-INDEX' will always be used for misc */ + list_for_each_entry(trav, &iobuf_pool->arenas[IOBUF_ARENA_MAX_INDEX], list) + { + iobuf_arena = trav; + break; + } + + iobuf = GF_CALLOC(1, sizeof(*iobuf), gf_common_mt_iobuf); + if (!iobuf) + goto out; + + /* 4096 is the alignment */ + iobuf->free_ptr = GF_CALLOC(1, ((page_size + GF_IOBUF_ALIGN_SIZE) - 1), + gf_common_mt_char); + if (!iobuf->free_ptr) + goto out; + + iobuf->ptr = GF_ALIGN_BUF(iobuf->free_ptr, GF_IOBUF_ALIGN_SIZE); + iobuf->iobuf_arena = iobuf_arena; + LOCK_INIT(&iobuf->lock); + + /* Hold a ref because you are allocating and using it */ + GF_ATOMIC_INIT(iobuf->ref, 1); + + ret = 0; out: - if (ret && iobuf) { - GF_FREE (iobuf->free_ptr); - GF_FREE (iobuf); - iobuf = NULL; - } + if (ret && iobuf) { + GF_FREE(iobuf->free_ptr); + GF_FREE(iobuf); + iobuf = NULL; + } - return iobuf; + return iobuf; } - struct iobuf * -iobuf_get2 (struct iobuf_pool *iobuf_pool, size_t page_size) +iobuf_get2(struct iobuf_pool *iobuf_pool, size_t page_size) { - struct iobuf *iobuf = NULL; - struct iobuf_arena *iobuf_arena = NULL; - size_t rounded_size = 0; - - if (page_size == 0) { - page_size = iobuf_pool->default_page_size; - } - - rounded_size = gf_iobuf_get_pagesize (page_size); - if (rounded_size == -1) { - /* make sure to provide the requested buffer with standard - memory allocations */ - iobuf = iobuf_get_from_stdalloc (iobuf_pool, page_size); - - gf_msg_debug ("iobuf", 0, "request for iobuf of size %zu " - "is serviced using standard calloc() (%p) as it " - "exceeds the maximum available buffer size", - page_size, iobuf); - - iobuf_pool->request_misses++; - return iobuf; - } + struct iobuf *iobuf = NULL; + struct iobuf_arena *iobuf_arena = NULL; + size_t rounded_size = 0; + + if (page_size == 0) { + page_size = iobuf_pool->default_page_size; + } + + rounded_size = gf_iobuf_get_pagesize(page_size); + if (rounded_size == -1) { + /* make sure to provide the requested buffer with standard + memory allocations */ + iobuf = iobuf_get_from_stdalloc(iobuf_pool, page_size); + + gf_msg_debug("iobuf", 0, + "request for iobuf of size %zu " + "is serviced using standard calloc() (%p) as it " + "exceeds the maximum available buffer size", + page_size, iobuf); + + iobuf_pool->request_misses++; + return iobuf; + } - pthread_mutex_lock (&iobuf_pool->mutex); - { - /* most eligible arena for picking an iobuf */ - iobuf_arena = __iobuf_select_arena (iobuf_pool, rounded_size); - if (!iobuf_arena) - goto unlock; + pthread_mutex_lock(&iobuf_pool->mutex); + { + /* most eligible arena for picking an iobuf */ + iobuf_arena = __iobuf_select_arena(iobuf_pool, rounded_size); + if (!iobuf_arena) + goto unlock; - iobuf = __iobuf_get (iobuf_arena, rounded_size); - if (!iobuf) - goto unlock; + iobuf = __iobuf_get(iobuf_arena, rounded_size); + if (!iobuf) + goto unlock; - iobuf_ref (iobuf); - } + iobuf_ref(iobuf); + } unlock: - pthread_mutex_unlock (&iobuf_pool->mutex); + pthread_mutex_unlock(&iobuf_pool->mutex); - return iobuf; + return iobuf; } struct iobuf * -iobuf_get_page_aligned (struct iobuf_pool *iobuf_pool, size_t page_size, - size_t align_size) +iobuf_get_page_aligned(struct iobuf_pool *iobuf_pool, size_t page_size, + size_t align_size) { - size_t req_size = 0; - struct iobuf *iobuf = NULL; + size_t req_size = 0; + struct iobuf *iobuf = NULL; - req_size = page_size; + req_size = page_size; - if (req_size == 0) { - req_size = iobuf_pool->default_page_size; - } + if (req_size == 0) { + req_size = iobuf_pool->default_page_size; + } - iobuf = iobuf_get2 (iobuf_pool, req_size + align_size); - if (!iobuf) - return NULL; - /* If std allocation was used, then free_ptr will be non-NULL. In this - * case, we do not want to modify the original free_ptr. - * On the other hand, if the buf was gotten through the available - * arenas, then we use iobuf->free_ptr to store the original - * pointer to the offset into the mmap'd block of memory and in turn - * reuse iobuf->ptr to hold the page-aligned address. And finally, in - * iobuf_put(), we copy iobuf->free_ptr into iobuf->ptr - back to where - * it was originally when __iobuf_get() returned this iobuf. - */ - if (!iobuf->free_ptr) - iobuf->free_ptr = iobuf->ptr; - iobuf->ptr = GF_ALIGN_BUF (iobuf->ptr, align_size); - - return iobuf; + iobuf = iobuf_get2(iobuf_pool, req_size + align_size); + if (!iobuf) + return NULL; + /* If std allocation was used, then free_ptr will be non-NULL. In this + * case, we do not want to modify the original free_ptr. + * On the other hand, if the buf was gotten through the available + * arenas, then we use iobuf->free_ptr to store the original + * pointer to the offset into the mmap'd block of memory and in turn + * reuse iobuf->ptr to hold the page-aligned address. And finally, in + * iobuf_put(), we copy iobuf->free_ptr into iobuf->ptr - back to where + * it was originally when __iobuf_get() returned this iobuf. + */ + if (!iobuf->free_ptr) + iobuf->free_ptr = iobuf->ptr; + iobuf->ptr = GF_ALIGN_BUF(iobuf->ptr, align_size); + + return iobuf; } struct iobuf * -iobuf_get (struct iobuf_pool *iobuf_pool) +iobuf_get(struct iobuf_pool *iobuf_pool) { - struct iobuf *iobuf = NULL; - struct iobuf_arena *iobuf_arena = NULL; + struct iobuf *iobuf = NULL; + struct iobuf_arena *iobuf_arena = NULL; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - pthread_mutex_lock (&iobuf_pool->mutex); - { - /* most eligible arena for picking an iobuf */ - iobuf_arena = __iobuf_select_arena (iobuf_pool, - iobuf_pool->default_page_size); - if (!iobuf_arena) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_ARENA_NOT_FOUND, "arena not found"); - goto unlock; - } - - iobuf = __iobuf_get (iobuf_arena, - iobuf_pool->default_page_size); - if (!iobuf) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_IOBUF_NOT_FOUND, "iobuf not found"); - goto unlock; - } - - iobuf_ref (iobuf); + pthread_mutex_lock(&iobuf_pool->mutex); + { + /* most eligible arena for picking an iobuf */ + iobuf_arena = __iobuf_select_arena(iobuf_pool, + iobuf_pool->default_page_size); + if (!iobuf_arena) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, + "arena not found"); + goto unlock; + } + + iobuf = __iobuf_get(iobuf_arena, iobuf_pool->default_page_size); + if (!iobuf) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_IOBUF_NOT_FOUND, + "iobuf not found"); + goto unlock; } + + iobuf_ref(iobuf); + } unlock: - pthread_mutex_unlock (&iobuf_pool->mutex); + pthread_mutex_unlock(&iobuf_pool->mutex); out: - return iobuf; + return iobuf; } void -__iobuf_put (struct iobuf *iobuf, struct iobuf_arena *iobuf_arena) +__iobuf_put(struct iobuf *iobuf, struct iobuf_arena *iobuf_arena) { - struct iobuf_pool *iobuf_pool = NULL; - int index = 0; + struct iobuf_pool *iobuf_pool = NULL; + int index = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_arena, out); - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_arena, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - iobuf_pool = iobuf_arena->iobuf_pool; + iobuf_pool = iobuf_arena->iobuf_pool; - index = gf_iobuf_get_arena_index (iobuf_arena->page_size); - if (index == -1) { - gf_msg_debug ("iobuf", 0, "freeing the iobuf (%p) " - "allocated with standard calloc()", iobuf); - - /* free up properly without bothering about lists and all */ - LOCK_DESTROY (&iobuf->lock); - GF_FREE (iobuf->free_ptr); - GF_FREE (iobuf); - return; - } + index = gf_iobuf_get_arena_index(iobuf_arena->page_size); + if (index == -1) { + gf_msg_debug("iobuf", 0, + "freeing the iobuf (%p) " + "allocated with standard calloc()", + iobuf); - if (iobuf_arena->passive_cnt == 0) { - list_del (&iobuf_arena->list); - list_add_tail (&iobuf_arena->list, &iobuf_pool->arenas[index]); - } + /* free up properly without bothering about lists and all */ + LOCK_DESTROY(&iobuf->lock); + GF_FREE(iobuf->free_ptr); + GF_FREE(iobuf); + return; + } - list_del_init (&iobuf->list); - iobuf_arena->active_cnt--; + if (iobuf_arena->passive_cnt == 0) { + list_del(&iobuf_arena->list); + list_add_tail(&iobuf_arena->list, &iobuf_pool->arenas[index]); + } - if (iobuf->free_ptr) { - iobuf->ptr = iobuf->free_ptr; - iobuf->free_ptr = NULL; - } + list_del_init(&iobuf->list); + iobuf_arena->active_cnt--; - list_add (&iobuf->list, &iobuf_arena->passive.list); - iobuf_arena->passive_cnt++; + if (iobuf->free_ptr) { + iobuf->ptr = iobuf->free_ptr; + iobuf->free_ptr = NULL; + } - if (iobuf_arena->active_cnt == 0) { - list_del (&iobuf_arena->list); - list_add_tail (&iobuf_arena->list, &iobuf_pool->purge[index]); - __iobuf_arena_prune (iobuf_pool, iobuf_arena, index); - } + list_add(&iobuf->list, &iobuf_arena->passive.list); + iobuf_arena->passive_cnt++; + + if (iobuf_arena->active_cnt == 0) { + list_del(&iobuf_arena->list); + list_add_tail(&iobuf_arena->list, &iobuf_pool->purge[index]); + __iobuf_arena_prune(iobuf_pool, iobuf_arena, index); + } out: - return; + return; } - void -iobuf_put (struct iobuf *iobuf) +iobuf_put(struct iobuf *iobuf) { - struct iobuf_arena *iobuf_arena = NULL; - struct iobuf_pool *iobuf_pool = NULL; + struct iobuf_arena *iobuf_arena = NULL; + struct iobuf_pool *iobuf_pool = NULL; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - iobuf_arena = iobuf->iobuf_arena; - if (!iobuf_arena) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, - "arena not found"); - return; - } + iobuf_arena = iobuf->iobuf_arena; + if (!iobuf_arena) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, + "arena not found"); + return; + } - iobuf_pool = iobuf_arena->iobuf_pool; - if (!iobuf_pool) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_POOL_NOT_FOUND, "iobuf pool not found"); - return; - } + iobuf_pool = iobuf_arena->iobuf_pool; + if (!iobuf_pool) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_POOL_NOT_FOUND, + "iobuf pool not found"); + return; + } - pthread_mutex_lock (&iobuf_pool->mutex); - { - __iobuf_put (iobuf, iobuf_arena); - } - pthread_mutex_unlock (&iobuf_pool->mutex); + pthread_mutex_lock(&iobuf_pool->mutex); + { + __iobuf_put(iobuf, iobuf_arena); + } + pthread_mutex_unlock(&iobuf_pool->mutex); out: - return; + return; } - void -iobuf_unref (struct iobuf *iobuf) +iobuf_unref(struct iobuf *iobuf) { - int ref = 0; + int ref = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - ref = GF_ATOMIC_DEC (iobuf->ref); + ref = GF_ATOMIC_DEC(iobuf->ref); - if (!ref) - iobuf_put (iobuf); + if (!ref) + iobuf_put(iobuf); out: - return; + return; } - struct iobuf * -iobuf_ref (struct iobuf *iobuf) +iobuf_ref(struct iobuf *iobuf) { - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); - GF_ATOMIC_INC (iobuf->ref); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); + GF_ATOMIC_INC(iobuf->ref); out: - return iobuf; + return iobuf; } - struct iobref * -iobref_new () +iobref_new() { - struct iobref *iobref = NULL; + struct iobref *iobref = NULL; - iobref = GF_MALLOC (sizeof (*iobref), gf_common_mt_iobref); - if (!iobref) - return NULL; + iobref = GF_MALLOC(sizeof(*iobref), gf_common_mt_iobref); + if (!iobref) + return NULL; - iobref->iobrefs = GF_CALLOC (sizeof (*iobref->iobrefs), - 16, gf_common_mt_iobrefs); - if (!iobref->iobrefs) { - GF_FREE (iobref); - return NULL; - } + iobref->iobrefs = GF_CALLOC(sizeof(*iobref->iobrefs), 16, + gf_common_mt_iobrefs); + if (!iobref->iobrefs) { + GF_FREE(iobref); + return NULL; + } - iobref->allocated = 16; - iobref->used = 0; + iobref->allocated = 16; + iobref->used = 0; - LOCK_INIT (&iobref->lock); + LOCK_INIT(&iobref->lock); - GF_ATOMIC_INIT (iobref->ref, 1); - return iobref; + GF_ATOMIC_INIT(iobref->ref, 1); + return iobref; } - struct iobref * -iobref_ref (struct iobref *iobref) +iobref_ref(struct iobref *iobref) { - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); - GF_ATOMIC_INC (iobref->ref); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); + GF_ATOMIC_INC(iobref->ref); out: - return iobref; + return iobref; } - void -iobref_destroy (struct iobref *iobref) +iobref_destroy(struct iobref *iobref) { - int i = 0; - struct iobuf *iobuf = NULL; + int i = 0; + struct iobuf *iobuf = NULL; - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); - for (i = 0; i < iobref->allocated; i++) { - iobuf = iobref->iobrefs[i]; + for (i = 0; i < iobref->allocated; i++) { + iobuf = iobref->iobrefs[i]; - iobref->iobrefs[i] = NULL; - if (iobuf) - iobuf_unref (iobuf); - } + iobref->iobrefs[i] = NULL; + if (iobuf) + iobuf_unref(iobuf); + } - GF_FREE (iobref->iobrefs); - GF_FREE (iobref); + GF_FREE(iobref->iobrefs); + GF_FREE(iobref); out: - return; + return; } - void -iobref_unref (struct iobref *iobref) +iobref_unref(struct iobref *iobref) { - int ref = 0; + int ref = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); - ref = GF_ATOMIC_DEC (iobref->ref); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); + ref = GF_ATOMIC_DEC(iobref->ref); - if (!ref) - iobref_destroy (iobref); + if (!ref) + iobref_destroy(iobref); out: - return; + return; } - void -iobref_clear (struct iobref *iobref) +iobref_clear(struct iobref *iobref) { - int i = 0; + int i = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); - for (; i < iobref->allocated; i++) { - if (iobref->iobrefs[i] != NULL) { - iobuf_unref (iobref->iobrefs[i]); - } else { - /** iobuf's are attached serially */ - break; - } + for (; i < iobref->allocated; i++) { + if (iobref->iobrefs[i] != NULL) { + iobuf_unref(iobref->iobrefs[i]); + } else { + /** iobuf's are attached serially */ + break; } + } - iobref_unref (iobref); + iobref_unref(iobref); - out: - return; +out: + return; } - static void -__iobref_grow (struct iobref *iobref) +__iobref_grow(struct iobref *iobref) { - void *newptr = NULL; - int i = 0; - - newptr = GF_REALLOC (iobref->iobrefs, - iobref->allocated * 2 * (sizeof (*iobref->iobrefs))); - if (newptr) { - iobref->iobrefs = newptr; - iobref->allocated *= 2; - - for (i = iobref->used; i < iobref->allocated; i++) - iobref->iobrefs[i] = NULL; - } + void *newptr = NULL; + int i = 0; + + newptr = GF_REALLOC(iobref->iobrefs, + iobref->allocated * 2 * (sizeof(*iobref->iobrefs))); + if (newptr) { + iobref->iobrefs = newptr; + iobref->allocated *= 2; + + for (i = iobref->used; i < iobref->allocated; i++) + iobref->iobrefs[i] = NULL; + } } - int -__iobref_add (struct iobref *iobref, struct iobuf *iobuf) +__iobref_add(struct iobref *iobref, struct iobuf *iobuf) { - int i = 0; - int ret = -ENOMEM; + int i = 0; + int ret = -ENOMEM; - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - if (iobref->used == iobref->allocated) { - __iobref_grow (iobref); + if (iobref->used == iobref->allocated) { + __iobref_grow(iobref); - if (iobref->used == iobref->allocated) { - ret = -ENOMEM; - goto out; - } - } - - for (i = 0; i < iobref->allocated; i++) { - if (iobref->iobrefs[i] == NULL) { - iobref->iobrefs[i] = iobuf_ref (iobuf); - iobref->used++; - ret = 0; - break; - } + if (iobref->used == iobref->allocated) { + ret = -ENOMEM; + goto out; + } + } + + for (i = 0; i < iobref->allocated; i++) { + if (iobref->iobrefs[i] == NULL) { + iobref->iobrefs[i] = iobuf_ref(iobuf); + iobref->used++; + ret = 0; + break; } + } out: - return ret; + return ret; } - int -iobref_add (struct iobref *iobref, struct iobuf *iobuf) +iobref_add(struct iobref *iobref, struct iobuf *iobuf) { - int ret = -EINVAL; + int ret = -EINVAL; - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - LOCK (&iobref->lock); - { - ret = __iobref_add (iobref, iobuf); - } - UNLOCK (&iobref->lock); + LOCK(&iobref->lock); + { + ret = __iobref_add(iobref, iobuf); + } + UNLOCK(&iobref->lock); out: - return ret; + return ret; } - int -iobref_merge (struct iobref *to, struct iobref *from) +iobref_merge(struct iobref *to, struct iobref *from) { - int i = 0; - int ret = 0; - struct iobuf *iobuf = NULL; + int i = 0; + int ret = 0; + struct iobuf *iobuf = NULL; - GF_VALIDATE_OR_GOTO ("iobuf", to, out); - GF_VALIDATE_OR_GOTO ("iobuf", from, out); + GF_VALIDATE_OR_GOTO("iobuf", to, out); + GF_VALIDATE_OR_GOTO("iobuf", from, out); - LOCK (&from->lock); - { - for (i = 0; i < from->allocated; i++) { - iobuf = from->iobrefs[i]; + LOCK(&from->lock); + { + for (i = 0; i < from->allocated; i++) { + iobuf = from->iobrefs[i]; - if (!iobuf) - break; + if (!iobuf) + break; - ret = iobref_add (to, iobuf); + ret = iobref_add(to, iobuf); - if (ret < 0) - break; - } + if (ret < 0) + break; } - UNLOCK (&from->lock); + } + UNLOCK(&from->lock); out: - return ret; + return ret; } - size_t -iobuf_size (struct iobuf *iobuf) +iobuf_size(struct iobuf *iobuf) { - size_t size = 0; + size_t size = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - if (!iobuf->iobuf_arena) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, - "arena not found"); - goto out; - } + if (!iobuf->iobuf_arena) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, + "arena not found"); + goto out; + } - if (!iobuf->iobuf_arena->iobuf_pool) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, LG_MSG_POOL_NOT_FOUND, - "pool not found"); - goto out; - } + if (!iobuf->iobuf_arena->iobuf_pool) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_POOL_NOT_FOUND, + "pool not found"); + goto out; + } - size = iobuf->iobuf_arena->page_size; + size = iobuf->iobuf_arena->page_size; out: - return size; + return size; } - size_t -iobref_size (struct iobref *iobref) +iobref_size(struct iobref *iobref) { - size_t size = 0; - int i = 0; + size_t size = 0; + int i = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobref, out); + GF_VALIDATE_OR_GOTO("iobuf", iobref, out); - LOCK (&iobref->lock); - { - for (i = 0; i < iobref->allocated; i++) { - if (iobref->iobrefs[i]) - size += iobuf_size (iobref->iobrefs[i]); - } + LOCK(&iobref->lock); + { + for (i = 0; i < iobref->allocated; i++) { + if (iobref->iobrefs[i]) + size += iobuf_size(iobref->iobrefs[i]); } - UNLOCK (&iobref->lock); + } + UNLOCK(&iobref->lock); out: - return size; + return size; } void -iobuf_info_dump (struct iobuf *iobuf, const char *key_prefix) +iobuf_info_dump(struct iobuf *iobuf, const char *key_prefix) { - char key[GF_DUMP_MAX_BUF_LEN]; - struct iobuf my_iobuf; - int ret = 0; + char key[GF_DUMP_MAX_BUF_LEN]; + struct iobuf my_iobuf; + int ret = 0; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf, out); - ret = TRY_LOCK(&iobuf->lock); - if (ret) { - return; - } - memcpy(&my_iobuf, iobuf, sizeof(my_iobuf)); - UNLOCK(&iobuf->lock); + ret = TRY_LOCK(&iobuf->lock); + if (ret) { + return; + } + memcpy(&my_iobuf, iobuf, sizeof(my_iobuf)); + UNLOCK(&iobuf->lock); - gf_proc_dump_build_key(key, key_prefix,"ref"); - gf_proc_dump_write(key, "%d", my_iobuf.ref); - gf_proc_dump_build_key(key, key_prefix,"ptr"); - gf_proc_dump_write(key, "%p", my_iobuf.ptr); + gf_proc_dump_build_key(key, key_prefix, "ref"); + gf_proc_dump_write(key, "%d", my_iobuf.ref); + gf_proc_dump_build_key(key, key_prefix, "ptr"); + gf_proc_dump_write(key, "%p", my_iobuf.ptr); out: - return; + return; } void -iobuf_arena_info_dump (struct iobuf_arena *iobuf_arena, const char *key_prefix) +iobuf_arena_info_dump(struct iobuf_arena *iobuf_arena, const char *key_prefix) { - char key[GF_DUMP_MAX_BUF_LEN]; - int i = 1; - struct iobuf *trav; - - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_arena, out); - - gf_proc_dump_build_key(key, key_prefix,"mem_base"); - gf_proc_dump_write(key, "%p", iobuf_arena->mem_base); - gf_proc_dump_build_key(key, key_prefix, "active_cnt"); - gf_proc_dump_write(key, "%d", iobuf_arena->active_cnt); - gf_proc_dump_build_key(key, key_prefix, "passive_cnt"); - gf_proc_dump_write(key, "%d", iobuf_arena->passive_cnt); - gf_proc_dump_build_key(key, key_prefix, "alloc_cnt"); - gf_proc_dump_write(key, "%"PRIu64, iobuf_arena->alloc_cnt); - gf_proc_dump_build_key(key, key_prefix, "max_active"); - gf_proc_dump_write(key, "%"PRIu64, iobuf_arena->max_active); - gf_proc_dump_build_key(key, key_prefix, "page_size"); - gf_proc_dump_write(key, "%"PRIu64, iobuf_arena->page_size); - list_for_each_entry (trav, &iobuf_arena->active.list, list) { - gf_proc_dump_build_key(key, key_prefix,"active_iobuf.%d", i++); - gf_proc_dump_add_section(key); - iobuf_info_dump(trav, key); - } + char key[GF_DUMP_MAX_BUF_LEN]; + int i = 1; + struct iobuf *trav; + + GF_VALIDATE_OR_GOTO("iobuf", iobuf_arena, out); + + gf_proc_dump_build_key(key, key_prefix, "mem_base"); + gf_proc_dump_write(key, "%p", iobuf_arena->mem_base); + gf_proc_dump_build_key(key, key_prefix, "active_cnt"); + gf_proc_dump_write(key, "%d", iobuf_arena->active_cnt); + gf_proc_dump_build_key(key, key_prefix, "passive_cnt"); + gf_proc_dump_write(key, "%d", iobuf_arena->passive_cnt); + gf_proc_dump_build_key(key, key_prefix, "alloc_cnt"); + gf_proc_dump_write(key, "%" PRIu64, iobuf_arena->alloc_cnt); + gf_proc_dump_build_key(key, key_prefix, "max_active"); + gf_proc_dump_write(key, "%" PRIu64, iobuf_arena->max_active); + gf_proc_dump_build_key(key, key_prefix, "page_size"); + gf_proc_dump_write(key, "%" PRIu64, iobuf_arena->page_size); + list_for_each_entry(trav, &iobuf_arena->active.list, list) + { + gf_proc_dump_build_key(key, key_prefix, "active_iobuf.%d", i++); + gf_proc_dump_add_section(key); + iobuf_info_dump(trav, key); + } out: - return; + return; } void -iobuf_stats_dump (struct iobuf_pool *iobuf_pool) +iobuf_stats_dump(struct iobuf_pool *iobuf_pool) { - char msg[1024]; - struct iobuf_arena *trav = NULL; - int i = 1; - int j = 0; - int ret = -1; + char msg[1024]; + struct iobuf_arena *trav = NULL; + int i = 1; + int j = 0; + int ret = -1; - GF_VALIDATE_OR_GOTO ("iobuf", iobuf_pool, out); + GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); - ret = pthread_mutex_trylock(&iobuf_pool->mutex); + ret = pthread_mutex_trylock(&iobuf_pool->mutex); - if (ret) { - return; + if (ret) { + return; + } + gf_proc_dump_add_section("iobuf.global"); + gf_proc_dump_write("iobuf_pool", "%p", iobuf_pool); + gf_proc_dump_write("iobuf_pool.default_page_size", "%d", + iobuf_pool->default_page_size); + gf_proc_dump_write("iobuf_pool.arena_size", "%d", iobuf_pool->arena_size); + gf_proc_dump_write("iobuf_pool.arena_cnt", "%d", iobuf_pool->arena_cnt); + gf_proc_dump_write("iobuf_pool.request_misses", "%" PRId64, + iobuf_pool->request_misses); + + for (j = 0; j < IOBUF_ARENA_MAX_INDEX; j++) { + list_for_each_entry(trav, &iobuf_pool->arenas[j], list) + { + snprintf(msg, sizeof(msg), "arena.%d", i); + gf_proc_dump_add_section(msg); + iobuf_arena_info_dump(trav, msg); + i++; } - gf_proc_dump_add_section("iobuf.global"); - gf_proc_dump_write("iobuf_pool","%p", iobuf_pool); - gf_proc_dump_write("iobuf_pool.default_page_size", "%d", - iobuf_pool->default_page_size); - gf_proc_dump_write("iobuf_pool.arena_size", "%d", - iobuf_pool->arena_size); - gf_proc_dump_write("iobuf_pool.arena_cnt", "%d", - iobuf_pool->arena_cnt); - gf_proc_dump_write("iobuf_pool.request_misses", "%"PRId64, - iobuf_pool->request_misses); - - for (j = 0; j < IOBUF_ARENA_MAX_INDEX; j++) { - list_for_each_entry (trav, &iobuf_pool->arenas[j], list) { - snprintf(msg, sizeof(msg), - "arena.%d", i); - gf_proc_dump_add_section(msg); - iobuf_arena_info_dump(trav,msg); - i++; - } - list_for_each_entry (trav, &iobuf_pool->purge[j], list) { - snprintf(msg, sizeof(msg), - "purge.%d", i); - gf_proc_dump_add_section(msg); - iobuf_arena_info_dump(trav,msg); - i++; - } - list_for_each_entry (trav, &iobuf_pool->filled[j], list) { - snprintf(msg, sizeof(msg), - "filled.%d", i); - gf_proc_dump_add_section(msg); - iobuf_arena_info_dump(trav,msg); - i++; - } - + list_for_each_entry(trav, &iobuf_pool->purge[j], list) + { + snprintf(msg, sizeof(msg), "purge.%d", i); + gf_proc_dump_add_section(msg); + iobuf_arena_info_dump(trav, msg); + i++; + } + list_for_each_entry(trav, &iobuf_pool->filled[j], list) + { + snprintf(msg, sizeof(msg), "filled.%d", i); + gf_proc_dump_add_section(msg); + iobuf_arena_info_dump(trav, msg); + i++; } + } - pthread_mutex_unlock(&iobuf_pool->mutex); + pthread_mutex_unlock(&iobuf_pool->mutex); out: - return; + return; } - void iobuf_to_iovec(struct iobuf *iob, struct iovec *iov) { - GF_VALIDATE_OR_GOTO ("iobuf", iob, out); - GF_VALIDATE_OR_GOTO ("iobuf", iov, out); + GF_VALIDATE_OR_GOTO("iobuf", iob, out); + GF_VALIDATE_OR_GOTO("iobuf", iov, out); - iov->iov_base = iobuf_ptr (iob); - iov->iov_len = iobuf_pagesize (iob); + iov->iov_base = iobuf_ptr(iob); + iov->iov_len = iobuf_pagesize(iob); out: - return; + return; } int -iobuf_copy (struct iobuf_pool *iobuf_pool, const struct iovec *iovec_src, - int iovcnt, struct iobref **iobref, struct iobuf **iobuf, - struct iovec *iov_dst) +iobuf_copy(struct iobuf_pool *iobuf_pool, const struct iovec *iovec_src, + int iovcnt, struct iobref **iobref, struct iobuf **iobuf, + struct iovec *iov_dst) { - size_t size = -1; - int ret = 0; - - size = iov_length (iovec_src, iovcnt); - - *iobuf = iobuf_get2 (iobuf_pool, size); - if (!(*iobuf)) { - ret = -1; - errno = ENOMEM; - goto out; - } - - *iobref = iobref_new (); - if (!(*iobref)) { - iobuf_unref (*iobuf); - errno = ENOMEM; - ret = -1; - goto out; - } - - ret = iobref_add (*iobref, *iobuf); - if (ret) { - iobuf_unref (*iobuf); - iobref_unref (*iobref); - errno = ENOMEM; - ret = -1; - goto out; - } - - iov_unload (iobuf_ptr (*iobuf), iovec_src, iovcnt); - - iov_dst->iov_base = iobuf_ptr (*iobuf); - iov_dst->iov_len = size; + size_t size = -1; + int ret = 0; + + size = iov_length(iovec_src, iovcnt); + + *iobuf = iobuf_get2(iobuf_pool, size); + if (!(*iobuf)) { + ret = -1; + errno = ENOMEM; + goto out; + } + + *iobref = iobref_new(); + if (!(*iobref)) { + iobuf_unref(*iobuf); + errno = ENOMEM; + ret = -1; + goto out; + } + + ret = iobref_add(*iobref, *iobuf); + if (ret) { + iobuf_unref(*iobuf); + iobref_unref(*iobref); + errno = ENOMEM; + ret = -1; + goto out; + } + + iov_unload(iobuf_ptr(*iobuf), iovec_src, iovcnt); + + iov_dst->iov_base = iobuf_ptr(*iobuf); + iov_dst->iov_len = size; out: - return ret; + return ret; } diff --git a/libglusterfs/src/latency.c b/libglusterfs/src/latency.c index fb3b155caa6..2dc2a318216 100644 --- a/libglusterfs/src/latency.c +++ b/libglusterfs/src/latency.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - /* * This file contains functions to support dumping of * latencies of FOPs broken down by subvolumes. @@ -21,82 +20,77 @@ #include "libglusterfs-messages.h" void -gf_update_latency (call_frame_t *frame) +gf_update_latency(call_frame_t *frame) { - double elapsed; - struct timespec *begin, *end; + double elapsed; + struct timespec *begin, *end; - fop_latency_t *lat; + fop_latency_t *lat; - begin = &frame->begin; - end = &frame->end; + begin = &frame->begin; + end = &frame->end; - if (!(begin->tv_sec && end->tv_sec)) - goto out; + if (!(begin->tv_sec && end->tv_sec)) + goto out; - elapsed = (end->tv_sec - begin->tv_sec) * 1e9 - + (end->tv_nsec - begin->tv_nsec); + elapsed = (end->tv_sec - begin->tv_sec) * 1e9 + + (end->tv_nsec - begin->tv_nsec); - if (frame->op < 0 || frame->op >= GF_FOP_MAXVALUE) { - gf_log ("[core]", GF_LOG_WARNING, - "Invalid frame op value: %d", - frame->op); - return; - } + if (frame->op < 0 || frame->op >= GF_FOP_MAXVALUE) { + gf_log("[core]", GF_LOG_WARNING, "Invalid frame op value: %d", + frame->op); + return; + } - /* Can happen mostly at initiator xlator, as STACK_WIND/UNWIND macros - set it right anyways for those frames */ - if (!frame->op) - frame->op = frame->root->op; + /* Can happen mostly at initiator xlator, as STACK_WIND/UNWIND macros + set it right anyways for those frames */ + if (!frame->op) + frame->op = frame->root->op; - lat = &frame->this->stats.interval.latencies[frame->op]; + lat = &frame->this->stats.interval.latencies[frame->op]; - if (lat->max < elapsed) - lat->max = elapsed; + if (lat->max < elapsed) + lat->max = elapsed; - if (lat->min > elapsed) - lat->min = elapsed; + if (lat->min > elapsed) + lat->min = elapsed; - lat->total += elapsed; - lat->count++; + lat->total += elapsed; + lat->count++; out: - return; + return; } - void -gf_proc_dump_latency_info (xlator_t *xl) +gf_proc_dump_latency_info(xlator_t *xl) { - char key_prefix[GF_DUMP_MAX_BUF_LEN]; - char key[GF_DUMP_MAX_BUF_LEN]; - int i; + char key_prefix[GF_DUMP_MAX_BUF_LEN]; + char key[GF_DUMP_MAX_BUF_LEN]; + int i; - snprintf (key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.latency", xl->name); - gf_proc_dump_add_section (key_prefix); + snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.latency", xl->name); + gf_proc_dump_add_section(key_prefix); - for (i = 0; i < GF_FOP_MAXVALUE; i++) { - gf_proc_dump_build_key (key, key_prefix, "%s", - (char *)gf_fop_list[i]); + for (i = 0; i < GF_FOP_MAXVALUE; i++) { + gf_proc_dump_build_key(key, key_prefix, "%s", (char *)gf_fop_list[i]); - fop_latency_t *lat = &xl->stats.interval.latencies[i]; + fop_latency_t *lat = &xl->stats.interval.latencies[i]; - /* Doesn't make sense to continue if there are no fops - came in the given interval */ - if (!lat->count) - continue; + /* Doesn't make sense to continue if there are no fops + came in the given interval */ + if (!lat->count) + continue; - gf_proc_dump_write (key, "%.03f,%"PRId64",%.03f", - (lat->total / lat->count), lat->count, - lat->total); - } + gf_proc_dump_write(key, "%.03f,%" PRId64 ",%.03f", + (lat->total / lat->count), lat->count, lat->total); + } - memset (xl->stats.interval.latencies, 0, - sizeof (xl->stats.interval.latencies)); + memset(xl->stats.interval.latencies, 0, + sizeof(xl->stats.interval.latencies)); - /* make sure 'min' is set to high value, so it would be - properly set later */ - for (i = 0; i < GF_FOP_MAXVALUE; i++) { - xl->stats.interval.latencies[i].min = 0xffffffff; - } + /* make sure 'min' is set to high value, so it would be + properly set later */ + for (i = 0; i < GF_FOP_MAXVALUE; i++) { + xl->stats.interval.latencies[i].min = 0xffffffff; + } } - diff --git a/libglusterfs/src/locking.c b/libglusterfs/src/locking.c index f27b0d05b35..89cbaa00c8b 100644 --- a/libglusterfs/src/locking.c +++ b/libglusterfs/src/locking.c @@ -19,10 +19,9 @@ int use_spinlocks = 0; -static void __attribute__((constructor)) -gf_lock_setup (void) +static void __attribute__((constructor)) gf_lock_setup(void) { - //use_spinlocks = (sysconf(_SC_NPROCESSORS_ONLN) > 1); + // use_spinlocks = (sysconf(_SC_NPROCESSORS_ONLN) > 1); } #endif diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index a46cb234b72..61909ef4dae 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -28,14 +28,14 @@ #include "syscall.h" -#define GF_JSON_MSG_LENGTH 8192 -#define GF_SYSLOG_CEE_FORMAT \ - "@cee: {\"msg\": \"%s\", \"gf_code\": \"%u\", \"gf_message\": \"%s\"}" -#define GF_LOG_CONTROL_FILE "/etc/glusterfs/logger.conf" -#define GF_LOG_BACKTRACE_DEPTH 5 -#define GF_LOG_BACKTRACE_SIZE 4096 -#define GF_LOG_TIMESTR_SIZE 256 -#define GF_MAX_SLOG_PAIR_COUNT 100 +#define GF_JSON_MSG_LENGTH 8192 +#define GF_SYSLOG_CEE_FORMAT \ + "@cee: {\"msg\": \"%s\", \"gf_code\": \"%u\", \"gf_message\": \"%s\"}" +#define GF_LOG_CONTROL_FILE "/etc/glusterfs/logger.conf" +#define GF_LOG_BACKTRACE_DEPTH 5 +#define GF_LOG_BACKTRACE_SIZE 4096 +#define GF_LOG_TIMESTR_SIZE 256 +#define GF_MAX_SLOG_PAIR_COUNT 100 #include "xlator.h" #include "logging.h" @@ -46,147 +46,146 @@ /* Do not replace gf_log in TEST_LOG with gf_msg, as there is a slight chance * that it could lead to an infinite recursion.*/ -#define TEST_LOG(__msg, __args ...) \ - gf_log ("logging-infra", GF_LOG_DEBUG, __msg, ##__args); +#define TEST_LOG(__msg, __args...) \ + gf_log("logging-infra", GF_LOG_DEBUG, __msg, ##__args); void -gf_log_flush_timeout_cbk (void *data); +gf_log_flush_timeout_cbk(void *data); int -gf_log_inject_timer_event (glusterfs_ctx_t *ctx); +gf_log_inject_timer_event(glusterfs_ctx_t *ctx); static void -gf_log_flush_extra_msgs (glusterfs_ctx_t *ctx, uint32_t new); +gf_log_flush_extra_msgs(glusterfs_ctx_t *ctx, uint32_t new); static char *gf_level_strings[] = {"", /* NONE */ - "M", /* EMERGENCY */ - "A", /* ALERT */ - "C", /* CRITICAL */ - "E", /* ERROR */ - "W", /* WARNING */ - "N", /* NOTICE */ - "I", /* INFO */ - "D", /* DEBUG */ - "T", /* TRACE */ - "" -}; + "M", /* EMERGENCY */ + "A", /* ALERT */ + "C", /* CRITICAL */ + "E", /* ERROR */ + "W", /* WARNING */ + "N", /* NOTICE */ + "I", /* INFO */ + "D", /* DEBUG */ + "T", /* TRACE */ + ""}; /* Ideally this should get moved to logging.h */ struct _msg_queue { - struct list_head msgs; + struct list_head msgs; }; struct _log_msg { - const char *msg; - struct list_head queue; + const char *msg; + struct list_head queue; }; void -gf_log_logrotate (int signum) +gf_log_logrotate(int signum) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) { - ctx->log.logrotate = 1; - ctx->log.cmd_history_logrotate = 1; - } + if (ctx) { + ctx->log.logrotate = 1; + ctx->log.cmd_history_logrotate = 1; + } } void -gf_log_enable_syslog (void) +gf_log_enable_syslog(void) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - ctx->log.gf_log_syslog = 1; + if (ctx) + ctx->log.gf_log_syslog = 1; } void -gf_log_disable_syslog (void) +gf_log_disable_syslog(void) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - ctx->log.gf_log_syslog = 0; + if (ctx) + ctx->log.gf_log_syslog = 0; } gf_loglevel_t -gf_log_get_loglevel (void) +gf_log_get_loglevel(void) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - return ctx->log.loglevel; - else - /* return global defaults (see gf_log_globals_init) */ - return GF_LOG_INFO; + if (ctx) + return ctx->log.loglevel; + else + /* return global defaults (see gf_log_globals_init) */ + return GF_LOG_INFO; } void -gf_log_set_loglevel (glusterfs_ctx_t *ctx, gf_loglevel_t level) +gf_log_set_loglevel(glusterfs_ctx_t *ctx, gf_loglevel_t level) { - if (ctx) - ctx->log.loglevel = level; + if (ctx) + ctx->log.loglevel = level; } int -gf_log_get_localtime (void) +gf_log_get_localtime(void) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - return ctx->log.localtime; - else - /* return global defaults (see gf_log_globals_init) */ - return 0; + if (ctx) + return ctx->log.localtime; + else + /* return global defaults (see gf_log_globals_init) */ + return 0; } void -gf_log_set_localtime (int on_off) +gf_log_set_localtime(int on_off) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - ctx->log.localtime = on_off; + if (ctx) + ctx->log.localtime = on_off; } void -gf_log_flush (void) +gf_log_flush(void) { - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; - this = THIS; - ctx = this->ctx; + this = THIS; + ctx = this->ctx; - if (ctx && ctx->log.logger == gf_logger_glusterlog) { - pthread_mutex_lock (&ctx->log.logfile_mutex); - fflush (ctx->log.gf_log_logfile); - pthread_mutex_unlock (&ctx->log.logfile_mutex); - } + if (ctx && ctx->log.logger == gf_logger_glusterlog) { + pthread_mutex_lock(&ctx->log.logfile_mutex); + fflush(ctx->log.gf_log_logfile); + pthread_mutex_unlock(&ctx->log.logfile_mutex); + } - return; + return; } void -gf_log_set_xl_loglevel (void *this, gf_loglevel_t level) +gf_log_set_xl_loglevel(void *this, gf_loglevel_t level) { - xlator_t *xl = this; - if (!xl) - return; - xl->loglevel = level; + xlator_t *xl = this; + if (!xl) + return; + xl->loglevel = level; } /* TODO: The following get/set functions are yet not invoked from anywhere @@ -207,104 +206,104 @@ gf_log_set_xl_loglevel (void *this, gf_loglevel_t level) * care needs to be taken to configure and start daemons based on the versions * that supports these features */ gf_log_format_t -gf_log_get_logformat (void) +gf_log_get_logformat(void) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - return ctx->log.logformat; - else - /* return global defaluts (see gf_log_globals_init) */ - return gf_logformat_withmsgid; + if (ctx) + return ctx->log.logformat; + else + /* return global defaluts (see gf_log_globals_init) */ + return gf_logformat_withmsgid; } void -gf_log_set_logformat (gf_log_format_t format) +gf_log_set_logformat(gf_log_format_t format) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - ctx->log.logformat = format; + if (ctx) + ctx->log.logformat = format; } gf_log_logger_t -gf_log_get_logger (void) +gf_log_get_logger(void) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - return ctx->log.logger; - else - /* return global defaluts (see gf_log_globals_init) */ - return gf_logger_glusterlog; + if (ctx) + return ctx->log.logger; + else + /* return global defaluts (see gf_log_globals_init) */ + return gf_logger_glusterlog; } void -gf_log_set_logger (gf_log_logger_t logger) +gf_log_set_logger(gf_log_logger_t logger) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - ctx->log.logger = logger; + if (ctx) + ctx->log.logger = logger; } gf_loglevel_t -gf_log_get_xl_loglevel (void *this) +gf_log_get_xl_loglevel(void *this) { - xlator_t *xl = this; - if (!xl) - return 0; - return xl->loglevel; + xlator_t *xl = this; + if (!xl) + return 0; + return xl->loglevel; } void -gf_log_set_log_buf_size (uint32_t buf_size) +gf_log_set_log_buf_size(uint32_t buf_size) { - uint32_t old = 0; - glusterfs_ctx_t *ctx = THIS->ctx; - - pthread_mutex_lock (&ctx->log.log_buf_lock); - { - old = ctx->log.lru_size; - ctx->log.lru_size = buf_size; - } - pthread_mutex_unlock (&ctx->log.log_buf_lock); - - /* If the old size is less than/equal to the new size, then do nothing. - * - * But if the new size is less than the old size, then - * a. If the cur size of the buf is less than or equal the new size, - * then do nothing. - * b. But if the current size of the buf is greater than the new size, - * then flush the least recently used (cur size - new_size) msgs - * to disk. - */ - if (buf_size < old) - gf_log_flush_extra_msgs (ctx, buf_size); + uint32_t old = 0; + glusterfs_ctx_t *ctx = THIS->ctx; + + pthread_mutex_lock(&ctx->log.log_buf_lock); + { + old = ctx->log.lru_size; + ctx->log.lru_size = buf_size; + } + pthread_mutex_unlock(&ctx->log.log_buf_lock); + + /* If the old size is less than/equal to the new size, then do nothing. + * + * But if the new size is less than the old size, then + * a. If the cur size of the buf is less than or equal the new size, + * then do nothing. + * b. But if the current size of the buf is greater than the new size, + * then flush the least recently used (cur size - new_size) msgs + * to disk. + */ + if (buf_size < old) + gf_log_flush_extra_msgs(ctx, buf_size); } void -gf_log_set_log_flush_timeout (uint32_t timeout) +gf_log_set_log_flush_timeout(uint32_t timeout) { - THIS->ctx->log.timeout = timeout; + THIS->ctx->log.timeout = timeout; } log_buf_t * -log_buf_new () +log_buf_new() { - log_buf_t *buf = NULL; + log_buf_t *buf = NULL; - buf = mem_get0 (THIS->ctx->logbuf_pool); + buf = mem_get0(THIS->ctx->logbuf_pool); - return buf; + return buf; } /* If log_buf_init() fails (indicated by a return value of -1), @@ -312,147 +311,145 @@ log_buf_new () * the log_buf_t object back to its memory pool. */ int -log_buf_init (log_buf_t *buf, const char *domain, const char *file, - const char *function, int32_t line, gf_loglevel_t level, - int errnum, uint64_t msgid, char **appmsgstr, int graph_id) +log_buf_init(log_buf_t *buf, const char *domain, const char *file, + const char *function, int32_t line, gf_loglevel_t level, + int errnum, uint64_t msgid, char **appmsgstr, int graph_id) { - int ret = -1; + int ret = -1; - if (!buf || !domain || !file || !function || !appmsgstr || !*appmsgstr) - goto out; + if (!buf || !domain || !file || !function || !appmsgstr || !*appmsgstr) + goto out; - buf->msg = gf_strdup (*appmsgstr); - if (!buf->msg) - goto out; + buf->msg = gf_strdup(*appmsgstr); + if (!buf->msg) + goto out; - buf->msg_id = msgid; - buf->errnum = errnum; - buf->domain = gf_strdup (domain); - if (!buf->domain) - goto out; + buf->msg_id = msgid; + buf->errnum = errnum; + buf->domain = gf_strdup(domain); + if (!buf->domain) + goto out; - buf->file = gf_strdup (file); - if (!buf->file) - goto out; + buf->file = gf_strdup(file); + if (!buf->file) + goto out; - buf->function = gf_strdup (function); - if (!buf->function) - goto out; + buf->function = gf_strdup(function); + if (!buf->function) + goto out; - buf->line = line; - buf->level = level; - buf->refcount = 0; - buf->graph_id = graph_id; - INIT_LIST_HEAD (&buf->msg_list); + buf->line = line; + buf->level = level; + buf->refcount = 0; + buf->graph_id = graph_id; + INIT_LIST_HEAD(&buf->msg_list); - ret = 0; + ret = 0; out: - return ret; + return ret; } int -log_buf_destroy (log_buf_t *buf) +log_buf_destroy(log_buf_t *buf) { + if (!buf) + return -1; - if (!buf) - return -1; - - GF_FREE (buf->msg); - GF_FREE (buf->domain); - GF_FREE (buf->file); - GF_FREE (buf->function); + GF_FREE(buf->msg); + GF_FREE(buf->domain); + GF_FREE(buf->file); + GF_FREE(buf->function); - mem_put (buf); - return 0; + mem_put(buf); + return 0; } static void gf_log_rotate(glusterfs_ctx_t *ctx) { - int fd = -1; - FILE *new_logfile = NULL; - FILE *old_logfile = NULL; - - /* not involving locks on initial check to speed it up */ - if (ctx->log.logrotate) { - /* let only one winner through on races */ - pthread_mutex_lock (&ctx->log.logfile_mutex); - - if (!ctx->log.logrotate) { - pthread_mutex_unlock (&ctx->log.logfile_mutex); - return; - } else { - ctx->log.logrotate = 0; - pthread_mutex_unlock (&ctx->log.logfile_mutex); - } - - fd = sys_open (ctx->log.filename, O_CREAT | O_WRONLY | O_APPEND, - S_IRUSR | S_IWUSR); - if (fd < 0) { - gf_msg ("logrotate", GF_LOG_ERROR, errno, - LG_MSG_FILE_OP_FAILED, "failed to open " - "logfile"); - return; - } + int fd = -1; + FILE *new_logfile = NULL; + FILE *old_logfile = NULL; + + /* not involving locks on initial check to speed it up */ + if (ctx->log.logrotate) { + /* let only one winner through on races */ + pthread_mutex_lock(&ctx->log.logfile_mutex); + + if (!ctx->log.logrotate) { + pthread_mutex_unlock(&ctx->log.logfile_mutex); + return; + } else { + ctx->log.logrotate = 0; + pthread_mutex_unlock(&ctx->log.logfile_mutex); + } - new_logfile = fdopen (fd, "a"); - if (!new_logfile) { - gf_msg ("logrotate", GF_LOG_CRITICAL, errno, - LG_MSG_FILE_OP_FAILED, "failed to open logfile" - " %s", ctx->log.filename); - sys_close (fd); - return; - } + fd = sys_open(ctx->log.filename, O_CREAT | O_WRONLY | O_APPEND, + S_IRUSR | S_IWUSR); + if (fd < 0) { + gf_msg("logrotate", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "failed to open " + "logfile"); + return; + } - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) - old_logfile = ctx->log.logfile; + new_logfile = fdopen(fd, "a"); + if (!new_logfile) { + gf_msg("logrotate", GF_LOG_CRITICAL, errno, LG_MSG_FILE_OP_FAILED, + "failed to open logfile" + " %s", + ctx->log.filename); + sys_close(fd); + return; + } - ctx->log.gf_log_logfile = ctx->log.logfile = - new_logfile; - } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) + old_logfile = ctx->log.logfile; - if (old_logfile != NULL) - fclose (old_logfile); + ctx->log.gf_log_logfile = ctx->log.logfile = new_logfile; } + pthread_mutex_unlock(&ctx->log.logfile_mutex); - return; + if (old_logfile != NULL) + fclose(old_logfile); + } + + return; } void -gf_log_globals_fini (void) +gf_log_globals_fini(void) { - /* TODO: Nobody is invoking the fini, but cleanup needs to happen here, - * needs cleanup for, log.ident, log.filename, closelog, log file close - * rotate state, possibly under a lock */ - pthread_mutex_destroy (&THIS->ctx->log.logfile_mutex); - pthread_mutex_destroy (&THIS->ctx->log.log_buf_lock); + /* TODO: Nobody is invoking the fini, but cleanup needs to happen here, + * needs cleanup for, log.ident, log.filename, closelog, log file close + * rotate state, possibly under a lock */ + pthread_mutex_destroy(&THIS->ctx->log.logfile_mutex); + pthread_mutex_destroy(&THIS->ctx->log.log_buf_lock); } void -gf_log_disable_suppression_before_exit (glusterfs_ctx_t *ctx) +gf_log_disable_suppression_before_exit(glusterfs_ctx_t *ctx) { - /* - * First set log buf size to 0. This would ensure two things: - * i. that all outstanding log messages are flushed to disk, and - * ii. all subsequent calls to gf_msg will result in the logs getting - * directly flushed to disk without being buffered. - * - * Then, cancel the current log timer event. - */ - - gf_log_set_log_buf_size (0); - pthread_mutex_lock (&ctx->log.log_buf_lock); - { - if (ctx->log.log_flush_timer) { - gf_timer_call_cancel (ctx, ctx->log.log_flush_timer); - ctx->log.log_flush_timer = NULL; - } + /* + * First set log buf size to 0. This would ensure two things: + * i. that all outstanding log messages are flushed to disk, and + * ii. all subsequent calls to gf_msg will result in the logs getting + * directly flushed to disk without being buffered. + * + * Then, cancel the current log timer event. + */ + + gf_log_set_log_buf_size(0); + pthread_mutex_lock(&ctx->log.log_buf_lock); + { + if (ctx->log.log_flush_timer) { + gf_timer_call_cancel(ctx, ctx->log.log_flush_timer); + ctx->log.log_flush_timer = NULL; } - pthread_mutex_unlock (&ctx->log.log_buf_lock); - + } + pthread_mutex_unlock(&ctx->log.log_buf_lock); } /** gf_log_fini - function to perform the cleanup of the log information @@ -461,45 +458,44 @@ gf_log_disable_suppression_before_exit (glusterfs_ctx_t *ctx) * failure: -1 */ int -gf_log_fini (void *data) +gf_log_fini(void *data) { - glusterfs_ctx_t *ctx = data; - int ret = 0; - FILE *old_logfile = NULL; + glusterfs_ctx_t *ctx = data; + int ret = 0; + FILE *old_logfile = NULL; - if (ctx == NULL) { - ret = -1; - goto out; - } + if (ctx == NULL) { + ret = -1; + goto out; + } - gf_log_disable_suppression_before_exit (ctx); + gf_log_disable_suppression_before_exit(ctx); - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) { - old_logfile = ctx->log.logfile; - - /* Logfile needs to be set to NULL, so that any - call to gf_log after calling gf_log_fini, will - log the message to stderr. - */ - ctx->log.loglevel = GF_LOG_NONE; - ctx->log.logfile = NULL; - } + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + old_logfile = ctx->log.logfile; + + /* Logfile needs to be set to NULL, so that any + call to gf_log after calling gf_log_fini, will + log the message to stderr. + */ + ctx->log.loglevel = GF_LOG_NONE; + ctx->log.logfile = NULL; } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + } + pthread_mutex_unlock(&ctx->log.logfile_mutex); - if (old_logfile && (fclose (old_logfile) != 0)) - ret = -1; + if (old_logfile && (fclose(old_logfile) != 0)) + ret = -1; - GF_FREE (ctx->log.ident); - GF_FREE (ctx->log.filename); + GF_FREE(ctx->log.ident); + GF_FREE(ctx->log.filename); - out: - return ret; +out: + return ret; } - /** * gf_openlog -function to open syslog specific to gluster based on * existence of file /etc/glusterfs/logger.conf @@ -512,27 +508,26 @@ gf_log_fini (void *data) * @return: void */ void -gf_openlog (const char *ident, int option, int facility) +gf_openlog(const char *ident, int option, int facility) { - int _option = option; - int _facility = facility; - - if (-1 == _option) { - _option = LOG_PID | LOG_NDELAY; - } - if (-1 == _facility) { - _facility = LOG_LOCAL1; - } - - /* TODO: Should check for errors here and return appropriately */ - setlocale(LC_ALL, ""); - setlocale(LC_NUMERIC, "C"); /* C-locale for strtod, ... */ - /* close the previous syslog if open as we are changing settings */ - closelog (); - openlog(ident, _option, _facility); + int _option = option; + int _facility = facility; + + if (-1 == _option) { + _option = LOG_PID | LOG_NDELAY; + } + if (-1 == _facility) { + _facility = LOG_LOCAL1; + } + + /* TODO: Should check for errors here and return appropriately */ + setlocale(LC_ALL, ""); + setlocale(LC_NUMERIC, "C"); /* C-locale for strtod, ... */ + /* close the previous syslog if open as we are changing settings */ + closelog(); + openlog(ident, _option, _facility); } - /** * _json_escape -function to convert string to json encoded string * @str: input string @@ -559,85 +554,75 @@ gf_openlog (const char *ident, int option, int facility) char * _json_escape(const char *str, char *buf, size_t len) { - static const unsigned char json_exceptions[UCHAR_MAX + 1] = - { - [0x01] = 1, [0x02] = 1, [0x03] = 1, [0x04] = 1, - [0x05] = 1, [0x06] = 1, [0x07] = 1, [0x08] = 1, - [0x09] = 1, [0x0a] = 1, [0x0b] = 1, [0x0c] = 1, - [0x0d] = 1, [0x0e] = 1, [0x0f] = 1, [0x10] = 1, - [0x11] = 1, [0x12] = 1, [0x13] = 1, [0x14] = 1, - [0x15] = 1, [0x16] = 1, [0x17] = 1, [0x18] = 1, - [0x19] = 1, [0x1a] = 1, [0x1b] = 1, [0x1c] = 1, - [0x1d] = 1, [0x1e] = 1, [0x1f] = 1, - ['\\'] = 1, ['"'] = 1 - }; - static const char json_hex_chars[16] = "0123456789abcdef"; - unsigned char *p = NULL; - size_t pos = 0; - - if (!str || !buf || len <= 0) { - return NULL; - } - - for (p = (unsigned char *)str; - *p && (pos + 1) < len; - p++) - { - if (json_exceptions[*p] == 0) { - buf[pos++] = *p; - continue; - } - - if ((pos + 2) >= len) { - break; - } - - switch (*p) - { - case '\b': - buf[pos++] = '\\'; - buf[pos++] = 'b'; - break; - case '\n': - buf[pos++] = '\\'; - buf[pos++] = 'n'; - break; - case '\r': - buf[pos++] = '\\'; - buf[pos++] = 'r'; - break; - case '\t': - buf[pos++] = '\\'; - buf[pos++] = 't'; - break; - case '\\': - buf[pos++] = '\\'; - buf[pos++] = '\\'; - break; - case '"': - buf[pos++] = '\\'; - buf[pos++] = '"'; - break; - default: - if ((pos + 6) >= len) { - buf[pos] = '\0'; - return (char *)p; - } - buf[pos++] = '\\'; - buf[pos++] = 'u'; - buf[pos++] = '0'; - buf[pos++] = '0'; - buf[pos++] = json_hex_chars[(*p) >> 4]; - buf[pos++] = json_hex_chars[(*p) & 0xf]; - break; + static const unsigned char json_exceptions[UCHAR_MAX + 1] = { + [0x01] = 1, [0x02] = 1, [0x03] = 1, [0x04] = 1, [0x05] = 1, [0x06] = 1, + [0x07] = 1, [0x08] = 1, [0x09] = 1, [0x0a] = 1, [0x0b] = 1, [0x0c] = 1, + [0x0d] = 1, [0x0e] = 1, [0x0f] = 1, [0x10] = 1, [0x11] = 1, [0x12] = 1, + [0x13] = 1, [0x14] = 1, [0x15] = 1, [0x16] = 1, [0x17] = 1, [0x18] = 1, + [0x19] = 1, [0x1a] = 1, [0x1b] = 1, [0x1c] = 1, [0x1d] = 1, [0x1e] = 1, + [0x1f] = 1, ['\\'] = 1, ['"'] = 1}; + static const char json_hex_chars[16] = "0123456789abcdef"; + unsigned char *p = NULL; + size_t pos = 0; + + if (!str || !buf || len <= 0) { + return NULL; + } + + for (p = (unsigned char *)str; *p && (pos + 1) < len; p++) { + if (json_exceptions[*p] == 0) { + buf[pos++] = *p; + continue; + } + + if ((pos + 2) >= len) { + break; + } + + switch (*p) { + case '\b': + buf[pos++] = '\\'; + buf[pos++] = 'b'; + break; + case '\n': + buf[pos++] = '\\'; + buf[pos++] = 'n'; + break; + case '\r': + buf[pos++] = '\\'; + buf[pos++] = 'r'; + break; + case '\t': + buf[pos++] = '\\'; + buf[pos++] = 't'; + break; + case '\\': + buf[pos++] = '\\'; + buf[pos++] = '\\'; + break; + case '"': + buf[pos++] = '\\'; + buf[pos++] = '"'; + break; + default: + if ((pos + 6) >= len) { + buf[pos] = '\0'; + return (char *)p; } + buf[pos++] = '\\'; + buf[pos++] = 'u'; + buf[pos++] = '0'; + buf[pos++] = '0'; + buf[pos++] = json_hex_chars[(*p) >> 4]; + buf[pos++] = json_hex_chars[(*p) & 0xf]; + break; } + } - buf[pos] = '\0'; - return (char *)p; + buf[pos] = '\0'; + return (char *)p; } - /** * gf_syslog -function to submit message to syslog specific to gluster * @facility_priority: facility_priority of syslog() @@ -646,158 +631,162 @@ _json_escape(const char *str, char *buf, size_t len) * @return: void */ void -gf_syslog (int facility_priority, char *format, ...) +gf_syslog(int facility_priority, char *format, ...) { - char *msg = NULL; - char json_msg[GF_JSON_MSG_LENGTH]; - GF_UNUSED char *p = NULL; - va_list ap; - - GF_ASSERT (format); - - va_start (ap, format); - if (vasprintf (&msg, format, ap) != -1) { - p = _json_escape (msg, json_msg, GF_JSON_MSG_LENGTH); - syslog (facility_priority, "%s", msg); - free (msg); - } else - syslog (GF_LOG_CRITICAL, "vasprintf() failed, out of memory?"); - va_end (ap); + char *msg = NULL; + char json_msg[GF_JSON_MSG_LENGTH]; + GF_UNUSED char *p = NULL; + va_list ap; + + GF_ASSERT(format); + + va_start(ap, format); + if (vasprintf(&msg, format, ap) != -1) { + p = _json_escape(msg, json_msg, GF_JSON_MSG_LENGTH); + syslog(facility_priority, "%s", msg); + free(msg); + } else + syslog(GF_LOG_CRITICAL, "vasprintf() failed, out of memory?"); + va_end(ap); } void -gf_log_globals_init (void *data, gf_loglevel_t level) +gf_log_globals_init(void *data, gf_loglevel_t level) { - glusterfs_ctx_t *ctx = data; + glusterfs_ctx_t *ctx = data; - pthread_mutex_init (&ctx->log.logfile_mutex, NULL); + pthread_mutex_init(&ctx->log.logfile_mutex, NULL); - ctx->log.loglevel = level; - ctx->log.gf_log_syslog = 1; - ctx->log.sys_log_level = GF_LOG_CRITICAL; - ctx->log.logger = gf_logger_glusterlog; - ctx->log.logformat = gf_logformat_withmsgid; - ctx->log.lru_size = GF_LOG_LRU_BUFSIZE_DEFAULT; - ctx->log.timeout = GF_LOG_FLUSH_TIMEOUT_DEFAULT; - ctx->log.localtime = GF_LOG_LOCALTIME_DEFAULT; + ctx->log.loglevel = level; + ctx->log.gf_log_syslog = 1; + ctx->log.sys_log_level = GF_LOG_CRITICAL; + ctx->log.logger = gf_logger_glusterlog; + ctx->log.logformat = gf_logformat_withmsgid; + ctx->log.lru_size = GF_LOG_LRU_BUFSIZE_DEFAULT; + ctx->log.timeout = GF_LOG_FLUSH_TIMEOUT_DEFAULT; + ctx->log.localtime = GF_LOG_LOCALTIME_DEFAULT; - pthread_mutex_init (&ctx->log.log_buf_lock, NULL); + pthread_mutex_init(&ctx->log.log_buf_lock, NULL); - INIT_LIST_HEAD (&ctx->log.lru_queue); + INIT_LIST_HEAD(&ctx->log.lru_queue); #ifdef GF_LINUX_HOST_OS - /* For the 'syslog' output. one can grep 'GlusterFS' in syslog - for serious logs */ - openlog ("GlusterFS", LOG_PID, LOG_DAEMON); + /* For the 'syslog' output. one can grep 'GlusterFS' in syslog + for serious logs */ + openlog("GlusterFS", LOG_PID, LOG_DAEMON); #endif - } int -gf_log_init (void *data, const char *file, const char *ident) +gf_log_init(void *data, const char *file, const char *ident) { - glusterfs_ctx_t *ctx = NULL; - int fd = -1; - struct stat buf; - - ctx = data; - - if (ctx == NULL) { - fprintf (stderr, "ERROR: ctx is NULL\n"); - return -1; - } - if (ident) { - GF_FREE (ctx->log.ident); - ctx->log.ident = gf_strdup (ident); - } - - /* we keep the files and the syslog open, so that on logger change, we - * are ready to log anywhere, that the new value specifies */ - if (ctx->log.ident) { - gf_openlog (ctx->log.ident, -1, LOG_DAEMON); - } else { - gf_openlog (NULL, -1, LOG_DAEMON); - } - /* TODO: make FACILITY configurable than LOG_DAEMON */ - if (sys_stat (GF_LOG_CONTROL_FILE, &buf) == 0) { - /* use syslog logging */ - ctx->log.log_control_file_found = 1; - } else { - /* use old style logging */ - ctx->log.log_control_file_found = 0; + glusterfs_ctx_t *ctx = NULL; + int fd = -1; + struct stat buf; + + ctx = data; + + if (ctx == NULL) { + fprintf(stderr, "ERROR: ctx is NULL\n"); + return -1; + } + if (ident) { + GF_FREE(ctx->log.ident); + ctx->log.ident = gf_strdup(ident); + } + + /* we keep the files and the syslog open, so that on logger change, we + * are ready to log anywhere, that the new value specifies */ + if (ctx->log.ident) { + gf_openlog(ctx->log.ident, -1, LOG_DAEMON); + } else { + gf_openlog(NULL, -1, LOG_DAEMON); + } + /* TODO: make FACILITY configurable than LOG_DAEMON */ + if (sys_stat(GF_LOG_CONTROL_FILE, &buf) == 0) { + /* use syslog logging */ + ctx->log.log_control_file_found = 1; + } else { + /* use old style logging */ + ctx->log.log_control_file_found = 0; + } + + if (!file) { + fprintf(stderr, "ERROR: no filename specified\n"); + return -1; + } + + /* free the (possible) previous filename */ + GF_FREE(ctx->log.filename); + ctx->log.filename = NULL; + + if (strcmp(file, "-") == 0) { + int dupfd = -1; + + ctx->log.filename = gf_strdup("/dev/stderr"); + if (!ctx->log.filename) { + fprintf(stderr, "ERROR: strdup failed\n"); + return -1; + } + + dupfd = dup(fileno(stderr)); + if (dupfd == -1) { + fprintf(stderr, "ERROR: could not dup %d (%s)\n", fileno(stderr), + strerror(errno)); + return -1; + } + + ctx->log.logfile = fdopen(dupfd, "a"); + if (!ctx->log.logfile) { + fprintf(stderr, "ERROR: could not fdopen on %d (%s)\n", dupfd, + strerror(errno)); + sys_close(dupfd); + return -1; + } + } else { + ctx->log.filename = gf_strdup(file); + if (!ctx->log.filename) { + fprintf(stderr, + "ERROR: updating log-filename failed: " + "%s\n", + strerror(errno)); + return -1; + } + + fd = sys_open(file, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR); + if (fd < 0) { + fprintf(stderr, + "ERROR: failed to create logfile" + " \"%s\" (%s)\n", + file, strerror(errno)); + return -1; } - if (!file) { - fprintf (stderr, "ERROR: no filename specified\n"); - return -1; + ctx->log.logfile = fdopen(fd, "a"); + if (!ctx->log.logfile) { + fprintf(stderr, + "ERROR: failed to open logfile \"%s\" " + "(%s)\n", + file, strerror(errno)); + sys_close(fd); + return -1; } + } - /* free the (possible) previous filename */ - GF_FREE (ctx->log.filename); - ctx->log.filename = NULL; - - if (strcmp (file, "-") == 0) { - int dupfd = -1; - - ctx->log.filename = gf_strdup ("/dev/stderr"); - if (!ctx->log.filename) { - fprintf (stderr, "ERROR: strdup failed\n"); - return -1; - } - - dupfd = dup (fileno (stderr)); - if (dupfd == -1) { - fprintf (stderr, "ERROR: could not dup %d (%s)\n", - fileno (stderr), strerror (errno)); - return -1; - } - - ctx->log.logfile = fdopen (dupfd, "a"); - if (!ctx->log.logfile) { - fprintf (stderr, "ERROR: could not fdopen on %d (%s)\n", - dupfd, strerror (errno)); - sys_close (dupfd); - return -1; - } - } else { - ctx->log.filename = gf_strdup (file); - if (!ctx->log.filename) { - fprintf (stderr, "ERROR: updating log-filename failed: " - "%s\n", strerror (errno)); - return -1; - } - - fd = sys_open (file, O_CREAT | O_WRONLY | O_APPEND, - S_IRUSR | S_IWUSR); - if (fd < 0) { - fprintf (stderr, "ERROR: failed to create logfile" - " \"%s\" (%s)\n", file, strerror (errno)); - return -1; - } + ctx->log.gf_log_logfile = ctx->log.logfile; - ctx->log.logfile = fdopen (fd, "a"); - if (!ctx->log.logfile) { - fprintf (stderr, "ERROR: failed to open logfile \"%s\" " - "(%s)\n", file, strerror (errno)); - sys_close (fd); - return -1; - } - } - - ctx->log.gf_log_logfile = ctx->log.logfile; - - return 0; + return 0; } void -set_sys_log_level (gf_loglevel_t level) +set_sys_log_level(gf_loglevel_t level) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = THIS->ctx; + ctx = THIS->ctx; - if (ctx) - ctx->log.sys_log_level = level; + if (ctx) + ctx->log.sys_log_level = level; } /* Check if we should be logging @@ -805,1844 +794,1857 @@ set_sys_log_level (gf_loglevel_t level) * _gf_true : Do not Print the log */ static gf_boolean_t -skip_logging (xlator_t *this, gf_loglevel_t level) +skip_logging(xlator_t *this, gf_loglevel_t level) { - gf_boolean_t ret = _gf_false; - gf_loglevel_t existing_level = GF_LOG_NONE; - - if (level == GF_LOG_NONE) { - ret = _gf_true; - goto out; - } - - existing_level = this->loglevel ? this->loglevel : this->ctx->log.loglevel; - if (level > existing_level) { - ret = _gf_true; - goto out; - } + gf_boolean_t ret = _gf_false; + gf_loglevel_t existing_level = GF_LOG_NONE; + + if (level == GF_LOG_NONE) { + ret = _gf_true; + goto out; + } + + existing_level = this->loglevel ? this->loglevel : this->ctx->log.loglevel; + if (level > existing_level) { + ret = _gf_true; + goto out; + } out: - return ret; + return ret; } int -_gf_log_callingfn (const char *domain, const char *file, const char *function, - int line, gf_loglevel_t level, const char *fmt, ...) +_gf_log_callingfn(const char *domain, const char *file, const char *function, + int line, gf_loglevel_t level, const char *fmt, ...) { - const char *basename = NULL; - xlator_t *this = NULL; - char *str1 = NULL; - char *str2 = NULL; - char *msg = NULL; - char timestr[256] = {0,}; - char *callstr = NULL; - struct timeval tv = {0,}; - size_t len = 0; - int ret = 0; - va_list ap; - glusterfs_ctx_t *ctx = NULL; - - this = THIS; - ctx = this->ctx; - - if (!ctx) - goto out; - - if (skip_logging (this, level)) - goto out; - - static char *level_strings[] = {"", /* NONE */ - "M", /* EMERGENCY */ - "A", /* ALERT */ - "C", /* CRITICAL */ - "E", /* ERROR */ - "W", /* WARNING */ - "N", /* NOTICE */ - "I", /* INFO */ - "D", /* DEBUG */ - "T", /* TRACE */ - ""}; - - if (!domain || !file || !function || !fmt) { - fprintf (stderr, - "logging: %s:%s():%d: invalid argument\n", - __FILE__, __PRETTY_FUNCTION__, __LINE__); - return -1; + const char *basename = NULL; + xlator_t *this = NULL; + char *str1 = NULL; + char *str2 = NULL; + char *msg = NULL; + char timestr[256] = { + 0, + }; + char *callstr = NULL; + struct timeval tv = { + 0, + }; + size_t len = 0; + int ret = 0; + va_list ap; + glusterfs_ctx_t *ctx = NULL; + + this = THIS; + ctx = this->ctx; + + if (!ctx) + goto out; + + if (skip_logging(this, level)) + goto out; + + static char *level_strings[] = {"", /* NONE */ + "M", /* EMERGENCY */ + "A", /* ALERT */ + "C", /* CRITICAL */ + "E", /* ERROR */ + "W", /* WARNING */ + "N", /* NOTICE */ + "I", /* INFO */ + "D", /* DEBUG */ + "T", /* TRACE */ + ""}; + + if (!domain || !file || !function || !fmt) { + fprintf(stderr, "logging: %s:%s():%d: invalid argument\n", __FILE__, + __PRETTY_FUNCTION__, __LINE__); + return -1; + } + + basename = strrchr(file, '/'); + if (basename) + basename++; + else + basename = file; + + /*Saving the backtrace to pre-allocated ctx->btbuf + * to avoid allocating memory from the heap*/ + callstr = gf_backtrace_save(NULL); + + if (ctx->log.log_control_file_found) { + int priority; + /* treat GF_LOG_TRACE and GF_LOG_NONE as LOG_DEBUG and + other level as is */ + if (GF_LOG_TRACE == level || GF_LOG_NONE == level) { + priority = LOG_DEBUG; + } else { + priority = level - 1; } - basename = strrchr (file, '/'); - if (basename) - basename++; - else - basename = file; + va_start(ap, fmt); + vasprintf(&str2, fmt, ap); + va_end(ap); - /*Saving the backtrace to pre-allocated ctx->btbuf - * to avoid allocating memory from the heap*/ - callstr = gf_backtrace_save (NULL); + gf_syslog(priority, "[%s:%d:%s] %s %d-%s: %s", basename, line, function, + callstr, ((this->graph) ? this->graph->id : 0), domain, str2); - if (ctx->log.log_control_file_found) - { - int priority; - /* treat GF_LOG_TRACE and GF_LOG_NONE as LOG_DEBUG and - other level as is */ - if (GF_LOG_TRACE == level || GF_LOG_NONE == level) { - priority = LOG_DEBUG; - } else { - priority = level - 1; - } + goto out; + } - va_start (ap, fmt); - vasprintf (&str2, fmt, ap); - va_end (ap); + ret = gettimeofday(&tv, NULL); + if (-1 == ret) + goto out; + va_start(ap, fmt); + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + snprintf(timestr + strlen(timestr), sizeof timestr - strlen(timestr), + ".%" GF_PRI_SUSECONDS, tv.tv_usec); - gf_syslog (priority, "[%s:%d:%s] %s %d-%s: %s", - basename, line, function, - callstr, - ((this->graph) ? this->graph->id:0), domain, - str2); + ret = gf_asprintf(&str1, "[%s] %s [%s:%d:%s] %s %d-%s: ", timestr, + level_strings[level], basename, line, function, callstr, + ((this->graph) ? this->graph->id : 0), domain); + if (-1 == ret) { + goto out; + } - goto out; - } + ret = vasprintf(&str2, fmt, ap); + if (-1 == ret) { + goto out; + } - ret = gettimeofday (&tv, NULL); - if (-1 == ret) - goto out; - va_start (ap, fmt); - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr), - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - - ret = gf_asprintf (&str1, "[%s] %s [%s:%d:%s] %s %d-%s: ", - timestr, level_strings[level], - basename, line, function, callstr, - ((this->graph) ? this->graph->id:0), domain); - if (-1 == ret) { - goto out; - } + va_end(ap); - ret = vasprintf (&str2, fmt, ap); - if (-1 == ret) { - goto out; - } + len = strlen(str1); + msg = GF_MALLOC(len + strlen(str2) + 1, gf_common_mt_char); + if (!msg) { + ret = -1; + goto out; + } - va_end (ap); + strcpy(msg, str1); + strcpy(msg + len, str2); - len = strlen (str1); - msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char); - if (!msg) { - ret = -1; - goto out; + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + fprintf(ctx->log.logfile, "%s\n", msg); + fflush(ctx->log.logfile); + } else if (ctx->log.loglevel >= level) { + fprintf(stderr, "%s\n", msg); + fflush(stderr); } - strcpy (msg, str1); - strcpy (msg + len, str2); - - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) { - fprintf (ctx->log.logfile, "%s\n", msg); - fflush (ctx->log.logfile); - } else if (ctx->log.loglevel >= level) { - fprintf (stderr, "%s\n", msg); - fflush (stderr); - } - #ifdef GF_LINUX_HOST_OS - /* We want only serious log in 'syslog', not our debug - and trace logs */ - if (ctx->log.gf_log_syslog && level && - (level <= ctx->log.sys_log_level)) - syslog ((level-1), "%s\n", msg); + /* We want only serious log in 'syslog', not our debug + and trace logs */ + if (ctx->log.gf_log_syslog && level && + (level <= ctx->log.sys_log_level)) + syslog((level - 1), "%s\n", msg); #endif - } + } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + pthread_mutex_unlock(&ctx->log.logfile_mutex); out: - GF_FREE (msg); + GF_FREE(msg); - GF_FREE (str1); + GF_FREE(str1); - FREE (str2); + FREE(str2); - va_end (ap); + va_end(ap); - return ret; + return ret; } int -_gf_msg_plain_internal (gf_loglevel_t level, const char *msg) +_gf_msg_plain_internal(gf_loglevel_t level, const char *msg) { - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - int priority; + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + int priority; - this = THIS; - ctx = this->ctx; + this = THIS; + ctx = this->ctx; - /* log to the configured logging service */ - switch (ctx->log.logger) { + /* log to the configured logging service */ + switch (ctx->log.logger) { case gf_logger_syslog: - if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { - SET_LOG_PRIO (level, priority); + if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { + SET_LOG_PRIO(level, priority); - syslog (priority, "%s", msg); - break; - } - /* NOTE: If syslog control file is absent, which is another - * way to control logging to syslog, then we will fall through - * to the gluster log. The ideal way to do things would be to - * not have the extra control file check */ + syslog(priority, "%s", msg); + break; + } + /* NOTE: If syslog control file is absent, which is another + * way to control logging to syslog, then we will fall through + * to the gluster log. The ideal way to do things would be to + * not have the extra control file check */ case gf_logger_glusterlog: - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) { - fprintf (ctx->log.logfile, "%s\n", msg); - fflush (ctx->log.logfile); - } else { - fprintf (stderr, "%s\n", msg); - fflush (stderr); - } + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + fprintf(ctx->log.logfile, "%s\n", msg); + fflush(ctx->log.logfile); + } else { + fprintf(stderr, "%s\n", msg); + fflush(stderr); + } #ifdef GF_LINUX_HOST_OS - /* We want only serious logs in 'syslog', not our debug - * and trace logs */ - if (ctx->log.gf_log_syslog && level && - (level <= ctx->log.sys_log_level)) - syslog ((level-1), "%s\n", msg); + /* We want only serious logs in 'syslog', not our debug + * and trace logs */ + if (ctx->log.gf_log_syslog && level && + (level <= ctx->log.sys_log_level)) + syslog((level - 1), "%s\n", msg); #endif - } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + } + pthread_mutex_unlock(&ctx->log.logfile_mutex); - break; - } + break; + } - return 0; + return 0; } int -_gf_msg_plain (gf_loglevel_t level, const char *fmt, ...) +_gf_msg_plain(gf_loglevel_t level, const char *fmt, ...) { - xlator_t *this = NULL; - int ret = 0; - va_list ap; - char *msg = NULL; - glusterfs_ctx_t *ctx = NULL; + xlator_t *this = NULL; + int ret = 0; + va_list ap; + char *msg = NULL; + glusterfs_ctx_t *ctx = NULL; - this = THIS; - ctx = this->ctx; + this = THIS; + ctx = this->ctx; - if (!ctx) - goto out; + if (!ctx) + goto out; - if (skip_logging (this, level)) - goto out; + if (skip_logging(this, level)) + goto out; - va_start (ap, fmt); - ret = vasprintf (&msg, fmt, ap); - va_end (ap); - if (-1 == ret) { - goto out; - } + va_start(ap, fmt); + ret = vasprintf(&msg, fmt, ap); + va_end(ap); + if (-1 == ret) { + goto out; + } - ret = _gf_msg_plain_internal (level, msg); + ret = _gf_msg_plain_internal(level, msg); - FREE (msg); + FREE(msg); out: - return ret; + return ret; } int -_gf_msg_vplain (gf_loglevel_t level, const char *fmt, va_list ap) +_gf_msg_vplain(gf_loglevel_t level, const char *fmt, va_list ap) { - xlator_t *this = NULL; - int ret = 0; - char *msg = NULL; - glusterfs_ctx_t *ctx = NULL; + xlator_t *this = NULL; + int ret = 0; + char *msg = NULL; + glusterfs_ctx_t *ctx = NULL; - this = THIS; - ctx = this->ctx; + this = THIS; + ctx = this->ctx; - if (!ctx) - goto out; + if (!ctx) + goto out; - if (skip_logging (this, level)) - goto out; + if (skip_logging(this, level)) + goto out; - ret = vasprintf (&msg, fmt, ap); - if (-1 == ret) { - goto out; - } + ret = vasprintf(&msg, fmt, ap); + if (-1 == ret) { + goto out; + } - ret = _gf_msg_plain_internal (level, msg); + ret = _gf_msg_plain_internal(level, msg); - FREE (msg); + FREE(msg); out: - return ret; + return ret; } int -_gf_msg_plain_nomem (gf_loglevel_t level, const char *msg) +_gf_msg_plain_nomem(gf_loglevel_t level, const char *msg) { - xlator_t *this = NULL; - int ret = 0; - glusterfs_ctx_t *ctx = NULL; + xlator_t *this = NULL; + int ret = 0; + glusterfs_ctx_t *ctx = NULL; - this = THIS; - ctx = this->ctx; + this = THIS; + ctx = this->ctx; - if (!ctx) - goto out; + if (!ctx) + goto out; - if (skip_logging (this, level)) - goto out; + if (skip_logging(this, level)) + goto out; - ret = _gf_msg_plain_internal (level, msg); + ret = _gf_msg_plain_internal(level, msg); out: - return ret; + return ret; } void -_gf_msg_backtrace_nomem (gf_loglevel_t level, int stacksize) +_gf_msg_backtrace_nomem(gf_loglevel_t level, int stacksize) { - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - void *array[200]; - size_t bt_size = 0; - int fd = -1; - - this = THIS; - ctx = this->ctx; - - if (!ctx) - goto out; - - /* syslog does not have fd support, hence no no-mem variant */ - if (ctx->log.logger != gf_logger_glusterlog) - goto out; - - if (skip_logging (this, level)) - goto out; - - bt_size = backtrace (array, ((stacksize <= 200)? stacksize : 200)); - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - fd = ctx->log.logfile? - fileno (ctx->log.logfile) : - fileno (stderr); - if (bt_size && (fd != -1)) { - /* print to the file fd, to prevent any - allocations from backtrace_symbols - */ - backtrace_symbols_fd (&array[0], bt_size, fd); - } - } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + void *array[200]; + size_t bt_size = 0; + int fd = -1; + + this = THIS; + ctx = this->ctx; + + if (!ctx) + goto out; + + /* syslog does not have fd support, hence no no-mem variant */ + if (ctx->log.logger != gf_logger_glusterlog) + goto out; + + if (skip_logging(this, level)) + goto out; + + bt_size = backtrace(array, ((stacksize <= 200) ? stacksize : 200)); + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + fd = ctx->log.logfile ? fileno(ctx->log.logfile) : fileno(stderr); + if (bt_size && (fd != -1)) { + /* print to the file fd, to prevent any + allocations from backtrace_symbols + */ + backtrace_symbols_fd(&array[0], bt_size, fd); + } + } + pthread_mutex_unlock(&ctx->log.logfile_mutex); out: - return; + return; } int -_gf_msg_backtrace (int stacksize, char *callstr, size_t strsize) +_gf_msg_backtrace(int stacksize, char *callstr, size_t strsize) { - int ret = -1; - int i = 0; - int size = 0; - int savstrsize = strsize; - void *array[200]; - char **callingfn = NULL; - - /* We chop off last 2 anyway, so if request is less than tolerance - * nothing to do */ - if (stacksize < 3) - goto out; - - size = backtrace (array, ((stacksize <= 200)? stacksize : 200)); - if ((size - 3) < 0) - goto out; - if (size) - callingfn = backtrace_symbols (&array[2], size - 2); - if (!callingfn) - goto out; - - ret = snprintf (callstr, strsize, "("); - PRINT_SIZE_CHECK (ret, out, strsize); - - for ((i = size - 3); i >= 0; i--) { - ret = snprintf (callstr + savstrsize - strsize, strsize, - "-->%s ", callingfn[i]); - PRINT_SIZE_CHECK (ret, out, strsize); - } - - ret = snprintf (callstr + savstrsize - strsize, strsize, ")"); - PRINT_SIZE_CHECK (ret, out, strsize); + int ret = -1; + int i = 0; + int size = 0; + int savstrsize = strsize; + void *array[200]; + char **callingfn = NULL; + + /* We chop off last 2 anyway, so if request is less than tolerance + * nothing to do */ + if (stacksize < 3) + goto out; + + size = backtrace(array, ((stacksize <= 200) ? stacksize : 200)); + if ((size - 3) < 0) + goto out; + if (size) + callingfn = backtrace_symbols(&array[2], size - 2); + if (!callingfn) + goto out; + + ret = snprintf(callstr, strsize, "("); + PRINT_SIZE_CHECK(ret, out, strsize); + + for ((i = size - 3); i >= 0; i--) { + ret = snprintf(callstr + savstrsize - strsize, strsize, "-->%s ", + callingfn[i]); + PRINT_SIZE_CHECK(ret, out, strsize); + } + + ret = snprintf(callstr + savstrsize - strsize, strsize, ")"); + PRINT_SIZE_CHECK(ret, out, strsize); out: - FREE (callingfn); - return ret; + FREE(callingfn); + return ret; } int -_gf_msg_nomem (const char *domain, const char *file, - const char *function, int line, gf_loglevel_t level, - size_t size) +_gf_msg_nomem(const char *domain, const char *file, const char *function, + int line, gf_loglevel_t level, size_t size) { - const char *basename = NULL; - xlator_t *this = NULL; - struct timeval tv = {0,}; - int ret = 0; - int fd = -1; - char msg[2048] = {0,}; - char timestr[GF_LOG_TIMESTR_SIZE] = {0,}; - glusterfs_ctx_t *ctx = NULL; - int wlen = 0; - int priority; - - this = THIS; - ctx = this->ctx; - - if (!ctx) - goto out; - - if (skip_logging (this, level)) - goto out; - - if (!domain || !file || !function) { - fprintf (stderr, - "logging: %s:%s():%d: invalid argument\n", - __FILE__, __PRETTY_FUNCTION__, __LINE__); - return -1; - } - - GET_FILE_NAME_TO_LOG (file, basename); + const char *basename = NULL; + xlator_t *this = NULL; + struct timeval tv = { + 0, + }; + int ret = 0; + int fd = -1; + char msg[2048] = { + 0, + }; + char timestr[GF_LOG_TIMESTR_SIZE] = { + 0, + }; + glusterfs_ctx_t *ctx = NULL; + int wlen = 0; + int priority; + + this = THIS; + ctx = this->ctx; + + if (!ctx) + goto out; + + if (skip_logging(this, level)) + goto out; + + if (!domain || !file || !function) { + fprintf(stderr, "logging: %s:%s():%d: invalid argument\n", __FILE__, + __PRETTY_FUNCTION__, __LINE__); + return -1; + } + + GET_FILE_NAME_TO_LOG(file, basename); + + ret = gettimeofday(&tv, NULL); + if (-1 == ret) + goto out; + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + ret = snprintf(timestr + strlen(timestr), sizeof timestr - strlen(timestr), + ".%" GF_PRI_SUSECONDS, tv.tv_usec); + if (-1 == ret) { + goto out; + } + + /* TODO: Currently we print in the enhanced format, with a message ID + * of 0. Need to enhance this to support format as configured */ + ret = snprintf(msg, sizeof msg, + "[%s] %s [MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %s: no memory " + "available for size (%" GF_PRI_SIZET + ")" + " [call stack follows]\n", + timestr, gf_level_strings[level], (uint64_t)0, basename, + line, function, domain, size); + if (-1 == ret) { + goto out; + } + + /* log to the configured logging service */ + switch (ctx->log.logger) { + case gf_logger_syslog: + if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { + SET_LOG_PRIO(level, priority); - ret = gettimeofday (&tv, NULL); - if (-1 == ret) - goto out; - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - ret = snprintf (timestr + strlen (timestr), - sizeof timestr - strlen (timestr), - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - if (-1 == ret) { - goto out; - } + /* if syslog allocates, then this may fail, but we + * cannot do much about it at the moment */ + /* There is no fd for syslog, hence no stack printed */ + syslog(priority, "%s", msg); + break; + } + /* NOTE: If syslog control file is absent, which is another + * way to control logging to syslog, then we will fall through + * to the gluster log. The ideal way to do things would be to + * not have the extra control file check */ + case gf_logger_glusterlog: + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + fd = ctx->log.logfile ? fileno(ctx->log.logfile) + : fileno(stderr); + if (fd == -1) { + pthread_mutex_unlock(&ctx->log.logfile_mutex); + goto out; + } - /* TODO: Currently we print in the enhanced format, with a message ID - * of 0. Need to enhance this to support format as configured */ - ret = snprintf (msg, sizeof msg, "[%s] %s [MSGID: %"PRIu64"]" - " [%s:%d:%s] %s: no memory " - "available for size (%"GF_PRI_SIZET")" - " [call stack follows]\n", - timestr, gf_level_strings[level], (uint64_t) 0, - basename, line, function, domain, size); - if (-1 == ret) { - goto out; - } + wlen = strlen(msg); - /* log to the configured logging service */ - switch (ctx->log.logger) { - case gf_logger_syslog: - if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { - SET_LOG_PRIO (level, priority); - - /* if syslog allocates, then this may fail, but we - * cannot do much about it at the moment */ - /* There is no fd for syslog, hence no stack printed */ - syslog (priority, "%s", msg); - break; + /* write directly to the fd to prevent out of order + * message and stack */ + ret = sys_write(fd, msg, wlen); + if (ret == -1) { + pthread_mutex_unlock(&ctx->log.logfile_mutex); + goto out; } - /* NOTE: If syslog control file is absent, which is another - * way to control logging to syslog, then we will fall through - * to the gluster log. The ideal way to do things would be to - * not have the extra control file check */ - case gf_logger_glusterlog: - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - fd = ctx->log.logfile? fileno (ctx->log.logfile) : - fileno (stderr); - if (fd == -1) { - pthread_mutex_unlock (&ctx->log.logfile_mutex); - goto out; - } - - wlen = strlen (msg); - - /* write directly to the fd to prevent out of order - * message and stack */ - ret = sys_write (fd, msg, wlen); - if (ret == -1) { - pthread_mutex_unlock (&ctx->log.logfile_mutex); - goto out; - } #ifdef GF_LINUX_HOST_OS - /* We want only serious log in 'syslog', not our debug - * and trace logs */ - if (ctx->log.gf_log_syslog && level && - (level <= ctx->log.sys_log_level)) - syslog ((level-1), "%s\n", msg); + /* We want only serious log in 'syslog', not our debug + * and trace logs */ + if (ctx->log.gf_log_syslog && level && + (level <= ctx->log.sys_log_level)) + syslog((level - 1), "%s\n", msg); #endif - } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + } + pthread_mutex_unlock(&ctx->log.logfile_mutex); - _gf_msg_backtrace_nomem (level, GF_LOG_BACKTRACE_DEPTH); + _gf_msg_backtrace_nomem(level, GF_LOG_BACKTRACE_DEPTH); - break; - } + break; + } out: - return ret; + return ret; } static int -gf_log_syslog (glusterfs_ctx_t *ctx, const char *domain, const char *file, - const char *function, int32_t line, gf_loglevel_t level, - int errnum, uint64_t msgid, char **appmsgstr, char *callstr, - int graph_id, gf_log_format_t fmt) +gf_log_syslog(glusterfs_ctx_t *ctx, const char *domain, const char *file, + const char *function, int32_t line, gf_loglevel_t level, + int errnum, uint64_t msgid, char **appmsgstr, char *callstr, + int graph_id, gf_log_format_t fmt) { - int priority; - - SET_LOG_PRIO (level, priority); - - /* log with appropriate format */ - switch (fmt) { - case gf_logformat_traditional: - if (!callstr) { - if (errnum) - syslog (priority, "[%s:%d:%s] %d-%s: %s [%s]", - file, line, function, graph_id, domain, - *appmsgstr, strerror(errnum)); - else - syslog (priority, "[%s:%d:%s] %d-%s: %s", - file, line, function, graph_id, domain, - *appmsgstr); - } else { - if (errnum) - syslog (priority, "[%s:%d:%s] %s %d-%s:" - " %s [%s]", - file, line, function, callstr, graph_id, - domain, *appmsgstr, strerror(errnum)); - else - syslog (priority, "[%s:%d:%s] %s %d-%s: %s", - file, line, function, callstr, graph_id, - domain, *appmsgstr); - } - break; - case gf_logformat_withmsgid: - if (!callstr) { - if (errnum) - syslog (priority, "[MSGID: %"PRIu64"]" - " [%s:%d:%s] %d-%s: %s [%s]", msgid, - file, line, function, graph_id, domain, - *appmsgstr, strerror(errnum)); - else - syslog (priority, "[MSGID: %"PRIu64"]" - " [%s:%d:%s] %d-%s: %s", - msgid, file, line, function, graph_id, - domain, *appmsgstr); - } else { - if (errnum) - syslog (priority, "[MSGID: %"PRIu64"]" - " [%s:%d:%s] %s %d-%s: %s [%s]", - msgid, file, line, function, callstr, - graph_id, domain, *appmsgstr, - strerror(errnum)); - else - syslog (priority, "[MSGID: %"PRIu64"]" - " [%s:%d:%s] %s %d-%s: %s", - msgid, file, line, function, callstr, - graph_id, domain, *appmsgstr); - } - break; - case gf_logformat_cee: - /* TODO: Enhance CEE with additional parameters */ - gf_syslog (priority, "[%s:%d:%s] %d-%s: %s", - file, line, function, graph_id, domain, *appmsgstr); - break; - - default: - /* NOTE: should not get here without logging */ - break; - } - - /* TODO: There can be no errors from gf_syslog? */ - return 0; + int priority; + + SET_LOG_PRIO(level, priority); + + /* log with appropriate format */ + switch (fmt) { + case gf_logformat_traditional: + if (!callstr) { + if (errnum) + syslog(priority, "[%s:%d:%s] %d-%s: %s [%s]", file, line, + function, graph_id, domain, *appmsgstr, + strerror(errnum)); + else + syslog(priority, "[%s:%d:%s] %d-%s: %s", file, line, + function, graph_id, domain, *appmsgstr); + } else { + if (errnum) + syslog(priority, + "[%s:%d:%s] %s %d-%s:" + " %s [%s]", + file, line, function, callstr, graph_id, domain, + *appmsgstr, strerror(errnum)); + else + syslog(priority, "[%s:%d:%s] %s %d-%s: %s", file, line, + function, callstr, graph_id, domain, *appmsgstr); + } + break; + case gf_logformat_withmsgid: + if (!callstr) { + if (errnum) + syslog(priority, + "[MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %d-%s: %s [%s]", + msgid, file, line, function, graph_id, domain, + *appmsgstr, strerror(errnum)); + else + syslog(priority, + "[MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %d-%s: %s", + msgid, file, line, function, graph_id, domain, + *appmsgstr); + } else { + if (errnum) + syslog(priority, + "[MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %s %d-%s: %s [%s]", + msgid, file, line, function, callstr, graph_id, + domain, *appmsgstr, strerror(errnum)); + else + syslog(priority, + "[MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %s %d-%s: %s", + msgid, file, line, function, callstr, graph_id, + domain, *appmsgstr); + } + break; + case gf_logformat_cee: + /* TODO: Enhance CEE with additional parameters */ + gf_syslog(priority, "[%s:%d:%s] %d-%s: %s", file, line, function, + graph_id, domain, *appmsgstr); + break; + + default: + /* NOTE: should not get here without logging */ + break; + } + + /* TODO: There can be no errors from gf_syslog? */ + return 0; } static int -gf_log_glusterlog (glusterfs_ctx_t *ctx, const char *domain, const char *file, - const char *function, int32_t line, gf_loglevel_t level, - int errnum, uint64_t msgid, char **appmsgstr, char *callstr, - struct timeval tv, int graph_id, gf_log_format_t fmt) +gf_log_glusterlog(glusterfs_ctx_t *ctx, const char *domain, const char *file, + const char *function, int32_t line, gf_loglevel_t level, + int errnum, uint64_t msgid, char **appmsgstr, char *callstr, + struct timeval tv, int graph_id, gf_log_format_t fmt) { - char timestr[GF_LOG_TIMESTR_SIZE] = {0,}; - char *header = NULL; - char *footer = NULL; - char *msg = NULL; - size_t hlen = 0, flen = 0, mlen = 0; - int ret = 0; - - /* rotate if required */ - gf_log_rotate(ctx); - - /* format the time stamp */ - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr), - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - - /* generate header and footer */ - if (fmt == gf_logformat_traditional) { - if (!callstr) { - ret = gf_asprintf (&header, "[%s] %s [%s:%d:%s]" - " %d-%s: ", - timestr, gf_level_strings[level], - file, line, function, graph_id, - domain); - } else { - ret = gf_asprintf (&header, "[%s] %s [%s:%d:%s] %s" - " %d-%s: ", - timestr, gf_level_strings[level], - file, line, function, callstr, - graph_id, domain); - } - if (-1 == ret) { - goto err; - } - } else { /* gf_logformat_withmsgid */ - /* CEE log format unsupported in logger_glusterlog, so just - * print enhanced log format */ - if (!callstr) { - ret = gf_asprintf (&header, "[%s] %s [MSGID: %"PRIu64"]" - " [%s:%d:%s] %d-%s: ", - timestr, gf_level_strings[level], - msgid, file, line, function, - graph_id, domain); - } else { - ret = gf_asprintf (&header, "[%s] %s [MSGID: %"PRIu64"]" - " [%s:%d:%s] %s %d-%s: ", - timestr, gf_level_strings[level], - msgid, file, line, function, callstr, - graph_id, domain); - } - if (-1 == ret) { - goto err; - } + char timestr[GF_LOG_TIMESTR_SIZE] = { + 0, + }; + char *header = NULL; + char *footer = NULL; + char *msg = NULL; + size_t hlen = 0, flen = 0, mlen = 0; + int ret = 0; + + /* rotate if required */ + gf_log_rotate(ctx); + + /* format the time stamp */ + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + snprintf(timestr + strlen(timestr), sizeof timestr - strlen(timestr), + ".%" GF_PRI_SUSECONDS, tv.tv_usec); + + /* generate header and footer */ + if (fmt == gf_logformat_traditional) { + if (!callstr) { + ret = gf_asprintf(&header, + "[%s] %s [%s:%d:%s]" + " %d-%s: ", + timestr, gf_level_strings[level], file, line, + function, graph_id, domain); + } else { + ret = gf_asprintf(&header, + "[%s] %s [%s:%d:%s] %s" + " %d-%s: ", + timestr, gf_level_strings[level], file, line, + function, callstr, graph_id, domain); } - - if (errnum) { - ret = gf_asprintf (&footer, " [%s]",strerror(errnum)); - if (-1 == ret) { - goto err; - } + if (-1 == ret) { + goto err; + } + } else { /* gf_logformat_withmsgid */ + /* CEE log format unsupported in logger_glusterlog, so just + * print enhanced log format */ + if (!callstr) { + ret = gf_asprintf(&header, + "[%s] %s [MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %d-%s: ", + timestr, gf_level_strings[level], msgid, file, + line, function, graph_id, domain); + } else { + ret = gf_asprintf(&header, + "[%s] %s [MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %s %d-%s: ", + timestr, gf_level_strings[level], msgid, file, + line, function, callstr, graph_id, domain); } - - /* generate the full message to log */ - hlen = strlen (header); - flen = footer? strlen (footer) : 0; - mlen = strlen (*appmsgstr); - msg = GF_MALLOC (hlen + flen + mlen + 1, gf_common_mt_char); - if (!msg) { - ret = -1; - goto err; + if (-1 == ret) { + goto err; } + } - strcpy (msg, header); - strcpy (msg + hlen, *appmsgstr); - if (footer) - strcpy (msg + hlen + mlen, footer); - - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) { - fprintf (ctx->log.logfile, "%s\n", msg); - fflush (ctx->log.logfile); - } else if (ctx->log.loglevel >= level) { - fprintf (stderr, "%s\n", msg); - fflush (stderr); - } + if (errnum) { + ret = gf_asprintf(&footer, " [%s]", strerror(errnum)); + if (-1 == ret) { + goto err; + } + } + + /* generate the full message to log */ + hlen = strlen(header); + flen = footer ? strlen(footer) : 0; + mlen = strlen(*appmsgstr); + msg = GF_MALLOC(hlen + flen + mlen + 1, gf_common_mt_char); + if (!msg) { + ret = -1; + goto err; + } + + strcpy(msg, header); + strcpy(msg + hlen, *appmsgstr); + if (footer) + strcpy(msg + hlen + mlen, footer); + + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + fprintf(ctx->log.logfile, "%s\n", msg); + fflush(ctx->log.logfile); + } else if (ctx->log.loglevel >= level) { + fprintf(stderr, "%s\n", msg); + fflush(stderr); + } #ifdef GF_LINUX_HOST_OS - /* We want only serious logs in 'syslog', not our debug - * and trace logs */ - if (ctx->log.gf_log_syslog && level && - (level <= ctx->log.sys_log_level)) - syslog ((level-1), "%s\n", msg); + /* We want only serious logs in 'syslog', not our debug + * and trace logs */ + if (ctx->log.gf_log_syslog && level && + (level <= ctx->log.sys_log_level)) + syslog((level - 1), "%s\n", msg); #endif - } + } - /* TODO: Plugin in memory log buffer retention here. For logs not - * flushed during cores, it would be useful to retain some of the last - * few messages in memory */ - pthread_mutex_unlock (&ctx->log.logfile_mutex); - ret = 0; + /* TODO: Plugin in memory log buffer retention here. For logs not + * flushed during cores, it would be useful to retain some of the last + * few messages in memory */ + pthread_mutex_unlock(&ctx->log.logfile_mutex); + ret = 0; err: - GF_FREE (msg); - GF_FREE (header); - GF_FREE (footer); + GF_FREE(msg); + GF_FREE(header); + GF_FREE(footer); - return ret; + return ret; } static int -gf_syslog_log_repetitions (const char *domain, const char *file, - const char *function, int32_t line, - gf_loglevel_t level, int errnum, uint64_t msgid, - char **appmsgstr, char *callstr, int refcount, - struct timeval oldest, struct timeval latest, - int graph_id) +gf_syslog_log_repetitions(const char *domain, const char *file, + const char *function, int32_t line, + gf_loglevel_t level, int errnum, uint64_t msgid, + char **appmsgstr, char *callstr, int refcount, + struct timeval oldest, struct timeval latest, + int graph_id) { - int priority; - char timestr_latest[256] = {0,}; - char timestr_oldest[256] = {0,}; - - SET_LOG_PRIO (level, priority); - - gf_time_fmt (timestr_latest, sizeof timestr_latest, latest.tv_sec, - gf_timefmt_FT); - snprintf (timestr_latest + strlen (timestr_latest), - sizeof (timestr_latest) - strlen (timestr_latest), - ".%"GF_PRI_SUSECONDS, latest.tv_usec); - - gf_time_fmt (timestr_oldest, sizeof timestr_oldest, oldest.tv_sec, - gf_timefmt_FT); - snprintf (timestr_oldest + strlen (timestr_oldest), - sizeof (timestr_oldest) - strlen (timestr_oldest), - ".%"GF_PRI_SUSECONDS, oldest.tv_usec); - - if (errnum) { - syslog (priority, "The message \"[MSGID: %"PRIu64"] [%s:%d:%s] " - "%d-%s: %s [%s] \" repeated %d times between %s and %s", - msgid, file, line, function, graph_id, domain, - *appmsgstr, strerror(errnum), refcount, timestr_oldest, - timestr_latest); - } else { - syslog (priority, "The message \"[MSGID: %"PRIu64"] [%s:%d:%s] " - "%d-%s: %s \" repeated %d times between %s and %s", - msgid, file, line, function, graph_id, domain, - *appmsgstr, refcount, timestr_oldest, timestr_latest); - } - return 0; + int priority; + char timestr_latest[256] = { + 0, + }; + char timestr_oldest[256] = { + 0, + }; + + SET_LOG_PRIO(level, priority); + + gf_time_fmt(timestr_latest, sizeof timestr_latest, latest.tv_sec, + gf_timefmt_FT); + snprintf(timestr_latest + strlen(timestr_latest), + sizeof(timestr_latest) - strlen(timestr_latest), + ".%" GF_PRI_SUSECONDS, latest.tv_usec); + + gf_time_fmt(timestr_oldest, sizeof timestr_oldest, oldest.tv_sec, + gf_timefmt_FT); + snprintf(timestr_oldest + strlen(timestr_oldest), + sizeof(timestr_oldest) - strlen(timestr_oldest), + ".%" GF_PRI_SUSECONDS, oldest.tv_usec); + + if (errnum) { + syslog(priority, + "The message \"[MSGID: %" PRIu64 + "] [%s:%d:%s] " + "%d-%s: %s [%s] \" repeated %d times between %s and %s", + msgid, file, line, function, graph_id, domain, *appmsgstr, + strerror(errnum), refcount, timestr_oldest, timestr_latest); + } else { + syslog(priority, + "The message \"[MSGID: %" PRIu64 + "] [%s:%d:%s] " + "%d-%s: %s \" repeated %d times between %s and %s", + msgid, file, line, function, graph_id, domain, *appmsgstr, + refcount, timestr_oldest, timestr_latest); + } + return 0; } static int -gf_glusterlog_log_repetitions (glusterfs_ctx_t *ctx, const char *domain, - const char *file, const char *function, - int32_t line, gf_loglevel_t level, int errnum, - uint64_t msgid, char **appmsgstr, char *callstr, - int refcount, struct timeval oldest, - struct timeval latest, int graph_id) +gf_glusterlog_log_repetitions(glusterfs_ctx_t *ctx, const char *domain, + const char *file, const char *function, + int32_t line, gf_loglevel_t level, int errnum, + uint64_t msgid, char **appmsgstr, char *callstr, + int refcount, struct timeval oldest, + struct timeval latest, int graph_id) { - int ret = 0; - size_t hlen = 0; - size_t flen = 0; - size_t mlen = 0; - char timestr_latest[256] = {0,}; - char timestr_oldest[256] = {0,}; - char errstr[256] = {0,}; - char *header = NULL; - char *footer = NULL; - char *msg = NULL; - - if (!ctx) - goto err; - - gf_log_rotate (ctx); - - gf_time_fmt (timestr_latest, sizeof timestr_latest, latest.tv_sec, - gf_timefmt_FT); - snprintf (timestr_latest + strlen (timestr_latest), - sizeof (timestr_latest) - strlen (timestr_latest), - ".%"GF_PRI_SUSECONDS, latest.tv_usec); - - gf_time_fmt (timestr_oldest, sizeof timestr_oldest, oldest.tv_sec, - gf_timefmt_FT); - snprintf (timestr_oldest + strlen (timestr_oldest), - sizeof (timestr_oldest) - strlen (timestr_oldest), - ".%"GF_PRI_SUSECONDS, oldest.tv_usec); - - ret = gf_asprintf (&header, "The message \"%s [MSGID: %"PRIu64"]" - " [%s:%d:%s] %d-%s: ", gf_level_strings[level], - msgid, file, line, function, graph_id, domain); - if (-1 == ret) - goto err; - - if (errnum) - snprintf (errstr, sizeof (errstr) - 1, " [%s]", - strerror (errnum)); - - ret = gf_asprintf (&footer, "%s\" repeated %d times between" - " [%s] and [%s]", errstr, refcount, timestr_oldest, - timestr_latest); - if (-1 == ret) - goto err; - - /* generate the full message to log */ - hlen = strlen (header); - flen = strlen (footer); - mlen = strlen (*appmsgstr); - msg = GF_MALLOC (hlen + flen + mlen + 1, gf_common_mt_char); - if (!msg) { - ret = -1; - goto err; + int ret = 0; + size_t hlen = 0; + size_t flen = 0; + size_t mlen = 0; + char timestr_latest[256] = { + 0, + }; + char timestr_oldest[256] = { + 0, + }; + char errstr[256] = { + 0, + }; + char *header = NULL; + char *footer = NULL; + char *msg = NULL; + + if (!ctx) + goto err; + + gf_log_rotate(ctx); + + gf_time_fmt(timestr_latest, sizeof timestr_latest, latest.tv_sec, + gf_timefmt_FT); + snprintf(timestr_latest + strlen(timestr_latest), + sizeof(timestr_latest) - strlen(timestr_latest), + ".%" GF_PRI_SUSECONDS, latest.tv_usec); + + gf_time_fmt(timestr_oldest, sizeof timestr_oldest, oldest.tv_sec, + gf_timefmt_FT); + snprintf(timestr_oldest + strlen(timestr_oldest), + sizeof(timestr_oldest) - strlen(timestr_oldest), + ".%" GF_PRI_SUSECONDS, oldest.tv_usec); + + ret = gf_asprintf(&header, + "The message \"%s [MSGID: %" PRIu64 + "]" + " [%s:%d:%s] %d-%s: ", + gf_level_strings[level], msgid, file, line, function, + graph_id, domain); + if (-1 == ret) + goto err; + + if (errnum) + snprintf(errstr, sizeof(errstr) - 1, " [%s]", strerror(errnum)); + + ret = gf_asprintf(&footer, + "%s\" repeated %d times between" + " [%s] and [%s]", + errstr, refcount, timestr_oldest, timestr_latest); + if (-1 == ret) + goto err; + + /* generate the full message to log */ + hlen = strlen(header); + flen = strlen(footer); + mlen = strlen(*appmsgstr); + msg = GF_MALLOC(hlen + flen + mlen + 1, gf_common_mt_char); + if (!msg) { + ret = -1; + goto err; + } + + strcpy(msg, header); + strcpy(msg + hlen, *appmsgstr); + strcpy(msg + hlen + mlen, footer); + + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + fprintf(ctx->log.logfile, "%s\n", msg); + fflush(ctx->log.logfile); + } else if (ctx->log.loglevel >= level) { + fprintf(stderr, "%s\n", msg); + fflush(stderr); } - strcpy (msg, header); - strcpy (msg + hlen, *appmsgstr); - strcpy (msg + hlen + mlen, footer); - - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) { - fprintf (ctx->log.logfile, "%s\n", msg); - fflush (ctx->log.logfile); - } else if (ctx->log.loglevel >= level) { - fprintf (stderr, "%s\n", msg); - fflush (stderr); - } - #ifdef GF_LINUX_HOST_OS - /* We want only serious logs in 'syslog', not our debug - * and trace logs */ - if (ctx->log.gf_log_syslog && level && - (level <= ctx->log.sys_log_level)) - syslog ((level-1), "%s\n", msg); + /* We want only serious logs in 'syslog', not our debug + * and trace logs */ + if (ctx->log.gf_log_syslog && level && + (level <= ctx->log.sys_log_level)) + syslog((level - 1), "%s\n", msg); #endif - } + } - /* TODO: Plugin in memory log buffer retention here. For logs not - * flushed during cores, it would be useful to retain some of the last - * few messages in memory */ - pthread_mutex_unlock (&ctx->log.logfile_mutex); - ret = 0; + /* TODO: Plugin in memory log buffer retention here. For logs not + * flushed during cores, it would be useful to retain some of the last + * few messages in memory */ + pthread_mutex_unlock(&ctx->log.logfile_mutex); + ret = 0; err: - GF_FREE (msg); - GF_FREE (header); - GF_FREE (footer); + GF_FREE(msg); + GF_FREE(header); + GF_FREE(footer); - return ret; + return ret; } static int -gf_log_print_with_repetitions (glusterfs_ctx_t *ctx, const char *domain, - const char *file, const char *function, - int32_t line, gf_loglevel_t level, int errnum, - uint64_t msgid, char **appmsgstr, char *callstr, - int refcount, struct timeval oldest, - struct timeval latest, int graph_id) +gf_log_print_with_repetitions(glusterfs_ctx_t *ctx, const char *domain, + const char *file, const char *function, + int32_t line, gf_loglevel_t level, int errnum, + uint64_t msgid, char **appmsgstr, char *callstr, + int refcount, struct timeval oldest, + struct timeval latest, int graph_id) { - int ret = -1; - gf_log_logger_t logger = 0; - - logger = ctx->log.logger; - - - switch (logger) { - case gf_logger_syslog: - if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { - ret = gf_syslog_log_repetitions (domain, file, function, - line, level, errnum, - msgid, appmsgstr, - callstr, refcount, - oldest, latest, - graph_id); - break; - } - case gf_logger_glusterlog: - ret = gf_glusterlog_log_repetitions (ctx, domain, file, - function, line, level, - errnum, msgid, appmsgstr, - callstr, refcount, oldest, - latest, graph_id); + int ret = -1; + gf_log_logger_t logger = 0; + + logger = ctx->log.logger; + + switch (logger) { + case gf_logger_syslog: + if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { + ret = gf_syslog_log_repetitions( + domain, file, function, line, level, errnum, msgid, + appmsgstr, callstr, refcount, oldest, latest, graph_id); break; - } + } + case gf_logger_glusterlog: + ret = gf_glusterlog_log_repetitions( + ctx, domain, file, function, line, level, errnum, msgid, + appmsgstr, callstr, refcount, oldest, latest, graph_id); + break; + } - return ret; + return ret; } static int -gf_log_print_plain_fmt (glusterfs_ctx_t *ctx, const char *domain, - const char *file, const char *function, int32_t line, - gf_loglevel_t level, int errnum, uint64_t msgid, - char **appmsgstr, char *callstr, struct timeval tv, - int graph_id, gf_log_format_t fmt) +gf_log_print_plain_fmt(glusterfs_ctx_t *ctx, const char *domain, + const char *file, const char *function, int32_t line, + gf_loglevel_t level, int errnum, uint64_t msgid, + char **appmsgstr, char *callstr, struct timeval tv, + int graph_id, gf_log_format_t fmt) { - int ret = -1; - gf_log_logger_t logger = 0; + int ret = -1; + gf_log_logger_t logger = 0; - logger = ctx->log.logger; + logger = ctx->log.logger; - /* log to the configured logging service */ - switch (logger) { + /* log to the configured logging service */ + switch (logger) { case gf_logger_syslog: - if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { - ret = gf_log_syslog (ctx, domain, file, function, line, - level, errnum, msgid, appmsgstr, - callstr, graph_id, fmt); - break; - } - /* NOTE: If syslog control file is absent, which is another - * way to control logging to syslog, then we will fall through - * to the gluster log. The ideal way to do things would be to - * not have the extra control file check */ - case gf_logger_glusterlog: - ret = gf_log_glusterlog (ctx, domain, file, function, line, - level, errnum, msgid, appmsgstr, - callstr, tv, graph_id, fmt); + if (ctx->log.log_control_file_found && ctx->log.gf_log_syslog) { + ret = gf_log_syslog(ctx, domain, file, function, line, level, + errnum, msgid, appmsgstr, callstr, graph_id, + fmt); break; - } + } + /* NOTE: If syslog control file is absent, which is another + * way to control logging to syslog, then we will fall through + * to the gluster log. The ideal way to do things would be to + * not have the extra control file check */ + case gf_logger_glusterlog: + ret = gf_log_glusterlog(ctx, domain, file, function, line, level, + errnum, msgid, appmsgstr, callstr, tv, + graph_id, fmt); + break; + } - return ret; + return ret; } void -gf_log_flush_message (log_buf_t *buf, glusterfs_ctx_t *ctx) +gf_log_flush_message(log_buf_t *buf, glusterfs_ctx_t *ctx) { - if (buf->refcount == 1) { - (void) gf_log_print_plain_fmt (ctx, buf->domain, buf->file, - buf->function, buf->line, - buf->level, buf->errnum, - buf->msg_id, &buf->msg, NULL, - buf->latest, buf->graph_id, - gf_logformat_withmsgid); - } - - if (buf->refcount > 1) { - gf_log_print_with_repetitions (ctx, buf->domain, buf->file, - buf->function, buf->line, - buf->level, buf->errnum, - buf->msg_id, &buf->msg, NULL, - buf->refcount, buf->oldest, - buf->latest, buf->graph_id); - } - return; + if (buf->refcount == 1) { + (void)gf_log_print_plain_fmt(ctx, buf->domain, buf->file, buf->function, + buf->line, buf->level, buf->errnum, + buf->msg_id, &buf->msg, NULL, buf->latest, + buf->graph_id, gf_logformat_withmsgid); + } + + if (buf->refcount > 1) { + gf_log_print_with_repetitions( + ctx, buf->domain, buf->file, buf->function, buf->line, buf->level, + buf->errnum, buf->msg_id, &buf->msg, NULL, buf->refcount, + buf->oldest, buf->latest, buf->graph_id); + } + return; } static void -gf_log_flush_list (struct list_head *copy, glusterfs_ctx_t *ctx) +gf_log_flush_list(struct list_head *copy, glusterfs_ctx_t *ctx) { - log_buf_t *iter = NULL; - log_buf_t *tmp = NULL; - - list_for_each_entry_safe (iter, tmp, copy, msg_list) { - gf_log_flush_message (iter, ctx); - list_del_init (&iter->msg_list); - log_buf_destroy (iter); - } + log_buf_t *iter = NULL; + log_buf_t *tmp = NULL; + + list_for_each_entry_safe(iter, tmp, copy, msg_list) + { + gf_log_flush_message(iter, ctx); + list_del_init(&iter->msg_list); + log_buf_destroy(iter); + } } void -gf_log_flush_msgs (glusterfs_ctx_t *ctx) +gf_log_flush_msgs(glusterfs_ctx_t *ctx) { - struct list_head copy; + struct list_head copy; - INIT_LIST_HEAD (©); + INIT_LIST_HEAD(©); - pthread_mutex_lock (&ctx->log.log_buf_lock); - { - list_splice_init (&ctx->log.lru_queue, ©); - ctx->log.lru_cur_size = 0; - } - pthread_mutex_unlock (&ctx->log.log_buf_lock); + pthread_mutex_lock(&ctx->log.log_buf_lock); + { + list_splice_init(&ctx->log.lru_queue, ©); + ctx->log.lru_cur_size = 0; + } + pthread_mutex_unlock(&ctx->log.log_buf_lock); - gf_log_flush_list (©, ctx); + gf_log_flush_list(©, ctx); - return; + return; } static void -gf_log_flush_extra_msgs (glusterfs_ctx_t *ctx, uint32_t new) +gf_log_flush_extra_msgs(glusterfs_ctx_t *ctx, uint32_t new) { - int count = 0; - int i = 0; - log_buf_t *iter = NULL; - log_buf_t *tmp = NULL; - struct list_head copy; - - INIT_LIST_HEAD (©); - - /* If the number of outstanding log messages does not cause list - * overflow even after reducing the size of the list, then do nothing. - * Otherwise (that is if there are more items in the list than there - * need to be after reducing its size), move the least recently used - * 'diff' elements to be flushed into a separate list... - */ - - pthread_mutex_lock (&ctx->log.log_buf_lock); + int count = 0; + int i = 0; + log_buf_t *iter = NULL; + log_buf_t *tmp = NULL; + struct list_head copy; + + INIT_LIST_HEAD(©); + + /* If the number of outstanding log messages does not cause list + * overflow even after reducing the size of the list, then do nothing. + * Otherwise (that is if there are more items in the list than there + * need to be after reducing its size), move the least recently used + * 'diff' elements to be flushed into a separate list... + */ + + pthread_mutex_lock(&ctx->log.log_buf_lock); + { + if (ctx->log.lru_cur_size <= new) + goto unlock; + count = ctx->log.lru_cur_size - new; + list_for_each_entry_safe(iter, tmp, &ctx->log.lru_queue, msg_list) { - if (ctx->log.lru_cur_size <= new) - goto unlock; - count = ctx->log.lru_cur_size - new; - list_for_each_entry_safe (iter, tmp, &ctx->log.lru_queue, - msg_list) { - if (i == count) - break; - - list_del_init (&iter->msg_list); - list_add_tail (&iter->msg_list, ©); - i++; - } - ctx->log.lru_cur_size = ctx->log.lru_cur_size - count; + if (i == count) + break; + + list_del_init(&iter->msg_list); + list_add_tail(&iter->msg_list, ©); + i++; } - // ... quickly unlock ... + ctx->log.lru_cur_size = ctx->log.lru_cur_size - count; + } + // ... quickly unlock ... unlock: - pthread_mutex_unlock (&ctx->log.log_buf_lock); - if (list_empty (©)) - return; + pthread_mutex_unlock(&ctx->log.log_buf_lock); + if (list_empty(©)) + return; - TEST_LOG("Log buffer size reduced. About to flush %d extra log " - "messages", count); - // ... and then flush them outside the lock. - gf_log_flush_list (©, ctx); - TEST_LOG("Just flushed %d extra log messages", count); + TEST_LOG( + "Log buffer size reduced. About to flush %d extra log " + "messages", + count); + // ... and then flush them outside the lock. + gf_log_flush_list(©, ctx); + TEST_LOG("Just flushed %d extra log messages", count); - return; + return; } static int -__gf_log_inject_timer_event (glusterfs_ctx_t *ctx) +__gf_log_inject_timer_event(glusterfs_ctx_t *ctx) { - int ret = -1; - struct timespec timeout = {0,}; + int ret = -1; + struct timespec timeout = { + 0, + }; - if (!ctx) - goto out; + if (!ctx) + goto out; - if (ctx->log.log_flush_timer) { - gf_timer_call_cancel (ctx, ctx->log.log_flush_timer); - ctx->log.log_flush_timer = NULL; - } + if (ctx->log.log_flush_timer) { + gf_timer_call_cancel(ctx, ctx->log.log_flush_timer); + ctx->log.log_flush_timer = NULL; + } - timeout.tv_sec = ctx->log.timeout; - timeout.tv_nsec = 0; + timeout.tv_sec = ctx->log.timeout; + timeout.tv_nsec = 0; - TEST_LOG("Starting timer now. Timeout = %u, current buf size = %d", - ctx->log.timeout, ctx->log.lru_size); - ctx->log.log_flush_timer = gf_timer_call_after (ctx, timeout, - gf_log_flush_timeout_cbk, - (void *)ctx); - if (!ctx->log.log_flush_timer) - goto out; + TEST_LOG("Starting timer now. Timeout = %u, current buf size = %d", + ctx->log.timeout, ctx->log.lru_size); + ctx->log.log_flush_timer = gf_timer_call_after( + ctx, timeout, gf_log_flush_timeout_cbk, (void *)ctx); + if (!ctx->log.log_flush_timer) + goto out; - ret = 0; + ret = 0; out: - return ret; + return ret; } int -gf_log_inject_timer_event (glusterfs_ctx_t *ctx) +gf_log_inject_timer_event(glusterfs_ctx_t *ctx) { - int ret = -1; + int ret = -1; - if (!ctx) - return -1; + if (!ctx) + return -1; - pthread_mutex_lock (&ctx->log.log_buf_lock); - { - ret = __gf_log_inject_timer_event (ctx); - } - pthread_mutex_unlock (&ctx->log.log_buf_lock); + pthread_mutex_lock(&ctx->log.log_buf_lock); + { + ret = __gf_log_inject_timer_event(ctx); + } + pthread_mutex_unlock(&ctx->log.log_buf_lock); - return ret; + return ret; } void -gf_log_flush_timeout_cbk (void *data) +gf_log_flush_timeout_cbk(void *data) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - ctx = (glusterfs_ctx_t *) data; + ctx = (glusterfs_ctx_t *)data; - TEST_LOG("Log timer timed out. About to flush outstanding messages if " - "present"); - gf_log_flush_msgs (ctx); + TEST_LOG( + "Log timer timed out. About to flush outstanding messages if " + "present"); + gf_log_flush_msgs(ctx); - (void) gf_log_inject_timer_event (ctx); + (void)gf_log_inject_timer_event(ctx); - return; + return; } static int -_gf_msg_internal (const char *domain, const char *file, const char *function, - int32_t line, gf_loglevel_t level, int errnum, uint64_t msgid, - char **appmsgstr, char *callstr, int graph_id) +_gf_msg_internal(const char *domain, const char *file, const char *function, + int32_t line, gf_loglevel_t level, int errnum, uint64_t msgid, + char **appmsgstr, char *callstr, int graph_id) { - int ret = -1; - uint32_t size = 0; - const char *basename = NULL; - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - log_buf_t *iter = NULL; - log_buf_t *buf_tmp = NULL; - log_buf_t *buf_new = NULL; - log_buf_t *first = NULL; - struct timeval tv = {0,}; - gf_boolean_t found = _gf_false; - gf_boolean_t flush_lru = _gf_false; - gf_boolean_t flush_logged_msg = _gf_false; - - this = THIS; - ctx = this->ctx; - - if (!ctx) - goto out; + int ret = -1; + uint32_t size = 0; + const char *basename = NULL; + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + log_buf_t *iter = NULL; + log_buf_t *buf_tmp = NULL; + log_buf_t *buf_new = NULL; + log_buf_t *first = NULL; + struct timeval tv = { + 0, + }; + gf_boolean_t found = _gf_false; + gf_boolean_t flush_lru = _gf_false; + gf_boolean_t flush_logged_msg = _gf_false; + + this = THIS; + ctx = this->ctx; + + if (!ctx) + goto out; + + GET_FILE_NAME_TO_LOG(file, basename); + + ret = gettimeofday(&tv, NULL); + if (ret) + goto out; + + /* If this function is called via _gf_msg_callingfn () (indicated by a + * non-NULL callstr), or if the logformat is traditional, flush the + * message directly to disk. + */ + + if ((callstr) || (ctx->log.logformat == gf_logformat_traditional)) { + ret = gf_log_print_plain_fmt(ctx, domain, basename, function, line, + level, errnum, msgid, appmsgstr, callstr, + tv, graph_id, gf_logformat_traditional); + goto out; + } + + pthread_mutex_lock(&ctx->log.log_buf_lock); + { + /* Check if the msg being logged is already part of the list */ + list_for_each_entry_safe_reverse(iter, buf_tmp, &ctx->log.lru_queue, + msg_list) + { + if (first == NULL) + // Remember the first (lru) element in first ptr + first = iter; - GET_FILE_NAME_TO_LOG (file, basename); + /* Try to fail the search early on by doing the less + * expensive integer comparisons and continue to string + * parameter comparisons only after all int parameters + * are found to be matching. + */ + if (line != iter->line) + continue; - ret = gettimeofday (&tv, NULL); - if (ret) - goto out; + if (errnum != iter->errnum) + continue; - /* If this function is called via _gf_msg_callingfn () (indicated by a - * non-NULL callstr), or if the logformat is traditional, flush the - * message directly to disk. - */ + if (msgid != iter->msg_id) + continue; - if ((callstr) || (ctx->log.logformat == gf_logformat_traditional)) { - ret = gf_log_print_plain_fmt (ctx, domain, basename, function, - line, level, errnum, msgid, - appmsgstr, callstr, tv, graph_id, - gf_logformat_traditional); - goto out; - } + if (level != iter->level) + continue; - pthread_mutex_lock (&ctx->log.log_buf_lock); - { - /* Check if the msg being logged is already part of the list */ - list_for_each_entry_safe_reverse (iter, buf_tmp, - &ctx->log.lru_queue, - msg_list) { - if (first == NULL) - // Remember the first (lru) element in first ptr - first = iter; - - /* Try to fail the search early on by doing the less - * expensive integer comparisons and continue to string - * parameter comparisons only after all int parameters - * are found to be matching. - */ - if (line != iter->line) - continue; - - if (errnum != iter->errnum) - continue; - - if (msgid != iter->msg_id) - continue; - - if (level != iter->level) - continue; - - if (graph_id != iter->graph_id) - continue; - - if (strcmp (domain, iter->domain)) - continue; - - if (strcmp (basename, iter->file)) - continue; - - if (strcmp (function, iter->function)) - continue; - - if (strcmp (*appmsgstr, iter->msg)) - continue; - - //Ah! Found a match! - list_move_tail (&iter->msg_list, &ctx->log.lru_queue); - iter->refcount++; - found = _gf_true; - //Update the 'latest' timestamp. - memcpy ((void *)&(iter->latest), (void *)&tv, - sizeof (struct timeval)); - break; - } - if (found) { - ret = 0; - goto unlock; - } - // else ... - - size = ctx->log.lru_size; - /* If the upper limit on the log buf size is 0, flush the msg to - * disk directly after unlock. There's no need to buffer the - * msg here. - */ - if (size == 0) { - flush_logged_msg = _gf_true; - goto unlock; - } else if ((ctx->log.lru_cur_size + 1) > size) { - /* If the list is full, flush the lru msg to disk and also - * release it after unlock, and ... - * */ - if (first->refcount >= 1) - TEST_LOG("Buffer overflow of a buffer whose size limit " - "is %d. About to flush least recently used log" - " message to disk", size); - list_del_init (&first->msg_list); - ctx->log.lru_cur_size--; - flush_lru = _gf_true; - } - /* create a new list element, initialise and enqueue it. - * Additionally, this being the first occurrence of the msg, - * log it directly to disk after unlock. */ - buf_new = log_buf_new (); - if (!buf_new) { - ret = -1; - goto unlock; - } - ret = log_buf_init (buf_new, domain, basename, function, line, - level, errnum, msgid, appmsgstr, graph_id); - if (ret) { - log_buf_destroy (buf_new); - goto unlock; - } + if (graph_id != iter->graph_id) + continue; - memcpy ((void *)&(buf_new->latest), (void *)&tv, - sizeof (struct timeval)); - memcpy ((void *)&(buf_new->oldest), (void *)&tv, - sizeof (struct timeval)); + if (strcmp(domain, iter->domain)) + continue; - list_add_tail (&buf_new->msg_list, &ctx->log.lru_queue); - ctx->log.lru_cur_size++; - flush_logged_msg = _gf_true; - ret = 0; - } -unlock: - pthread_mutex_unlock (&ctx->log.log_buf_lock); + if (strcmp(basename, iter->file)) + continue; - /* Value of @ret is a don't-care below since irrespective of success or - * failure post setting of @flush_lru, @first must be flushed and freed. - */ - if (flush_lru) { - gf_log_flush_message (first, ctx); - log_buf_destroy (first); + if (strcmp(function, iter->function)) + continue; + + if (strcmp(*appmsgstr, iter->msg)) + continue; + + // Ah! Found a match! + list_move_tail(&iter->msg_list, &ctx->log.lru_queue); + iter->refcount++; + found = _gf_true; + // Update the 'latest' timestamp. + memcpy((void *)&(iter->latest), (void *)&tv, + sizeof(struct timeval)); + break; } - /* Similarly, irrespective of whether all operations since setting of - * @flush_logged_msg were successful or not, flush the message being - * logged to disk in the plain format. - */ - if (flush_logged_msg) { - ret = gf_log_print_plain_fmt (ctx, domain, basename, - function, line, level, - errnum, msgid, appmsgstr, - callstr, tv, graph_id, - gf_logformat_withmsgid); + if (found) { + ret = 0; + goto unlock; } + // else ... + + size = ctx->log.lru_size; + /* If the upper limit on the log buf size is 0, flush the msg to + * disk directly after unlock. There's no need to buffer the + * msg here. + */ + if (size == 0) { + flush_logged_msg = _gf_true; + goto unlock; + } else if ((ctx->log.lru_cur_size + 1) > size) { + /* If the list is full, flush the lru msg to disk and also + * release it after unlock, and ... + * */ + if (first->refcount >= 1) + TEST_LOG( + "Buffer overflow of a buffer whose size limit " + "is %d. About to flush least recently used log" + " message to disk", + size); + list_del_init(&first->msg_list); + ctx->log.lru_cur_size--; + flush_lru = _gf_true; + } + /* create a new list element, initialise and enqueue it. + * Additionally, this being the first occurrence of the msg, + * log it directly to disk after unlock. */ + buf_new = log_buf_new(); + if (!buf_new) { + ret = -1; + goto unlock; + } + ret = log_buf_init(buf_new, domain, basename, function, line, level, + errnum, msgid, appmsgstr, graph_id); + if (ret) { + log_buf_destroy(buf_new); + goto unlock; + } + + memcpy((void *)&(buf_new->latest), (void *)&tv, sizeof(struct timeval)); + memcpy((void *)&(buf_new->oldest), (void *)&tv, sizeof(struct timeval)); + + list_add_tail(&buf_new->msg_list, &ctx->log.lru_queue); + ctx->log.lru_cur_size++; + flush_logged_msg = _gf_true; + ret = 0; + } +unlock: + pthread_mutex_unlock(&ctx->log.log_buf_lock); + + /* Value of @ret is a don't-care below since irrespective of success or + * failure post setting of @flush_lru, @first must be flushed and freed. + */ + if (flush_lru) { + gf_log_flush_message(first, ctx); + log_buf_destroy(first); + } + /* Similarly, irrespective of whether all operations since setting of + * @flush_logged_msg were successful or not, flush the message being + * logged to disk in the plain format. + */ + if (flush_logged_msg) { + ret = gf_log_print_plain_fmt(ctx, domain, basename, function, line, + level, errnum, msgid, appmsgstr, callstr, + tv, graph_id, gf_logformat_withmsgid); + } out: - return ret; + return ret; } int -_gf_msg (const char *domain, const char *file, const char *function, - int32_t line, gf_loglevel_t level, int errnum, int trace, - uint64_t msgid, const char *fmt, ...) +_gf_msg(const char *domain, const char *file, const char *function, + int32_t line, gf_loglevel_t level, int errnum, int trace, + uint64_t msgid, const char *fmt, ...) { - int ret = 0; - char *msgstr = NULL; - va_list ap; - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - char callstr[GF_LOG_BACKTRACE_SIZE] = {0,}; - int passcallstr = 0; - int log_inited = 0; - - /* in args check */ - if (!domain || !file || !function || !fmt) { - fprintf (stderr, - "logging: %s:%s():%d: invalid argument\n", - __FILE__, __PRETTY_FUNCTION__, __LINE__); - return -1; - } - - this = THIS; - - if (this == NULL) - return -1; - - ctx = this->ctx; - if (ctx == NULL) { - /* messages before context initialization are ignored */ - return -1; - } - - /* check if we should be logging */ - if (skip_logging (this, level)) - goto out; - - if (trace) { - ret = _gf_msg_backtrace (GF_LOG_BACKTRACE_DEPTH, callstr, - GF_LOG_BACKTRACE_SIZE); - if (ret >= 0) - passcallstr = 1; - else - ret = 0; - } - - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) { - log_inited = 1; - } - } - pthread_mutex_unlock (&ctx->log.logfile_mutex); - - /* form the message */ - va_start (ap, fmt); - ret = vasprintf (&msgstr, fmt, ap); - va_end (ap); - - /* log */ - if (ret != -1) { - if (!log_inited && ctx->log.gf_log_syslog) { - ret = gf_log_syslog (ctx, domain, file, function, line, - level, errnum, msgid, &msgstr, - (passcallstr? callstr : NULL), - (this->graph)? this->graph->id : 0, - gf_logformat_traditional); - } else { - ret = _gf_msg_internal (domain, file, function, line, - level, errnum, msgid, &msgstr, - (passcallstr? callstr : NULL), - (this->graph)? this->graph->id : 0); - } + int ret = 0; + char *msgstr = NULL; + va_list ap; + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + char callstr[GF_LOG_BACKTRACE_SIZE] = { + 0, + }; + int passcallstr = 0; + int log_inited = 0; + + /* in args check */ + if (!domain || !file || !function || !fmt) { + fprintf(stderr, "logging: %s:%s():%d: invalid argument\n", __FILE__, + __PRETTY_FUNCTION__, __LINE__); + return -1; + } + + this = THIS; + + if (this == NULL) + return -1; + + ctx = this->ctx; + if (ctx == NULL) { + /* messages before context initialization are ignored */ + return -1; + } + + /* check if we should be logging */ + if (skip_logging(this, level)) + goto out; + + if (trace) { + ret = _gf_msg_backtrace(GF_LOG_BACKTRACE_DEPTH, callstr, + GF_LOG_BACKTRACE_SIZE); + if (ret >= 0) + passcallstr = 1; + else + ret = 0; + } + + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + log_inited = 1; + } + } + pthread_mutex_unlock(&ctx->log.logfile_mutex); + + /* form the message */ + va_start(ap, fmt); + ret = vasprintf(&msgstr, fmt, ap); + va_end(ap); + + /* log */ + if (ret != -1) { + if (!log_inited && ctx->log.gf_log_syslog) { + ret = gf_log_syslog( + ctx, domain, file, function, line, level, errnum, msgid, + &msgstr, (passcallstr ? callstr : NULL), + (this->graph) ? this->graph->id : 0, gf_logformat_traditional); } else { - /* man (3) vasprintf states on error strp contents - * are undefined, be safe */ - msgstr = NULL; + ret = _gf_msg_internal(domain, file, function, line, level, errnum, + msgid, &msgstr, + (passcallstr ? callstr : NULL), + (this->graph) ? this->graph->id : 0); } + } else { + /* man (3) vasprintf states on error strp contents + * are undefined, be safe */ + msgstr = NULL; + } - FREE (msgstr); + FREE(msgstr); out: - return ret; + return ret; } /* TODO: Deprecate (delete) _gf_log, _gf_log_callingfn, * once messages are changed to use _gf_msgXXX APIs for logging */ int -_gf_log (const char *domain, const char *file, const char *function, int line, - gf_loglevel_t level, const char *fmt, ...) +_gf_log(const char *domain, const char *file, const char *function, int line, + gf_loglevel_t level, const char *fmt, ...) { - const char *basename = NULL; - FILE *new_logfile = NULL; - va_list ap; - char timestr[GF_LOG_TIMESTR_SIZE] = {0,}; - struct timeval tv = {0,}; - char *str1 = NULL; - char *str2 = NULL; - char *msg = NULL; - size_t len = 0; - int ret = 0; - int fd = -1; - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - - this = THIS; - ctx = this->ctx; - - if (!ctx) - goto out; - - if (skip_logging (this, level)) - goto out; - - static char *level_strings[] = {"", /* NONE */ - "M", /* EMERGENCY */ - "A", /* ALERT */ - "C", /* CRITICAL */ - "E", /* ERROR */ - "W", /* WARNING */ - "N", /* NOTICE */ - "I", /* INFO */ - "D", /* DEBUG */ - "T", /* TRACE */ - ""}; - - if (!domain || !file || !function || !fmt) { - fprintf (stderr, - "logging: %s:%s():%d: invalid argument\n", - __FILE__, __PRETTY_FUNCTION__, __LINE__); - return -1; + const char *basename = NULL; + FILE *new_logfile = NULL; + va_list ap; + char timestr[GF_LOG_TIMESTR_SIZE] = { + 0, + }; + struct timeval tv = { + 0, + }; + char *str1 = NULL; + char *str2 = NULL; + char *msg = NULL; + size_t len = 0; + int ret = 0; + int fd = -1; + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + + this = THIS; + ctx = this->ctx; + + if (!ctx) + goto out; + + if (skip_logging(this, level)) + goto out; + + static char *level_strings[] = {"", /* NONE */ + "M", /* EMERGENCY */ + "A", /* ALERT */ + "C", /* CRITICAL */ + "E", /* ERROR */ + "W", /* WARNING */ + "N", /* NOTICE */ + "I", /* INFO */ + "D", /* DEBUG */ + "T", /* TRACE */ + ""}; + + if (!domain || !file || !function || !fmt) { + fprintf(stderr, "logging: %s:%s():%d: invalid argument\n", __FILE__, + __PRETTY_FUNCTION__, __LINE__); + return -1; + } + + basename = strrchr(file, '/'); + if (basename) + basename++; + else + basename = file; + + if (ctx->log.log_control_file_found) { + int priority; + /* treat GF_LOG_TRACE and GF_LOG_NONE as LOG_DEBUG and + other level as is */ + if (GF_LOG_TRACE == level || GF_LOG_NONE == level) { + priority = LOG_DEBUG; + } else { + priority = level - 1; } - basename = strrchr (file, '/'); - if (basename) - basename++; - else - basename = file; + va_start(ap, fmt); + vasprintf(&str2, fmt, ap); + va_end(ap); - if (ctx->log.log_control_file_found) - { - int priority; - /* treat GF_LOG_TRACE and GF_LOG_NONE as LOG_DEBUG and - other level as is */ - if (GF_LOG_TRACE == level || GF_LOG_NONE == level) { - priority = LOG_DEBUG; - } else { - priority = level - 1; - } + gf_syslog(priority, "[%s:%d:%s] %d-%s: %s", basename, line, function, + ((this->graph) ? this->graph->id : 0), domain, str2); + goto err; + } - va_start (ap, fmt); - vasprintf (&str2, fmt, ap); - va_end (ap); + if (ctx->log.logrotate) { + ctx->log.logrotate = 0; - gf_syslog (priority, "[%s:%d:%s] %d-%s: %s", - basename, line, function, - ((this->graph) ? this->graph->id:0), domain, str2); - goto err; + fd = sys_open(ctx->log.filename, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR); + if (fd < 0) { + gf_msg("logrotate", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "failed to open logfile"); + return -1; } + sys_close(fd); - if (ctx->log.logrotate) { - ctx->log.logrotate = 0; - - fd = sys_open (ctx->log.filename, - O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR); - if (fd < 0) { - gf_msg ("logrotate", GF_LOG_ERROR, errno, - LG_MSG_FILE_OP_FAILED, - "failed to open logfile"); - return -1; - } - sys_close (fd); - - new_logfile = fopen (ctx->log.filename, "a"); - if (!new_logfile) { - gf_msg ("logrotate", GF_LOG_CRITICAL, errno, - LG_MSG_FILE_OP_FAILED, - "failed to open logfile %s", - ctx->log.filename); - goto log; - } - - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - if (ctx->log.logfile) - fclose (ctx->log.logfile); - - ctx->log.gf_log_logfile = - ctx->log.logfile = new_logfile; - } - pthread_mutex_unlock (&ctx->log.logfile_mutex); - + new_logfile = fopen(ctx->log.filename, "a"); + if (!new_logfile) { + gf_msg("logrotate", GF_LOG_CRITICAL, errno, LG_MSG_FILE_OP_FAILED, + "failed to open logfile %s", ctx->log.filename); + goto log; } -log: - ret = gettimeofday (&tv, NULL); - if (-1 == ret) - goto out; - va_start (ap, fmt); - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr), - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - - ret = gf_asprintf (&str1, "[%s] %s [%s:%d:%s] %d-%s: ", - timestr, level_strings[level], - basename, line, function, - ((this->graph)?this->graph->id:0), domain); - if (-1 == ret) { - goto err; - } + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) + fclose(ctx->log.logfile); - ret = vasprintf (&str2, fmt, ap); - if (-1 == ret) { - goto err; + ctx->log.gf_log_logfile = ctx->log.logfile = new_logfile; } + pthread_mutex_unlock(&ctx->log.logfile_mutex); + } - va_end (ap); - - len = strlen (str1); - msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char); - if (!msg) { - goto err; +log: + ret = gettimeofday(&tv, NULL); + if (-1 == ret) + goto out; + va_start(ap, fmt); + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + snprintf(timestr + strlen(timestr), sizeof timestr - strlen(timestr), + ".%" GF_PRI_SUSECONDS, tv.tv_usec); + + ret = gf_asprintf(&str1, "[%s] %s [%s:%d:%s] %d-%s: ", timestr, + level_strings[level], basename, line, function, + ((this->graph) ? this->graph->id : 0), domain); + if (-1 == ret) { + goto err; + } + + ret = vasprintf(&str2, fmt, ap); + if (-1 == ret) { + goto err; + } + + va_end(ap); + + len = strlen(str1); + msg = GF_MALLOC(len + strlen(str2) + 1, gf_common_mt_char); + if (!msg) { + goto err; + } + + strcpy(msg, str1); + strcpy(msg + len, str2); + + pthread_mutex_lock(&ctx->log.logfile_mutex); + { + if (ctx->log.logfile) { + fprintf(ctx->log.logfile, "%s\n", msg); + fflush(ctx->log.logfile); + } else if (ctx->log.loglevel >= level) { + fprintf(stderr, "%s\n", msg); + fflush(stderr); } - strcpy (msg, str1); - strcpy (msg + len, str2); - - pthread_mutex_lock (&ctx->log.logfile_mutex); - { - - if (ctx->log.logfile) { - fprintf (ctx->log.logfile, "%s\n", msg); - fflush (ctx->log.logfile); - } else if (ctx->log.loglevel >= level) { - fprintf (stderr, "%s\n", msg); - fflush (stderr); - } - #ifdef GF_LINUX_HOST_OS - /* We want only serious log in 'syslog', not our debug - and trace logs */ - if (ctx->log.gf_log_syslog && level && - (level <= ctx->log.sys_log_level)) - syslog ((level-1), "%s\n", msg); + /* We want only serious log in 'syslog', not our debug + and trace logs */ + if (ctx->log.gf_log_syslog && level && + (level <= ctx->log.sys_log_level)) + syslog((level - 1), "%s\n", msg); #endif - } + } - pthread_mutex_unlock (&ctx->log.logfile_mutex); + pthread_mutex_unlock(&ctx->log.logfile_mutex); err: - GF_FREE (msg); + GF_FREE(msg); - GF_FREE (str1); + GF_FREE(str1); - FREE (str2); + FREE(str2); out: - va_end (ap); - return (0); + va_end(ap); + return (0); } int -_gf_log_eh (const char *function, const char *fmt, ...) +_gf_log_eh(const char *function, const char *fmt, ...) { - int ret = -1; - va_list ap; - char *str1 = NULL; - char *str2 = NULL; - char *msg = NULL; - xlator_t *this = NULL; - - this = THIS; - - ret = gf_asprintf (&str1, "[%d] %s: ", - ((this->graph)?this->graph->id:0), - function); - if (-1 == ret) { - goto out; - } + int ret = -1; + va_list ap; + char *str1 = NULL; + char *str2 = NULL; + char *msg = NULL; + xlator_t *this = NULL; - va_start (ap, fmt); + this = THIS; - ret = vasprintf (&str2, fmt, ap); - if (-1 == ret) { - goto out; - } + ret = gf_asprintf(&str1, "[%d] %s: ", ((this->graph) ? this->graph->id : 0), + function); + if (-1 == ret) { + goto out; + } - msg = GF_MALLOC (strlen (str1) + strlen (str2) + 1, gf_common_mt_char); - if (!msg) { - ret = -1; - goto out; - } + va_start(ap, fmt); + + ret = vasprintf(&str2, fmt, ap); + if (-1 == ret) { + goto out; + } - strcpy (msg, str1); - strcat (msg, str2); + msg = GF_MALLOC(strlen(str1) + strlen(str2) + 1, gf_common_mt_char); + if (!msg) { + ret = -1; + goto out; + } - ret = eh_save_history (this->history, msg); - if (ret < 0) - GF_FREE (msg); + strcpy(msg, str1); + strcat(msg, str2); + + ret = eh_save_history(this->history, msg); + if (ret < 0) + GF_FREE(msg); out: - GF_FREE (str1); + GF_FREE(str1); - /* Use FREE instead of GF_FREE since str2 was allocated by vasprintf */ - if (str2) - FREE (str2); + /* Use FREE instead of GF_FREE since str2 was allocated by vasprintf */ + if (str2) + FREE(str2); - va_end (ap); + va_end(ap); - return ret; + return ret; } int -gf_cmd_log_init (const char *filename) +gf_cmd_log_init(const char *filename) { - int fd = -1; - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - - this = THIS; - ctx = this->ctx; - - if (!ctx) - return -1; - - if (!filename){ - gf_msg (this->name, GF_LOG_CRITICAL, 0, LG_MSG_INVALID_ENTRY, - "gf_cmd_log_init: no filename specified\n"); - return -1; - } - - ctx->log.cmd_log_filename = gf_strdup (filename); - if (!ctx->log.cmd_log_filename) { - return -1; - } - /* close and reopen cmdlogfile for log rotate*/ - if (ctx->log.cmdlogfile) { - fclose (ctx->log.cmdlogfile); - ctx->log.cmdlogfile = NULL; - } - - fd = sys_open (ctx->log.cmd_log_filename, - O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR); - if (fd < 0) { - gf_msg (this->name, GF_LOG_CRITICAL, errno, - LG_MSG_FILE_OP_FAILED, "failed to open cmd_log_file"); - return -1; - } - - ctx->log.cmdlogfile = fdopen (fd, "a"); - if (!ctx->log.cmdlogfile){ - gf_msg (this->name, GF_LOG_CRITICAL, errno, - LG_MSG_FILE_OP_FAILED, - "gf_cmd_log_init: failed to open logfile \"%s\" " - "\n", ctx->log.cmd_log_filename); - sys_close (fd); - return -1; - } - return 0; + int fd = -1; + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + + this = THIS; + ctx = this->ctx; + + if (!ctx) + return -1; + + if (!filename) { + gf_msg(this->name, GF_LOG_CRITICAL, 0, LG_MSG_INVALID_ENTRY, + "gf_cmd_log_init: no filename specified\n"); + return -1; + } + + ctx->log.cmd_log_filename = gf_strdup(filename); + if (!ctx->log.cmd_log_filename) { + return -1; + } + /* close and reopen cmdlogfile for log rotate*/ + if (ctx->log.cmdlogfile) { + fclose(ctx->log.cmdlogfile); + ctx->log.cmdlogfile = NULL; + } + + fd = sys_open(ctx->log.cmd_log_filename, O_CREAT | O_WRONLY | O_APPEND, + S_IRUSR | S_IWUSR); + if (fd < 0) { + gf_msg(this->name, GF_LOG_CRITICAL, errno, LG_MSG_FILE_OP_FAILED, + "failed to open cmd_log_file"); + return -1; + } + + ctx->log.cmdlogfile = fdopen(fd, "a"); + if (!ctx->log.cmdlogfile) { + gf_msg(this->name, GF_LOG_CRITICAL, errno, LG_MSG_FILE_OP_FAILED, + "gf_cmd_log_init: failed to open logfile \"%s\" " + "\n", + ctx->log.cmd_log_filename); + sys_close(fd); + return -1; + } + return 0; } int -gf_cmd_log (const char *domain, const char *fmt, ...) +gf_cmd_log(const char *domain, const char *fmt, ...) { - va_list ap; - char timestr[64]; - struct timeval tv = {0,}; - char *str1 = NULL; - char *str2 = NULL; - char *msg = NULL; - size_t len = 0; - int ret = 0; - int fd = -1; - glusterfs_ctx_t *ctx = NULL; - - ctx = THIS->ctx; - - if (!ctx) - return -1; - - if (!ctx->log.cmdlogfile) - return -1; - - - if (!domain || !fmt) { - gf_msg_trace ("glusterd", 0, - "logging: invalid argument\n"); - return -1; - } + va_list ap; + char timestr[64]; + struct timeval tv = { + 0, + }; + char *str1 = NULL; + char *str2 = NULL; + char *msg = NULL; + size_t len = 0; + int ret = 0; + int fd = -1; + glusterfs_ctx_t *ctx = NULL; + + ctx = THIS->ctx; + + if (!ctx) + return -1; + + if (!ctx->log.cmdlogfile) + return -1; + + if (!domain || !fmt) { + gf_msg_trace("glusterd", 0, "logging: invalid argument\n"); + return -1; + } + + ret = gettimeofday(&tv, NULL); + if (ret == -1) + goto out; + va_start(ap, fmt); + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + snprintf(timestr + strlen(timestr), GF_LOG_TIMESTR_SIZE - strlen(timestr), + ".%" GF_PRI_SUSECONDS, tv.tv_usec); + + ret = gf_asprintf(&str1, "[%s] %s : ", timestr, domain); + if (ret == -1) { + goto out; + } + + ret = vasprintf(&str2, fmt, ap); + if (ret == -1) { + goto out; + } + + va_end(ap); + + len = strlen(str1); + msg = GF_MALLOC(len + strlen(str2) + 1, gf_common_mt_char); + if (!msg) { + goto out; + } + + strcpy(msg, str1); + strcpy(msg + len, str2); + + /* close and reopen cmdlogfile fd for in case of log rotate*/ + if (ctx->log.cmd_history_logrotate) { + ctx->log.cmd_history_logrotate = 0; - ret = gettimeofday (&tv, NULL); - if (ret == -1) - goto out; - va_start (ap, fmt); - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - snprintf (timestr + strlen (timestr), - GF_LOG_TIMESTR_SIZE - strlen (timestr), - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - - ret = gf_asprintf (&str1, "[%s] %s : ", - timestr, domain); - if (ret == -1) { - goto out; - } - - ret = vasprintf (&str2, fmt, ap); - if (ret == -1) { - goto out; + if (ctx->log.cmdlogfile) { + fclose(ctx->log.cmdlogfile); + ctx->log.cmdlogfile = NULL; } - va_end (ap); - - len = strlen (str1); - msg = GF_MALLOC (len + strlen (str2) + 1, gf_common_mt_char); - if (!msg) { - goto out; + fd = sys_open(ctx->log.cmd_log_filename, O_CREAT | O_WRONLY | O_APPEND, + S_IRUSR | S_IWUSR); + if (fd < 0) { + gf_msg(THIS->name, GF_LOG_CRITICAL, errno, LG_MSG_FILE_OP_FAILED, + "failed to open " + "logfile \"%s\" \n", + ctx->log.cmd_log_filename); + ret = -1; + goto out; } - strcpy (msg, str1); - strcpy (msg + len, str2); - - /* close and reopen cmdlogfile fd for in case of log rotate*/ - if (ctx->log.cmd_history_logrotate) { - ctx->log.cmd_history_logrotate = 0; - - if (ctx->log.cmdlogfile) { - fclose (ctx->log.cmdlogfile); - ctx->log.cmdlogfile = NULL; - } - - fd = sys_open (ctx->log.cmd_log_filename, - O_CREAT | O_WRONLY | O_APPEND, - S_IRUSR | S_IWUSR); - if (fd < 0) { - gf_msg (THIS->name, GF_LOG_CRITICAL, errno, - LG_MSG_FILE_OP_FAILED, "failed to open " - "logfile \"%s\" \n", ctx->log.cmd_log_filename); - ret = -1; - goto out; - } - - ctx->log.cmdlogfile = fdopen (fd, "a"); - if (!ctx->log.cmdlogfile) { - gf_msg (THIS->name, GF_LOG_CRITICAL, errno, - LG_MSG_FILE_OP_FAILED, - "failed to open logfile \"%s\"" - " \n", ctx->log.cmd_log_filename); - ret = -1; - sys_close (fd); - goto out; - } + ctx->log.cmdlogfile = fdopen(fd, "a"); + if (!ctx->log.cmdlogfile) { + gf_msg(THIS->name, GF_LOG_CRITICAL, errno, LG_MSG_FILE_OP_FAILED, + "failed to open logfile \"%s\"" + " \n", + ctx->log.cmd_log_filename); + ret = -1; + sys_close(fd); + goto out; } + } - fprintf (ctx->log.cmdlogfile, "%s\n", msg); - fflush (ctx->log.cmdlogfile); + fprintf(ctx->log.cmdlogfile, "%s\n", msg); + fflush(ctx->log.cmdlogfile); out: - GF_FREE (msg); + GF_FREE(msg); - GF_FREE (str1); + GF_FREE(str1); - FREE (str2); + FREE(str2); - va_end (ap); + va_end(ap); - return ret; + return ret; } static int -_do_slog_format (const char *event, va_list inp, char **msg) { - va_list valist_tmp; - int i = 0; - int j = 0; - int k = 0; - int ret = 0; - char *fmt = NULL; - char *buffer = NULL; - int num_format_chars = 0; - char format_char = '%'; - char *tmp1 = NULL; - char *tmp2 = NULL; - - ret = gf_asprintf (&tmp2, "%s", event); - if (ret == -1) +_do_slog_format(const char *event, va_list inp, char **msg) +{ + va_list valist_tmp; + int i = 0; + int j = 0; + int k = 0; + int ret = 0; + char *fmt = NULL; + char *buffer = NULL; + int num_format_chars = 0; + char format_char = '%'; + char *tmp1 = NULL; + char *tmp2 = NULL; + + ret = gf_asprintf(&tmp2, "%s", event); + if (ret == -1) + goto out; + + /* Hardcoded value for max key value pairs, exits early */ + /* from loop if found NULL */ + for (i = 0; i < GF_MAX_SLOG_PAIR_COUNT; i++) { + fmt = va_arg(inp, char *); + if (fmt == NULL) { + break; + } + + /* Get number of times % is used in input for formatting, */ + /* this count will be used to skip those many args from the */ + /* main list and will be used to format inner format */ + num_format_chars = 0; + for (k = 0; fmt[k] != '\0'; k++) { + /* If %% is used then that is escaped */ + if (fmt[k] == format_char && fmt[k + 1] == format_char) { + k++; + } else if (fmt[k] == format_char) { + num_format_chars++; + } + } + + tmp1 = gf_strdup(tmp2); + if (!tmp1) { + ret = -1; + goto out; + } + + GF_FREE(tmp2); + tmp2 = NULL; + + if (num_format_chars > 0) { + /* Make separate valist and format the string */ + va_copy(valist_tmp, inp); + ret = gf_vasprintf(&buffer, fmt, valist_tmp); + if (ret < 0) { + va_end(valist_tmp); goto out; + } + va_end(valist_tmp); - /* Hardcoded value for max key value pairs, exits early */ - /* from loop if found NULL */ - for (i = 0; i < GF_MAX_SLOG_PAIR_COUNT; i++) { - fmt = va_arg (inp, char*); - if (fmt == NULL) { - break; - } - - /* Get number of times % is used in input for formatting, */ - /* this count will be used to skip those many args from the */ - /* main list and will be used to format inner format */ - num_format_chars = 0; - for (k = 0; fmt[k] != '\0'; k++) { - /* If %% is used then that is escaped */ - if (fmt[k] == format_char && fmt[k+1] == format_char) { - k++; - } else if (fmt[k] == format_char) { - num_format_chars++; - } - } - - tmp1 = gf_strdup (tmp2); - if (!tmp1) { - ret = -1; - goto out; - } + for (j = 0; j < num_format_chars; j++) { + /* Skip the va_arg value since these values + are already used for internal formatting */ + (void)va_arg(inp, void *); + } - GF_FREE (tmp2); - tmp2 = NULL; - - if (num_format_chars > 0) { - /* Make separate valist and format the string */ - va_copy (valist_tmp, inp); - ret = gf_vasprintf (&buffer, fmt, valist_tmp); - if (ret < 0) { - va_end (valist_tmp); - goto out; - } - va_end (valist_tmp); - - for (j = 0; j < num_format_chars; j++) { - /* Skip the va_arg value since these values - are already used for internal formatting */ - (void) va_arg (inp, void*); - } - - ret = gf_asprintf (&tmp2, "%s\t%s", tmp1, buffer); - if (ret < 0) - goto out; - - GF_FREE (buffer); - buffer = NULL; - } else { - ret = gf_asprintf (&tmp2, "%s\t%s", tmp1, fmt); - if (ret < 0) - goto out; - } + ret = gf_asprintf(&tmp2, "%s\t%s", tmp1, buffer); + if (ret < 0) + goto out; - GF_FREE (tmp1); - tmp1 = NULL; + GF_FREE(buffer); + buffer = NULL; + } else { + ret = gf_asprintf(&tmp2, "%s\t%s", tmp1, fmt); + if (ret < 0) + goto out; } - *msg = gf_strdup (tmp2); - if (!*msg) - ret = -1; + GF_FREE(tmp1); + tmp1 = NULL; + } - out: - if (buffer) - GF_FREE (buffer); + *msg = gf_strdup(tmp2); + if (!*msg) + ret = -1; - if (tmp1) - GF_FREE (tmp1); +out: + if (buffer) + GF_FREE(buffer); - if (tmp2) - GF_FREE (tmp2); + if (tmp1) + GF_FREE(tmp1); - return ret; + if (tmp2) + GF_FREE(tmp2); + + return ret; } int -_gf_smsg (const char *domain, const char *file, const char *function, - int32_t line, gf_loglevel_t level, int errnum, int trace, - uint64_t msgid, const char *event, ...) +_gf_smsg(const char *domain, const char *file, const char *function, + int32_t line, gf_loglevel_t level, int errnum, int trace, + uint64_t msgid, const char *event, ...) { - va_list valist; - char *msg = NULL; - int ret = 0; + va_list valist; + char *msg = NULL; + int ret = 0; - va_start (valist, event); - ret = _do_slog_format (event, valist, &msg); - if (ret == -1) - goto out; + va_start(valist, event); + ret = _do_slog_format(event, valist, &msg); + if (ret == -1) + goto out; - ret = _gf_msg (domain, file, function, line, level, errnum, trace, - msgid, "%s", msg); + ret = _gf_msg(domain, file, function, line, level, errnum, trace, msgid, + "%s", msg); - out: - va_end (valist); - if (msg) - GF_FREE (msg); - return ret; +out: + va_end(valist); + if (msg) + GF_FREE(msg); + return ret; } int -_gf_slog (const char *domain, const char *file, const char *function, int line, - gf_loglevel_t level, const char *event, ...) +_gf_slog(const char *domain, const char *file, const char *function, int line, + gf_loglevel_t level, const char *event, ...) { - va_list valist; - char *msg = NULL; - int ret = 0; + va_list valist; + char *msg = NULL; + int ret = 0; - va_start (valist, event); - ret = _do_slog_format (event, valist, &msg); - if (ret == -1) - goto out; + va_start(valist, event); + ret = _do_slog_format(event, valist, &msg); + if (ret == -1) + goto out; - ret = _gf_log (domain, file, function, line, level, "%s", msg); + ret = _gf_log(domain, file, function, line, level, "%s", msg); - out: - va_end (valist); - if (msg) - GF_FREE (msg); - return ret; +out: + va_end(valist); + if (msg) + GF_FREE(msg); + return ret; } diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c index 4b140296b4f..cff96323867 100644 --- a/libglusterfs/src/mem-pool.c +++ b/libglusterfs/src/mem-pool.c @@ -18,528 +18,519 @@ #include "libglusterfs-messages.h" void -gf_mem_acct_enable_set (void *data) +gf_mem_acct_enable_set(void *data) { - glusterfs_ctx_t *ctx = NULL; + glusterfs_ctx_t *ctx = NULL; - REQUIRE(data != NULL); + REQUIRE(data != NULL); - ctx = data; + ctx = data; - GF_ASSERT (ctx != NULL); + GF_ASSERT(ctx != NULL); - ctx->mem_acct_enable = 1; + ctx->mem_acct_enable = 1; - ENSURE(1 == ctx->mem_acct_enable); + ENSURE(1 == ctx->mem_acct_enable); - return; + return; } int -gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr, size_t size, - uint32_t type, const char *typestr) +gf_mem_set_acct_info(xlator_t *xl, char **alloc_ptr, size_t size, uint32_t type, + const char *typestr) { + void *ptr = NULL; + struct mem_header *header = NULL; - void *ptr = NULL; - struct mem_header *header = NULL; + if (!alloc_ptr) + return -1; - if (!alloc_ptr) - return -1; + ptr = *alloc_ptr; - ptr = *alloc_ptr; + GF_ASSERT(xl != NULL); - GF_ASSERT (xl != NULL); + GF_ASSERT(xl->mem_acct != NULL); - GF_ASSERT (xl->mem_acct != NULL); + GF_ASSERT(type <= xl->mem_acct->num_types); - GF_ASSERT (type <= xl->mem_acct->num_types); + LOCK(&xl->mem_acct->rec[type].lock); + { + if (!xl->mem_acct->rec[type].typestr) + xl->mem_acct->rec[type].typestr = typestr; + xl->mem_acct->rec[type].size += size; + xl->mem_acct->rec[type].num_allocs++; + xl->mem_acct->rec[type].total_allocs++; + xl->mem_acct->rec[type].max_size = max(xl->mem_acct->rec[type].max_size, + xl->mem_acct->rec[type].size); + xl->mem_acct->rec[type].max_num_allocs = max( + xl->mem_acct->rec[type].max_num_allocs, + xl->mem_acct->rec[type].num_allocs); + } + UNLOCK(&xl->mem_acct->rec[type].lock); - LOCK(&xl->mem_acct->rec[type].lock); - { - if (!xl->mem_acct->rec[type].typestr) - xl->mem_acct->rec[type].typestr = typestr; - xl->mem_acct->rec[type].size += size; - xl->mem_acct->rec[type].num_allocs++; - xl->mem_acct->rec[type].total_allocs++; - xl->mem_acct->rec[type].max_size = - max (xl->mem_acct->rec[type].max_size, - xl->mem_acct->rec[type].size); - xl->mem_acct->rec[type].max_num_allocs = - max (xl->mem_acct->rec[type].max_num_allocs, - xl->mem_acct->rec[type].num_allocs); - } - UNLOCK(&xl->mem_acct->rec[type].lock); + GF_ATOMIC_INC(xl->mem_acct->refcnt); - GF_ATOMIC_INC (xl->mem_acct->refcnt); - - header = (struct mem_header *) ptr; - header->type = type; - header->size = size; - header->mem_acct = xl->mem_acct; - header->magic = GF_MEM_HEADER_MAGIC; + header = (struct mem_header *)ptr; + header->type = type; + header->size = size; + header->mem_acct = xl->mem_acct; + header->magic = GF_MEM_HEADER_MAGIC; #ifdef DEBUG - INIT_LIST_HEAD(&header->acct_list); - LOCK(&xl->mem_acct->rec[type].lock); - { - list_add (&header->acct_list, - &(xl->mem_acct->rec[type].obj_list)); - } - UNLOCK(&xl->mem_acct->rec[type].lock); + INIT_LIST_HEAD(&header->acct_list); + LOCK(&xl->mem_acct->rec[type].lock); + { + list_add(&header->acct_list, &(xl->mem_acct->rec[type].obj_list)); + } + UNLOCK(&xl->mem_acct->rec[type].lock); #endif - ptr += sizeof (struct mem_header); - /* data follows in this gap of 'size' bytes */ - *(uint32_t *) (ptr + size) = GF_MEM_TRAILER_MAGIC; + ptr += sizeof(struct mem_header); + /* data follows in this gap of 'size' bytes */ + *(uint32_t *)(ptr + size) = GF_MEM_TRAILER_MAGIC; - *alloc_ptr = ptr; - return 0; + *alloc_ptr = ptr; + return 0; } - void * -__gf_calloc (size_t nmemb, size_t size, uint32_t type, const char *typestr) +__gf_calloc(size_t nmemb, size_t size, uint32_t type, const char *typestr) { - size_t tot_size = 0; - size_t req_size = 0; - char *ptr = NULL; - xlator_t *xl = NULL; + size_t tot_size = 0; + size_t req_size = 0; + char *ptr = NULL; + xlator_t *xl = NULL; - if (!THIS->ctx->mem_acct_enable) - return CALLOC (nmemb, size); + if (!THIS->ctx->mem_acct_enable) + return CALLOC(nmemb, size); - xl = THIS; + xl = THIS; - req_size = nmemb * size; - tot_size = req_size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; + req_size = nmemb * size; + tot_size = req_size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; - ptr = calloc (1, tot_size); + ptr = calloc(1, tot_size); - if (!ptr) { - gf_msg_nomem ("", GF_LOG_ALERT, tot_size); - return NULL; - } - gf_mem_set_acct_info (xl, &ptr, req_size, type, typestr); + if (!ptr) { + gf_msg_nomem("", GF_LOG_ALERT, tot_size); + return NULL; + } + gf_mem_set_acct_info(xl, &ptr, req_size, type, typestr); - return (void *)ptr; + return (void *)ptr; } void * -__gf_malloc (size_t size, uint32_t type, const char *typestr) +__gf_malloc(size_t size, uint32_t type, const char *typestr) { - size_t tot_size = 0; - char *ptr = NULL; - xlator_t *xl = NULL; + size_t tot_size = 0; + char *ptr = NULL; + xlator_t *xl = NULL; - if (!THIS->ctx->mem_acct_enable) - return MALLOC (size); + if (!THIS->ctx->mem_acct_enable) + return MALLOC(size); - xl = THIS; + xl = THIS; - tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; + tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; - ptr = malloc (tot_size); - if (!ptr) { - gf_msg_nomem ("", GF_LOG_ALERT, tot_size); - return NULL; - } - gf_mem_set_acct_info (xl, &ptr, size, type, typestr); + ptr = malloc(tot_size); + if (!ptr) { + gf_msg_nomem("", GF_LOG_ALERT, tot_size); + return NULL; + } + gf_mem_set_acct_info(xl, &ptr, size, type, typestr); - return (void *)ptr; + return (void *)ptr; } void * -__gf_realloc (void *ptr, size_t size) +__gf_realloc(void *ptr, size_t size) { - size_t tot_size = 0; - char *new_ptr; - struct mem_header *old_header = NULL; - struct mem_header *new_header = NULL; - struct mem_header tmp_header; + size_t tot_size = 0; + char *new_ptr; + struct mem_header *old_header = NULL; + struct mem_header *new_header = NULL; + struct mem_header tmp_header; - if (!THIS->ctx->mem_acct_enable) - return REALLOC (ptr, size); + if (!THIS->ctx->mem_acct_enable) + return REALLOC(ptr, size); - REQUIRE(NULL != ptr); + REQUIRE(NULL != ptr); - old_header = (struct mem_header *) (ptr - GF_MEM_HEADER_SIZE); - GF_ASSERT (old_header->magic == GF_MEM_HEADER_MAGIC); - tmp_header = *old_header; + old_header = (struct mem_header *)(ptr - GF_MEM_HEADER_SIZE); + GF_ASSERT(old_header->magic == GF_MEM_HEADER_MAGIC); + tmp_header = *old_header; #ifdef DEBUG - int type = 0; - size_t copy_size = 0; - - /* Making these changes for realloc is not straightforward. So - * I am simulating realloc using calloc and free - */ - - type = tmp_header.type; - new_ptr = __gf_calloc (1, size, type, - tmp_header.mem_acct->rec[type].typestr); - if (new_ptr) { - copy_size = (size > tmp_header.size) ? tmp_header.size : size; - memcpy (new_ptr, ptr, copy_size); - __gf_free (ptr); - } - - /* This is not quite what the man page says should happen */ - return new_ptr; + int type = 0; + size_t copy_size = 0; + + /* Making these changes for realloc is not straightforward. So + * I am simulating realloc using calloc and free + */ + + type = tmp_header.type; + new_ptr = __gf_calloc(1, size, type, + tmp_header.mem_acct->rec[type].typestr); + if (new_ptr) { + copy_size = (size > tmp_header.size) ? tmp_header.size : size; + memcpy(new_ptr, ptr, copy_size); + __gf_free(ptr); + } + + /* This is not quite what the man page says should happen */ + return new_ptr; #endif - tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; - new_ptr = realloc (old_header, tot_size); - if (!new_ptr) { - gf_msg_nomem ("", GF_LOG_ALERT, tot_size); - return NULL; - } - - /* - * We used to pass (char **)&ptr as the second - * argument after the value of realloc was saved - * in ptr, but the compiler warnings complained - * about the casting to and forth from void ** to - * char **. - * TBD: it would be nice to adjust the memory accounting info here, - * but calling gf_mem_set_acct_info here is wrong because it bumps - * up counts as though this is a new allocation - which it's not. - * The consequence of doing nothing here is only that the sizes will be - * wrong, but at least the counts won't be. - uint32_t type = 0; - xlator_t *xl = NULL; - type = header->type; - xl = (xlator_t *) header->xlator; - gf_mem_set_acct_info (xl, &new_ptr, size, type, NULL); - */ - - new_header = (struct mem_header *) new_ptr; - *new_header = tmp_header; - new_header->size = size; - - new_ptr += sizeof (struct mem_header); - /* data follows in this gap of 'size' bytes */ - *(uint32_t *) (new_ptr + size) = GF_MEM_TRAILER_MAGIC; - - return (void *)new_ptr; + tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE; + new_ptr = realloc(old_header, tot_size); + if (!new_ptr) { + gf_msg_nomem("", GF_LOG_ALERT, tot_size); + return NULL; + } + + /* + * We used to pass (char **)&ptr as the second + * argument after the value of realloc was saved + * in ptr, but the compiler warnings complained + * about the casting to and forth from void ** to + * char **. + * TBD: it would be nice to adjust the memory accounting info here, + * but calling gf_mem_set_acct_info here is wrong because it bumps + * up counts as though this is a new allocation - which it's not. + * The consequence of doing nothing here is only that the sizes will be + * wrong, but at least the counts won't be. + uint32_t type = 0; + xlator_t *xl = NULL; + type = header->type; + xl = (xlator_t *) header->xlator; + gf_mem_set_acct_info (xl, &new_ptr, size, type, NULL); + */ + + new_header = (struct mem_header *)new_ptr; + *new_header = tmp_header; + new_header->size = size; + + new_ptr += sizeof(struct mem_header); + /* data follows in this gap of 'size' bytes */ + *(uint32_t *)(new_ptr + size) = GF_MEM_TRAILER_MAGIC; + + return (void *)new_ptr; } int -gf_vasprintf (char **string_ptr, const char *format, va_list arg) +gf_vasprintf(char **string_ptr, const char *format, va_list arg) { - va_list arg_save; - char *str = NULL; - int size = 0; - int rv = 0; - - if (!string_ptr || !format) - return -1; - - va_copy (arg_save, arg); - - size = vsnprintf (NULL, 0, format, arg); - size++; - str = GF_MALLOC (size, gf_common_mt_asprintf); - if (str == NULL) { - /* log is done in GF_MALLOC itself */ - va_end (arg_save); - return -1; - } - rv = vsnprintf (str, size, format, arg_save); - - *string_ptr = str; - va_end (arg_save); - return (rv); + va_list arg_save; + char *str = NULL; + int size = 0; + int rv = 0; + + if (!string_ptr || !format) + return -1; + + va_copy(arg_save, arg); + + size = vsnprintf(NULL, 0, format, arg); + size++; + str = GF_MALLOC(size, gf_common_mt_asprintf); + if (str == NULL) { + /* log is done in GF_MALLOC itself */ + va_end(arg_save); + return -1; + } + rv = vsnprintf(str, size, format, arg_save); + + *string_ptr = str; + va_end(arg_save); + return (rv); } int -gf_asprintf (char **string_ptr, const char *format, ...) +gf_asprintf(char **string_ptr, const char *format, ...) { - va_list arg; - int rv = 0; + va_list arg; + int rv = 0; - va_start (arg, format); - rv = gf_vasprintf (string_ptr, format, arg); - va_end (arg); + va_start(arg, format); + rv = gf_vasprintf(string_ptr, format, arg); + va_end(arg); - return rv; + return rv; } #ifdef DEBUG void -__gf_mem_invalidate (void *ptr) +__gf_mem_invalidate(void *ptr) { - struct mem_header *header = ptr; - void *end = NULL; - - struct mem_invalid inval = { - .magic = GF_MEM_INVALID_MAGIC, - .mem_acct = header->mem_acct, - .type = header->type, - .size = header->size, - .baseaddr = ptr + GF_MEM_HEADER_SIZE, - }; - - /* calculate the last byte of the allocated area */ - end = ptr + GF_MEM_HEADER_SIZE + inval.size + GF_MEM_TRAILER_SIZE; - - /* overwrite the old mem_header */ - memcpy (ptr, &inval, sizeof (inval)); - ptr += sizeof (inval); - - /* zero out remaining (old) mem_header bytes) */ - memset (ptr, 0x00, sizeof (*header) - sizeof (inval)); - ptr += sizeof (*header) - sizeof (inval); - - /* zero out the first byte of data */ - *(uint32_t *)(ptr) = 0x00; - ptr += 1; - - /* repeated writes of invalid structurein data area */ - while ((ptr + (sizeof (inval))) < (end - 1)) { - memcpy (ptr, &inval, sizeof (inval)); - ptr += sizeof (inval); - } - - /* fill out remaining data area with 0xff */ - memset (ptr, 0xff, end - ptr); + struct mem_header *header = ptr; + void *end = NULL; + + struct mem_invalid inval = { + .magic = GF_MEM_INVALID_MAGIC, + .mem_acct = header->mem_acct, + .type = header->type, + .size = header->size, + .baseaddr = ptr + GF_MEM_HEADER_SIZE, + }; + + /* calculate the last byte of the allocated area */ + end = ptr + GF_MEM_HEADER_SIZE + inval.size + GF_MEM_TRAILER_SIZE; + + /* overwrite the old mem_header */ + memcpy(ptr, &inval, sizeof(inval)); + ptr += sizeof(inval); + + /* zero out remaining (old) mem_header bytes) */ + memset(ptr, 0x00, sizeof(*header) - sizeof(inval)); + ptr += sizeof(*header) - sizeof(inval); + + /* zero out the first byte of data */ + *(uint32_t *)(ptr) = 0x00; + ptr += 1; + + /* repeated writes of invalid structurein data area */ + while ((ptr + (sizeof(inval))) < (end - 1)) { + memcpy(ptr, &inval, sizeof(inval)); + ptr += sizeof(inval); + } + + /* fill out remaining data area with 0xff */ + memset(ptr, 0xff, end - ptr); } #endif /* DEBUG */ void -__gf_free (void *free_ptr) +__gf_free(void *free_ptr) { - void *ptr = NULL; - struct mem_acct *mem_acct; - struct mem_header *header = NULL; + void *ptr = NULL; + struct mem_acct *mem_acct; + struct mem_header *header = NULL; - if (!THIS->ctx->mem_acct_enable) { - FREE (free_ptr); - return; - } - - if (!free_ptr) - return; - - ptr = free_ptr - GF_MEM_HEADER_SIZE; - header = (struct mem_header *) ptr; - - //Possible corruption, assert here - GF_ASSERT (GF_MEM_HEADER_MAGIC == header->magic); - - mem_acct = header->mem_acct; - if (!mem_acct) { - goto free; - } + if (!THIS->ctx->mem_acct_enable) { + FREE(free_ptr); + return; + } - // This points to a memory overrun - GF_ASSERT (GF_MEM_TRAILER_MAGIC == - *(uint32_t *)((char *)free_ptr + header->size)); + if (!free_ptr) + return; - LOCK (&mem_acct->rec[header->type].lock); - { - mem_acct->rec[header->type].size -= header->size; - mem_acct->rec[header->type].num_allocs--; - /* If all the instances are freed up then ensure typestr is set - * to NULL */ - if (!mem_acct->rec[header->type].num_allocs) - mem_acct->rec[header->type].typestr = NULL; + ptr = free_ptr - GF_MEM_HEADER_SIZE; + header = (struct mem_header *)ptr; + + // Possible corruption, assert here + GF_ASSERT(GF_MEM_HEADER_MAGIC == header->magic); + + mem_acct = header->mem_acct; + if (!mem_acct) { + goto free; + } + + // This points to a memory overrun + GF_ASSERT(GF_MEM_TRAILER_MAGIC == + *(uint32_t *)((char *)free_ptr + header->size)); + + LOCK(&mem_acct->rec[header->type].lock); + { + mem_acct->rec[header->type].size -= header->size; + mem_acct->rec[header->type].num_allocs--; + /* If all the instances are freed up then ensure typestr is set + * to NULL */ + if (!mem_acct->rec[header->type].num_allocs) + mem_acct->rec[header->type].typestr = NULL; #ifdef DEBUG - list_del (&header->acct_list); + list_del(&header->acct_list); #endif - } - UNLOCK (&mem_acct->rec[header->type].lock); + } + UNLOCK(&mem_acct->rec[header->type].lock); - if (GF_ATOMIC_DEC (mem_acct->refcnt) == 0) { - FREE (mem_acct); - } + if (GF_ATOMIC_DEC(mem_acct->refcnt) == 0) { + FREE(mem_acct); + } free: #ifdef DEBUG - __gf_mem_invalidate (ptr); + __gf_mem_invalidate(ptr); #endif - FREE (ptr); + FREE(ptr); } -#define POOL_SMALLEST 7 /* i.e. 128 */ -#define POOL_LARGEST 20 /* i.e. 1048576 */ -#define NPOOLS (POOL_LARGEST - POOL_SMALLEST + 1) +#define POOL_SMALLEST 7 /* i.e. 128 */ +#define POOL_LARGEST 20 /* i.e. 1048576 */ +#define NPOOLS (POOL_LARGEST - POOL_SMALLEST + 1) -static pthread_key_t pool_key; -static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER; -static struct list_head pool_threads; -static pthread_mutex_t pool_free_lock = PTHREAD_MUTEX_INITIALIZER; -static struct list_head pool_free_threads; -static struct mem_pool_shared pools[NPOOLS]; -static size_t pool_list_size; +static pthread_key_t pool_key; +static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER; +static struct list_head pool_threads; +static pthread_mutex_t pool_free_lock = PTHREAD_MUTEX_INITIALIZER; +static struct list_head pool_free_threads; +static struct mem_pool_shared pools[NPOOLS]; +static size_t pool_list_size; #if !defined(GF_DISABLE_MEMPOOL) -#define N_COLD_LISTS 1024 +#define N_COLD_LISTS 1024 #define POOL_SWEEP_SECS 30 -static unsigned long sweep_times; -static unsigned long sweep_usecs; -static unsigned long frees_to_system; +static unsigned long sweep_times; +static unsigned long sweep_usecs; +static unsigned long frees_to_system; typedef struct { - struct list_head death_row; - pooled_obj_hdr_t *cold_lists[N_COLD_LISTS]; - unsigned int n_cold_lists; + struct list_head death_row; + pooled_obj_hdr_t *cold_lists[N_COLD_LISTS]; + unsigned int n_cold_lists; } sweep_state_t; enum init_state { - GF_MEMPOOL_INIT_NONE = 0, - GF_MEMPOOL_INIT_PREINIT, - GF_MEMPOOL_INIT_EARLY, - GF_MEMPOOL_INIT_LATE, - GF_MEMPOOL_INIT_DESTROY + GF_MEMPOOL_INIT_NONE = 0, + GF_MEMPOOL_INIT_PREINIT, + GF_MEMPOOL_INIT_EARLY, + GF_MEMPOOL_INIT_LATE, + GF_MEMPOOL_INIT_DESTROY }; -static enum init_state init_done = GF_MEMPOOL_INIT_NONE; -static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; -static unsigned int init_count = 0; -static pthread_t sweeper_tid; - +static enum init_state init_done = GF_MEMPOOL_INIT_NONE; +static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; +static unsigned int init_count = 0; +static pthread_t sweeper_tid; void -collect_garbage (sweep_state_t *state, per_thread_pool_list_t *pool_list) +collect_garbage(sweep_state_t *state, per_thread_pool_list_t *pool_list) { - unsigned int i; - per_thread_pool_t *pt_pool; + unsigned int i; + per_thread_pool_t *pt_pool; - if (pool_list->poison) { - list_del (&pool_list->thr_list); - list_add (&pool_list->thr_list, &state->death_row); - return; - } + if (pool_list->poison) { + list_del(&pool_list->thr_list); + list_add(&pool_list->thr_list, &state->death_row); + return; + } - if (state->n_cold_lists >= N_COLD_LISTS) { - return; - } + if (state->n_cold_lists >= N_COLD_LISTS) { + return; + } - (void) pthread_spin_lock (&pool_list->lock); - for (i = 0; i < NPOOLS; ++i) { - pt_pool = &pool_list->pools[i]; - if (pt_pool->cold_list) { - state->cold_lists[state->n_cold_lists++] - = pt_pool->cold_list; - } - pt_pool->cold_list = pt_pool->hot_list; - pt_pool->hot_list = NULL; - if (state->n_cold_lists >= N_COLD_LISTS) { - /* We'll just catch up on a future pass. */ - break; - } + (void)pthread_spin_lock(&pool_list->lock); + for (i = 0; i < NPOOLS; ++i) { + pt_pool = &pool_list->pools[i]; + if (pt_pool->cold_list) { + state->cold_lists[state->n_cold_lists++] = pt_pool->cold_list; + } + pt_pool->cold_list = pt_pool->hot_list; + pt_pool->hot_list = NULL; + if (state->n_cold_lists >= N_COLD_LISTS) { + /* We'll just catch up on a future pass. */ + break; } - (void) pthread_spin_unlock (&pool_list->lock); + } + (void)pthread_spin_unlock(&pool_list->lock); } - void -free_obj_list (pooled_obj_hdr_t *victim) +free_obj_list(pooled_obj_hdr_t *victim) { - pooled_obj_hdr_t *next; - - while (victim) { - next = victim->next; - free (victim); - victim = next; - ++frees_to_system; - } + pooled_obj_hdr_t *next; + + while (victim) { + next = victim->next; + free(victim); + victim = next; + ++frees_to_system; + } } void * -pool_sweeper (void *arg) +pool_sweeper(void *arg) { - sweep_state_t state; - per_thread_pool_list_t *pool_list; - per_thread_pool_list_t *next_pl; - per_thread_pool_t *pt_pool; - unsigned int i; - struct timeval begin_time; - struct timeval end_time; - struct timeval elapsed; - - /* - * This is all a bit inelegant, but the point is to avoid doing - * expensive things (like freeing thousands of objects) while holding a - * global lock. Thus, we split each iteration into three passes, with - * only the first and fastest holding the lock. - */ - - for (;;) { - sleep (POOL_SWEEP_SECS); - (void) pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - INIT_LIST_HEAD (&state.death_row); - state.n_cold_lists = 0; - - /* First pass: collect stuff that needs our attention. */ - (void) gettimeofday (&begin_time, NULL); - (void) pthread_mutex_lock (&pool_lock); - list_for_each_entry_safe (pool_list, next_pl, - &pool_threads, thr_list) { - collect_garbage (&state, pool_list); - } - (void) pthread_mutex_unlock (&pool_lock); - (void) gettimeofday (&end_time, NULL); - timersub (&end_time, &begin_time, &elapsed); - sweep_usecs += elapsed.tv_sec * 1000000 + elapsed.tv_usec; - sweep_times += 1; - - /* Second pass: free dead pools. */ - (void) pthread_mutex_lock (&pool_free_lock); - list_for_each_entry_safe (pool_list, next_pl, - &state.death_row, thr_list) { - for (i = 0; i < NPOOLS; ++i) { - pt_pool = &pool_list->pools[i]; - free_obj_list (pt_pool->cold_list); - free_obj_list (pt_pool->hot_list); - pt_pool->hot_list = pt_pool->cold_list = NULL; - } - list_del (&pool_list->thr_list); - list_add (&pool_list->thr_list, &pool_free_threads); - } - (void) pthread_mutex_unlock (&pool_free_lock); + sweep_state_t state; + per_thread_pool_list_t *pool_list; + per_thread_pool_list_t *next_pl; + per_thread_pool_t *pt_pool; + unsigned int i; + struct timeval begin_time; + struct timeval end_time; + struct timeval elapsed; + + /* + * This is all a bit inelegant, but the point is to avoid doing + * expensive things (like freeing thousands of objects) while holding a + * global lock. Thus, we split each iteration into three passes, with + * only the first and fastest holding the lock. + */ + + for (;;) { + sleep(POOL_SWEEP_SECS); + (void)pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + INIT_LIST_HEAD(&state.death_row); + state.n_cold_lists = 0; + + /* First pass: collect stuff that needs our attention. */ + (void)gettimeofday(&begin_time, NULL); + (void)pthread_mutex_lock(&pool_lock); + list_for_each_entry_safe(pool_list, next_pl, &pool_threads, thr_list) + { + collect_garbage(&state, pool_list); + } + (void)pthread_mutex_unlock(&pool_lock); + (void)gettimeofday(&end_time, NULL); + timersub(&end_time, &begin_time, &elapsed); + sweep_usecs += elapsed.tv_sec * 1000000 + elapsed.tv_usec; + sweep_times += 1; - /* Third pass: free cold objects from live pools. */ - for (i = 0; i < state.n_cold_lists; ++i) { - free_obj_list (state.cold_lists[i]); - } - (void) pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); + /* Second pass: free dead pools. */ + (void)pthread_mutex_lock(&pool_free_lock); + list_for_each_entry_safe(pool_list, next_pl, &state.death_row, thr_list) + { + for (i = 0; i < NPOOLS; ++i) { + pt_pool = &pool_list->pools[i]; + free_obj_list(pt_pool->cold_list); + free_obj_list(pt_pool->hot_list); + pt_pool->hot_list = pt_pool->cold_list = NULL; + } + list_del(&pool_list->thr_list); + list_add(&pool_list->thr_list, &pool_free_threads); } -} + (void)pthread_mutex_unlock(&pool_free_lock); + /* Third pass: free cold objects from live pools. */ + for (i = 0; i < state.n_cold_lists; ++i) { + free_obj_list(state.cold_lists[i]); + } + (void)pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + } +} void -pool_destructor (void *arg) +pool_destructor(void *arg) { - per_thread_pool_list_t *pool_list = arg; + per_thread_pool_list_t *pool_list = arg; - /* The pool-sweeper thread will take it from here. */ - pool_list->poison = 1; + /* The pool-sweeper thread will take it from here. */ + pool_list->poison = 1; } - static __attribute__((constructor)) void -mem_pools_preinit (void) +mem_pools_preinit(void) { - unsigned int i; + unsigned int i; - INIT_LIST_HEAD (&pool_threads); - INIT_LIST_HEAD (&pool_free_threads); + INIT_LIST_HEAD(&pool_threads); + INIT_LIST_HEAD(&pool_free_threads); - for (i = 0; i < NPOOLS; ++i) { - pools[i].power_of_two = POOL_SMALLEST + i; + for (i = 0; i < NPOOLS; ++i) { + pools[i].power_of_two = POOL_SMALLEST + i; - GF_ATOMIC_INIT (pools[i].allocs_hot, 0); - GF_ATOMIC_INIT (pools[i].allocs_cold, 0); - GF_ATOMIC_INIT (pools[i].allocs_stdc, 0); - GF_ATOMIC_INIT (pools[i].frees_to_list, 0); - } + GF_ATOMIC_INIT(pools[i].allocs_hot, 0); + GF_ATOMIC_INIT(pools[i].allocs_cold, 0); + GF_ATOMIC_INIT(pools[i].allocs_stdc, 0); + GF_ATOMIC_INIT(pools[i].frees_to_list, 0); + } - pool_list_size = sizeof (per_thread_pool_list_t) - + sizeof (per_thread_pool_t) * (NPOOLS - 1); + pool_list_size = sizeof(per_thread_pool_list_t) + + sizeof(per_thread_pool_t) * (NPOOLS - 1); - init_done = GF_MEMPOOL_INIT_PREINIT; + init_done = GF_MEMPOOL_INIT_PREINIT; } /* Use mem_pools_init_early() function for basic initialization. There will be @@ -547,358 +538,365 @@ mem_pools_preinit (void) * been called. Calling mem_get() will be possible after this function has * setup the basic structures. */ void -mem_pools_init_early (void) +mem_pools_init_early(void) { - pthread_mutex_lock (&init_mutex); - /* Use a pthread_key destructor to clean up when a thread exits. - * - * We won't increase init_count here, that is only done when the - * pool_sweeper thread is started too. - */ - if (init_done == GF_MEMPOOL_INIT_PREINIT || - init_done == GF_MEMPOOL_INIT_DESTROY) { - /* key has not been created yet */ - if (pthread_key_create (&pool_key, pool_destructor) != 0) { - gf_log ("mem-pool", GF_LOG_CRITICAL, - "failed to initialize mem-pool key"); - } - - init_done = GF_MEMPOOL_INIT_EARLY; - } else { - gf_log ("mem-pool", GF_LOG_CRITICAL, - "incorrect order of mem-pool initialization " - "(init_done=%d)", init_done); - } - - pthread_mutex_unlock (&init_mutex); + pthread_mutex_lock(&init_mutex); + /* Use a pthread_key destructor to clean up when a thread exits. + * + * We won't increase init_count here, that is only done when the + * pool_sweeper thread is started too. + */ + if (init_done == GF_MEMPOOL_INIT_PREINIT || + init_done == GF_MEMPOOL_INIT_DESTROY) { + /* key has not been created yet */ + if (pthread_key_create(&pool_key, pool_destructor) != 0) { + gf_log("mem-pool", GF_LOG_CRITICAL, + "failed to initialize mem-pool key"); + } + + init_done = GF_MEMPOOL_INIT_EARLY; + } else { + gf_log("mem-pool", GF_LOG_CRITICAL, + "incorrect order of mem-pool initialization " + "(init_done=%d)", + init_done); + } + + pthread_mutex_unlock(&init_mutex); } /* Call mem_pools_init_late() once threading has been configured completely. * This prevent the pool_sweeper thread from getting killed once the main() * thread exits during deamonizing. */ void -mem_pools_init_late (void) +mem_pools_init_late(void) { - pthread_mutex_lock (&init_mutex); - if ((init_count++) == 0) { - (void) gf_thread_create (&sweeper_tid, NULL, pool_sweeper, - NULL, "memsweep"); - - init_done = GF_MEMPOOL_INIT_LATE; - } - pthread_mutex_unlock (&init_mutex); + pthread_mutex_lock(&init_mutex); + if ((init_count++) == 0) { + (void)gf_thread_create(&sweeper_tid, NULL, pool_sweeper, NULL, + "memsweep"); + + init_done = GF_MEMPOOL_INIT_LATE; + } + pthread_mutex_unlock(&init_mutex); } void -mem_pools_fini (void) +mem_pools_fini(void) { - pthread_mutex_lock (&init_mutex); - switch (init_count) { + pthread_mutex_lock(&init_mutex); + switch (init_count) { case 0: - /* - * If init_count is already zero (as e.g. if somebody called - * this before mem_pools_init_late) then the sweeper was - * probably never even started so we don't need to stop it. - * Even if there's some crazy circumstance where there is a - * sweeper but init_count is still zero, that just means we'll - * leave it running. Not perfect, but far better than any - * known alternative. - */ - break; - case 1: - { - per_thread_pool_list_t *pool_list; - per_thread_pool_list_t *next_pl; - unsigned int i; - - /* if only mem_pools_init_early() was called, sweeper_tid will - * be invalid and the functions will error out. That is not - * critical. In all other cases, the sweeper_tid will be valid - * and the thread gets stopped. */ - (void) pthread_cancel (sweeper_tid); - (void) pthread_join (sweeper_tid, NULL); - - /* Need to clean the pool_key to prevent further usage of the - * per_thread_pool_list_t structure that is stored for each - * thread. - * This also prevents calling pool_destructor() when a thread - * exits, so there is no chance on a use-after-free of the - * per_thread_pool_list_t structure. */ - (void) pthread_key_delete (pool_key); - - /* free all objects from all pools */ - list_for_each_entry_safe (pool_list, next_pl, - &pool_threads, thr_list) { - for (i = 0; i < NPOOLS; ++i) { - free_obj_list (pool_list->pools[i].hot_list); - free_obj_list (pool_list->pools[i].cold_list); - pool_list->pools[i].hot_list = NULL; - pool_list->pools[i].cold_list = NULL; - } - - list_del (&pool_list->thr_list); - FREE (pool_list); + /* + * If init_count is already zero (as e.g. if somebody called + * this before mem_pools_init_late) then the sweeper was + * probably never even started so we don't need to stop it. + * Even if there's some crazy circumstance where there is a + * sweeper but init_count is still zero, that just means we'll + * leave it running. Not perfect, but far better than any + * known alternative. + */ + break; + case 1: { + per_thread_pool_list_t *pool_list; + per_thread_pool_list_t *next_pl; + unsigned int i; + + /* if only mem_pools_init_early() was called, sweeper_tid will + * be invalid and the functions will error out. That is not + * critical. In all other cases, the sweeper_tid will be valid + * and the thread gets stopped. */ + (void)pthread_cancel(sweeper_tid); + (void)pthread_join(sweeper_tid, NULL); + + /* Need to clean the pool_key to prevent further usage of the + * per_thread_pool_list_t structure that is stored for each + * thread. + * This also prevents calling pool_destructor() when a thread + * exits, so there is no chance on a use-after-free of the + * per_thread_pool_list_t structure. */ + (void)pthread_key_delete(pool_key); + + /* free all objects from all pools */ + list_for_each_entry_safe(pool_list, next_pl, &pool_threads, + thr_list) + { + for (i = 0; i < NPOOLS; ++i) { + free_obj_list(pool_list->pools[i].hot_list); + free_obj_list(pool_list->pools[i].cold_list); + pool_list->pools[i].hot_list = NULL; + pool_list->pools[i].cold_list = NULL; } - list_for_each_entry_safe (pool_list, next_pl, - &pool_free_threads, thr_list) { - list_del (&pool_list->thr_list); - FREE (pool_list); - } + list_del(&pool_list->thr_list); + FREE(pool_list); + } - init_done = GF_MEMPOOL_INIT_DESTROY; - /* Fall through. */ + list_for_each_entry_safe(pool_list, next_pl, &pool_free_threads, + thr_list) + { + list_del(&pool_list->thr_list); + FREE(pool_list); + } + + init_done = GF_MEMPOOL_INIT_DESTROY; + /* Fall through. */ } default: - --init_count; - } - pthread_mutex_unlock (&init_mutex); + --init_count; + } + pthread_mutex_unlock(&init_mutex); } #else -void mem_pools_init_early (void) {} -void mem_pools_init_late (void) {} -void mem_pools_fini (void) {} +void +mem_pools_init_early(void) +{ +} +void +mem_pools_init_late(void) +{ +} +void +mem_pools_fini(void) +{ +} #endif struct mem_pool * -mem_pool_new_fn (glusterfs_ctx_t *ctx, unsigned long sizeof_type, - unsigned long count, char *name) +mem_pool_new_fn(glusterfs_ctx_t *ctx, unsigned long sizeof_type, + unsigned long count, char *name) { - unsigned int i; - struct mem_pool *new = NULL; - struct mem_pool_shared *pool = NULL; - - if (!sizeof_type) { - gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return NULL; - } - - for (i = 0; i < NPOOLS; ++i) { - if (sizeof_type <= AVAILABLE_SIZE(pools[i].power_of_two)) { - pool = &pools[i]; - break; - } - } - - if (!pool) { - gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return NULL; - } - - new = GF_CALLOC (sizeof (struct mem_pool), 1, gf_common_mt_mem_pool); - if (!new) - return NULL; - - new->ctx = ctx; - new->sizeof_type = sizeof_type; - new->count = count; - new->name = name; - new->pool = pool; - GF_ATOMIC_INIT (new->active, 0); - INIT_LIST_HEAD (&new->owner); - - LOCK (&ctx->lock); - { - list_add (&new->owner, &ctx->mempool_list); - } - UNLOCK (&ctx->lock); - - return new; + unsigned int i; + struct mem_pool *new = NULL; + struct mem_pool_shared *pool = NULL; + + if (!sizeof_type) { + gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return NULL; + } + + for (i = 0; i < NPOOLS; ++i) { + if (sizeof_type <= AVAILABLE_SIZE(pools[i].power_of_two)) { + pool = &pools[i]; + break; + } + } + + if (!pool) { + gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return NULL; + } + + new = GF_CALLOC(sizeof(struct mem_pool), 1, gf_common_mt_mem_pool); + if (!new) + return NULL; + + new->ctx = ctx; + new->sizeof_type = sizeof_type; + new->count = count; + new->name = name; + new->pool = pool; + GF_ATOMIC_INIT(new->active, 0); + INIT_LIST_HEAD(&new->owner); + + LOCK(&ctx->lock); + { + list_add(&new->owner, &ctx->mempool_list); + } + UNLOCK(&ctx->lock); + + return new; } -void* -mem_get0 (struct mem_pool *mem_pool) +void * +mem_get0(struct mem_pool *mem_pool) { - void *ptr = NULL; + void *ptr = NULL; - if (!mem_pool) { - gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return NULL; - } + if (!mem_pool) { + gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return NULL; + } - ptr = mem_get(mem_pool); - if (ptr) { + ptr = mem_get(mem_pool); + if (ptr) { #if defined(GF_DISABLE_MEMPOOL) - memset (ptr, 0, mem_pool->sizeof_type); + memset(ptr, 0, mem_pool->sizeof_type); #else - memset (ptr, 0, AVAILABLE_SIZE(mem_pool->pool->power_of_two)); + memset(ptr, 0, AVAILABLE_SIZE(mem_pool->pool->power_of_two)); #endif - } + } - return ptr; + return ptr; } - per_thread_pool_list_t * -mem_get_pool_list (void) +mem_get_pool_list(void) { - per_thread_pool_list_t *pool_list; - unsigned int i; - - pool_list = pthread_getspecific (pool_key); - if (pool_list) { - return pool_list; - } - - (void) pthread_mutex_lock (&pool_free_lock); - if (!list_empty (&pool_free_threads)) { - pool_list = list_entry (pool_free_threads.next, - per_thread_pool_list_t, thr_list); - list_del (&pool_list->thr_list); - } - (void) pthread_mutex_unlock (&pool_free_lock); + per_thread_pool_list_t *pool_list; + unsigned int i; + pool_list = pthread_getspecific(pool_key); + if (pool_list) { + return pool_list; + } + + (void)pthread_mutex_lock(&pool_free_lock); + if (!list_empty(&pool_free_threads)) { + pool_list = list_entry(pool_free_threads.next, per_thread_pool_list_t, + thr_list); + list_del(&pool_list->thr_list); + } + (void)pthread_mutex_unlock(&pool_free_lock); + + if (!pool_list) { + pool_list = CALLOC(pool_list_size, 1); if (!pool_list) { - pool_list = CALLOC (pool_list_size, 1); - if (!pool_list) { - return NULL; - } + return NULL; + } - INIT_LIST_HEAD (&pool_list->thr_list); - (void) pthread_spin_init (&pool_list->lock, - PTHREAD_PROCESS_PRIVATE); - for (i = 0; i < NPOOLS; ++i) { - pool_list->pools[i].parent = &pools[i]; - pool_list->pools[i].hot_list = NULL; - pool_list->pools[i].cold_list = NULL; - } + INIT_LIST_HEAD(&pool_list->thr_list); + (void)pthread_spin_init(&pool_list->lock, PTHREAD_PROCESS_PRIVATE); + for (i = 0; i < NPOOLS; ++i) { + pool_list->pools[i].parent = &pools[i]; + pool_list->pools[i].hot_list = NULL; + pool_list->pools[i].cold_list = NULL; } + } - (void) pthread_mutex_lock (&pool_lock); - pool_list->poison = 0; - list_add (&pool_list->thr_list, &pool_threads); - (void) pthread_mutex_unlock (&pool_lock); + (void)pthread_mutex_lock(&pool_lock); + pool_list->poison = 0; + list_add(&pool_list->thr_list, &pool_threads); + (void)pthread_mutex_unlock(&pool_lock); - (void) pthread_setspecific (pool_key, pool_list); - return pool_list; + (void)pthread_setspecific(pool_key, pool_list); + return pool_list; } pooled_obj_hdr_t * -mem_get_from_pool (per_thread_pool_t *pt_pool) +mem_get_from_pool(per_thread_pool_t *pt_pool) { - pooled_obj_hdr_t *retval; - - retval = pt_pool->hot_list; - if (retval) { - GF_ATOMIC_INC (pt_pool->parent->allocs_hot); - pt_pool->hot_list = retval->next; - return retval; - } - - retval = pt_pool->cold_list; - if (retval) { - GF_ATOMIC_INC (pt_pool->parent->allocs_cold); - pt_pool->cold_list = retval->next; - return retval; - } - - GF_ATOMIC_INC (pt_pool->parent->allocs_stdc); - return malloc (1 << pt_pool->parent->power_of_two); + pooled_obj_hdr_t *retval; + + retval = pt_pool->hot_list; + if (retval) { + GF_ATOMIC_INC(pt_pool->parent->allocs_hot); + pt_pool->hot_list = retval->next; + return retval; + } + + retval = pt_pool->cold_list; + if (retval) { + GF_ATOMIC_INC(pt_pool->parent->allocs_cold); + pt_pool->cold_list = retval->next; + return retval; + } + + GF_ATOMIC_INC(pt_pool->parent->allocs_stdc); + return malloc(1 << pt_pool->parent->power_of_two); } - void * -mem_get (struct mem_pool *mem_pool) +mem_get(struct mem_pool *mem_pool) { #if defined(GF_DISABLE_MEMPOOL) - return GF_MALLOC (mem_pool->sizeof_type, gf_common_mt_mem_pool); + return GF_MALLOC(mem_pool->sizeof_type, gf_common_mt_mem_pool); #else - per_thread_pool_list_t *pool_list; - per_thread_pool_t *pt_pool; - pooled_obj_hdr_t *retval; - - if (!mem_pool) { - gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return NULL; - } - - pool_list = mem_get_pool_list (); - if (!pool_list || pool_list->poison) { - return NULL; - } - - (void) pthread_spin_lock (&pool_list->lock); - pt_pool = &pool_list->pools[mem_pool->pool->power_of_two-POOL_SMALLEST]; - retval = mem_get_from_pool (pt_pool); - - if (!retval) { - (void) pthread_spin_unlock (&pool_list->lock); - return NULL; - } - - retval->magic = GF_MEM_HEADER_MAGIC; - retval->pool = mem_pool; - retval->pool_list = pool_list; - retval->power_of_two = mem_pool->pool->power_of_two; - (void) pthread_spin_unlock (&pool_list->lock); - - GF_ATOMIC_INC (mem_pool->active); - - return retval + 1; + per_thread_pool_list_t *pool_list; + per_thread_pool_t *pt_pool; + pooled_obj_hdr_t *retval; + + if (!mem_pool) { + gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return NULL; + } + + pool_list = mem_get_pool_list(); + if (!pool_list || pool_list->poison) { + return NULL; + } + + (void)pthread_spin_lock(&pool_list->lock); + pt_pool = &pool_list->pools[mem_pool->pool->power_of_two - POOL_SMALLEST]; + retval = mem_get_from_pool(pt_pool); + + if (!retval) { + (void)pthread_spin_unlock(&pool_list->lock); + return NULL; + } + + retval->magic = GF_MEM_HEADER_MAGIC; + retval->pool = mem_pool; + retval->pool_list = pool_list; + retval->power_of_two = mem_pool->pool->power_of_two; + (void)pthread_spin_unlock(&pool_list->lock); + + GF_ATOMIC_INC(mem_pool->active); + + return retval + 1; #endif /* GF_DISABLE_MEMPOOL */ } - void -mem_put (void *ptr) +mem_put(void *ptr) { #if defined(GF_DISABLE_MEMPOOL) - GF_FREE (ptr); + GF_FREE(ptr); #else - pooled_obj_hdr_t *hdr; - per_thread_pool_list_t *pool_list; - per_thread_pool_t *pt_pool; - - if (!ptr) { - gf_msg_callingfn ("mem-pool", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return; - } - - hdr = ((pooled_obj_hdr_t *)ptr) - 1; - if (hdr->magic != GF_MEM_HEADER_MAGIC) { - /* Not one of ours; don't touch it. */ - return; - } - pool_list = hdr->pool_list; - pt_pool = &pool_list->pools[hdr->power_of_two-POOL_SMALLEST]; + pooled_obj_hdr_t *hdr; + per_thread_pool_list_t *pool_list; + per_thread_pool_t *pt_pool; - GF_ATOMIC_DEC (hdr->pool->active); + if (!ptr) { + gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return; + } - (void) pthread_spin_lock (&pool_list->lock); - hdr->magic = GF_MEM_INVALID_MAGIC; - hdr->next = pt_pool->hot_list; - pt_pool->hot_list = hdr; - GF_ATOMIC_INC (pt_pool->parent->frees_to_list); - (void) pthread_spin_unlock (&pool_list->lock); + hdr = ((pooled_obj_hdr_t *)ptr) - 1; + if (hdr->magic != GF_MEM_HEADER_MAGIC) { + /* Not one of ours; don't touch it. */ + return; + } + pool_list = hdr->pool_list; + pt_pool = &pool_list->pools[hdr->power_of_two - POOL_SMALLEST]; + + GF_ATOMIC_DEC(hdr->pool->active); + + (void)pthread_spin_lock(&pool_list->lock); + hdr->magic = GF_MEM_INVALID_MAGIC; + hdr->next = pt_pool->hot_list; + pt_pool->hot_list = hdr; + GF_ATOMIC_INC(pt_pool->parent->frees_to_list); + (void)pthread_spin_unlock(&pool_list->lock); #endif /* GF_DISABLE_MEMPOOL */ } void -mem_pool_destroy (struct mem_pool *pool) +mem_pool_destroy(struct mem_pool *pool) { - if (!pool) - return; - - /* remove this pool from the owner (glusterfs_ctx_t) */ - LOCK (&pool->ctx->lock); - { - list_del (&pool->owner); - } - UNLOCK (&pool->ctx->lock); - - /* free this pool, but keep the mem_pool_shared */ - GF_FREE (pool); + if (!pool) + return; - /* - * Pools are now permanent, so the mem_pool->pool is kept around. All - * of the objects *in* the pool will eventually be freed via the - * pool-sweeper thread, and this way we don't have to add a lot of - * reference-counting complexity. - */ + /* remove this pool from the owner (glusterfs_ctx_t) */ + LOCK(&pool->ctx->lock); + { + list_del(&pool->owner); + } + UNLOCK(&pool->ctx->lock); + + /* free this pool, but keep the mem_pool_shared */ + GF_FREE(pool); + + /* + * Pools are now permanent, so the mem_pool->pool is kept around. All + * of the objects *in* the pool will eventually be freed via the + * pool-sweeper thread, and this way we don't have to add a lot of + * reference-counting complexity. + */ } diff --git a/libglusterfs/src/monitoring.c b/libglusterfs/src/monitoring.c index 10b0a817e40..041b70acf7a 100644 --- a/libglusterfs/src/monitoring.c +++ b/libglusterfs/src/monitoring.c @@ -17,254 +17,256 @@ static void dump_mem_acct_details(xlator_t *xl, int fd) { - struct mem_acct_rec *mem_rec; - int i = 0; - - if (!xl || !xl->mem_acct || (xl->ctx->active != xl->graph)) - return; - - dprintf (fd, "# %s.%s.total.num_types %d\n", xl->type, xl->name, - xl->mem_acct->num_types); - - dprintf (fd, "# type, in-use-size, in-use-units, max-size, " - "max-units, total-allocs\n"); - - for (i = 0; i < xl->mem_acct->num_types; i++) { - mem_rec = &xl->mem_acct->rec[i]; - if (mem_rec->num_allocs == 0) - continue; - dprintf (fd, "# %s, %"GF_PRI_SIZET", %u, %"GF_PRI_SIZET", %u," - " %u\n", mem_rec->typestr, mem_rec->size, - mem_rec->num_allocs, mem_rec->max_size, - mem_rec->max_num_allocs, mem_rec->total_allocs); - } + struct mem_acct_rec *mem_rec; + int i = 0; + + if (!xl || !xl->mem_acct || (xl->ctx->active != xl->graph)) + return; + + dprintf(fd, "# %s.%s.total.num_types %d\n", xl->type, xl->name, + xl->mem_acct->num_types); + + dprintf(fd, + "# type, in-use-size, in-use-units, max-size, " + "max-units, total-allocs\n"); + + for (i = 0; i < xl->mem_acct->num_types; i++) { + mem_rec = &xl->mem_acct->rec[i]; + if (mem_rec->num_allocs == 0) + continue; + dprintf(fd, + "# %s, %" GF_PRI_SIZET ", %u, %" GF_PRI_SIZET + ", %u," + " %u\n", + mem_rec->typestr, mem_rec->size, mem_rec->num_allocs, + mem_rec->max_size, mem_rec->max_num_allocs, + mem_rec->total_allocs); + } } static void -dump_global_memory_accounting (int fd) +dump_global_memory_accounting(int fd) { #if MEMORY_ACCOUNTING_STATS - int i = 0; - uint64_t count = 0; - - uint64_t tcalloc = GF_ATOMIC_GET (gf_memory_stat_counts.total_calloc); - uint64_t tmalloc = GF_ATOMIC_GET (gf_memory_stat_counts.total_malloc); - uint64_t tfree = GF_ATOMIC_GET (gf_memory_stat_counts.total_free); - - dprintf (fd, "memory.total.calloc %lu\n", tcalloc); - dprintf (fd, "memory.total.malloc %lu\n", tmalloc); - dprintf (fd, "memory.total.realloc %lu\n", - GF_ATOMIC_GET (gf_memory_stat_counts.total_realloc)); - dprintf (fd, "memory.total.free %lu\n", tfree); - dprintf (fd, "memory.total.in-use %lu\n", ((tcalloc + tmalloc) - tfree)); - - for (i = 0; i < GF_BLK_MAX_VALUE; i++) { - count = GF_ATOMIC_GET (gf_memory_stat_counts.blk_size[i]); - dprintf (fd, "memory.total.blk_size.%s %lu\n", - gf_mem_stats_blk[i].blk_size_str, count); - } - - dprintf (fd, "#----\n"); + int i = 0; + uint64_t count = 0; + + uint64_t tcalloc = GF_ATOMIC_GET(gf_memory_stat_counts.total_calloc); + uint64_t tmalloc = GF_ATOMIC_GET(gf_memory_stat_counts.total_malloc); + uint64_t tfree = GF_ATOMIC_GET(gf_memory_stat_counts.total_free); + + dprintf(fd, "memory.total.calloc %lu\n", tcalloc); + dprintf(fd, "memory.total.malloc %lu\n", tmalloc); + dprintf(fd, "memory.total.realloc %lu\n", + GF_ATOMIC_GET(gf_memory_stat_counts.total_realloc)); + dprintf(fd, "memory.total.free %lu\n", tfree); + dprintf(fd, "memory.total.in-use %lu\n", ((tcalloc + tmalloc) - tfree)); + + for (i = 0; i < GF_BLK_MAX_VALUE; i++) { + count = GF_ATOMIC_GET(gf_memory_stat_counts.blk_size[i]); + dprintf(fd, "memory.total.blk_size.%s %lu\n", + gf_mem_stats_blk[i].blk_size_str, count); + } + + dprintf(fd, "#----\n"); #endif - /* This is not a metric to be watched in admin guide, - but keeping it here till we resolve all leak-issues - would be great */ + /* This is not a metric to be watched in admin guide, + but keeping it here till we resolve all leak-issues + would be great */ } - static void -dump_latency_and_count (xlator_t *xl, int fd) +dump_latency_and_count(xlator_t *xl, int fd) { - int32_t index = 0; - uint64_t fop; - uint64_t cbk; - uint64_t count; - - if (xl->winds) - dprintf (fd, "%s.total.pending-winds.count %lu\n", xl->name, xl->winds); - - /* Need 'fuse' data, and don't need all the old graph info */ - if ((xl != xl->ctx->master) && (xl->ctx->active != xl->graph)) - return; - - count = GF_ATOMIC_GET (xl->stats.total.count); - dprintf (fd, "%s.total.fop-count %lu\n", xl->name, count); - - count = GF_ATOMIC_GET (xl->stats.interval.count); - dprintf (fd, "%s.interval.fop-count %lu\n", xl->name, count); - GF_ATOMIC_INIT (xl->stats.interval.count, 0); - - for (index = 0; index < GF_FOP_MAXVALUE; index++) { - fop = GF_ATOMIC_GET (xl->stats.total.metrics[index].fop); - if (fop) { - dprintf (fd, "%s.total.%s.count %lu\n", - xl->name, gf_fop_list[index], fop); - } - fop = GF_ATOMIC_GET (xl->stats.interval.metrics[index].fop); - if (fop) { - dprintf (fd, "%s.interval.%s.count %lu\n", - xl->name, gf_fop_list[index], fop); - } - cbk = GF_ATOMIC_GET (xl->stats.interval.metrics[index].cbk); - if (cbk) { - dprintf (fd, "%s.interval.%s.fail_count %lu\n", - xl->name, gf_fop_list[index], cbk); - } - if (xl->stats.interval.latencies[index].count != 0.0) { - dprintf (fd, "%s.interval.%s.latency %lf\n", - xl->name, gf_fop_list[index], - (xl->stats.interval.latencies[index].total / - xl->stats.interval.latencies[index].count)); - dprintf (fd, "%s.interval.%s.max %lf\n", - xl->name, gf_fop_list[index], - xl->stats.interval.latencies[index].max); - dprintf (fd, "%s.interval.%s.min %lf\n", - xl->name, gf_fop_list[index], - xl->stats.interval.latencies[index].min); - } - GF_ATOMIC_INIT (xl->stats.interval.metrics[index].cbk, 0); - GF_ATOMIC_INIT (xl->stats.interval.metrics[index].fop, 0); + int32_t index = 0; + uint64_t fop; + uint64_t cbk; + uint64_t count; + + if (xl->winds) + dprintf(fd, "%s.total.pending-winds.count %lu\n", xl->name, xl->winds); + + /* Need 'fuse' data, and don't need all the old graph info */ + if ((xl != xl->ctx->master) && (xl->ctx->active != xl->graph)) + return; + + count = GF_ATOMIC_GET(xl->stats.total.count); + dprintf(fd, "%s.total.fop-count %lu\n", xl->name, count); + + count = GF_ATOMIC_GET(xl->stats.interval.count); + dprintf(fd, "%s.interval.fop-count %lu\n", xl->name, count); + GF_ATOMIC_INIT(xl->stats.interval.count, 0); + + for (index = 0; index < GF_FOP_MAXVALUE; index++) { + fop = GF_ATOMIC_GET(xl->stats.total.metrics[index].fop); + if (fop) { + dprintf(fd, "%s.total.%s.count %lu\n", xl->name, gf_fop_list[index], + fop); } - memset (xl->stats.interval.latencies, 0, - sizeof (xl->stats.interval.latencies)); + fop = GF_ATOMIC_GET(xl->stats.interval.metrics[index].fop); + if (fop) { + dprintf(fd, "%s.interval.%s.count %lu\n", xl->name, + gf_fop_list[index], fop); + } + cbk = GF_ATOMIC_GET(xl->stats.interval.metrics[index].cbk); + if (cbk) { + dprintf(fd, "%s.interval.%s.fail_count %lu\n", xl->name, + gf_fop_list[index], cbk); + } + if (xl->stats.interval.latencies[index].count != 0.0) { + dprintf(fd, "%s.interval.%s.latency %lf\n", xl->name, + gf_fop_list[index], + (xl->stats.interval.latencies[index].total / + xl->stats.interval.latencies[index].count)); + dprintf(fd, "%s.interval.%s.max %lf\n", xl->name, + gf_fop_list[index], + xl->stats.interval.latencies[index].max); + dprintf(fd, "%s.interval.%s.min %lf\n", xl->name, + gf_fop_list[index], + xl->stats.interval.latencies[index].min); + } + GF_ATOMIC_INIT(xl->stats.interval.metrics[index].cbk, 0); + GF_ATOMIC_INIT(xl->stats.interval.metrics[index].fop, 0); + } + memset(xl->stats.interval.latencies, 0, + sizeof(xl->stats.interval.latencies)); } static inline void -dump_call_stack_details (glusterfs_ctx_t *ctx, int fd) +dump_call_stack_details(glusterfs_ctx_t *ctx, int fd) { - dprintf (fd, "total.stack.count %lu\n", - GF_ATOMIC_GET (ctx->pool->total_count)); - dprintf (fd, "total.stack.in-flight %lu\n", - ctx->pool->cnt); + dprintf(fd, "total.stack.count %lu\n", + GF_ATOMIC_GET(ctx->pool->total_count)); + dprintf(fd, "total.stack.in-flight %lu\n", ctx->pool->cnt); } static inline void -dump_dict_details (glusterfs_ctx_t *ctx, int fd) +dump_dict_details(glusterfs_ctx_t *ctx, int fd) { - uint64_t total_dicts = 0; - uint64_t total_pairs = 0; - - total_dicts = GF_ATOMIC_GET (ctx->stats.total_dicts_used); - total_pairs = GF_ATOMIC_GET (ctx->stats.total_pairs_used); - - dprintf (fd, "total.dict.max-pairs-per %lu\n", - GF_ATOMIC_GET (ctx->stats.max_dict_pairs)); - dprintf (fd, "total.dict.pairs-used %lu\n", total_pairs); - dprintf (fd, "total.dict.used %lu\n", total_dicts); - dprintf (fd, "total.dict.average-pairs %lu\n", - (total_pairs / total_dicts)); + uint64_t total_dicts = 0; + uint64_t total_pairs = 0; + + total_dicts = GF_ATOMIC_GET(ctx->stats.total_dicts_used); + total_pairs = GF_ATOMIC_GET(ctx->stats.total_pairs_used); + + dprintf(fd, "total.dict.max-pairs-per %lu\n", + GF_ATOMIC_GET(ctx->stats.max_dict_pairs)); + dprintf(fd, "total.dict.pairs-used %lu\n", total_pairs); + dprintf(fd, "total.dict.used %lu\n", total_dicts); + dprintf(fd, "total.dict.average-pairs %lu\n", (total_pairs / total_dicts)); } static void -dump_inode_stats (glusterfs_ctx_t *ctx, int fd) +dump_inode_stats(glusterfs_ctx_t *ctx, int fd) { } static void -dump_global_metrics (glusterfs_ctx_t *ctx, int fd) +dump_global_metrics(glusterfs_ctx_t *ctx, int fd) { - struct timeval tv; - time_t nowtime; - struct tm *nowtm; - char tmbuf[64] = {0,}; - - gettimeofday(&tv, NULL); - nowtime = tv.tv_sec; - nowtm = localtime(&nowtime); - strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm); - - /* Let every file have information on which process dumped info */ - dprintf (fd, "## %s\n", ctx->cmdlinestr); - dprintf (fd, "### %s\n", tmbuf); - dprintf (fd, "### BrickName: %s\n", ctx->cmd_args.brick_name); - dprintf (fd, "### MountName: %s\n", ctx->cmd_args.mount_point); - dprintf (fd, "### VolumeName: %s\n", ctx->cmd_args.volume_name); - - /* Dump memory accounting */ - dump_global_memory_accounting (fd); - dprintf (fd, "# -----\n"); - - dump_call_stack_details (ctx, fd); - dump_dict_details (ctx, fd); - dprintf (fd, "# -----\n"); - - dump_inode_stats (ctx, fd); - dprintf (fd, "# -----\n"); + struct timeval tv; + time_t nowtime; + struct tm *nowtm; + char tmbuf[64] = { + 0, + }; + + gettimeofday(&tv, NULL); + nowtime = tv.tv_sec; + nowtm = localtime(&nowtime); + strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm); + + /* Let every file have information on which process dumped info */ + dprintf(fd, "## %s\n", ctx->cmdlinestr); + dprintf(fd, "### %s\n", tmbuf); + dprintf(fd, "### BrickName: %s\n", ctx->cmd_args.brick_name); + dprintf(fd, "### MountName: %s\n", ctx->cmd_args.mount_point); + dprintf(fd, "### VolumeName: %s\n", ctx->cmd_args.volume_name); + + /* Dump memory accounting */ + dump_global_memory_accounting(fd); + dprintf(fd, "# -----\n"); + + dump_call_stack_details(ctx, fd); + dump_dict_details(ctx, fd); + dprintf(fd, "# -----\n"); + + dump_inode_stats(ctx, fd); + dprintf(fd, "# -----\n"); } static void -dump_xl_metrics (glusterfs_ctx_t *ctx, int fd) +dump_xl_metrics(glusterfs_ctx_t *ctx, int fd) { - xlator_t *xl; + xlator_t *xl; - xl = ctx->active->top; + xl = ctx->active->top; - while (xl) { - dump_latency_and_count (xl, fd); - dump_mem_acct_details (xl, fd); - if (xl->dump_metrics) - xl->dump_metrics (xl, fd); - xl = xl->next; - } + while (xl) { + dump_latency_and_count(xl, fd); + dump_mem_acct_details(xl, fd); + if (xl->dump_metrics) + xl->dump_metrics(xl, fd); + xl = xl->next; + } - if (ctx->master) { - xl = ctx->master; + if (ctx->master) { + xl = ctx->master; - dump_latency_and_count (xl, fd); - dump_mem_acct_details (xl, fd); - if (xl->dump_metrics) - xl->dump_metrics (xl, fd); - } + dump_latency_and_count(xl, fd); + dump_mem_acct_details(xl, fd); + if (xl->dump_metrics) + xl->dump_metrics(xl, fd); + } - return; + return; } char * -gf_monitor_metrics (glusterfs_ctx_t *ctx) +gf_monitor_metrics(glusterfs_ctx_t *ctx) { - int ret = -1; - int fd = 0; - char *filepath, *dumppath; - - dumppath = ctx->config.metrics_dumppath; - if (dumppath == NULL) { - dumppath = GLUSTER_METRICS_DIR; - } - - ret = gf_asprintf(&filepath, "%s/gmetrics.XXXXXX", dumppath); - if (ret < 0) { - return NULL; - } - - /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ - fd = mkstemp (filepath); - if (fd < 0) { - gf_msg ("monitoring", GF_LOG_ERROR, 0, LG_MSG_STRDUP_ERROR, - "failed to open tmp file %s (%s)", - filepath, strerror (errno)); - GF_FREE (filepath); - return NULL; - } - - dump_global_metrics (ctx, fd); - - dump_xl_metrics (ctx, fd); - - /* This below line is used just to capture any errors with dprintf() */ - ret = dprintf (fd, "\n# End of metrics\n"); - if (ret < 0) { - gf_msg ("monitoring", GF_LOG_WARNING, 0, LG_MSG_STRDUP_ERROR, - "dprintf() failed: %s", strerror (errno)); - } - - ret = sys_fsync (fd); - if (ret < 0) { - gf_msg ("monitoring", GF_LOG_WARNING, 0, LG_MSG_STRDUP_ERROR, - "fsync() failed: %s", strerror (errno)); - } - sys_close (fd); - - /* Figure this out, not happy with returning this string */ - return filepath; + int ret = -1; + int fd = 0; + char *filepath, *dumppath; + + dumppath = ctx->config.metrics_dumppath; + if (dumppath == NULL) { + dumppath = GLUSTER_METRICS_DIR; + } + + ret = gf_asprintf(&filepath, "%s/gmetrics.XXXXXX", dumppath); + if (ret < 0) { + return NULL; + } + + /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ + fd = mkstemp(filepath); + if (fd < 0) { + gf_msg("monitoring", GF_LOG_ERROR, 0, LG_MSG_STRDUP_ERROR, + "failed to open tmp file %s (%s)", filepath, strerror(errno)); + GF_FREE(filepath); + return NULL; + } + + dump_global_metrics(ctx, fd); + + dump_xl_metrics(ctx, fd); + + /* This below line is used just to capture any errors with dprintf() */ + ret = dprintf(fd, "\n# End of metrics\n"); + if (ret < 0) { + gf_msg("monitoring", GF_LOG_WARNING, 0, LG_MSG_STRDUP_ERROR, + "dprintf() failed: %s", strerror(errno)); + } + + ret = sys_fsync(fd); + if (ret < 0) { + gf_msg("monitoring", GF_LOG_WARNING, 0, LG_MSG_STRDUP_ERROR, + "fsync() failed: %s", strerror(errno)); + } + sys_close(fd); + + /* Figure this out, not happy with returning this string */ + return filepath; } diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index a0f04c772e8..30607d2e390 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -16,1238 +16,1206 @@ #define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL) - static int -xlator_option_validate_path (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_path(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - char errstr[256]; - - if (strstr (value, "../")) { - snprintf (errstr, 256, - "invalid path given '%s'", - value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - /* Make sure the given path is valid */ - if (value[0] != '/') { - snprintf (errstr, 256, - "option %s %s: '%s' is not an " - "absolute path name", - key, value, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - ret = 0; + int ret = -1; + char errstr[256]; + + if (strstr(value, "../")) { + snprintf(errstr, 256, "invalid path given '%s'", value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + /* Make sure the given path is valid */ + if (value[0] != '/') { + snprintf(errstr, 256, + "option %s %s: '%s' is not an " + "absolute path name", + key, value, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + ret = 0; out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } static int -xlator_option_validate_int (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_int(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - long long inputll = 0; - unsigned long long uinputll = 0; - int ret = -1; - char errstr[256]; - - /* Check the range */ - if (gf_string2longlong (value, &inputll) != 0) { - snprintf (errstr, 256, - "invalid number format \"%s\" in option \"%s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - /* Handle '-0' */ - if ((inputll == 0) && (gf_string2ulonglong (value, &uinputll) != 0)) { - snprintf (errstr, 256, - "invalid number format \"%s\" in option \"%s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0) && - (opt->validate == GF_OPT_VALIDATE_BOTH)) { - gf_msg_trace (xl->name, 0, "no range check required for " - "'option %s %s'", key, value); - ret = 0; - goto out; + long long inputll = 0; + unsigned long long uinputll = 0; + int ret = -1; + char errstr[256]; + + /* Check the range */ + if (gf_string2longlong(value, &inputll) != 0) { + snprintf(errstr, 256, "invalid number format \"%s\" in option \"%s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + /* Handle '-0' */ + if ((inputll == 0) && (gf_string2ulonglong(value, &uinputll) != 0)) { + snprintf(errstr, 256, "invalid number format \"%s\" in option \"%s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0) && + (opt->validate == GF_OPT_VALIDATE_BOTH)) { + gf_msg_trace(xl->name, 0, + "no range check required for " + "'option %s %s'", + key, value); + ret = 0; + goto out; + } + + if (opt->validate == GF_OPT_VALIDATE_MIN) { + if (inputll < opt->min) { + snprintf(errstr, 256, + "'%lld' in 'option %s %s' is smaller than " + "minimum value '%.0f'", + inputll, key, value, opt->min); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", + errstr); + goto out; } - - if (opt->validate == GF_OPT_VALIDATE_MIN) { - if (inputll < opt->min) { - snprintf (errstr, 256, - "'%lld' in 'option %s %s' is smaller than " - "minimum value '%.0f'", inputll, key, - value, opt->min); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_INVALID_ENTRY, "%s", errstr); - goto out; - } - } else if (opt->validate == GF_OPT_VALIDATE_MAX) { - if (inputll > opt->max) { - snprintf (errstr, 256, - "'%lld' in 'option %s %s' is greater than " - "maximum value '%.0f'", inputll, key, - value, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_INVALID_ENTRY, "%s", errstr); - goto out; - } - } else if ((inputll < opt->min) || (inputll > opt->max)) { - snprintf (errstr, 256, - "'%lld' in 'option %s %s' is out of range " - "[%.0f - %.0f]", - inputll, key, value, opt->min, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", - errstr); - goto out; + } else if (opt->validate == GF_OPT_VALIDATE_MAX) { + if (inputll > opt->max) { + snprintf(errstr, 256, + "'%lld' in 'option %s %s' is greater than " + "maximum value '%.0f'", + inputll, key, value, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", + errstr); + goto out; } - - ret = 0; + } else if ((inputll < opt->min) || (inputll > opt->max)) { + snprintf(errstr, 256, + "'%lld' in 'option %s %s' is out of range " + "[%.0f - %.0f]", + inputll, key, value, opt->min, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", errstr); + goto out; + } + + ret = 0; out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } - static int -xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_sizet(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - size_t size = 0; - int ret = 0; - char errstr[256]; - - /* Check the range */ - if (gf_string2bytesize_size (value, &size) != 0) { - snprintf (errstr, 256, - "invalid number format \"%s\" in option \"%s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - ret = -1; - goto out; - } - - if ((opt->min == 0) && (opt->max == 0)) { - gf_msg_trace (xl->name, 0, "no range check required for " - "'option %s %s'", key, value); - goto out; - } - - if ((size < opt->min) || (size > opt->max)) { - snprintf (errstr, 256, - "'%" GF_PRI_SIZET "' in 'option %s %s' " - "is out of range [%.0f - %.0f]", - size, key, value, opt->min, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_OUT_OF_RANGE, "%s", errstr); - ret = -1; - } + size_t size = 0; + int ret = 0; + char errstr[256]; + + /* Check the range */ + if (gf_string2bytesize_size(value, &size) != 0) { + snprintf(errstr, 256, "invalid number format \"%s\" in option \"%s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + ret = -1; + goto out; + } + + if ((opt->min == 0) && (opt->max == 0)) { + gf_msg_trace(xl->name, 0, + "no range check required for " + "'option %s %s'", + key, value); + goto out; + } + + if ((size < opt->min) || (size > opt->max)) { + snprintf(errstr, 256, + "'%" GF_PRI_SIZET + "' in 'option %s %s' " + "is out of range [%.0f - %.0f]", + size, key, value, opt->min, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", errstr); + ret = -1; + } out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } - static int -xlator_option_validate_bool (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_bool(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - char errstr[256]; - gf_boolean_t is_valid; + int ret = -1; + char errstr[256]; + gf_boolean_t is_valid; + /* Check if the value is one of + '0|1|on|off|no|yes|true|false|enable|disable' */ - /* Check if the value is one of - '0|1|on|off|no|yes|true|false|enable|disable' */ + if (gf_string2boolean(value, &is_valid) != 0) { + snprintf(errstr, 256, "option %s %s: '%s' is not a valid boolean value", + key, value, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } - if (gf_string2boolean (value, &is_valid) != 0) { - snprintf (errstr, 256, - "option %s %s: '%s' is not a valid boolean value", - key, value, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - ret = 0; + ret = 0; out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } - static int -xlator_option_validate_xlator (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_xlator(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - char errstr[256]; - xlator_t *xlopt = NULL; - - - /* Check if the value is one of the xlators */ - xlopt = xl; - while (xlopt->prev) - xlopt = xlopt->prev; - - while (xlopt) { - if (strcmp (value, xlopt->name) == 0) { - ret = 0; - break; - } - xlopt = xlopt->next; + int ret = -1; + char errstr[256]; + xlator_t *xlopt = NULL; + + /* Check if the value is one of the xlators */ + xlopt = xl; + while (xlopt->prev) + xlopt = xlopt->prev; + + while (xlopt) { + if (strcmp(value, xlopt->name) == 0) { + ret = 0; + break; } + xlopt = xlopt->next; + } - if (!xlopt) { - snprintf (errstr, 256, - "option %s %s: '%s' is not a valid volume name", - key, value, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } + if (!xlopt) { + snprintf(errstr, 256, "option %s %s: '%s' is not a valid volume name", + key, value, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } - ret = 0; + ret = 0; out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } void -set_error_str (char *errstr, size_t len, volume_option_t *opt, const char *key, - const char *value) +set_error_str(char *errstr, size_t len, volume_option_t *opt, const char *key, + const char *value) { - int i = 0; - int ret = 0; - - ret = snprintf (errstr, len, "option %s %s: '%s' is not valid " - "(possible options are ", key, value, value); - - for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && opt->value[i];) { - ret += snprintf (errstr + ret, len - ret, "%s", opt->value[i]); - if (((++i) < ZR_OPTION_MAX_ARRAY_SIZE) && - (opt->value[i])) - ret += snprintf (errstr + ret, len - ret, ", "); - else - ret += snprintf (errstr + ret, len - ret, ".)"); - } - return; + int i = 0; + int ret = 0; + + ret = snprintf(errstr, len, + "option %s %s: '%s' is not valid " + "(possible options are ", + key, value, value); + + for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && opt->value[i];) { + ret += snprintf(errstr + ret, len - ret, "%s", opt->value[i]); + if (((++i) < ZR_OPTION_MAX_ARRAY_SIZE) && (opt->value[i])) + ret += snprintf(errstr + ret, len - ret, ", "); + else + ret += snprintf(errstr + ret, len - ret, ".)"); + } + return; } int -is_all_whitespaces (const char *value) +is_all_whitespaces(const char *value) { - int i = 0; - size_t len = 0; + int i = 0; + size_t len = 0; - if (value == NULL) - return -1; + if (value == NULL) + return -1; - len = strlen (value); + len = strlen(value); - for (i = 0; i < len; i++) { - if (value[i] == ' ') - continue; - else - return 0; - } + for (i = 0; i < len; i++) { + if (value[i] == ' ') + continue; + else + return 0; + } - return 1; + return 1; } static int -xlator_option_validate_str (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_str(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - int i = 0; - char errstr[4096] = {0,}; - - /* Check if the '*str' is valid */ - if (GF_OPTION_LIST_EMPTY(opt)) { - ret = 0; - goto out; - } - - if (is_all_whitespaces (value) == 1) - goto out; - - for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && opt->value[i]; i++) { - #ifdef GF_DARWIN_HOST_OS - if (fnmatch (opt->value[i], value, 0) == 0) { - ret = 0; - break; - } - #else - if (fnmatch (opt->value[i], value, FNM_EXTMATCH) == 0) { - ret = 0; - break; - } - #endif - } - - if ((i == ZR_OPTION_MAX_ARRAY_SIZE) || (!opt->value[i])) - goto out; - /* enter here only if - * 1. reached end of opt->value array and haven't - * validated input - * OR - * 2. valid input list is less than - * ZR_OPTION_MAX_ARRAY_SIZE and input has not - * matched all possible input values. - */ - + int ret = -1; + int i = 0; + char errstr[4096] = { + 0, + }; + + /* Check if the '*str' is valid */ + if (GF_OPTION_LIST_EMPTY(opt)) { ret = 0; + goto out; + } -out: - if (ret) { - set_error_str (errstr, sizeof (errstr), opt, key, value); + if (is_all_whitespaces(value) == 1) + goto out; - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - if (op_errstr) - *op_errstr = gf_strdup (errstr); + for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) && opt->value[i]; i++) { +#ifdef GF_DARWIN_HOST_OS + if (fnmatch(opt->value[i], value, 0) == 0) { + ret = 0; + break; } - return ret; -} - - -static int -xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) -{ - double percent = 0; - int ret = -1; - char errstr[256]; - - /* Check if the value is valid percentage */ - if (gf_string2percent (value, &percent) != 0) { - snprintf (errstr, 256, - "invalid percent format \"%s\" in \"option %s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - if ((percent < 0.0) || (percent > 100.0)) { - snprintf (errstr, 256, - "'%lf' in 'option %s %s' is out of range [0 - 100]", - percent, key, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", - errstr); - goto out; +#else + if (fnmatch(opt->value[i], value, FNM_EXTMATCH) == 0) { + ret = 0; + break; } +#endif + } + + if ((i == ZR_OPTION_MAX_ARRAY_SIZE) || (!opt->value[i])) + goto out; + /* enter here only if + * 1. reached end of opt->value array and haven't + * validated input + * OR + * 2. valid input list is less than + * ZR_OPTION_MAX_ARRAY_SIZE and input has not + * matched all possible input values. + */ + + ret = 0; - ret = 0; out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret) { + set_error_str(errstr, sizeof(errstr), opt, key, value); + + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + if (op_errstr) + *op_errstr = gf_strdup(errstr); + } + return ret; } static int -xlator_option_validate_fractional_value (const char *value) +xlator_option_validate_percent(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - const char *s = NULL; - int ret = 0; - - s = strchr (value, '.'); - if (s) { - for (s = s+1; *s != '\0'; s++) { - if (*s != '0') { - return -1; - } - } - } - - return ret; + double percent = 0; + int ret = -1; + char errstr[256]; + + /* Check if the value is valid percentage */ + if (gf_string2percent(value, &percent) != 0) { + snprintf(errstr, 256, "invalid percent format \"%s\" in \"option %s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + if ((percent < 0.0) || (percent > 100.0)) { + snprintf(errstr, 256, + "'%lf' in 'option %s %s' is out of range [0 - 100]", percent, + key, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } static int -xlator_option_validate_percent_or_sizet (xlator_t *xl, const char *key, - const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_fractional_value(const char *value) { - int ret = -1; - char errstr[256]; - double size = 0; - gf_boolean_t is_percent = _gf_false; - - if (gf_string2percent_or_bytesize (value, &size, &is_percent) == 0) { - if (is_percent) { - if ((size < 0.0) || (size > 100.0)) { - snprintf (errstr, sizeof (errstr), - "'%lf' in 'option %s %s' is out" - " of range [0 - 100]", size, key, - value); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_OUT_OF_RANGE, "%s", errstr); - goto out; - } - ret = 0; - goto out; - } - - /*Input value of size(in byte) should not be fractional*/ - ret = xlator_option_validate_fractional_value (value); - if (ret) { - snprintf (errstr, sizeof (errstr), "'%lf' in 'option %s" - " %s' should not be fractional value. Use " - "valid unsigned integer value.", size, key, - value); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_INVALID_ENTRY, "%s", errstr); - goto out; - } - - /* Check the range */ - if ((opt->min == 0) && (opt->max == 0)) { - gf_msg_trace (xl->name, 0, "no range check required " - "for 'option %s %s'", key, value); - ret = 0; - goto out; - } - if ((size < opt->min) || (size > opt->max)) { - snprintf (errstr, 256, - "'%lf' in 'option %s %s'" - " is out of range [%.0f - %.0f]", - size, key, value, opt->min, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, - "%s", errstr); - goto out; - } - ret = 0; - goto out; - } - - /* If control reaches here, invalid argument */ - - snprintf (errstr, 256, - "invalid number format \"%s\" in \"option %s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + const char *s = NULL; + int ret = 0; + s = strchr(value, '.'); + if (s) { + for (s = s + 1; *s != '\0'; s++) { + if (*s != '0') { + return -1; + } + } + } -out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + return ret; } - static int -xlator_option_validate_time (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_percent_or_sizet(xlator_t *xl, const char *key, + const char *value, volume_option_t *opt, + char **op_errstr) { - int ret = -1; - char errstr[256]; - uint32_t input_time = 0; - - /* Check if the value is valid time */ - if (gf_string2time (value, &input_time) != 0) { - snprintf (errstr, 256, - "invalid time format \"%s\" in " - "\"option %s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); + int ret = -1; + char errstr[256]; + double size = 0; + gf_boolean_t is_percent = _gf_false; + + if (gf_string2percent_or_bytesize(value, &size, &is_percent) == 0) { + if (is_percent) { + if ((size < 0.0) || (size > 100.0)) { + snprintf(errstr, sizeof(errstr), + "'%lf' in 'option %s %s' is out" + " of range [0 - 100]", + size, key, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", + errstr); goto out; + } + ret = 0; + goto out; } - if ((opt->min == 0) && (opt->max == 0)) { - gf_msg_trace (xl->name, 0, "no range check required for " - "'option %s %s'", key, value); - ret = 0; - goto out; + /*Input value of size(in byte) should not be fractional*/ + ret = xlator_option_validate_fractional_value(value); + if (ret) { + snprintf(errstr, sizeof(errstr), + "'%lf' in 'option %s" + " %s' should not be fractional value. Use " + "valid unsigned integer value.", + size, key, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", + errstr); + goto out; } - if ((input_time < opt->min) || (input_time > opt->max)) { - snprintf (errstr, 256, - "'%"PRIu32"' in 'option %s %s' is " - "out of range [%.0f - %.0f]", - input_time, key, value, - opt->min, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", - errstr); - goto out; + /* Check the range */ + if ((opt->min == 0) && (opt->max == 0)) { + gf_msg_trace(xl->name, 0, + "no range check required " + "for 'option %s %s'", + key, value); + ret = 0; + goto out; + } + if ((size < opt->min) || (size > opt->max)) { + snprintf(errstr, 256, + "'%lf' in 'option %s %s'" + " is out of range [%.0f - %.0f]", + size, key, value, opt->min, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", + errstr); + goto out; } - ret = 0; + goto out; + } + + /* If control reaches here, invalid argument */ + + snprintf(errstr, 256, "invalid number format \"%s\" in \"option %s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } - static int -xlator_option_validate_double (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_time(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - double input = 0.0; - int ret = -1; - char errstr[256]; - - /* Check the range */ - if (gf_string2double (value, &input) != 0) { - snprintf (errstr, 256, - "invalid number format \"%s\" in option \"%s\"", - value, key); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - goto out; - } - - if ((opt->min == 0) && (opt->max == 0) && - (opt->validate == GF_OPT_VALIDATE_BOTH)) { - gf_msg_trace (xl->name, 0, "no range check required for " - "'option %s %s'", key, value); - ret = 0; - goto out; - } - - if (opt->validate == GF_OPT_VALIDATE_MIN) { - if (input < opt->min) { - snprintf (errstr, 256, - "'%f' in 'option %s %s' is smaller than " - "minimum value '%f'", input, key, - value, opt->min); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_INVALID_ENTRY, "%s", errstr); - goto out; - } - } else if (opt->validate == GF_OPT_VALIDATE_MAX) { - if (input > opt->max) { - snprintf (errstr, 256, - "'%f' in 'option %s %s' is greater than " - "maximum value '%f'", input, key, - value, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, - LG_MSG_INVALID_ENTRY, "%s", errstr); - goto out; - } - } else if ((input < opt->min) || (input > opt->max)) { - snprintf (errstr, 256, - "'%f' in 'option %s %s' is out of range " - "[%f - %f]", - input, key, value, opt->min, opt->max); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", - errstr); - goto out; - } - + int ret = -1; + char errstr[256]; + uint32_t input_time = 0; + + /* Check if the value is valid time */ + if (gf_string2time(value, &input_time) != 0) { + snprintf(errstr, 256, + "invalid time format \"%s\" in " + "\"option %s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0)) { + gf_msg_trace(xl->name, 0, + "no range check required for " + "'option %s %s'", + key, value); ret = 0; + goto out; + } + + if ((input_time < opt->min) || (input_time > opt->max)) { + snprintf(errstr, 256, + "'%" PRIu32 + "' in 'option %s %s' is " + "out of range [%.0f - %.0f]", + input_time, key, value, opt->min, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", errstr); + goto out; + } + + ret = 0; out: - if (ret && op_errstr) - *op_errstr = gf_strdup (errstr); - return ret; + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; } - static int -xlator_option_validate_addr (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_double(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - char errstr[256]; - - if (!valid_internet_address ((char *)value, _gf_false)) { - snprintf (errstr, 256, - "option %s %s: '%s' is not a valid internet-address," - " it does not conform to standards.", - key, value, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - if (op_errstr) - *op_errstr = gf_strdup (errstr); - } - + double input = 0.0; + int ret = -1; + char errstr[256]; + + /* Check the range */ + if (gf_string2double(value, &input) != 0) { + snprintf(errstr, 256, "invalid number format \"%s\" in option \"%s\"", + value, key); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + goto out; + } + + if ((opt->min == 0) && (opt->max == 0) && + (opt->validate == GF_OPT_VALIDATE_BOTH)) { + gf_msg_trace(xl->name, 0, + "no range check required for " + "'option %s %s'", + key, value); ret = 0; + goto out; + } + + if (opt->validate == GF_OPT_VALIDATE_MIN) { + if (input < opt->min) { + snprintf(errstr, 256, + "'%f' in 'option %s %s' is smaller than " + "minimum value '%f'", + input, key, value, opt->min); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", + errstr); + goto out; + } + } else if (opt->validate == GF_OPT_VALIDATE_MAX) { + if (input > opt->max) { + snprintf(errstr, 256, + "'%f' in 'option %s %s' is greater than " + "maximum value '%f'", + input, key, value, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", + errstr); + goto out; + } + } else if ((input < opt->min) || (input > opt->max)) { + snprintf(errstr, 256, + "'%f' in 'option %s %s' is out of range " + "[%f - %f]", + input, key, value, opt->min, opt->max); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s", errstr); + goto out; + } + + ret = 0; +out: + if (ret && op_errstr) + *op_errstr = gf_strdup(errstr); + return ret; +} - return ret; +static int +xlator_option_validate_addr(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) +{ + int ret = -1; + char errstr[256]; + + if (!valid_internet_address((char *)value, _gf_false)) { + snprintf(errstr, 256, + "option %s %s: '%s' is not a valid internet-address," + " it does not conform to standards.", + key, value, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + if (op_errstr) + *op_errstr = gf_strdup(errstr); + } + + ret = 0; + + return ret; } int -xlator_option_validate_addr_list (xlator_t *xl, const char *key, - const char *value, volume_option_t *opt, - char **op_errstr) +xlator_option_validate_addr_list(xlator_t *xl, const char *key, + const char *value, volume_option_t *opt, + char **op_errstr) { - int ret = -1; - char *dup_val = NULL; - char *addr_tok = NULL; - char *save_ptr = NULL; - char *entry = NULL; - char *entry_ptr = NULL; - char *dir_and_addr = NULL; - char *addr_ptr = NULL; - char *addr_list = NULL; - char *addr = NULL; - char *dir = NULL; - char errstr[4096] = {0,}; - - dup_val = gf_strdup (value); - if (!dup_val) + int ret = -1; + char *dup_val = NULL; + char *addr_tok = NULL; + char *save_ptr = NULL; + char *entry = NULL; + char *entry_ptr = NULL; + char *dir_and_addr = NULL; + char *addr_ptr = NULL; + char *addr_list = NULL; + char *addr = NULL; + char *dir = NULL; + char errstr[4096] = { + 0, + }; + + dup_val = gf_strdup(value); + if (!dup_val) + goto out; + + if (dup_val[0] != '/' && !strchr(dup_val, '(')) { + /* Possible old format, handle it for back-ward compatibility */ + addr_tok = strtok_r(dup_val, ",", &save_ptr); + while (addr_tok) { + if (!valid_internet_address(addr_tok, _gf_true)) goto out; - if (dup_val[0] != '/' && !strchr (dup_val, '(')) { - /* Possible old format, handle it for back-ward compatibility */ - addr_tok = strtok_r (dup_val, ",", &save_ptr); - while (addr_tok) { - if (!valid_internet_address (addr_tok, _gf_true)) - goto out; + addr_tok = strtok_r(NULL, ",", &save_ptr); + } + ret = 0; + goto out; + } + + /* Lets handle the value with new format */ + entry = strtok_r(dup_val, ",", &entry_ptr); + while (entry) { + dir_and_addr = gf_strdup(entry); + if (!dir_and_addr) + goto out; + + dir = strtok_r(dir_and_addr, "(", &addr_ptr); + if (dir[0] != '/') { + /* Valid format should be starting from '/' */ + goto out; + } + /* dir = strtok_r (NULL, " =", &addr_tmp); */ + addr = strtok_r(NULL, ")", &addr_ptr); + if (!addr) + goto out; + + addr_list = gf_strdup(addr); + if (!addr_list) + goto out; - addr_tok = strtok_r (NULL, ",", &save_ptr); - } - ret = 0; + /* This format be separated by '|' */ + addr_tok = strtok_r(addr_list, "|", &save_ptr); + if (addr_tok == NULL) + goto out; + while (addr_tok) { + if (!valid_internet_address(addr_tok, _gf_true)) goto out; - } - /* Lets handle the value with new format */ - entry = strtok_r (dup_val, ",", &entry_ptr); - while (entry) { - dir_and_addr = gf_strdup (entry); - if (!dir_and_addr) - goto out; - - dir = strtok_r (dir_and_addr, "(", &addr_ptr); - if (dir[0] != '/') { - /* Valid format should be starting from '/' */ - goto out; - } - /* dir = strtok_r (NULL, " =", &addr_tmp); */ - addr = strtok_r (NULL, ")", &addr_ptr); - if (!addr) - goto out; - - addr_list = gf_strdup (addr); - if (!addr_list) - goto out; - - /* This format be separated by '|' */ - addr_tok = strtok_r (addr_list, "|", &save_ptr); - if (addr_tok == NULL) - goto out; - while (addr_tok) { - if (!valid_internet_address (addr_tok, _gf_true)) - goto out; - - addr_tok = strtok_r (NULL, "|", &save_ptr); - } - entry = strtok_r (NULL, ",", &entry_ptr); - GF_FREE (dir_and_addr); - GF_FREE (addr_list); - addr_list = NULL; - dir_and_addr = NULL; + addr_tok = strtok_r(NULL, "|", &save_ptr); } + entry = strtok_r(NULL, ",", &entry_ptr); + GF_FREE(dir_and_addr); + GF_FREE(addr_list); + addr_list = NULL; + dir_and_addr = NULL; + } - ret = 0; + ret = 0; out: - if (ret) { - snprintf (errstr, sizeof (errstr), "option %s %s: '%s' is not " - "a valid internet-address-list", key, value, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - if (op_errstr) - *op_errstr = gf_strdup (errstr); - } - GF_FREE (dup_val); - GF_FREE (dir_and_addr); - GF_FREE (addr_list); - return ret; + if (ret) { + snprintf(errstr, sizeof(errstr), + "option %s %s: '%s' is not " + "a valid internet-address-list", + key, value, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + if (op_errstr) + *op_errstr = gf_strdup(errstr); + } + GF_FREE(dup_val); + GF_FREE(dir_and_addr); + GF_FREE(addr_list); + return ret; } static int -xlator_option_validate_mntauth (xlator_t *xl, const char *key, - const char *value, volume_option_t *opt, - char **op_errstr) +xlator_option_validate_mntauth(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - char *dup_val = NULL; - char *addr_tok = NULL; - char *save_ptr = NULL; - char errstr[4096] = {0,}; - - dup_val = gf_strdup (value); - if (!dup_val) - goto out; - - addr_tok = strtok_r (dup_val, ",", &save_ptr); - if (addr_tok == NULL) - goto out; - while (addr_tok) { - if (!valid_mount_auth_address (addr_tok)) - goto out; - - addr_tok = strtok_r (NULL, ",", &save_ptr); - } - ret = 0; + int ret = -1; + char *dup_val = NULL; + char *addr_tok = NULL; + char *save_ptr = NULL; + char errstr[4096] = { + 0, + }; + + dup_val = gf_strdup(value); + if (!dup_val) + goto out; + + addr_tok = strtok_r(dup_val, ",", &save_ptr); + if (addr_tok == NULL) + goto out; + while (addr_tok) { + if (!valid_mount_auth_address(addr_tok)) + goto out; + + addr_tok = strtok_r(NULL, ",", &save_ptr); + } + ret = 0; out: - if (ret) { - snprintf (errstr, sizeof (errstr), "option %s %s: '%s' is not " - "a valid mount-auth-address", key, value, value); - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", - errstr); - if (op_errstr) - *op_errstr = gf_strdup (errstr); - } - GF_FREE (dup_val); - - return ret; + if (ret) { + snprintf(errstr, sizeof(errstr), + "option %s %s: '%s' is not " + "a valid mount-auth-address", + key, value, value); + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s", errstr); + if (op_errstr) + *op_errstr = gf_strdup(errstr); + } + GF_FREE(dup_val); + + return ret; } /*XXX: the rules to validate are as per block-size required for stripe xlator */ static int -gf_validate_size (const char *sizestr, volume_option_t *opt) +gf_validate_size(const char *sizestr, volume_option_t *opt) { - size_t value = 0; - int ret = 0; + size_t value = 0; + int ret = 0; - GF_ASSERT (opt); + GF_ASSERT(opt); - if (gf_string2bytesize_size (sizestr, &value) != 0 || - value < opt->min || - value % 512) { - ret = -1; - goto out; - } + if (gf_string2bytesize_size(sizestr, &value) != 0 || value < opt->min || + value % 512) { + ret = -1; + goto out; + } - out: - gf_msg_debug (THIS->name, 0, "Returning %d", ret); - return ret; +out: + gf_msg_debug(THIS->name, 0, "Returning %d", ret); + return ret; } static int -gf_validate_number (const char *numstr, volume_option_t *opt) +gf_validate_number(const char *numstr, volume_option_t *opt) { - int32_t value; - return gf_string2int32 (numstr, &value); + int32_t value; + return gf_string2int32(numstr, &value); } /* Parses the string to be of the form <key1>:<value1>,<key2>:<value2>... * * takes two optional validaters key_validator and value_validator */ static int -validate_list_elements (const char *string, volume_option_t *opt, - int (key_validator)( const char *), - int (value_validator)( const char *, volume_option_t *)) +validate_list_elements(const char *string, volume_option_t *opt, + int(key_validator)(const char *), + int(value_validator)(const char *, volume_option_t *)) { - - char *dup_string = NULL; - char *str_sav = NULL; - char *substr_sav = NULL; - char *str_ptr = NULL; - char *key = NULL; - char *value = NULL; - int ret = 0; - - GF_ASSERT (string); - - dup_string = gf_strdup (string); - if (NULL == dup_string) - goto out; - - str_ptr = strtok_r (dup_string, ",", &str_sav); - if (str_ptr == NULL) { - ret = -1; - goto out; + char *dup_string = NULL; + char *str_sav = NULL; + char *substr_sav = NULL; + char *str_ptr = NULL; + char *key = NULL; + char *value = NULL; + int ret = 0; + + GF_ASSERT(string); + + dup_string = gf_strdup(string); + if (NULL == dup_string) + goto out; + + str_ptr = strtok_r(dup_string, ",", &str_sav); + if (str_ptr == NULL) { + ret = -1; + goto out; + } + while (str_ptr) { + key = strtok_r(str_ptr, ":", &substr_sav); + if (!key || (key_validator && key_validator(key))) { + ret = -1; + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY, + "invalid list '%s', key " + "'%s' not valid.", + string, key); + goto out; } - while (str_ptr) { - - key = strtok_r (str_ptr, ":", &substr_sav); - if (!key || - (key_validator && key_validator(key))) { - ret = -1; - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_ENTRY, "invalid list '%s', key " - "'%s' not valid.", string, key); - goto out; - } - - value = strtok_r (NULL, ":", &substr_sav); - if (!value || - (value_validator && value_validator(value, opt))) { - ret = -1; - gf_msg (THIS->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_ENTRY, "invalid list '%s', " - "value '%s' not valid.", string, key); - goto out; - } - - str_ptr = strtok_r (NULL, ",", &str_sav); - substr_sav = NULL; + + value = strtok_r(NULL, ":", &substr_sav); + if (!value || (value_validator && value_validator(value, opt))) { + ret = -1; + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY, + "invalid list '%s', " + "value '%s' not valid.", + string, key); + goto out; } - out: - GF_FREE (dup_string); - gf_msg_debug (THIS->name, 0, "Returning %d", ret); - return ret; + str_ptr = strtok_r(NULL, ",", &str_sav); + substr_sav = NULL; + } + +out: + GF_FREE(dup_string); + gf_msg_debug(THIS->name, 0, "Returning %d", ret); + return ret; } static int -xlator_option_validate_priority_list (xlator_t *xl, const char *key, - const char *value, volume_option_t *opt, - char **op_errstr) +xlator_option_validate_priority_list(xlator_t *xl, const char *key, + const char *value, volume_option_t *opt, + char **op_errstr) { - int ret =0; - char errstr[1024] = {0, }; - - GF_ASSERT (value); - - ret = validate_list_elements (value, opt, NULL, &gf_validate_number); - if (ret) { - snprintf (errstr, 1024, - "option %s %s: '%s' is not a valid " - "priority-list", key, value, value); - *op_errstr = gf_strdup (errstr); - } - - return ret; + int ret = 0; + char errstr[1024] = { + 0, + }; + + GF_ASSERT(value); + + ret = validate_list_elements(value, opt, NULL, &gf_validate_number); + if (ret) { + snprintf(errstr, 1024, + "option %s %s: '%s' is not a valid " + "priority-list", + key, value, value); + *op_errstr = gf_strdup(errstr); + } + + return ret; } static int -xlator_option_validate_size_list (xlator_t *xl, const char *key, - const char *value, volume_option_t *opt, - char **op_errstr) +xlator_option_validate_size_list(xlator_t *xl, const char *key, + const char *value, volume_option_t *opt, + char **op_errstr) { - - int ret = 0; - char errstr[1024] = {0, }; - - GF_ASSERT (value); - - ret = gf_validate_size (value, opt); - if (ret) - ret = validate_list_elements (value, opt, NULL, &gf_validate_size); - - if (ret) { - snprintf (errstr, 1024, - "option %s %s: '%s' is not a valid " - "size-list", key, value, value); - *op_errstr = gf_strdup (errstr); - } - - return ret; - + int ret = 0; + char errstr[1024] = { + 0, + }; + + GF_ASSERT(value); + + ret = gf_validate_size(value, opt); + if (ret) + ret = validate_list_elements(value, opt, NULL, &gf_validate_size); + + if (ret) { + snprintf(errstr, 1024, + "option %s %s: '%s' is not a valid " + "size-list", + key, value, value); + *op_errstr = gf_strdup(errstr); + } + + return ret; } static int -xlator_option_validate_any (xlator_t *xl, const char *key, const char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate_any(xlator_t *xl, const char *key, const char *value, + volume_option_t *opt, char **op_errstr) { - return 0; + return 0; } -typedef int (xlator_option_validator_t) (xlator_t *xl, const char *key, - const char *value, - volume_option_t *opt, char **operrstr); +typedef int(xlator_option_validator_t)(xlator_t *xl, const char *key, + const char *value, volume_option_t *opt, + char **operrstr); int -xlator_option_validate (xlator_t *xl, char *key, char *value, - volume_option_t *opt, char **op_errstr) +xlator_option_validate(xlator_t *xl, char *key, char *value, + volume_option_t *opt, char **op_errstr) { - int ret = -1; - xlator_option_validator_t *validate; - xlator_option_validator_t *validators[] = { - [GF_OPTION_TYPE_PATH] = xlator_option_validate_path, - [GF_OPTION_TYPE_INT] = xlator_option_validate_int, - [GF_OPTION_TYPE_SIZET] = xlator_option_validate_sizet, - [GF_OPTION_TYPE_BOOL] = xlator_option_validate_bool, - [GF_OPTION_TYPE_XLATOR] = xlator_option_validate_xlator, - [GF_OPTION_TYPE_STR] = xlator_option_validate_str, - [GF_OPTION_TYPE_PERCENT] = xlator_option_validate_percent, - [GF_OPTION_TYPE_PERCENT_OR_SIZET] = - xlator_option_validate_percent_or_sizet, - [GF_OPTION_TYPE_TIME] = xlator_option_validate_time, - [GF_OPTION_TYPE_DOUBLE] = xlator_option_validate_double, - [GF_OPTION_TYPE_INTERNET_ADDRESS] = xlator_option_validate_addr, - [GF_OPTION_TYPE_INTERNET_ADDRESS_LIST] = - xlator_option_validate_addr_list, - [GF_OPTION_TYPE_PRIORITY_LIST] = - xlator_option_validate_priority_list, - [GF_OPTION_TYPE_SIZE_LIST] = xlator_option_validate_size_list, - [GF_OPTION_TYPE_ANY] = xlator_option_validate_any, - [GF_OPTION_TYPE_CLIENT_AUTH_ADDR] = xlator_option_validate_mntauth, - [GF_OPTION_TYPE_MAX] = NULL, - }; - - if (opt->type > GF_OPTION_TYPE_MAX) { - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, - "unknown option type '%d'", opt->type); - goto out; - } - - validate = validators[opt->type]; - - ret = validate (xl, key, value, opt, op_errstr); + int ret = -1; + xlator_option_validator_t *validate; + xlator_option_validator_t *validators[] = { + [GF_OPTION_TYPE_PATH] = xlator_option_validate_path, + [GF_OPTION_TYPE_INT] = xlator_option_validate_int, + [GF_OPTION_TYPE_SIZET] = xlator_option_validate_sizet, + [GF_OPTION_TYPE_BOOL] = xlator_option_validate_bool, + [GF_OPTION_TYPE_XLATOR] = xlator_option_validate_xlator, + [GF_OPTION_TYPE_STR] = xlator_option_validate_str, + [GF_OPTION_TYPE_PERCENT] = xlator_option_validate_percent, + [GF_OPTION_TYPE_PERCENT_OR_SIZET] = + xlator_option_validate_percent_or_sizet, + [GF_OPTION_TYPE_TIME] = xlator_option_validate_time, + [GF_OPTION_TYPE_DOUBLE] = xlator_option_validate_double, + [GF_OPTION_TYPE_INTERNET_ADDRESS] = xlator_option_validate_addr, + [GF_OPTION_TYPE_INTERNET_ADDRESS_LIST] = + xlator_option_validate_addr_list, + [GF_OPTION_TYPE_PRIORITY_LIST] = xlator_option_validate_priority_list, + [GF_OPTION_TYPE_SIZE_LIST] = xlator_option_validate_size_list, + [GF_OPTION_TYPE_ANY] = xlator_option_validate_any, + [GF_OPTION_TYPE_CLIENT_AUTH_ADDR] = xlator_option_validate_mntauth, + [GF_OPTION_TYPE_MAX] = NULL, + }; + + if (opt->type > GF_OPTION_TYPE_MAX) { + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "unknown option type '%d'", opt->type); + goto out; + } + + validate = validators[opt->type]; + + ret = validate(xl, key, value, opt, op_errstr); out: - return ret; + return ret; } - volume_option_t * -xlator_volume_option_get_list (volume_opt_list_t *vol_list, const char *key) +xlator_volume_option_get_list(volume_opt_list_t *vol_list, const char *key) { - volume_option_t *opt = NULL; - volume_opt_list_t *opt_list = NULL; - volume_option_t *found = NULL; - int index = 0; - int i = 0; - char *cmp_key = NULL; - - if (!vol_list->given_opt) { - opt_list = list_entry (vol_list->list.next, volume_opt_list_t, - list); - opt = opt_list->given_opt; - } else - opt = vol_list->given_opt; - - for (index = 0; opt[index].key[0]; index++) { - for (i = 0; i < ZR_VOLUME_MAX_NUM_KEY; i++) { - cmp_key = opt[index].key[i]; - if (!cmp_key) - break; - if (fnmatch (cmp_key, key, FNM_NOESCAPE) == 0) { - found = &opt[index]; - goto out; - } - } + volume_option_t *opt = NULL; + volume_opt_list_t *opt_list = NULL; + volume_option_t *found = NULL; + int index = 0; + int i = 0; + char *cmp_key = NULL; + + if (!vol_list->given_opt) { + opt_list = list_entry(vol_list->list.next, volume_opt_list_t, list); + opt = opt_list->given_opt; + } else + opt = vol_list->given_opt; + + for (index = 0; opt[index].key[0]; index++) { + for (i = 0; i < ZR_VOLUME_MAX_NUM_KEY; i++) { + cmp_key = opt[index].key[i]; + if (!cmp_key) + break; + if (fnmatch(cmp_key, key, FNM_NOESCAPE) == 0) { + found = &opt[index]; + goto out; + } } + } out: - return found; + return found; } - volume_option_t * -xlator_volume_option_get (xlator_t *xl, const char *key) +xlator_volume_option_get(xlator_t *xl, const char *key) { - volume_opt_list_t *vol_list = NULL; - volume_option_t *found = NULL; + volume_opt_list_t *vol_list = NULL; + volume_option_t *found = NULL; - list_for_each_entry (vol_list, &xl->volume_options, list) { - found = xlator_volume_option_get_list (vol_list, key); - if (found) - break; - } + list_for_each_entry(vol_list, &xl->volume_options, list) + { + found = xlator_volume_option_get_list(vol_list, key); + if (found) + break; + } - return found; + return found; } - static int -xl_opt_validate (dict_t *dict, char *key, data_t *value, void *data) +xl_opt_validate(dict_t *dict, char *key, data_t *value, void *data) { - xlator_t *xl = NULL; - volume_opt_list_t *vol_opt = NULL; - volume_option_t *opt = NULL; - int ret = 0; - char *errstr = NULL; - - struct { - xlator_t *this; - volume_opt_list_t *vol_opt; - char *errstr; - } *stub; - - stub = data; - xl = stub->this; - vol_opt = stub->vol_opt; - - opt = xlator_volume_option_get_list (vol_opt, key); - if (!opt) - return 0; - - ret = xlator_option_validate (xl, key, value->data, opt, &errstr); - if (ret) - gf_msg (xl->name, GF_LOG_WARNING, 0, LG_MSG_VALIDATE_RETURNS, - "validate of %s returned %d", key, ret); - - if (errstr) - /* possible small leak of previously set stub->errstr */ - stub->errstr = errstr; - - if (fnmatch (opt->key[0], key, FNM_NOESCAPE) != 0) { - gf_msg (xl->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY, - "option '%s' is deprecated, preferred is '%s', " - "continuing with correction", key, opt->key[0]); - dict_set (dict, opt->key[0], value); - dict_del (dict, key); - } + xlator_t *xl = NULL; + volume_opt_list_t *vol_opt = NULL; + volume_option_t *opt = NULL; + int ret = 0; + char *errstr = NULL; + + struct { + xlator_t *this; + volume_opt_list_t *vol_opt; + char *errstr; + } * stub; + + stub = data; + xl = stub->this; + vol_opt = stub->vol_opt; + + opt = xlator_volume_option_get_list(vol_opt, key); + if (!opt) return 0; -} + ret = xlator_option_validate(xl, key, value->data, opt, &errstr); + if (ret) + gf_msg(xl->name, GF_LOG_WARNING, 0, LG_MSG_VALIDATE_RETURNS, + "validate of %s returned %d", key, ret); + + if (errstr) + /* possible small leak of previously set stub->errstr */ + stub->errstr = errstr; + + if (fnmatch(opt->key[0], key, FNM_NOESCAPE) != 0) { + gf_msg(xl->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY, + "option '%s' is deprecated, preferred is '%s', " + "continuing with correction", + key, opt->key[0]); + dict_set(dict, opt->key[0], value); + dict_del(dict, key); + } + return 0; +} int -xlator_options_validate_list (xlator_t *xl, dict_t *options, - volume_opt_list_t *vol_opt, char **op_errstr) +xlator_options_validate_list(xlator_t *xl, dict_t *options, + volume_opt_list_t *vol_opt, char **op_errstr) { - int ret = 0; - struct { - xlator_t *this; - volume_opt_list_t *vol_opt; - char *errstr; - } stub; - - stub.this = xl; - stub.vol_opt = vol_opt; - stub.errstr = NULL; - - dict_foreach (options, xl_opt_validate, &stub); - if (stub.errstr) { - ret = -1; - if (op_errstr) - *op_errstr = stub.errstr; - } - - return ret; + int ret = 0; + struct { + xlator_t *this; + volume_opt_list_t *vol_opt; + char *errstr; + } stub; + + stub.this = xl; + stub.vol_opt = vol_opt; + stub.errstr = NULL; + + dict_foreach(options, xl_opt_validate, &stub); + if (stub.errstr) { + ret = -1; + if (op_errstr) + *op_errstr = stub.errstr; + } + + return ret; } - int -xlator_options_validate (xlator_t *xl, dict_t *options, char **op_errstr) +xlator_options_validate(xlator_t *xl, dict_t *options, char **op_errstr) { - int ret = 0; - volume_opt_list_t *vol_opt = NULL; - - - if (!xl) { - gf_msg_debug (THIS->name, 0, "'this' not a valid ptr"); - ret = -1; - goto out; - } - - if (list_empty (&xl->volume_options)) - goto out; - - list_for_each_entry (vol_opt, &xl->volume_options, list) { - ret = xlator_options_validate_list (xl, options, vol_opt, - op_errstr); - } + int ret = 0; + volume_opt_list_t *vol_opt = NULL; + + if (!xl) { + gf_msg_debug(THIS->name, 0, "'this' not a valid ptr"); + ret = -1; + goto out; + } + + if (list_empty(&xl->volume_options)) + goto out; + + list_for_each_entry(vol_opt, &xl->volume_options, list) + { + ret = xlator_options_validate_list(xl, options, vol_opt, op_errstr); + } out: - return ret; + return ret; } - int -xlator_validate_rec (xlator_t *xlator, char **op_errstr) +xlator_validate_rec(xlator_t *xlator, char **op_errstr) { - int ret = -1; - xlator_list_t *trav = NULL; - xlator_t *old_THIS = NULL; - - GF_VALIDATE_OR_GOTO ("xlator", xlator, out); + int ret = -1; + xlator_list_t *trav = NULL; + xlator_t *old_THIS = NULL; - trav = xlator->children; + GF_VALIDATE_OR_GOTO("xlator", xlator, out); - while (trav) { - if (xlator_validate_rec (trav->xlator, op_errstr)) { - gf_msg ("xlator", GF_LOG_WARNING, 0, - LG_MSG_VALIDATE_REC_FAILED, "validate_rec " - "failed"); - goto out; - } + trav = xlator->children; - trav = trav->next; + while (trav) { + if (xlator_validate_rec(trav->xlator, op_errstr)) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_VALIDATE_REC_FAILED, + "validate_rec " + "failed"); + goto out; } - if (xlator_dynload (xlator)) - gf_msg_debug (xlator->name, 0, "Did not load the symbols"); + trav = trav->next; + } - old_THIS = THIS; - THIS = xlator; + if (xlator_dynload(xlator)) + gf_msg_debug(xlator->name, 0, "Did not load the symbols"); - /* Need this here, as this graph has not yet called init() */ - if (!xlator->mem_acct) { - if (!xlator->mem_acct_init) - xlator->mem_acct_init = default_mem_acct_init; - xlator->mem_acct_init (xlator); - } + old_THIS = THIS; + THIS = xlator; - ret = xlator_options_validate (xlator, xlator->options, op_errstr); - THIS = old_THIS; + /* Need this here, as this graph has not yet called init() */ + if (!xlator->mem_acct) { + if (!xlator->mem_acct_init) + xlator->mem_acct_init = default_mem_acct_init; + xlator->mem_acct_init(xlator); + } - if (ret) { - gf_msg (xlator->name, GF_LOG_INFO, 0, LG_MSG_INVALID_ENTRY, - "%s", *op_errstr); - goto out; - } + ret = xlator_options_validate(xlator, xlator->options, op_errstr); + THIS = old_THIS; - gf_msg_debug (xlator->name, 0, "Validated options"); + if (ret) { + gf_msg(xlator->name, GF_LOG_INFO, 0, LG_MSG_INVALID_ENTRY, "%s", + *op_errstr); + goto out; + } - ret = 0; + gf_msg_debug(xlator->name, 0, "Validated options"); + + ret = 0; out: - return ret; + return ret; } - int -graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr) +graph_reconf_validateopt(glusterfs_graph_t *graph, char **op_errstr) { - xlator_t *xlator = NULL; - int ret = -1; + xlator_t *xlator = NULL; + int ret = -1; - GF_ASSERT (graph); + GF_ASSERT(graph); - xlator = graph->first; + xlator = graph->first; - ret = xlator_validate_rec (xlator, op_errstr); + ret = xlator_validate_rec(xlator, op_errstr); - return ret; + return ret; } - static int -xlator_reconfigure_rec (xlator_t *old_xl, xlator_t *new_xl) +xlator_reconfigure_rec(xlator_t *old_xl, xlator_t *new_xl) { - xlator_list_t *trav1 = NULL; - xlator_list_t *trav2 = NULL; - int32_t ret = -1; - xlator_t *old_THIS = NULL; + xlator_list_t *trav1 = NULL; + xlator_list_t *trav2 = NULL; + int32_t ret = -1; + xlator_t *old_THIS = NULL; - GF_VALIDATE_OR_GOTO ("xlator", old_xl, out); - GF_VALIDATE_OR_GOTO ("xlator", new_xl, out); + GF_VALIDATE_OR_GOTO("xlator", old_xl, out); + GF_VALIDATE_OR_GOTO("xlator", new_xl, out); - trav1 = old_xl->children; - trav2 = new_xl->children; + trav1 = old_xl->children; + trav2 = new_xl->children; - while (trav1 && trav2) { - ret = xlator_reconfigure_rec (trav1->xlator, trav2->xlator); - if (ret) - goto out; + while (trav1 && trav2) { + ret = xlator_reconfigure_rec(trav1->xlator, trav2->xlator); + if (ret) + goto out; - gf_msg_debug (trav1->xlator->name, 0, "reconfigured"); + gf_msg_debug(trav1->xlator->name, 0, "reconfigured"); - trav1 = trav1->next; - trav2 = trav2->next; - } + trav1 = trav1->next; + trav2 = trav2->next; + } - if (old_xl->reconfigure) { - old_THIS = THIS; - THIS = old_xl; + if (old_xl->reconfigure) { + old_THIS = THIS; + THIS = old_xl; - xlator_init_lock (); - ret = old_xl->reconfigure (old_xl, new_xl->options); - xlator_init_unlock (); + xlator_init_lock(); + ret = old_xl->reconfigure(old_xl, new_xl->options); + xlator_init_unlock(); - THIS = old_THIS; + THIS = old_THIS; - if (ret) - goto out; - } else { - gf_msg_debug (old_xl->name, 0, "No reconfigure() found"); - } + if (ret) + goto out; + } else { + gf_msg_debug(old_xl->name, 0, "No reconfigure() found"); + } - ret = 0; + ret = 0; out: - return ret; + return ret; } - int -xlator_tree_reconfigure (xlator_t *old_xl, xlator_t *new_xl) +xlator_tree_reconfigure(xlator_t *old_xl, xlator_t *new_xl) { - xlator_t *new_top = NULL; - xlator_t *old_top = NULL; + xlator_t *new_top = NULL; + xlator_t *old_top = NULL; - GF_ASSERT (old_xl); - GF_ASSERT (new_xl); + GF_ASSERT(old_xl); + GF_ASSERT(new_xl); - old_top = old_xl; - new_top = new_xl; + old_top = old_xl; + new_top = new_xl; - return xlator_reconfigure_rec (old_top, new_top); + return xlator_reconfigure_rec(old_top, new_top); } - int -xlator_option_info_list (volume_opt_list_t *list, char *key, - char **def_val, char **descr) +xlator_option_info_list(volume_opt_list_t *list, char *key, char **def_val, + char **descr) { - int ret = -1; - volume_option_t *opt = NULL; + int ret = -1; + volume_option_t *opt = NULL; + opt = xlator_volume_option_get_list(list, key); + if (!opt) + goto out; - opt = xlator_volume_option_get_list (list, key); - if (!opt) - goto out; - - if (def_val) - *def_val = opt->default_value; - if (descr) - *descr = opt->description; + if (def_val) + *def_val = opt->default_value; + if (descr) + *descr = opt->description; - ret = 0; + ret = 0; out: - return ret; + return ret; } - static int -pass (char *in, char **out) +pass(char *in, char **out) { - *out = in; - return 0; + *out = in; + return 0; } - static int -xl_by_name (char *in, xlator_t **out) +xl_by_name(char *in, xlator_t **out) { - xlator_t *xl = NULL; + xlator_t *xl = NULL; - xl = xlator_search_by_name (THIS, in); + xl = xlator_search_by_name(THIS, in); - if (!xl) - return -1; - *out = xl; - return 0; + if (!xl) + return -1; + *out = xl; + return 0; } - static int -pc_or_size (char *in, double *out) +pc_or_size(char *in, double *out) { - double pc = 0; - int ret = 0; - size_t size = 0; - - if (gf_string2percent (in, &pc) == 0) { - if (pc > 100.0) { - ret = gf_string2bytesize_size (in, &size); - if (!ret) - *out = size; - } else { - *out = pc; - } + double pc = 0; + int ret = 0; + size_t size = 0; + + if (gf_string2percent(in, &pc) == 0) { + if (pc > 100.0) { + ret = gf_string2bytesize_size(in, &size); + if (!ret) + *out = size; } else { - ret = gf_string2bytesize_size (in, &size); - if (!ret) - *out = size; + *out = pc; } - return ret; + } else { + ret = gf_string2bytesize_size(in, &size); + if (!ret) + *out = size; + } + return ret; } DEFINE_INIT_OPT(char *, str, pass); @@ -1265,7 +1233,6 @@ DEFINE_INIT_OPT(char *, path, pass); DEFINE_INIT_OPT(double, double, gf_string2double); DEFINE_INIT_OPT(uint32_t, time, gf_string2time); - DEFINE_RECONF_OPT(char *, str, pass); DEFINE_RECONF_OPT(uint64_t, uint64, gf_string2uint64); DEFINE_RECONF_OPT(int64_t, int64, gf_string2int64); diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h index e47d7496a39..b0f76d5639c 100644 --- a/libglusterfs/src/options.h +++ b/libglusterfs/src/options.h @@ -76,8 +76,8 @@ typedef enum { * try a solution in GD2 for this. */ /* typedef int (*option_validation_fn) (glusterd_volinfo_t *volinfo, dict_t - *dict, char *key, char *value, char **op_errstr); -*/ + *dict, char *key, char *value, char **op_errstr); + */ /* Each translator should define this structure */ /* XXX: This structure is in use by GD2, and SHOULD NOT be modified. diff --git a/libglusterfs/src/parse-utils.c b/libglusterfs/src/parse-utils.c index 304232f6b56..d3fd0963507 100644 --- a/libglusterfs/src/parse-utils.c +++ b/libglusterfs/src/parse-utils.c @@ -36,33 +36,33 @@ * : failure: NULL (on failure to compile regex or allocate memory) */ struct parser * -parser_init (const char *regex) +parser_init(const char *regex) { - int rc = 0; - struct parser *parser = NULL; - - parser = GF_MALLOC (sizeof(*parser), gf_common_mt_parser_t); - if (!parser) - goto out; - - parser->regex = gf_strdup (regex); - if (!parser->regex) { - GF_FREE (parser); - parser = NULL; - goto out; - } - - rc = regcomp (&parser->preg, parser->regex, REG_EXTENDED); - if (rc != 0) { - gf_msg (GF_PARSE, GF_LOG_INFO, 0, LG_MSG_REGEX_OP_FAILED, - "Failed to compile regex pattern."); - parser_deinit (parser); - parser = NULL; - goto out; - } - parser->complete_str = NULL; + int rc = 0; + struct parser *parser = NULL; + + parser = GF_MALLOC(sizeof(*parser), gf_common_mt_parser_t); + if (!parser) + goto out; + + parser->regex = gf_strdup(regex); + if (!parser->regex) { + GF_FREE(parser); + parser = NULL; + goto out; + } + + rc = regcomp(&parser->preg, parser->regex, REG_EXTENDED); + if (rc != 0) { + gf_msg(GF_PARSE, GF_LOG_INFO, 0, LG_MSG_REGEX_OP_FAILED, + "Failed to compile regex pattern."); + parser_deinit(parser); + parser = NULL; + goto out; + } + parser->complete_str = NULL; out: - return parser; + return parser; } /** @@ -78,22 +78,22 @@ out: * failure: -EINVAL for NULL args, -ENOMEM for allocation errors */ int -parser_set_string (struct parser *parser, const char *complete_str) +parser_set_string(struct parser *parser, const char *complete_str) { - int ret = -EINVAL; + int ret = -EINVAL; - GF_VALIDATE_OR_GOTO (GF_PARSE, parser, out); - GF_VALIDATE_OR_GOTO (GF_PARSE, complete_str, out); + GF_VALIDATE_OR_GOTO(GF_PARSE, parser, out); + GF_VALIDATE_OR_GOTO(GF_PARSE, complete_str, out); - parser->complete_str = gf_strdup (complete_str); - GF_CHECK_ALLOC_AND_LOG (GF_PARSE, parser, ret, - "Failed to duplicate string!", out); + parser->complete_str = gf_strdup(complete_str); + GF_CHECK_ALLOC_AND_LOG(GF_PARSE, parser, ret, "Failed to duplicate string!", + out); - /* Point the temp internal string to what we just dup'ed */ - parser->_rstr = (char *)parser->complete_str; - ret = 0; + /* Point the temp internal string to what we just dup'ed */ + parser->_rstr = (char *)parser->complete_str; + ret = 0; out: - return ret; + return ret; } /** @@ -107,17 +107,17 @@ out: * : failure: -EINVAL on NULL args */ int -parser_unset_string (struct parser *parser) +parser_unset_string(struct parser *parser) { - int ret = -EINVAL; + int ret = -EINVAL; - GF_VALIDATE_OR_GOTO (GF_PARSE, parser, out); + GF_VALIDATE_OR_GOTO(GF_PARSE, parser, out); - GF_FREE (parser->complete_str); - parser->complete_str = NULL; /* Avoid double frees in parser_deinit */ - ret = 0; + GF_FREE(parser->complete_str); + parser->complete_str = NULL; /* Avoid double frees in parser_deinit */ + ret = 0; out: - return ret; + return ret; } /** @@ -128,15 +128,15 @@ out: * @return : nothing */ void -parser_deinit (struct parser *ptr) +parser_deinit(struct parser *ptr) { - if (!ptr) - return; + if (!ptr) + return; - regfree (&ptr->preg); - GF_FREE (ptr->complete_str); - GF_FREE (ptr->regex); - GF_FREE (ptr); + regfree(&ptr->preg); + GF_FREE(ptr->complete_str); + GF_FREE(ptr->regex); + GF_FREE(ptr); } /** @@ -149,29 +149,28 @@ parser_deinit (struct parser *ptr) * : failure: NULL */ char * -parser_get_next_match (struct parser *parser) +parser_get_next_match(struct parser *parser) { - int rc = -EINVAL; - size_t copy_len = 0; - char *match = NULL; + int rc = -EINVAL; + size_t copy_len = 0; + char *match = NULL; - GF_VALIDATE_OR_GOTO (GF_PARSE, parser, out); + GF_VALIDATE_OR_GOTO(GF_PARSE, parser, out); - rc = regexec (&parser->preg, parser->_rstr, 1, parser->pmatch, 0); - if (rc != 0) { - gf_msg_debug (GF_PARSE, 0, - "Could not match %s with regex %s", - parser->_rstr, parser->regex); - goto out; - } + rc = regexec(&parser->preg, parser->_rstr, 1, parser->pmatch, 0); + if (rc != 0) { + gf_msg_debug(GF_PARSE, 0, "Could not match %s with regex %s", + parser->_rstr, parser->regex); + goto out; + } - copy_len = parser->pmatch[0].rm_eo - parser->pmatch[0].rm_so; + copy_len = parser->pmatch[0].rm_eo - parser->pmatch[0].rm_so; - match = gf_strndup (parser->_rstr + parser->pmatch[0].rm_so, copy_len); - GF_CHECK_ALLOC_AND_LOG (GF_PARSE, match, rc, - "Duplicating match failed!", out); + match = gf_strndup(parser->_rstr + parser->pmatch[0].rm_so, copy_len); + GF_CHECK_ALLOC_AND_LOG(GF_PARSE, match, rc, "Duplicating match failed!", + out); - parser->_rstr = &parser->_rstr[parser->pmatch[0].rm_eo]; + parser->_rstr = &parser->_rstr[parser->pmatch[0].rm_eo]; out: - return match; + return match; } diff --git a/libglusterfs/src/quota-common-utils.c b/libglusterfs/src/quota-common-utils.c index a0a7dd5aafe..7e271ad7d07 100644 --- a/libglusterfs/src/quota-common-utils.c +++ b/libglusterfs/src/quota-common-utils.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - #include "dict.h" #include "logging.h" #include "byte-order.h" @@ -17,227 +16,224 @@ #include "libglusterfs-messages.h" gf_boolean_t -quota_meta_is_null (const quota_meta_t *meta) +quota_meta_is_null(const quota_meta_t *meta) { - if (meta->size == 0 && - meta->file_count == 0 && - meta->dir_count == 0) - return _gf_true; + if (meta->size == 0 && meta->file_count == 0 && meta->dir_count == 0) + return _gf_true; - return _gf_false; + return _gf_false; } int32_t -quota_data_to_meta (data_t *data, char *key, quota_meta_t *meta) +quota_data_to_meta(data_t *data, char *key, quota_meta_t *meta) { - int32_t ret = -1; - quota_meta_t *value = NULL; - int64_t *size = NULL; - - if (!data || !key || !meta) - goto out; - - if (data->len > sizeof (int64_t)) { - value = (quota_meta_t *) data->data; - meta->size = ntoh64 (value->size); - meta->file_count = ntoh64 (value->file_count); - if (data->len > (sizeof (int64_t)) * 2) - meta->dir_count = ntoh64 (value->dir_count); - else - meta->dir_count = 0; - } else { - size = (int64_t *) data->data; - meta->size = ntoh64 (*size); - meta->file_count = 0; - meta->dir_count = 0; - /* This can happen during software upgrade. - * Older version of glusterfs will not have inode count. - * Return failure, this will be healed as part of lookup - */ - gf_msg_callingfn ("quota", GF_LOG_DEBUG, 0, - LG_MSG_QUOTA_XATTRS_MISSING, "Object quota " - "xattrs missing: len = %d", data->len); - ret = -2; - goto out; - } - - ret = 0; + int32_t ret = -1; + quota_meta_t *value = NULL; + int64_t *size = NULL; + + if (!data || !key || !meta) + goto out; + + if (data->len > sizeof(int64_t)) { + value = (quota_meta_t *)data->data; + meta->size = ntoh64(value->size); + meta->file_count = ntoh64(value->file_count); + if (data->len > (sizeof(int64_t)) * 2) + meta->dir_count = ntoh64(value->dir_count); + else + meta->dir_count = 0; + } else { + size = (int64_t *)data->data; + meta->size = ntoh64(*size); + meta->file_count = 0; + meta->dir_count = 0; + /* This can happen during software upgrade. + * Older version of glusterfs will not have inode count. + * Return failure, this will be healed as part of lookup + */ + gf_msg_callingfn("quota", GF_LOG_DEBUG, 0, LG_MSG_QUOTA_XATTRS_MISSING, + "Object quota " + "xattrs missing: len = %d", + data->len); + ret = -2; + goto out; + } + + ret = 0; out: - return ret; + return ret; } int32_t -quota_dict_get_inode_meta (dict_t *dict, char *key, quota_meta_t *meta) +quota_dict_get_inode_meta(dict_t *dict, char *key, quota_meta_t *meta) { - int32_t ret = -1; - data_t *data = NULL; + int32_t ret = -1; + data_t *data = NULL; - if (!dict || !key || !meta) - goto out; + if (!dict || !key || !meta) + goto out; - data = dict_get (dict, key); - if (!data || !data->data) - goto out; + data = dict_get(dict, key); + if (!data || !data->data) + goto out; - ret = quota_data_to_meta (data, key, meta); + ret = quota_data_to_meta(data, key, meta); out: - return ret; + return ret; } int32_t -quota_dict_get_meta (dict_t *dict, char *key, quota_meta_t *meta) +quota_dict_get_meta(dict_t *dict, char *key, quota_meta_t *meta) { - int32_t ret = -1; + int32_t ret = -1; - ret = quota_dict_get_inode_meta (dict, key, meta); - if (ret == -2) - ret = 0; + ret = quota_dict_get_inode_meta(dict, key, meta); + if (ret == -2) + ret = 0; - return ret; + return ret; } int32_t -quota_dict_set_meta (dict_t *dict, char *key, const quota_meta_t *meta, - ia_type_t ia_type) +quota_dict_set_meta(dict_t *dict, char *key, const quota_meta_t *meta, + ia_type_t ia_type) { - int32_t ret = -ENOMEM; - quota_meta_t *value = NULL; - - value = GF_MALLOC (sizeof (quota_meta_t), gf_common_quota_meta_t); - if (value == NULL) { - goto out; - } - - value->size = hton64 (meta->size); - value->file_count = hton64 (meta->file_count); - value->dir_count = hton64 (meta->dir_count); - - if (ia_type == IA_IFDIR) { - ret = dict_set_bin (dict, key, value, sizeof (*value)); - } else { - /* For a file we don't need to store dir_count in the - * quota size xattr, so we set the len of the data in the dict - * as 128bits, so when the posix xattrop reads the dict, it only - * performs operations on size and file_count - */ - ret = dict_set_bin (dict, key, value, - sizeof (*value) - sizeof (int64_t)); - } - - if (ret < 0) { - gf_msg_callingfn ("quota", GF_LOG_ERROR, 0, - LG_MSG_DICT_SET_FAILED, "dict set failed"); - GF_FREE (value); - } + int32_t ret = -ENOMEM; + quota_meta_t *value = NULL; + + value = GF_MALLOC(sizeof(quota_meta_t), gf_common_quota_meta_t); + if (value == NULL) { + goto out; + } + + value->size = hton64(meta->size); + value->file_count = hton64(meta->file_count); + value->dir_count = hton64(meta->dir_count); + + if (ia_type == IA_IFDIR) { + ret = dict_set_bin(dict, key, value, sizeof(*value)); + } else { + /* For a file we don't need to store dir_count in the + * quota size xattr, so we set the len of the data in the dict + * as 128bits, so when the posix xattrop reads the dict, it only + * performs operations on size and file_count + */ + ret = dict_set_bin(dict, key, value, sizeof(*value) - sizeof(int64_t)); + } + + if (ret < 0) { + gf_msg_callingfn("quota", GF_LOG_ERROR, 0, LG_MSG_DICT_SET_FAILED, + "dict set failed"); + GF_FREE(value); + } out: - return ret; + return ret; } int32_t -quota_conf_read_header (int fd, char *buf) +quota_conf_read_header(int fd, char *buf) { - int ret = 0; - const int header_len = SLEN (QUOTA_CONF_HEADER); - - ret = gf_nread (fd, buf, header_len); - if (ret <= 0) { - goto out; - } else if (ret > 0 && ret != header_len) { - ret = -1; - goto out; - } + int ret = 0; + const int header_len = SLEN(QUOTA_CONF_HEADER); - buf[header_len-1] = 0; + ret = gf_nread(fd, buf, header_len); + if (ret <= 0) { + goto out; + } else if (ret > 0 && ret != header_len) { + ret = -1; + goto out; + } + + buf[header_len - 1] = 0; out: - if (ret < 0) - gf_msg_callingfn ("quota", GF_LOG_ERROR, 0, - LG_MSG_QUOTA_CONF_ERROR, "failed to read " - "header from a quota conf"); + if (ret < 0) + gf_msg_callingfn("quota", GF_LOG_ERROR, 0, LG_MSG_QUOTA_CONF_ERROR, + "failed to read " + "header from a quota conf"); - return ret; + return ret; } int32_t -quota_conf_read_version (int fd, float *version) +quota_conf_read_version(int fd, float *version) { - int ret = 0; - char buf[PATH_MAX] = ""; - char *tail = NULL; - float value = 0.0f; - - ret = quota_conf_read_header (fd, buf); - if (ret == 0) { - /* quota.conf is empty */ - value = GF_QUOTA_CONF_VERSION; - goto out; - } else if (ret < 0) { - goto out; - } - - value = strtof ((buf + strlen(buf) - 3), &tail); - if (tail[0] != '\0') { - ret = -1; - gf_msg_callingfn ("quota", GF_LOG_ERROR, 0, - LG_MSG_QUOTA_CONF_ERROR, "invalid quota conf" - " version"); - goto out; - } - - ret = 0; + int ret = 0; + char buf[PATH_MAX] = ""; + char *tail = NULL; + float value = 0.0f; + + ret = quota_conf_read_header(fd, buf); + if (ret == 0) { + /* quota.conf is empty */ + value = GF_QUOTA_CONF_VERSION; + goto out; + } else if (ret < 0) { + goto out; + } + + value = strtof((buf + strlen(buf) - 3), &tail); + if (tail[0] != '\0') { + ret = -1; + gf_msg_callingfn("quota", GF_LOG_ERROR, 0, LG_MSG_QUOTA_CONF_ERROR, + "invalid quota conf" + " version"); + goto out; + } + + ret = 0; out: - if (ret >= 0) - *version = value; - else - gf_msg_callingfn ("quota", GF_LOG_ERROR, 0, - LG_MSG_QUOTA_CONF_ERROR, "failed to " - "read version from a quota conf header"); - - return ret; + if (ret >= 0) + *version = value; + else + gf_msg_callingfn("quota", GF_LOG_ERROR, 0, LG_MSG_QUOTA_CONF_ERROR, + "failed to " + "read version from a quota conf header"); + + return ret; } int32_t -quota_conf_read_gfid (int fd, void *buf, char *type, float version) +quota_conf_read_gfid(int fd, void *buf, char *type, float version) { - int ret = 0; - - ret = gf_nread (fd, buf, 16); - if (ret <= 0) - goto out; - - if (ret != 16) { - ret = -1; - goto out; - } - - if (version >= 1.2f) { - ret = gf_nread (fd, type, 1); - if (ret != 1) { - ret = -1; - goto out; - } - ret = 17; - } else { - *type = GF_QUOTA_CONF_TYPE_USAGE; + int ret = 0; + + ret = gf_nread(fd, buf, 16); + if (ret <= 0) + goto out; + + if (ret != 16) { + ret = -1; + goto out; + } + + if (version >= 1.2f) { + ret = gf_nread(fd, type, 1); + if (ret != 1) { + ret = -1; + goto out; } + ret = 17; + } else { + *type = GF_QUOTA_CONF_TYPE_USAGE; + } out: - if (ret < 0) - gf_msg_callingfn ("quota", GF_LOG_ERROR, 0, - LG_MSG_QUOTA_CONF_ERROR, "failed to " - "read gfid from a quota conf"); + if (ret < 0) + gf_msg_callingfn("quota", GF_LOG_ERROR, 0, LG_MSG_QUOTA_CONF_ERROR, + "failed to " + "read gfid from a quota conf"); - return ret; + return ret; } int32_t -quota_conf_skip_header (int fd) +quota_conf_skip_header(int fd) { - return gf_skip_header_section (fd, strlen (QUOTA_CONF_HEADER)); + return gf_skip_header_section(fd, strlen(QUOTA_CONF_HEADER)); } - diff --git a/libglusterfs/src/rbthash.c b/libglusterfs/src/rbthash.c index 4d654066e13..0068b7b881e 100644 --- a/libglusterfs/src/rbthash.c +++ b/libglusterfs/src/rbthash.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - #include "rbthash.h" #include "rb.h" #include "locking.h" @@ -19,59 +18,57 @@ #include <pthread.h> #include <string.h> - int -rbthash_comparator (void *entry1, void *entry2, void *param) +rbthash_comparator(void *entry1, void *entry2, void *param) { - int ret = 0; - rbthash_entry_t *e1 = NULL; - rbthash_entry_t *e2 = NULL; + int ret = 0; + rbthash_entry_t *e1 = NULL; + rbthash_entry_t *e2 = NULL; - if ((!entry1) || (!entry2) || (!param)) - return -1; + if ((!entry1) || (!entry2) || (!param)) + return -1; - e1 = (rbthash_entry_t *)entry1; - e2 = (rbthash_entry_t *)entry2; + e1 = (rbthash_entry_t *)entry1; + e2 = (rbthash_entry_t *)entry2; - if (e1->keylen != e2->keylen) { - if (e1->keylen < e2->keylen) - ret = -1; - else if (e1->keylen > e2->keylen) - ret = 1; - } else - ret = memcmp (e1->key, e2->key, e1->keylen); + if (e1->keylen != e2->keylen) { + if (e1->keylen < e2->keylen) + ret = -1; + else if (e1->keylen > e2->keylen) + ret = 1; + } else + ret = memcmp(e1->key, e2->key, e1->keylen); - return ret; + return ret; } - int -__rbthash_init_buckets (rbthash_table_t *tbl, int buckets) +__rbthash_init_buckets(rbthash_table_t *tbl, int buckets) { - int i = 0; - int ret = -1; - - if (!tbl) - return -1; - - for (; i < buckets; i++) { - LOCK_INIT (&tbl->buckets[i].bucketlock); - tbl->buckets[i].bucket = rb_create ((rb_comparison_func *)rbthash_comparator, tbl, NULL); - if (!tbl->buckets[i].bucket) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RB_TABLE_CREATE_FAILED, "Failed to " - "create rb table bucket"); - ret = -1; - goto err; - } + int i = 0; + int ret = -1; + + if (!tbl) + return -1; + + for (; i < buckets; i++) { + LOCK_INIT(&tbl->buckets[i].bucketlock); + tbl->buckets[i].bucket = rb_create( + (rb_comparison_func *)rbthash_comparator, tbl, NULL); + if (!tbl->buckets[i].bucket) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RB_TABLE_CREATE_FAILED, + "Failed to " + "create rb table bucket"); + ret = -1; + goto err; } + } - ret = 0; + ret = 0; err: - return ret; + return ret; } - /* * rbthash_table_init - Initialize a RBT based hash table * @buckets - Number of buckets in the hash table @@ -83,391 +80,377 @@ err: */ rbthash_table_t * -rbthash_table_init (glusterfs_ctx_t *ctx, int buckets, rbt_hasher_t hfunc, - rbt_data_destroyer_t dfunc, - unsigned long expected_entries, - struct mem_pool *entrypool) +rbthash_table_init(glusterfs_ctx_t *ctx, int buckets, rbt_hasher_t hfunc, + rbt_data_destroyer_t dfunc, unsigned long expected_entries, + struct mem_pool *entrypool) { - rbthash_table_t *newtab = NULL; - int ret = -1; - - if (!hfunc) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_HASH_FUNC_ERROR, - "Hash function not given"); - return NULL; + rbthash_table_t *newtab = NULL; + int ret = -1; + + if (!hfunc) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_HASH_FUNC_ERROR, + "Hash function not given"); + return NULL; + } + + if (!entrypool && !expected_entries) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Both mem-pool and expected entries not provided"); + return NULL; + } + + if (entrypool && expected_entries) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Both mem-pool and expected entries are provided"); + return NULL; + } + + newtab = GF_CALLOC(1, sizeof(*newtab), gf_common_mt_rbthash_table_t); + if (!newtab) + return NULL; + + newtab->buckets = GF_CALLOC(buckets, sizeof(struct rbthash_bucket), + gf_common_mt_rbthash_bucket); + if (!newtab->buckets) { + goto free_newtab; + } + + if (expected_entries) { + newtab->entrypool = mem_pool_new_ctx(ctx, rbthash_entry_t, + expected_entries); + if (!newtab->entrypool) { + goto free_buckets; } - - if (!entrypool && !expected_entries) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, - "Both mem-pool and expected entries not provided"); - return NULL; - } - - if (entrypool && expected_entries) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, - "Both mem-pool and expected entries are provided"); - return NULL; - } - - - newtab = GF_CALLOC (1, sizeof (*newtab), - gf_common_mt_rbthash_table_t); - if (!newtab) - return NULL; - - newtab->buckets = GF_CALLOC (buckets, sizeof (struct rbthash_bucket), - gf_common_mt_rbthash_bucket); - if (!newtab->buckets) { - goto free_newtab; - } - - if (expected_entries) { - newtab->entrypool = - mem_pool_new_ctx (ctx, rbthash_entry_t, - expected_entries); - if (!newtab->entrypool) { - goto free_buckets; - } - newtab->pool_alloced = _gf_true; - } else { - newtab->entrypool = entrypool; - } - - LOCK_INIT (&newtab->tablelock); - INIT_LIST_HEAD (&newtab->list); - newtab->numbuckets = buckets; - ret = __rbthash_init_buckets (newtab, buckets); - - if (ret == -1) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_INIT_BUCKET_FAILED, - "Failed to init buckets"); - if (newtab->pool_alloced) - mem_pool_destroy (newtab->entrypool); - } else { - gf_msg_trace (GF_RBTHASH, 0, "Inited hash table: buckets:" - " %d", buckets); - } - - newtab->hashfunc = hfunc; - newtab->dfunc = dfunc; + newtab->pool_alloced = _gf_true; + } else { + newtab->entrypool = entrypool; + } + + LOCK_INIT(&newtab->tablelock); + INIT_LIST_HEAD(&newtab->list); + newtab->numbuckets = buckets; + ret = __rbthash_init_buckets(newtab, buckets); + + if (ret == -1) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_INIT_BUCKET_FAILED, + "Failed to init buckets"); + if (newtab->pool_alloced) + mem_pool_destroy(newtab->entrypool); + } else { + gf_msg_trace(GF_RBTHASH, 0, + "Inited hash table: buckets:" + " %d", + buckets); + } + + newtab->hashfunc = hfunc; + newtab->dfunc = dfunc; free_buckets: - if (ret == -1) - GF_FREE (newtab->buckets); + if (ret == -1) + GF_FREE(newtab->buckets); free_newtab: - if (ret == -1) { - GF_FREE (newtab); - newtab = NULL; - } + if (ret == -1) { + GF_FREE(newtab); + newtab = NULL; + } - return newtab; + return newtab; } rbthash_entry_t * -rbthash_init_entry (rbthash_table_t *tbl, void *data, void *key, int keylen) +rbthash_init_entry(rbthash_table_t *tbl, void *data, void *key, int keylen) { - int ret = -1; - rbthash_entry_t *entry = NULL; - - if ((!tbl) || (!data) || (!key)) - return NULL; - - entry = mem_get (tbl->entrypool); - if (!entry) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_GET_ENTRY_FAILED, - "Failed to get entry from mem-pool"); - goto ret; - } - - entry->data = data; - entry->key = GF_MALLOC (keylen, gf_common_mt_char); - if (!entry->key) { - goto free_entry; - } - - INIT_LIST_HEAD (&entry->list); - memcpy (entry->key, key, keylen); - entry->keylen = keylen; - entry->keyhash = tbl->hashfunc (entry->key, entry->keylen); - gf_msg_trace (GF_RBTHASH, 0, "HASH: %u", entry->keyhash); - - ret = 0; + int ret = -1; + rbthash_entry_t *entry = NULL; + + if ((!tbl) || (!data) || (!key)) + return NULL; + + entry = mem_get(tbl->entrypool); + if (!entry) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_GET_ENTRY_FAILED, + "Failed to get entry from mem-pool"); + goto ret; + } + + entry->data = data; + entry->key = GF_MALLOC(keylen, gf_common_mt_char); + if (!entry->key) { + goto free_entry; + } + + INIT_LIST_HEAD(&entry->list); + memcpy(entry->key, key, keylen); + entry->keylen = keylen; + entry->keyhash = tbl->hashfunc(entry->key, entry->keylen); + gf_msg_trace(GF_RBTHASH, 0, "HASH: %u", entry->keyhash); + + ret = 0; free_entry: - if (ret == -1) { - mem_put (entry); - entry = NULL; - } + if (ret == -1) { + mem_put(entry); + entry = NULL; + } ret: - return entry; + return entry; } - void -rbthash_deinit_entry (rbthash_table_t *tbl, rbthash_entry_t *entry) +rbthash_deinit_entry(rbthash_table_t *tbl, rbthash_entry_t *entry) { + if (!entry) + return; - if (!entry) - return; - - GF_FREE (entry->key); - - if (tbl) { - if ((entry->data) && (tbl->dfunc)) - tbl->dfunc (entry->data); + GF_FREE(entry->key); - LOCK (&tbl->tablelock); - { - list_del_init (&entry->list); - } - UNLOCK (&tbl->tablelock); + if (tbl) { + if ((entry->data) && (tbl->dfunc)) + tbl->dfunc(entry->data); - mem_put (entry); + LOCK(&tbl->tablelock); + { + list_del_init(&entry->list); } + UNLOCK(&tbl->tablelock); - return; -} + mem_put(entry); + } + return; +} static struct rbthash_bucket * -rbthash_entry_bucket (rbthash_table_t *tbl, rbthash_entry_t * entry) +rbthash_entry_bucket(rbthash_table_t *tbl, rbthash_entry_t *entry) { - int nbucket = 0; + int nbucket = 0; - nbucket = (entry->keyhash % tbl->numbuckets); - gf_msg_trace (GF_RBTHASH, 0, "BUCKET: %d", nbucket); - return &tbl->buckets[nbucket]; + nbucket = (entry->keyhash % tbl->numbuckets); + gf_msg_trace(GF_RBTHASH, 0, "BUCKET: %d", nbucket); + return &tbl->buckets[nbucket]; } - int -rbthash_insert_entry (rbthash_table_t *tbl, rbthash_entry_t *entry) +rbthash_insert_entry(rbthash_table_t *tbl, rbthash_entry_t *entry) { - struct rbthash_bucket *bucket = NULL; - int ret = -1; - - if ((!tbl) || (!entry)) - return -1; - - bucket = rbthash_entry_bucket (tbl, entry); - if (!bucket) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_GET_BUCKET_FAILED, - "Failed to get bucket"); - goto err; + struct rbthash_bucket *bucket = NULL; + int ret = -1; + + if ((!tbl) || (!entry)) + return -1; + + bucket = rbthash_entry_bucket(tbl, entry); + if (!bucket) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_GET_BUCKET_FAILED, + "Failed to get bucket"); + goto err; + } + + ret = 0; + LOCK(&bucket->bucketlock); + { + if (!rb_probe(bucket->bucket, (void *)entry)) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_INSERT_FAILED, + "Failed to insert" + " entry"); + ret = -1; } - - ret = 0; - LOCK (&bucket->bucketlock); - { - if (!rb_probe (bucket->bucket, (void *)entry)) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_INSERT_FAILED, "Failed to insert" - " entry"); - ret = -1; - } - } - UNLOCK (&bucket->bucketlock); + } + UNLOCK(&bucket->bucketlock); err: - return ret; + return ret; } - int -rbthash_insert (rbthash_table_t *tbl, void *data, void *key, int keylen) +rbthash_insert(rbthash_table_t *tbl, void *data, void *key, int keylen) { - rbthash_entry_t *entry = NULL; - int ret = -1; - - if ((!tbl) || (!data) || (!key)) - return -1; - - entry = rbthash_init_entry (tbl, data, key, keylen); - if (!entry) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_INIT_ENTRY_FAILED, - "Failed to init entry"); - goto err; - } + rbthash_entry_t *entry = NULL; + int ret = -1; - ret = rbthash_insert_entry (tbl, entry); + if ((!tbl) || (!data) || (!key)) + return -1; - if (ret == -1) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_INSERT_FAILED, - "Failed to insert entry"); - rbthash_deinit_entry (tbl, entry); - } + entry = rbthash_init_entry(tbl, data, key, keylen); + if (!entry) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_INIT_ENTRY_FAILED, + "Failed to init entry"); + goto err; + } - LOCK (&tbl->tablelock); - { - list_add_tail (&entry->list, &tbl->list); - } - UNLOCK (&tbl->tablelock); + ret = rbthash_insert_entry(tbl, entry); + + if (ret == -1) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_INSERT_FAILED, + "Failed to insert entry"); + rbthash_deinit_entry(tbl, entry); + } + + LOCK(&tbl->tablelock); + { + list_add_tail(&entry->list, &tbl->list); + } + UNLOCK(&tbl->tablelock); err: - return ret; + return ret; } static struct rbthash_bucket * -rbthash_key_bucket (rbthash_table_t *tbl, void *key, int keylen) +rbthash_key_bucket(rbthash_table_t *tbl, void *key, int keylen) { - uint32_t keyhash = 0; - int nbucket = 0; + uint32_t keyhash = 0; + int nbucket = 0; - if ((!tbl) || (!key)) - return NULL; + if ((!tbl) || (!key)) + return NULL; - keyhash = tbl->hashfunc (key, keylen); - gf_msg_trace (GF_RBTHASH, 0, "HASH: %u", keyhash); - nbucket = (keyhash % tbl->numbuckets); - gf_msg_trace (GF_RBTHASH, 0, "BUCKET: %u", nbucket); + keyhash = tbl->hashfunc(key, keylen); + gf_msg_trace(GF_RBTHASH, 0, "HASH: %u", keyhash); + nbucket = (keyhash % tbl->numbuckets); + gf_msg_trace(GF_RBTHASH, 0, "BUCKET: %u", nbucket); - return &tbl->buckets[nbucket]; + return &tbl->buckets[nbucket]; } - void * -rbthash_get (rbthash_table_t *tbl, void *key, int keylen) +rbthash_get(rbthash_table_t *tbl, void *key, int keylen) { - struct rbthash_bucket *bucket = NULL; - rbthash_entry_t *entry = NULL; - rbthash_entry_t searchentry = {0, }; - - if ((!tbl) || (!key)) - return NULL; - - bucket = rbthash_key_bucket (tbl, key, keylen); - if (!bucket) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_GET_BUCKET_FAILED, - "Failed to get bucket"); - return NULL; - } - - searchentry.key = key; - searchentry.keylen = keylen; - LOCK (&bucket->bucketlock); - { - entry = rb_find (bucket->bucket, &searchentry); - } - UNLOCK (&bucket->bucketlock); - - if (!entry) - return NULL; - - return entry->data; + struct rbthash_bucket *bucket = NULL; + rbthash_entry_t *entry = NULL; + rbthash_entry_t searchentry = { + 0, + }; + + if ((!tbl) || (!key)) + return NULL; + + bucket = rbthash_key_bucket(tbl, key, keylen); + if (!bucket) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_GET_BUCKET_FAILED, + "Failed to get bucket"); + return NULL; + } + + searchentry.key = key; + searchentry.keylen = keylen; + LOCK(&bucket->bucketlock); + { + entry = rb_find(bucket->bucket, &searchentry); + } + UNLOCK(&bucket->bucketlock); + + if (!entry) + return NULL; + + return entry->data; } - void * -rbthash_remove (rbthash_table_t *tbl, void *key, int keylen) +rbthash_remove(rbthash_table_t *tbl, void *key, int keylen) { - struct rbthash_bucket *bucket = NULL; - rbthash_entry_t *entry = NULL; - rbthash_entry_t searchentry = {0, }; - void *dataref = NULL; - - if ((!tbl) || (!key)) - return NULL; - - bucket = rbthash_key_bucket (tbl, key, keylen); - if (!bucket) { - gf_msg (GF_RBTHASH, GF_LOG_ERROR, 0, - LG_MSG_RBTHASH_GET_BUCKET_FAILED, - "Failed to get bucket"); - return NULL; - } - - searchentry.key = key; - searchentry.keylen = keylen; - - LOCK (&bucket->bucketlock); - { - entry = rb_delete (bucket->bucket, &searchentry); - } - UNLOCK (&bucket->bucketlock); - - if (!entry) - return NULL; - - GF_FREE (entry->key); - dataref = entry->data; - - LOCK (&tbl->tablelock); - { - list_del_init (&entry->list); - } - UNLOCK (&tbl->tablelock); - - mem_put (entry); - - return dataref; + struct rbthash_bucket *bucket = NULL; + rbthash_entry_t *entry = NULL; + rbthash_entry_t searchentry = { + 0, + }; + void *dataref = NULL; + + if ((!tbl) || (!key)) + return NULL; + + bucket = rbthash_key_bucket(tbl, key, keylen); + if (!bucket) { + gf_msg(GF_RBTHASH, GF_LOG_ERROR, 0, LG_MSG_RBTHASH_GET_BUCKET_FAILED, + "Failed to get bucket"); + return NULL; + } + + searchentry.key = key; + searchentry.keylen = keylen; + + LOCK(&bucket->bucketlock); + { + entry = rb_delete(bucket->bucket, &searchentry); + } + UNLOCK(&bucket->bucketlock); + + if (!entry) + return NULL; + + GF_FREE(entry->key); + dataref = entry->data; + + LOCK(&tbl->tablelock); + { + list_del_init(&entry->list); + } + UNLOCK(&tbl->tablelock); + + mem_put(entry); + + return dataref; } - void -rbthash_entry_deiniter (void *entry, void *rbparam) +rbthash_entry_deiniter(void *entry, void *rbparam) { - if (!entry) - return; + if (!entry) + return; - rbthash_deinit_entry (rbparam, entry); + rbthash_deinit_entry(rbparam, entry); } - void -rbthash_table_destroy_buckets (rbthash_table_t *tbl) +rbthash_table_destroy_buckets(rbthash_table_t *tbl) { - int x = 0; - if (!tbl) - return; + int x = 0; + if (!tbl) + return; - for (;x < tbl->numbuckets; x++) { - LOCK_DESTROY (&tbl->buckets[x].bucketlock); - rb_destroy (tbl->buckets[x].bucket, rbthash_entry_deiniter); - } + for (; x < tbl->numbuckets; x++) { + LOCK_DESTROY(&tbl->buckets[x].bucketlock); + rb_destroy(tbl->buckets[x].bucket, rbthash_entry_deiniter); + } - return; + return; } - void -rbthash_table_destroy (rbthash_table_t *tbl) +rbthash_table_destroy(rbthash_table_t *tbl) { - if (!tbl) - return; + if (!tbl) + return; - rbthash_table_destroy_buckets (tbl); - if (tbl->pool_alloced) - mem_pool_destroy (tbl->entrypool); + rbthash_table_destroy_buckets(tbl); + if (tbl->pool_alloced) + mem_pool_destroy(tbl->entrypool); - GF_FREE (tbl->buckets); - GF_FREE (tbl); + GF_FREE(tbl->buckets); + GF_FREE(tbl); } - void -rbthash_table_traverse (rbthash_table_t *tbl, rbt_traverse_t traverse, - void *mydata) +rbthash_table_traverse(rbthash_table_t *tbl, rbt_traverse_t traverse, + void *mydata) { - rbthash_entry_t *entry = NULL; + rbthash_entry_t *entry = NULL; - if ((tbl == NULL) || (traverse == NULL)) { - goto out; - } + if ((tbl == NULL) || (traverse == NULL)) { + goto out; + } - LOCK (&tbl->tablelock); + LOCK(&tbl->tablelock); + { + list_for_each_entry(entry, &tbl->list, list) { - list_for_each_entry (entry, &tbl->list, list) { - traverse (entry->data, mydata); - } + traverse(entry->data, mydata); } - UNLOCK (&tbl->tablelock); + } + UNLOCK(&tbl->tablelock); out: - return; + return; } diff --git a/libglusterfs/src/refcount.c b/libglusterfs/src/refcount.c index 714bb9afef6..a522d86a677 100644 --- a/libglusterfs/src/refcount.c +++ b/libglusterfs/src/refcount.c @@ -14,96 +14,95 @@ #ifndef REFCOUNT_NEEDS_LOCK void * -_gf_ref_get (gf_ref_t *ref) +_gf_ref_get(gf_ref_t *ref) { - unsigned int cnt = __sync_fetch_and_add (&ref->cnt, 1); - - /* if cnt == 0, we're in a fatal position, the object will be free'd - * - * There is a race when two threads do a _gf_ref_get(). Only one of - * them may get a 0 returned. That is acceptable, because one - * _gf_ref_get() returning 0 should be handled as a fatal problem and - * when correct usage/locking is used, it should never happen. - */ - GF_ASSERT (cnt != 0); - - return cnt ? ref->data : NULL; + unsigned int cnt = __sync_fetch_and_add(&ref->cnt, 1); + + /* if cnt == 0, we're in a fatal position, the object will be free'd + * + * There is a race when two threads do a _gf_ref_get(). Only one of + * them may get a 0 returned. That is acceptable, because one + * _gf_ref_get() returning 0 should be handled as a fatal problem and + * when correct usage/locking is used, it should never happen. + */ + GF_ASSERT(cnt != 0); + + return cnt ? ref->data : NULL; } unsigned int -_gf_ref_put (gf_ref_t *ref) +_gf_ref_put(gf_ref_t *ref) { - unsigned int cnt = __sync_fetch_and_sub (&ref->cnt, 1); + unsigned int cnt = __sync_fetch_and_sub(&ref->cnt, 1); - /* if cnt == 1, the last user just did a _gf_ref_put() - * - * When cnt == 0, one _gf_ref_put() was done too much and there has - * been a thread using the refcounted structure when it was not - * supposed to. - */ - GF_ASSERT (cnt != 0); + /* if cnt == 1, the last user just did a _gf_ref_put() + * + * When cnt == 0, one _gf_ref_put() was done too much and there has + * been a thread using the refcounted structure when it was not + * supposed to. + */ + GF_ASSERT(cnt != 0); - if (cnt == 1 && ref->release) - ref->release (ref->data); + if (cnt == 1 && ref->release) + ref->release(ref->data); - return (cnt != 1); + return (cnt != 1); } #else void * -_gf_ref_get (gf_ref_t *ref) +_gf_ref_get(gf_ref_t *ref) { - unsigned int cnt = 0; - - LOCK (&ref->lk); - { - /* never can be 0, should have been free'd */ - if (ref->cnt > 0) - cnt = ++ref->cnt; - else - GF_ASSERT (ref->cnt > 0); - } - UNLOCK (&ref->lk); - - return cnt ? ref->data : NULL; + unsigned int cnt = 0; + + LOCK(&ref->lk); + { + /* never can be 0, should have been free'd */ + if (ref->cnt > 0) + cnt = ++ref->cnt; + else + GF_ASSERT(ref->cnt > 0); + } + UNLOCK(&ref->lk); + + return cnt ? ref->data : NULL; } unsigned int -_gf_ref_put (gf_ref_t *ref) +_gf_ref_put(gf_ref_t *ref) { - unsigned int cnt = 0; - int release = 0; - - LOCK (&ref->lk); - { - if (ref->cnt != 0) { - cnt = --ref->cnt; - /* call release() only when cnt == 0 */ - release = (cnt == 0); - } else - GF_ASSERT (ref->cnt != 0); - } - UNLOCK (&ref->lk); - - if (release && ref->release) - ref->release (ref->data); - - return !release; + unsigned int cnt = 0; + int release = 0; + + LOCK(&ref->lk); + { + if (ref->cnt != 0) { + cnt = --ref->cnt; + /* call release() only when cnt == 0 */ + release = (cnt == 0); + } else + GF_ASSERT(ref->cnt != 0); + } + UNLOCK(&ref->lk); + + if (release && ref->release) + ref->release(ref->data); + + return !release; } #endif /* REFCOUNT_NEEDS_LOCK */ - void -_gf_ref_init (gf_ref_t *ref, gf_ref_release_t release, void *data) +_gf_ref_init(gf_ref_t *ref, gf_ref_release_t release, void *data) { - GF_ASSERT (ref); + GF_ASSERT(ref); #ifdef REFCOUNT_NEEDS_LOCK - LOCK_INIT (&ref->lk); + LOCK_INIT(&ref->lk); #endif - ref->cnt = 1; - ref->release = release; - ref->data = data; + ref->cnt = 1; + ref->release = release; + ref->data = data; } diff --git a/libglusterfs/src/rot-buffs.c b/libglusterfs/src/rot-buffs.c index cbded2b3f46..c5147321c60 100644 --- a/libglusterfs/src/rot-buffs.c +++ b/libglusterfs/src/rot-buffs.c @@ -26,10 +26,10 @@ * TODO: do away with opaques (use arrays with indexing). */ -#define ROT_BUFF_DEFAULT_COUNT 2 -#define ROT_BUFF_ALLOC_SIZE (1 * 1024 * 1024) /* 1MB per iovec */ +#define ROT_BUFF_DEFAULT_COUNT 2 +#define ROT_BUFF_ALLOC_SIZE (1 * 1024 * 1024) /* 1MB per iovec */ -#define RLIST_IOV_MELDED_ALLOC_SIZE (RBUF_IOVEC_SIZE + ROT_BUFF_ALLOC_SIZE) +#define RLIST_IOV_MELDED_ALLOC_SIZE (RBUF_IOVEC_SIZE + ROT_BUFF_ALLOC_SIZE) /** * iovec list is not shrunk (deallocated) if usage/total count @@ -37,373 +37,369 @@ * most of the workloads. for the rest shrinking iovec list is * generous. */ -#define RVEC_LOW_WATERMARK_COUNT 1 +#define RVEC_LOW_WATERMARK_COUNT 1 #define RVEC_HIGH_WATERMARK_COUNT (1 << 4) -static inline -rbuf_list_t *rbuf_current_buffer (rbuf_t *rbuf) +static inline rbuf_list_t * +rbuf_current_buffer(rbuf_t *rbuf) { - return rbuf->current; + return rbuf->current; } static void -rlist_mark_waiting (rbuf_list_t *rlist) +rlist_mark_waiting(rbuf_list_t *rlist) { - LOCK (&rlist->c_lock); - { - rlist->awaiting = _gf_true; - } - UNLOCK (&rlist->c_lock); + LOCK(&rlist->c_lock); + { + rlist->awaiting = _gf_true; + } + UNLOCK(&rlist->c_lock); } static int -__rlist_has_waiter (rbuf_list_t *rlist) +__rlist_has_waiter(rbuf_list_t *rlist) { - return (rlist->awaiting == _gf_true); + return (rlist->awaiting == _gf_true); } static void * -rbuf_alloc_rvec () +rbuf_alloc_rvec() { - return GF_CALLOC (1, RLIST_IOV_MELDED_ALLOC_SIZE, gf_common_mt_rvec_t); + return GF_CALLOC(1, RLIST_IOV_MELDED_ALLOC_SIZE, gf_common_mt_rvec_t); } static void -rlist_reset_vector_usage (rbuf_list_t *rlist) +rlist_reset_vector_usage(rbuf_list_t *rlist) { - rlist->used = 1; + rlist->used = 1; } static void -rlist_increment_vector_usage (rbuf_list_t *rlist) +rlist_increment_vector_usage(rbuf_list_t *rlist) { - rlist->used++; + rlist->used++; } static void -rlist_increment_total_usage (rbuf_list_t *rlist) +rlist_increment_total_usage(rbuf_list_t *rlist) { - rlist->total++; + rlist->total++; } static int -rvec_in_watermark_range (rbuf_list_t *rlist) +rvec_in_watermark_range(rbuf_list_t *rlist) { - return ((rlist->total >= RVEC_LOW_WATERMARK_COUNT) - && (rlist->total <= RVEC_HIGH_WATERMARK_COUNT)); + return ((rlist->total >= RVEC_LOW_WATERMARK_COUNT) && + (rlist->total <= RVEC_HIGH_WATERMARK_COUNT)); } static void -rbuf_reset_rvec (rbuf_iovec_t *rvec) +rbuf_reset_rvec(rbuf_iovec_t *rvec) { - /* iov_base is _never_ modified */ - rvec->iov.iov_len = 0; + /* iov_base is _never_ modified */ + rvec->iov.iov_len = 0; } /* TODO: alloc multiple rbuf_iovec_t */ static int -rlist_add_new_vec (rbuf_list_t *rlist) +rlist_add_new_vec(rbuf_list_t *rlist) { - rbuf_iovec_t *rvec = NULL; + rbuf_iovec_t *rvec = NULL; - rvec = (rbuf_iovec_t *) rbuf_alloc_rvec (); - if (!rvec) - return -1; - INIT_LIST_HEAD (&rvec->list); - rvec->iov.iov_base = ((char *)rvec) + RBUF_IOVEC_SIZE; - rvec->iov.iov_len = 0; + rvec = (rbuf_iovec_t *)rbuf_alloc_rvec(); + if (!rvec) + return -1; + INIT_LIST_HEAD(&rvec->list); + rvec->iov.iov_base = ((char *)rvec) + RBUF_IOVEC_SIZE; + rvec->iov.iov_len = 0; - list_add_tail (&rvec->list, &rlist->veclist); + list_add_tail(&rvec->list, &rlist->veclist); - rlist->rvec = rvec; /* cache the latest */ + rlist->rvec = rvec; /* cache the latest */ - rlist_increment_vector_usage (rlist); - rlist_increment_total_usage (rlist); + rlist_increment_vector_usage(rlist); + rlist_increment_total_usage(rlist); - return 0; + return 0; } static void -rlist_free_rvec (rbuf_iovec_t *rvec) +rlist_free_rvec(rbuf_iovec_t *rvec) { - if (!rvec) - return; - list_del (&rvec->list); - GF_FREE (rvec); + if (!rvec) + return; + list_del(&rvec->list); + GF_FREE(rvec); } static void -rlist_purge_all_rvec (rbuf_list_t *rlist) +rlist_purge_all_rvec(rbuf_list_t *rlist) { - rbuf_iovec_t *rvec = NULL; - - if (!rlist) - return; - while (!list_empty (&rlist->veclist)) { - rvec = list_first_entry (&rlist->veclist, rbuf_iovec_t, list); - rlist_free_rvec (rvec); - } + rbuf_iovec_t *rvec = NULL; + + if (!rlist) + return; + while (!list_empty(&rlist->veclist)) { + rvec = list_first_entry(&rlist->veclist, rbuf_iovec_t, list); + rlist_free_rvec(rvec); + } } static void -rlist_shrink_rvec (rbuf_list_t *rlist, unsigned long long shrink) +rlist_shrink_rvec(rbuf_list_t *rlist, unsigned long long shrink) { - rbuf_iovec_t *rvec = NULL; + rbuf_iovec_t *rvec = NULL; - while (!list_empty (&rlist->veclist) && (shrink-- > 0)) { - rvec = list_first_entry (&rlist->veclist, rbuf_iovec_t, list); - rlist_free_rvec (rvec); - } + while (!list_empty(&rlist->veclist) && (shrink-- > 0)) { + rvec = list_first_entry(&rlist->veclist, rbuf_iovec_t, list); + rlist_free_rvec(rvec); + } } static void -rbuf_purge_rlist (rbuf_t *rbuf) +rbuf_purge_rlist(rbuf_t *rbuf) { - rbuf_list_t *rlist = NULL; + rbuf_list_t *rlist = NULL; - while (!list_empty (&rbuf->freelist)) { - rlist = list_first_entry (&rbuf->freelist, rbuf_list_t, list); - list_del (&rlist->list); + while (!list_empty(&rbuf->freelist)) { + rlist = list_first_entry(&rbuf->freelist, rbuf_list_t, list); + list_del(&rlist->list); - rlist_purge_all_rvec (rlist); + rlist_purge_all_rvec(rlist); - LOCK_DESTROY (&rlist->c_lock); + LOCK_DESTROY(&rlist->c_lock); - (void) pthread_mutex_destroy (&rlist->b_lock); - (void) pthread_cond_destroy (&rlist->b_cond); + (void)pthread_mutex_destroy(&rlist->b_lock); + (void)pthread_cond_destroy(&rlist->b_cond); - GF_FREE (rlist); - } + GF_FREE(rlist); + } } rbuf_t * -rbuf_init (int bufcount) +rbuf_init(int bufcount) { - int j = 0; - int ret = 0; - rbuf_t *rbuf = NULL; - rbuf_list_t *rlist = NULL; - - if (bufcount <= 0) - bufcount = ROT_BUFF_DEFAULT_COUNT; - - rbuf = GF_CALLOC (1, sizeof (rbuf_t), gf_common_mt_rbuf_t); - if (!rbuf) - goto error_return; - - LOCK_INIT (&rbuf->lock); - INIT_LIST_HEAD (&rbuf->freelist); - - /* it could have been one big calloc() but this is just once.. */ - for (j = 0; j < bufcount; j++) { - rlist = GF_CALLOC (1, - sizeof (rbuf_list_t), gf_common_mt_rlist_t); - if (!rlist) { - ret = -1; - break; - } - - INIT_LIST_HEAD (&rlist->list); - INIT_LIST_HEAD (&rlist->veclist); - - rlist->pending = rlist->completed = 0; - - ret = rlist_add_new_vec (rlist); - if (ret) - break; - - LOCK_INIT (&rlist->c_lock); - - rlist->awaiting = _gf_false; - ret = pthread_mutex_init (&rlist->b_lock, 0); - if (ret != 0) { - GF_FREE (rlist); - break; - } - - ret = pthread_cond_init (&rlist->b_cond, 0); - if (ret != 0) { - GF_FREE (rlist); - break; - } - - list_add_tail (&rlist->list, &rbuf->freelist); + int j = 0; + int ret = 0; + rbuf_t *rbuf = NULL; + rbuf_list_t *rlist = NULL; + + if (bufcount <= 0) + bufcount = ROT_BUFF_DEFAULT_COUNT; + + rbuf = GF_CALLOC(1, sizeof(rbuf_t), gf_common_mt_rbuf_t); + if (!rbuf) + goto error_return; + + LOCK_INIT(&rbuf->lock); + INIT_LIST_HEAD(&rbuf->freelist); + + /* it could have been one big calloc() but this is just once.. */ + for (j = 0; j < bufcount; j++) { + rlist = GF_CALLOC(1, sizeof(rbuf_list_t), gf_common_mt_rlist_t); + if (!rlist) { + ret = -1; + break; } - if (ret != 0) - goto dealloc_rlist; + INIT_LIST_HEAD(&rlist->list); + INIT_LIST_HEAD(&rlist->veclist); - /* cache currently used buffer: first in the list */ - rbuf->current = list_first_entry (&rbuf->freelist, rbuf_list_t, list); - return rbuf; + rlist->pending = rlist->completed = 0; - dealloc_rlist: - rbuf_purge_rlist (rbuf); - LOCK_DESTROY (&rbuf->lock); - GF_FREE (rbuf); - error_return: - return NULL; + ret = rlist_add_new_vec(rlist); + if (ret) + break; + + LOCK_INIT(&rlist->c_lock); + + rlist->awaiting = _gf_false; + ret = pthread_mutex_init(&rlist->b_lock, 0); + if (ret != 0) { + GF_FREE(rlist); + break; + } + + ret = pthread_cond_init(&rlist->b_cond, 0); + if (ret != 0) { + GF_FREE(rlist); + break; + } + + list_add_tail(&rlist->list, &rbuf->freelist); + } + + if (ret != 0) + goto dealloc_rlist; + + /* cache currently used buffer: first in the list */ + rbuf->current = list_first_entry(&rbuf->freelist, rbuf_list_t, list); + return rbuf; + +dealloc_rlist: + rbuf_purge_rlist(rbuf); + LOCK_DESTROY(&rbuf->lock); + GF_FREE(rbuf); +error_return: + return NULL; } void -rbuf_dtor (rbuf_t *rbuf) +rbuf_dtor(rbuf_t *rbuf) { - if (!rbuf) - return; - rbuf->current = NULL; - rbuf_purge_rlist (rbuf); - LOCK_DESTROY (&rbuf->lock); + if (!rbuf) + return; + rbuf->current = NULL; + rbuf_purge_rlist(rbuf); + LOCK_DESTROY(&rbuf->lock); - GF_FREE (rbuf); + GF_FREE(rbuf); } static char * -rbuf_adjust_write_area (struct iovec *iov, size_t bytes) +rbuf_adjust_write_area(struct iovec *iov, size_t bytes) { - char *wbuf = NULL; + char *wbuf = NULL; - wbuf = iov->iov_base + iov->iov_len; - iov->iov_len += bytes; - return wbuf; + wbuf = iov->iov_base + iov->iov_len; + iov->iov_len += bytes; + return wbuf; } static char * -rbuf_alloc_write_area (rbuf_list_t *rlist, size_t bytes) +rbuf_alloc_write_area(rbuf_list_t *rlist, size_t bytes) { - int ret = 0; - struct iovec *iov = NULL; - - /* check for available space in _current_ IO buffer */ - iov = &rlist->rvec->iov; - if (iov->iov_len + bytes <= ROT_BUFF_ALLOC_SIZE) - return rbuf_adjust_write_area (iov, bytes); /* fast path */ - - /* not enough bytes, try next available buffers */ - if (list_is_last (&rlist->rvec->list, &rlist->veclist)) { - /* OH! consumed all vector buffers */ - GF_ASSERT (rlist->used == rlist->total); - ret = rlist_add_new_vec (rlist); - if (ret) - goto error_return; - } else { - /* not the end, have available rbuf_iovec's */ - rlist->rvec = list_next_entry (rlist->rvec, list); - rlist->used++; - rbuf_reset_rvec (rlist->rvec); - } + int ret = 0; + struct iovec *iov = NULL; + + /* check for available space in _current_ IO buffer */ + iov = &rlist->rvec->iov; + if (iov->iov_len + bytes <= ROT_BUFF_ALLOC_SIZE) + return rbuf_adjust_write_area(iov, bytes); /* fast path */ + + /* not enough bytes, try next available buffers */ + if (list_is_last(&rlist->rvec->list, &rlist->veclist)) { + /* OH! consumed all vector buffers */ + GF_ASSERT(rlist->used == rlist->total); + ret = rlist_add_new_vec(rlist); + if (ret) + goto error_return; + } else { + /* not the end, have available rbuf_iovec's */ + rlist->rvec = list_next_entry(rlist->rvec, list); + rlist->used++; + rbuf_reset_rvec(rlist->rvec); + } - iov = &rlist->rvec->iov; - return rbuf_adjust_write_area (iov, bytes); + iov = &rlist->rvec->iov; + return rbuf_adjust_write_area(iov, bytes); - error_return: - return NULL; +error_return: + return NULL; } char * -rbuf_reserve_write_area (rbuf_t *rbuf, size_t bytes, void **opaque) +rbuf_reserve_write_area(rbuf_t *rbuf, size_t bytes, void **opaque) { - char *wbuf = NULL; - rbuf_list_t *rlist = NULL; - - if (!rbuf || (bytes <= 0) || (bytes > ROT_BUFF_ALLOC_SIZE) || !opaque) - return NULL; - - LOCK (&rbuf->lock); - { - rlist = rbuf_current_buffer (rbuf); - wbuf = rbuf_alloc_write_area (rlist, bytes); - if (!wbuf) - goto unblock; - rlist->pending++; - } - unblock: - UNLOCK (&rbuf->lock); + char *wbuf = NULL; + rbuf_list_t *rlist = NULL; + + if (!rbuf || (bytes <= 0) || (bytes > ROT_BUFF_ALLOC_SIZE) || !opaque) + return NULL; - if (wbuf) - *opaque = rlist; - return wbuf; + LOCK(&rbuf->lock); + { + rlist = rbuf_current_buffer(rbuf); + wbuf = rbuf_alloc_write_area(rlist, bytes); + if (!wbuf) + goto unblock; + rlist->pending++; + } +unblock: + UNLOCK(&rbuf->lock); + + if (wbuf) + *opaque = rlist; + return wbuf; } static void -rbuf_notify_waiter (rbuf_list_t *rlist) +rbuf_notify_waiter(rbuf_list_t *rlist) { - pthread_mutex_lock (&rlist->b_lock); - { - pthread_cond_signal (&rlist->b_cond); - } - pthread_mutex_unlock (&rlist->b_lock); + pthread_mutex_lock(&rlist->b_lock); + { + pthread_cond_signal(&rlist->b_cond); + } + pthread_mutex_unlock(&rlist->b_lock); } int -rbuf_write_complete (void *opaque) +rbuf_write_complete(void *opaque) { - rbuf_list_t *rlist = NULL; - gf_boolean_t notify = _gf_false; - - if (!opaque) - return -1; - - rlist = opaque; - - LOCK (&rlist->c_lock); - { - rlist->completed++; - /** - * it's safe to test ->pending without rbuf->lock *only* if - * there's a waiter as there can be no new incoming writes. - */ - if (__rlist_has_waiter (rlist) - && (rlist->completed == rlist->pending)) - notify = _gf_true; - } - UNLOCK (&rlist->c_lock); + rbuf_list_t *rlist = NULL; + gf_boolean_t notify = _gf_false; + + if (!opaque) + return -1; + + rlist = opaque; + + LOCK(&rlist->c_lock); + { + rlist->completed++; + /** + * it's safe to test ->pending without rbuf->lock *only* if + * there's a waiter as there can be no new incoming writes. + */ + if (__rlist_has_waiter(rlist) && (rlist->completed == rlist->pending)) + notify = _gf_true; + } + UNLOCK(&rlist->c_lock); - if (notify) - rbuf_notify_waiter (rlist); + if (notify) + rbuf_notify_waiter(rlist); - return 0; + return 0; } int -rbuf_get_buffer (rbuf_t *rbuf, - void **opaque, sequence_fn *seqfn, void *mydata) +rbuf_get_buffer(rbuf_t *rbuf, void **opaque, sequence_fn *seqfn, void *mydata) { - int retval = RBUF_CONSUMABLE; - rbuf_list_t *rlist = NULL; - - if (!rbuf || !opaque) - return -1; - - LOCK (&rbuf->lock); - { - rlist = rbuf_current_buffer (rbuf); - if (!rlist->pending) { - retval = RBUF_EMPTY; - goto unblock; - } - - if (list_is_singular (&rbuf->freelist)) { - /** - * removal would lead to writer starvation, disallow - * switching. - */ - retval = RBUF_WOULD_STARVE; - goto unblock; - } - - list_del_init (&rlist->list); - if (seqfn) - seqfn (rlist, mydata); - rbuf->current = - list_first_entry (&rbuf->freelist, rbuf_list_t, list); + int retval = RBUF_CONSUMABLE; + rbuf_list_t *rlist = NULL; + + if (!rbuf || !opaque) + return -1; + + LOCK(&rbuf->lock); + { + rlist = rbuf_current_buffer(rbuf); + if (!rlist->pending) { + retval = RBUF_EMPTY; + goto unblock; + } + + if (list_is_singular(&rbuf->freelist)) { + /** + * removal would lead to writer starvation, disallow + * switching. + */ + retval = RBUF_WOULD_STARVE; + goto unblock; } - unblock: - UNLOCK (&rbuf->lock); - if (retval == RBUF_CONSUMABLE) - *opaque = rlist; /* caller _owns_ the buffer */ + list_del_init(&rlist->list); + if (seqfn) + seqfn(rlist, mydata); + rbuf->current = list_first_entry(&rbuf->freelist, rbuf_list_t, list); + } +unblock: + UNLOCK(&rbuf->lock); - return retval; + if (retval == RBUF_CONSUMABLE) + *opaque = rlist; /* caller _owns_ the buffer */ + + return retval; } /** @@ -412,10 +408,10 @@ rbuf_get_buffer (rbuf_t *rbuf, */ static void -__rbuf_wait_for_writers (rbuf_list_t *rlist) +__rbuf_wait_for_writers(rbuf_list_t *rlist) { - while (rlist->completed != rlist->pending) - pthread_cond_wait (&rlist->b_cond, &rlist->b_lock); + while (rlist->completed != rlist->pending) + pthread_cond_wait(&rlist->b_cond, &rlist->b_lock); } #ifndef M_E @@ -423,69 +419,69 @@ __rbuf_wait_for_writers (rbuf_list_t *rlist) #endif static void -rlist_shrink_vector (rbuf_list_t *rlist) +rlist_shrink_vector(rbuf_list_t *rlist) { - unsigned long long shrink = 0; - - /** - * fast path: don't bother to deallocate if vectors are hardly - * used. - */ - if (rvec_in_watermark_range (rlist)) - return; - - /** - * Calculate the shrink count based on total allocated vectors. - * Note that the calculation sticks to rlist->total irrespective - * of the actual usage count (rlist->used). Later, ->used could - * be used to apply slack to the calculation based on how much - * it lags from ->total. For now, let's stick to slow decay. - */ - shrink = rlist->total - (rlist->total * pow (M_E, -0.2)); - - rlist_shrink_rvec (rlist, shrink); - rlist->total -= shrink; + unsigned long long shrink = 0; + + /** + * fast path: don't bother to deallocate if vectors are hardly + * used. + */ + if (rvec_in_watermark_range(rlist)) + return; + + /** + * Calculate the shrink count based on total allocated vectors. + * Note that the calculation sticks to rlist->total irrespective + * of the actual usage count (rlist->used). Later, ->used could + * be used to apply slack to the calculation based on how much + * it lags from ->total. For now, let's stick to slow decay. + */ + shrink = rlist->total - (rlist->total * pow(M_E, -0.2)); + + rlist_shrink_rvec(rlist, shrink); + rlist->total -= shrink; } int -rbuf_wait_for_completion (rbuf_t *rbuf, void *opaque, - void (*fn)(rbuf_list_t *, void *), void *arg) +rbuf_wait_for_completion(rbuf_t *rbuf, void *opaque, + void (*fn)(rbuf_list_t *, void *), void *arg) { - rbuf_list_t *rlist = NULL; + rbuf_list_t *rlist = NULL; - if (!rbuf || !opaque) - return -1; + if (!rbuf || !opaque) + return -1; - rlist = opaque; + rlist = opaque; - pthread_mutex_lock (&rlist->b_lock); - { - rlist_mark_waiting (rlist); - __rbuf_wait_for_writers (rlist); - } - pthread_mutex_unlock (&rlist->b_lock); + pthread_mutex_lock(&rlist->b_lock); + { + rlist_mark_waiting(rlist); + __rbuf_wait_for_writers(rlist); + } + pthread_mutex_unlock(&rlist->b_lock); - /** - * from here on, no need of locking until the rlist is put - * back into rotation. - */ + /** + * from here on, no need of locking until the rlist is put + * back into rotation. + */ - fn (rlist, arg); /* invoke dispatcher */ + fn(rlist, arg); /* invoke dispatcher */ - rlist->awaiting = _gf_false; - rlist->pending = rlist->completed = 0; + rlist->awaiting = _gf_false; + rlist->pending = rlist->completed = 0; - rlist_shrink_vector (rlist); - rlist_reset_vector_usage (rlist); + rlist_shrink_vector(rlist); + rlist_reset_vector_usage(rlist); - rlist->rvec = list_first_entry (&rlist->veclist, rbuf_iovec_t, list); - rbuf_reset_rvec (rlist->rvec); + rlist->rvec = list_first_entry(&rlist->veclist, rbuf_iovec_t, list); + rbuf_reset_rvec(rlist->rvec); - LOCK (&rbuf->lock); - { - list_add_tail (&rlist->list, &rbuf->freelist); - } - UNLOCK (&rbuf->lock); + LOCK(&rbuf->lock); + { + list_add_tail(&rlist->list, &rbuf->freelist); + } + UNLOCK(&rbuf->lock); - return 0; + return 0; } diff --git a/libglusterfs/src/run.c b/libglusterfs/src/run.c index c501bab9685..41275066b20 100644 --- a/libglusterfs/src/run.c +++ b/libglusterfs/src/run.c @@ -42,8 +42,9 @@ * * $ cc -DRUN_DO_DEMO -DRUN_STANDALONE -orun run.c */ -#if defined(RUN_STANDALONE ) || defined(RUN_DO_DEMO) -int close_fds_except (int *fdv, size_t count); +#if defined(RUN_STANDALONE) || defined(RUN_DO_DEMO) +int +close_fds_except(int *fdv, size_t count); #define sys_read(f, b, c) read(f, b, c) #define sys_write(f, b, c) write(f, b, c) #define sys_close(f) close(f) @@ -54,36 +55,37 @@ int close_fds_except (int *fdv, size_t count); #define gf_strdup(s) strdup(s) #define gf_vasprintf(p, f, va) vasprintf(p, f, va) #define gf_loglevel_t int -#define gf_msg_callingfn(dom, level, errnum, msgid, fmt, args...) printf("LOG: " fmt "\n", ##args) +#define gf_msg_callingfn(dom, level, errnum, msgid, fmt, args...) \ + printf("LOG: " fmt "\n", ##args) #define LOG_DEBUG 0 #ifdef RUN_STANDALONE #include <stdbool.h> #include <sys/resource.h> int -close_fds_except (int *fdv, size_t count) +close_fds_except(int *fdv, size_t count) { - int i = 0; - size_t j = 0; - bool should_close = true; - struct rlimit rl; - int ret = -1; - - ret = getrlimit (RLIMIT_NOFILE, &rl); - if (ret) - return ret; - - for (i = 0; i < rl.rlim_cur; i++) { - should_close = true; - for (j = 0; j < count; j++) { - if (i == fdv[j]) { - should_close = false; - break; - } - } - if (should_close) - sys_close (i); + int i = 0; + size_t j = 0; + bool should_close = true; + struct rlimit rl; + int ret = -1; + + ret = getrlimit(RLIMIT_NOFILE, &rl); + if (ret) + return ret; + + for (i = 0; i < rl.rlim_cur; i++) { + should_close = true; + for (j = 0; j < count; j++) { + if (i == fdv[j]) { + should_close = false; + break; + } } - return 0; + if (should_close) + sys_close(i); + } + return 0; } #endif #ifdef __linux__ @@ -97,470 +99,472 @@ close_fds_except (int *fdv, size_t count) #include "run.h" void -runinit (runner_t *runner) +runinit(runner_t *runner) { - int i = 0; - - runner->argvlen = 64; - runner->argv = GF_CALLOC (runner->argvlen, - sizeof (*runner->argv), - gf_common_mt_run_argv); - runner->runerr = runner->argv ? 0 : errno; - runner->chpid = -1; - for (i = 0; i < 3; i++) { - runner->chfd[i] = -1; - runner->chio[i] = NULL; - } + int i = 0; + + runner->argvlen = 64; + runner->argv = GF_CALLOC(runner->argvlen, sizeof(*runner->argv), + gf_common_mt_run_argv); + runner->runerr = runner->argv ? 0 : errno; + runner->chpid = -1; + for (i = 0; i < 3; i++) { + runner->chfd[i] = -1; + runner->chio[i] = NULL; + } } FILE * -runner_chio (runner_t *runner, int fd) +runner_chio(runner_t *runner, int fd) { - GF_ASSERT (fd > 0 && fd < 3); + GF_ASSERT(fd > 0 && fd < 3); - if ((fd > 0) && (fd < 3)) - return runner->chio[fd]; + if ((fd > 0) && (fd < 3)) + return runner->chio[fd]; - return NULL; + return NULL; } static void -runner_insert_arg (runner_t *runner, char *arg) +runner_insert_arg(runner_t *runner, char *arg) { - int i = 0; + int i = 0; - GF_ASSERT (arg); + GF_ASSERT(arg); - if (runner->runerr) - return; + if (runner->runerr) + return; - for (i = 0; i < runner->argvlen; i++) { - if (runner->argv[i] == NULL) - break; - } - GF_ASSERT (i < runner->argvlen); - - if (i == runner->argvlen - 1) { - runner->argv = GF_REALLOC (runner->argv, - runner->argvlen * 2 * sizeof (*runner->argv)); - if (!runner->argv) { - runner->runerr = errno; - return; - } - memset (/* "+" is aware of the type of its left side, - * no need to multiply with type-size */ - runner->argv + runner->argvlen, - 0, runner->argvlen * sizeof (*runner->argv)); - runner->argvlen *= 2; - } + for (i = 0; i < runner->argvlen; i++) { + if (runner->argv[i] == NULL) + break; + } + GF_ASSERT(i < runner->argvlen); - runner->argv[i] = arg; + if (i == runner->argvlen - 1) { + runner->argv = GF_REALLOC(runner->argv, + runner->argvlen * 2 * sizeof(*runner->argv)); + if (!runner->argv) { + runner->runerr = errno; + return; + } + memset(/* "+" is aware of the type of its left side, + * no need to multiply with type-size */ + runner->argv + runner->argvlen, 0, + runner->argvlen * sizeof(*runner->argv)); + runner->argvlen *= 2; + } + + runner->argv[i] = arg; } void -runner_add_arg (runner_t *runner, const char *arg) +runner_add_arg(runner_t *runner, const char *arg) { - arg = gf_strdup (arg); - if (!arg) { - runner->runerr = errno; - return; - } + arg = gf_strdup(arg); + if (!arg) { + runner->runerr = errno; + return; + } - runner_insert_arg (runner, (char *)arg); + runner_insert_arg(runner, (char *)arg); } static void -runner_va_add_args (runner_t *runner, va_list argp) +runner_va_add_args(runner_t *runner, va_list argp) { - const char *arg; + const char *arg; - while ((arg = va_arg (argp, const char *))) - runner_add_arg (runner, arg); + while ((arg = va_arg(argp, const char *))) + runner_add_arg(runner, arg); } void -runner_add_args (runner_t *runner, ...) +runner_add_args(runner_t *runner, ...) { - va_list argp; + va_list argp; - va_start (argp, runner); - runner_va_add_args (runner, argp); - va_end (argp); + va_start(argp, runner); + runner_va_add_args(runner, argp); + va_end(argp); } void -runner_argprintf (runner_t *runner, const char *format, ...) +runner_argprintf(runner_t *runner, const char *format, ...) { - va_list argva; - char *arg = NULL; - int ret = 0; + va_list argva; + char *arg = NULL; + int ret = 0; - va_start (argva, format); - ret = gf_vasprintf (&arg, format, argva); - va_end (argva); + va_start(argva, format); + ret = gf_vasprintf(&arg, format, argva); + va_end(argva); - if (ret < 0) { - runner->runerr = errno; - return; - } + if (ret < 0) { + runner->runerr = errno; + return; + } - runner_insert_arg (runner, arg); + runner_insert_arg(runner, arg); } void -runner_log (runner_t *runner, const char *dom, gf_loglevel_t lvl, - const char *msg) +runner_log(runner_t *runner, const char *dom, gf_loglevel_t lvl, + const char *msg) { - char *buf = NULL; - size_t len = 0; - int i = 0; - - if (runner->runerr) - return; - - for (i = 0;; i++) { - if (runner->argv[i] == NULL) - break; - len += (strlen (runner->argv[i]) + 1); - } - - buf = GF_CALLOC (1, len + 1, gf_common_mt_run_logbuf); - if (!buf) { - runner->runerr = errno; - return; - } - for (i = 0;; i++) { - if (runner->argv[i] == NULL) - break; - strcat (buf, runner->argv[i]); - strcat (buf, " "); - } - if (len > 0) - buf[len - 1] = '\0'; - - gf_msg_callingfn (dom, lvl, 0, LG_MSG_RUNNER_LOG, "%s: %s", msg, buf); - - GF_FREE (buf); + char *buf = NULL; + size_t len = 0; + int i = 0; + + if (runner->runerr) + return; + + for (i = 0;; i++) { + if (runner->argv[i] == NULL) + break; + len += (strlen(runner->argv[i]) + 1); + } + + buf = GF_CALLOC(1, len + 1, gf_common_mt_run_logbuf); + if (!buf) { + runner->runerr = errno; + return; + } + for (i = 0;; i++) { + if (runner->argv[i] == NULL) + break; + strcat(buf, runner->argv[i]); + strcat(buf, " "); + } + if (len > 0) + buf[len - 1] = '\0'; + + gf_msg_callingfn(dom, lvl, 0, LG_MSG_RUNNER_LOG, "%s: %s", msg, buf); + + GF_FREE(buf); } void -runner_redir (runner_t *runner, int fd, int tgt_fd) +runner_redir(runner_t *runner, int fd, int tgt_fd) { - GF_ASSERT (fd > 0 && fd < 3); + GF_ASSERT(fd > 0 && fd < 3); - if ((fd > 0) && (fd < 3)) - runner->chfd[fd] = (tgt_fd >= 0) ? tgt_fd : -2; + if ((fd > 0) && (fd < 3)) + runner->chfd[fd] = (tgt_fd >= 0) ? tgt_fd : -2; } int -runner_start (runner_t *runner) +runner_start(runner_t *runner) { - int pi[3][2] = {{-1, -1}, {-1, -1}, {-1, -1}}; - int xpi[2]; - int ret = 0; - int errno_priv = 0; - int i = 0; - sigset_t set; - - if (runner->runerr) { - errno = runner->runerr; - return -1; - } - - GF_ASSERT (runner->argv[0]); - - /* set up a channel to child to communicate back - * possible execve(2) failures - */ - ret = pipe(xpi); - if (ret != -1) - ret = fcntl (xpi[1], F_SETFD, FD_CLOEXEC); - - for (i = 0; i < 3; i++) { - if (runner->chfd[i] != -2) - continue; - ret = pipe (pi[i]); - if (ret != -1) { - runner->chio[i] = fdopen (pi[i][i ? 0 : 1], i ? "r" : "w"); - if (!runner->chio[i]) - ret = -1; - } + int pi[3][2] = {{-1, -1}, {-1, -1}, {-1, -1}}; + int xpi[2]; + int ret = 0; + int errno_priv = 0; + int i = 0; + sigset_t set; + + if (runner->runerr) { + errno = runner->runerr; + return -1; + } + + GF_ASSERT(runner->argv[0]); + + /* set up a channel to child to communicate back + * possible execve(2) failures + */ + ret = pipe(xpi); + if (ret != -1) + ret = fcntl(xpi[1], F_SETFD, FD_CLOEXEC); + + for (i = 0; i < 3; i++) { + if (runner->chfd[i] != -2) + continue; + ret = pipe(pi[i]); + if (ret != -1) { + runner->chio[i] = fdopen(pi[i][i ? 0 : 1], i ? "r" : "w"); + if (!runner->chio[i]) + ret = -1; } + } - if (ret != -1) - runner->chpid = fork (); - switch (runner->chpid) { + if (ret != -1) + runner->chpid = fork(); + switch (runner->chpid) { case -1: - errno_priv = errno; - sys_close (xpi[0]); - sys_close (xpi[1]); - for (i = 0; i < 3; i++) { - sys_close (pi[i][0]); - sys_close (pi[i][1]); - } - errno = errno_priv; - return -1; + errno_priv = errno; + sys_close(xpi[0]); + sys_close(xpi[1]); + for (i = 0; i < 3; i++) { + sys_close(pi[i][0]); + sys_close(pi[i][1]); + } + errno = errno_priv; + return -1; case 0: - for (i = 0; i < 3; i++) - sys_close (pi[i][i ? 0 : 1]); - sys_close (xpi[0]); - ret = 0; - - for (i = 0; i < 3; i++) { - if (ret == -1) - break; - switch (runner->chfd[i]) { - case -1: - /* no redir */ - break; - case -2: - /* redir to pipe */ - ret = dup2 (pi[i][i ? 1 : 0], i); - break; - default: - /* redir to file */ - ret = dup2 (runner->chfd[i], i); - } - } - - if (ret != -1 ) { - int fdv[4] = {0, 1, 2, xpi[1]}; - - ret = close_fds_except(fdv, sizeof (fdv) / sizeof (*fdv)); - } - - if (ret != -1) { - /* save child from inheriting our signal handling */ - sigemptyset (&set); - sigprocmask (SIG_SETMASK, &set, NULL); - - execvp (runner->argv[0], runner->argv); - } - ret = sys_write (xpi[1], &errno, sizeof (errno)); - _exit (1); - } - - errno_priv = errno; - for (i = 0; i < 3; i++) - sys_close (pi[i][i ? 1 : 0]); - sys_close (xpi[1]); - if (ret == -1) { - for (i = 0; i < 3; i++) { - if (runner->chio[i]) { - fclose (runner->chio[i]); - runner->chio[i] = NULL; - } + for (i = 0; i < 3; i++) + sys_close(pi[i][i ? 0 : 1]); + sys_close(xpi[0]); + ret = 0; + + for (i = 0; i < 3; i++) { + if (ret == -1) + break; + switch (runner->chfd[i]) { + case -1: + /* no redir */ + break; + case -2: + /* redir to pipe */ + ret = dup2(pi[i][i ? 1 : 0], i); + break; + default: + /* redir to file */ + ret = dup2(runner->chfd[i], i); } - } else { - ret = sys_read (xpi[0], (char *)&errno_priv, sizeof (errno_priv)); - sys_close (xpi[0]); - if (ret <= 0) - return 0; - GF_ASSERT (ret == sizeof (errno_priv)); + } + + if (ret != -1) { + int fdv[4] = {0, 1, 2, xpi[1]}; + + ret = close_fds_except(fdv, sizeof(fdv) / sizeof(*fdv)); + } + + if (ret != -1) { + /* save child from inheriting our signal handling */ + sigemptyset(&set); + sigprocmask(SIG_SETMASK, &set, NULL); + + execvp(runner->argv[0], runner->argv); + } + ret = sys_write(xpi[1], &errno, sizeof(errno)); + _exit(1); + } + + errno_priv = errno; + for (i = 0; i < 3; i++) + sys_close(pi[i][i ? 1 : 0]); + sys_close(xpi[1]); + if (ret == -1) { + for (i = 0; i < 3; i++) { + if (runner->chio[i]) { + fclose(runner->chio[i]); + runner->chio[i] = NULL; + } } - errno = errno_priv; - return -1; + } else { + ret = sys_read(xpi[0], (char *)&errno_priv, sizeof(errno_priv)); + sys_close(xpi[0]); + if (ret <= 0) + return 0; + GF_ASSERT(ret == sizeof(errno_priv)); + } + errno = errno_priv; + return -1; } int -runner_end_reuse (runner_t *runner) +runner_end_reuse(runner_t *runner) { - int i = 0; - int ret = 1; - int chstat = 0; - - if (runner->chpid > 0) { - if (waitpid (runner->chpid, &chstat, 0) == runner->chpid) { - if (WIFEXITED(chstat)) { - ret = WEXITSTATUS(chstat); - } else { - ret = chstat; - } - } + int i = 0; + int ret = 1; + int chstat = 0; + + if (runner->chpid > 0) { + if (waitpid(runner->chpid, &chstat, 0) == runner->chpid) { + if (WIFEXITED(chstat)) { + ret = WEXITSTATUS(chstat); + } else { + ret = chstat; + } } + } - for (i = 0; i < 3; i++) { - if (runner->chio[i]) { - fclose (runner->chio[i]); - runner->chio[i] = NULL; - } + for (i = 0; i < 3; i++) { + if (runner->chio[i]) { + fclose(runner->chio[i]); + runner->chio[i] = NULL; } + } - return -ret; + return -ret; } int -runner_end (runner_t *runner) +runner_end(runner_t *runner) { - int i = 0; - int ret = -1; - char **p = NULL; + int i = 0; + int ret = -1; + char **p = NULL; - ret = runner_end_reuse (runner); + ret = runner_end_reuse(runner); - if (runner->argv) { - for (p = runner->argv; *p; p++) - GF_FREE (*p); - GF_FREE (runner->argv); - } - for (i = 0; i < 3; i++) - sys_close (runner->chfd[i]); + if (runner->argv) { + for (p = runner->argv; *p; p++) + GF_FREE(*p); + GF_FREE(runner->argv); + } + for (i = 0; i < 3; i++) + sys_close(runner->chfd[i]); - return ret; + return ret; } static int -runner_run_generic (runner_t *runner, int (*rfin)(runner_t *runner)) +runner_run_generic(runner_t *runner, int (*rfin)(runner_t *runner)) { - int ret = 0; + int ret = 0; - ret = runner_start (runner); - if (ret) - goto out; - ret = rfin (runner); + ret = runner_start(runner); + if (ret) + goto out; + ret = rfin(runner); out: - return ret; + return ret; } int -runner_run (runner_t *runner) +runner_run(runner_t *runner) { - return runner_run_generic (runner, runner_end); + return runner_run_generic(runner, runner_end); } - int -runner_run_nowait (runner_t *runner) +runner_run_nowait(runner_t *runner) { - int pid; + int pid; - pid = fork (); + pid = fork(); - if (!pid) { - setsid (); - _exit (runner_start (runner)); - } + if (!pid) { + setsid(); + _exit(runner_start(runner)); + } - if (pid > 0) - runner->chpid = pid; - return runner_end (runner); + if (pid > 0) + runner->chpid = pid; + return runner_end(runner); } - int -runner_run_reuse (runner_t *runner) +runner_run_reuse(runner_t *runner) { - return runner_run_generic (runner, runner_end_reuse); + return runner_run_generic(runner, runner_end_reuse); } int -runcmd (const char *arg, ...) +runcmd(const char *arg, ...) { - runner_t runner; - va_list argp; + runner_t runner; + va_list argp; - runinit (&runner); - /* ISO C requires a named argument before '...' */ - runner_add_arg (&runner, arg); + runinit(&runner); + /* ISO C requires a named argument before '...' */ + runner_add_arg(&runner, arg); - va_start (argp, arg); - runner_va_add_args (&runner, argp); - va_end (argp); + va_start(argp, arg); + runner_va_add_args(&runner, argp); + va_end(argp); - return runner_run (&runner); + return runner_run(&runner); } #ifdef RUN_DO_DEMO static void -TBANNER (const char *txt) +TBANNER(const char *txt) { - printf("######\n### demoing %s\n", txt); + printf("######\n### demoing %s\n", txt); } int -main (int argc, char **argv) +main(int argc, char **argv) { - runner_t runner; - char buf[80]; - char *wdbuf;; - int ret; - int fd; - long pathmax = pathconf ("/", _PC_PATH_MAX); - struct timeval tv = {0,}; - struct timeval *tvp = NULL; - char *tfile; - - wdbuf = malloc (pathmax); - assert (wdbuf); - getcwd (wdbuf, pathmax); - - TBANNER ("basic functionality: running \"echo a b\""); - runcmd ("echo", "a", "b", NULL); - - TBANNER ("argv extension: running \"echo 1 2 ... 100\""); - runcmd ("echo", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", - "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", - "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", - "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", - "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", - "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", - "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", - "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", - "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", NULL); - - TBANNER ("add_args, argprintf, log, and popen-style functionality:\n" - " running a multiline echo command, emit a log about it,\n" - " redirect it to a pipe, read output lines\n" - " and print them prefixed with \"got: \""); - runinit (&runner); - runner_add_args (&runner, "echo", "pid:", NULL); - runner_argprintf (&runner, "%d\n", getpid()); - runner_add_arg (&runner, "wd:"); - runner_add_arg (&runner, wdbuf); - runner_redir (&runner, 1, RUN_PIPE); - runner_start (&runner); - runner_log (&runner, "(x)", LOG_DEBUG, "starting program"); - while (fgets (buf, sizeof(buf), runner_chio (&runner, 1))) - printf ("got: %s", buf); - runner_end (&runner); - - TBANNER ("execve error reporting: running a non-existent command"); - ret = runcmd ("bafflavvitty", NULL); - printf ("%d %d [%s]\n", ret, errno, strerror (errno)); - - TBANNER ("output redirection: running \"echo foo\" redirected " - "to a temp file"); - tfile = strdup ("/tmp/foofXXXXXX"); - assert (tfile); - fd = mkstemp (tfile); - assert (fd != -1); - printf ("redirecting to %s\n", tfile); - runinit (&runner); - runner_add_args (&runner, "echo", "foo", NULL); - runner_redir (&runner, 1, fd); - ret = runner_run (&runner); - printf ("runner_run returned: %d", ret); - if (ret != 0) - printf (", with errno %d [%s]", errno, strerror (errno)); - putchar ('\n'); - - /* sleep for seconds given as argument (0 means forever) - * to allow investigation of post-execution state to - * cbeck for resource leaks (eg. zombies). - */ - if (argc > 1) { - tv.tv_sec = strtoul (argv[1], NULL, 10); - printf ("### %s", "sleeping for"); - if (tv.tv_sec > 0) { - printf (" %d seconds\n", tv.tv_sec); - tvp = &tv; - } else - printf ("%s\n", "ever"); - select (0, 0, 0, 0, tvp); - } - - return 0; + runner_t runner; + char buf[80]; + char *wdbuf; + ; + int ret; + int fd; + long pathmax = pathconf("/", _PC_PATH_MAX); + struct timeval tv = { + 0, + }; + struct timeval *tvp = NULL; + char *tfile; + + wdbuf = malloc(pathmax); + assert(wdbuf); + getcwd(wdbuf, pathmax); + + TBANNER("basic functionality: running \"echo a b\""); + runcmd("echo", "a", "b", NULL); + + TBANNER("argv extension: running \"echo 1 2 ... 100\""); + runcmd("echo", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", + "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", + "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", + "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", + "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", + "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", + "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", + "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", + "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", + "100", NULL); + + TBANNER( + "add_args, argprintf, log, and popen-style functionality:\n" + " running a multiline echo command, emit a log about it,\n" + " redirect it to a pipe, read output lines\n" + " and print them prefixed with \"got: \""); + runinit(&runner); + runner_add_args(&runner, "echo", "pid:", NULL); + runner_argprintf(&runner, "%d\n", getpid()); + runner_add_arg(&runner, "wd:"); + runner_add_arg(&runner, wdbuf); + runner_redir(&runner, 1, RUN_PIPE); + runner_start(&runner); + runner_log(&runner, "(x)", LOG_DEBUG, "starting program"); + while (fgets(buf, sizeof(buf), runner_chio(&runner, 1))) + printf("got: %s", buf); + runner_end(&runner); + + TBANNER("execve error reporting: running a non-existent command"); + ret = runcmd("bafflavvitty", NULL); + printf("%d %d [%s]\n", ret, errno, strerror(errno)); + + TBANNER( + "output redirection: running \"echo foo\" redirected " + "to a temp file"); + tfile = strdup("/tmp/foofXXXXXX"); + assert(tfile); + fd = mkstemp(tfile); + assert(fd != -1); + printf("redirecting to %s\n", tfile); + runinit(&runner); + runner_add_args(&runner, "echo", "foo", NULL); + runner_redir(&runner, 1, fd); + ret = runner_run(&runner); + printf("runner_run returned: %d", ret); + if (ret != 0) + printf(", with errno %d [%s]", errno, strerror(errno)); + putchar('\n'); + + /* sleep for seconds given as argument (0 means forever) + * to allow investigation of post-execution state to + * cbeck for resource leaks (eg. zombies). + */ + if (argc > 1) { + tv.tv_sec = strtoul(argv[1], NULL, 10); + printf("### %s", "sleeping for"); + if (tv.tv_sec > 0) { + printf(" %d seconds\n", tv.tv_sec); + tvp = &tv; + } else + printf("%s\n", "ever"); + select(0, 0, 0, 0, tvp); + } + + return 0; } #endif diff --git a/libglusterfs/src/stack.c b/libglusterfs/src/stack.c index 037f565aba3..7196c18418e 100644 --- a/libglusterfs/src/stack.c +++ b/libglusterfs/src/stack.c @@ -13,433 +13,433 @@ #include "libglusterfs-messages.h" call_frame_t * -create_frame (xlator_t *xl, call_pool_t *pool) +create_frame(xlator_t *xl, call_pool_t *pool) { - call_stack_t *stack = NULL; - call_frame_t *frame = NULL; - - if (!xl || !pool) { - return NULL; - } - - stack = mem_get0 (pool->stack_mem_pool); - if (!stack) - return NULL; - - INIT_LIST_HEAD (&stack->myframes); - - frame = mem_get0 (pool->frame_mem_pool); - if (!frame) { - mem_put (stack); - return NULL; - } - - frame->root = stack; - frame->this = xl; - LOCK_INIT (&frame->lock); - INIT_LIST_HEAD (&frame->frames); - list_add (&frame->frames, &stack->myframes); - - stack->pool = pool; - stack->ctx = xl->ctx; - - if (frame->root->ctx->measure_latency) { - timespec_now (&stack->tv); - memcpy (&frame->begin, &stack->tv, - sizeof (stack->tv)); - } - - LOCK (&pool->lock); - { - list_add (&stack->all_frames, &pool->all_frames); - pool->cnt++; - } - UNLOCK (&pool->lock); - GF_ATOMIC_INC (pool->total_count); - - LOCK_INIT (&stack->stack_lock); - - return frame; + call_stack_t *stack = NULL; + call_frame_t *frame = NULL; + + if (!xl || !pool) { + return NULL; + } + + stack = mem_get0(pool->stack_mem_pool); + if (!stack) + return NULL; + + INIT_LIST_HEAD(&stack->myframes); + + frame = mem_get0(pool->frame_mem_pool); + if (!frame) { + mem_put(stack); + return NULL; + } + + frame->root = stack; + frame->this = xl; + LOCK_INIT(&frame->lock); + INIT_LIST_HEAD(&frame->frames); + list_add(&frame->frames, &stack->myframes); + + stack->pool = pool; + stack->ctx = xl->ctx; + + if (frame->root->ctx->measure_latency) { + timespec_now(&stack->tv); + memcpy(&frame->begin, &stack->tv, sizeof(stack->tv)); + } + + LOCK(&pool->lock); + { + list_add(&stack->all_frames, &pool->all_frames); + pool->cnt++; + } + UNLOCK(&pool->lock); + GF_ATOMIC_INC(pool->total_count); + + LOCK_INIT(&stack->stack_lock); + + return frame; } void -call_stack_set_groups (call_stack_t *stack, int ngrps, gid_t **groupbuf_p) +call_stack_set_groups(call_stack_t *stack, int ngrps, gid_t **groupbuf_p) { - /* We take the ownership of the passed group buffer. */ - - if (ngrps <= SMALL_GROUP_COUNT) { - memcpy (stack->groups_small, *groupbuf_p, - sizeof (gid_t) * ngrps); - stack->groups = stack->groups_small; - GF_FREE (*groupbuf_p); - } else { - stack->groups_large = *groupbuf_p; - stack->groups = stack->groups_large; - } - - stack->ngrps = ngrps; - /* Set a canary. */ - *groupbuf_p = (void *)0xdeadf00d; + /* We take the ownership of the passed group buffer. */ + + if (ngrps <= SMALL_GROUP_COUNT) { + memcpy(stack->groups_small, *groupbuf_p, sizeof(gid_t) * ngrps); + stack->groups = stack->groups_small; + GF_FREE(*groupbuf_p); + } else { + stack->groups_large = *groupbuf_p; + stack->groups = stack->groups_large; + } + + stack->ngrps = ngrps; + /* Set a canary. */ + *groupbuf_p = (void *)0xdeadf00d; } void -gf_proc_dump_call_frame (call_frame_t *call_frame, const char *key_buf,...) +gf_proc_dump_call_frame(call_frame_t *call_frame, const char *key_buf, ...) { + char prefix[GF_DUMP_MAX_BUF_LEN]; + va_list ap; + call_frame_t my_frame; + int ret = -1; + char timestr[256] = { + 0, + }; + int len; + + if (!call_frame) + return; - char prefix[GF_DUMP_MAX_BUF_LEN]; - va_list ap; - call_frame_t my_frame; - int ret = -1; - char timestr[256] = {0,}; - int len; + GF_ASSERT(key_buf); - if (!call_frame) - return; + va_start(ap, key_buf); + vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN, key_buf, ap); + va_end(ap); - GF_ASSERT (key_buf); + ret = TRY_LOCK(&call_frame->lock); + if (ret) + goto out; - va_start(ap, key_buf); - vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN, key_buf, ap); - va_end(ap); + memcpy(&my_frame, call_frame, sizeof(my_frame)); + UNLOCK(&call_frame->lock); - ret = TRY_LOCK(&call_frame->lock); - if (ret) - goto out; - - memcpy(&my_frame, call_frame, sizeof(my_frame)); - UNLOCK(&call_frame->lock); - - if (my_frame.root->ctx->measure_latency) { - gf_time_fmt (timestr, sizeof (timestr), my_frame.begin.tv_sec, - gf_timefmt_FT); - len = strlen (timestr); - snprintf (timestr + len, sizeof (timestr) - len, - ".%"GF_PRI_SNSECONDS, my_frame.begin.tv_nsec); - gf_proc_dump_write("frame-creation-time", "%s", timestr); - gf_proc_dump_write("timings", "%ld.%"GF_PRI_SNSECONDS - " -> %ld.%"GF_PRI_SNSECONDS, - my_frame.begin.tv_sec, - my_frame.begin.tv_nsec, - my_frame.end.tv_sec, - my_frame.end.tv_nsec); - } - - gf_proc_dump_write("frame", "%p", call_frame); - gf_proc_dump_write("ref_count", "%d", my_frame.ref_count); - gf_proc_dump_write("translator", "%s", my_frame.this->name); - gf_proc_dump_write("complete", "%d", my_frame.complete); - - if (my_frame.parent) - gf_proc_dump_write("parent", "%s", my_frame.parent->this->name); - - if (my_frame.wind_from) - gf_proc_dump_write("wind_from", "%s", my_frame.wind_from); - - if (my_frame.wind_to) - gf_proc_dump_write("wind_to", "%s", my_frame.wind_to); - - if (my_frame.unwind_from) - gf_proc_dump_write("unwind_from", "%s", my_frame.unwind_from); - - if (my_frame.unwind_to) - gf_proc_dump_write("unwind_to", "%s", my_frame.unwind_to); - - ret = 0; + if (my_frame.root->ctx->measure_latency) { + gf_time_fmt(timestr, sizeof(timestr), my_frame.begin.tv_sec, + gf_timefmt_FT); + len = strlen(timestr); + snprintf(timestr + len, sizeof(timestr) - len, ".%" GF_PRI_SNSECONDS, + my_frame.begin.tv_nsec); + gf_proc_dump_write("frame-creation-time", "%s", timestr); + gf_proc_dump_write( + "timings", "%ld.%" GF_PRI_SNSECONDS " -> %ld.%" GF_PRI_SNSECONDS, + my_frame.begin.tv_sec, my_frame.begin.tv_nsec, my_frame.end.tv_sec, + my_frame.end.tv_nsec); + } + + gf_proc_dump_write("frame", "%p", call_frame); + gf_proc_dump_write("ref_count", "%d", my_frame.ref_count); + gf_proc_dump_write("translator", "%s", my_frame.this->name); + gf_proc_dump_write("complete", "%d", my_frame.complete); + + if (my_frame.parent) + gf_proc_dump_write("parent", "%s", my_frame.parent->this->name); + + if (my_frame.wind_from) + gf_proc_dump_write("wind_from", "%s", my_frame.wind_from); + + if (my_frame.wind_to) + gf_proc_dump_write("wind_to", "%s", my_frame.wind_to); + + if (my_frame.unwind_from) + gf_proc_dump_write("unwind_from", "%s", my_frame.unwind_from); + + if (my_frame.unwind_to) + gf_proc_dump_write("unwind_to", "%s", my_frame.unwind_to); + + ret = 0; out: - if (ret) { - gf_proc_dump_write("Unable to dump the frame information", - "(Lock acquisition failed) %p", my_frame); - return; - } + if (ret) { + gf_proc_dump_write("Unable to dump the frame information", + "(Lock acquisition failed) %p", my_frame); + return; + } } - void -gf_proc_dump_call_stack (call_stack_t *call_stack, const char *key_buf,...) +gf_proc_dump_call_stack(call_stack_t *call_stack, const char *key_buf, ...) { - char prefix[GF_DUMP_MAX_BUF_LEN]; - va_list ap; - call_frame_t *trav; - int32_t i = 1, cnt = 0; - char timestr[256] = {0,}; - int len; - - if (!call_stack) - return; - - GF_ASSERT (key_buf); - - va_start(ap, key_buf); - vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN, key_buf, ap); - va_end(ap); - - cnt = call_frames_count (call_stack); - gf_time_fmt (timestr, sizeof (timestr), call_stack->tv.tv_sec, - gf_timefmt_FT); - len = strlen (timestr); - snprintf (timestr + len, sizeof (timestr) - len, - ".%"GF_PRI_SNSECONDS, call_stack->tv.tv_nsec); - gf_proc_dump_write("callstack-creation-time", "%s", timestr); - - gf_proc_dump_write("stack", "%p", call_stack); - gf_proc_dump_write("uid", "%d", call_stack->uid); - gf_proc_dump_write("gid", "%d", call_stack->gid); - gf_proc_dump_write("pid", "%d", call_stack->pid); - gf_proc_dump_write("unique", "%Ld", call_stack->unique); - gf_proc_dump_write("lk-owner", "%s", lkowner_utoa (&call_stack->lk_owner)); - gf_proc_dump_write("ctime", "%lld.%"GF_PRI_SNSECONDS, - call_stack->tv.tv_sec, call_stack->tv.tv_nsec); - - if (call_stack->type == GF_OP_TYPE_FOP) - gf_proc_dump_write("op", "%s", - (char *)gf_fop_list[call_stack->op]); - else - gf_proc_dump_write("op", "stack"); - - gf_proc_dump_write("type", "%d", call_stack->type); - gf_proc_dump_write("cnt", "%d", cnt); - - list_for_each_entry (trav, &call_stack->myframes, frames) { - gf_proc_dump_add_section("%s.frame.%d", prefix, i); - gf_proc_dump_call_frame(trav, "%s.frame.%d", prefix, i); - i++; - } + char prefix[GF_DUMP_MAX_BUF_LEN]; + va_list ap; + call_frame_t *trav; + int32_t i = 1, cnt = 0; + char timestr[256] = { + 0, + }; + int len; + + if (!call_stack) + return; + + GF_ASSERT(key_buf); + + va_start(ap, key_buf); + vsnprintf(prefix, GF_DUMP_MAX_BUF_LEN, key_buf, ap); + va_end(ap); + + cnt = call_frames_count(call_stack); + gf_time_fmt(timestr, sizeof(timestr), call_stack->tv.tv_sec, gf_timefmt_FT); + len = strlen(timestr); + snprintf(timestr + len, sizeof(timestr) - len, ".%" GF_PRI_SNSECONDS, + call_stack->tv.tv_nsec); + gf_proc_dump_write("callstack-creation-time", "%s", timestr); + + gf_proc_dump_write("stack", "%p", call_stack); + gf_proc_dump_write("uid", "%d", call_stack->uid); + gf_proc_dump_write("gid", "%d", call_stack->gid); + gf_proc_dump_write("pid", "%d", call_stack->pid); + gf_proc_dump_write("unique", "%Ld", call_stack->unique); + gf_proc_dump_write("lk-owner", "%s", lkowner_utoa(&call_stack->lk_owner)); + gf_proc_dump_write("ctime", "%lld.%" GF_PRI_SNSECONDS, + call_stack->tv.tv_sec, call_stack->tv.tv_nsec); + + if (call_stack->type == GF_OP_TYPE_FOP) + gf_proc_dump_write("op", "%s", (char *)gf_fop_list[call_stack->op]); + else + gf_proc_dump_write("op", "stack"); + + gf_proc_dump_write("type", "%d", call_stack->type); + gf_proc_dump_write("cnt", "%d", cnt); + + list_for_each_entry(trav, &call_stack->myframes, frames) + { + gf_proc_dump_add_section("%s.frame.%d", prefix, i); + gf_proc_dump_call_frame(trav, "%s.frame.%d", prefix, i); + i++; + } } void -gf_proc_dump_pending_frames (call_pool_t *call_pool) +gf_proc_dump_pending_frames(call_pool_t *call_pool) { + call_stack_t *trav = NULL; + int i = 1; + int ret = -1; + gf_boolean_t section_added = _gf_false; - call_stack_t *trav = NULL; - int i = 1; - int ret = -1; - gf_boolean_t section_added = _gf_false; - - if (!call_pool) - return; - - ret = TRY_LOCK (&(call_pool->lock)); - if (ret) - goto out; - + if (!call_pool) + return; - gf_proc_dump_add_section("global.callpool"); - section_added = _gf_true; - gf_proc_dump_write("callpool_address","%p", call_pool); - gf_proc_dump_write("callpool.cnt","%d", call_pool->cnt); + ret = TRY_LOCK(&(call_pool->lock)); + if (ret) + goto out; + gf_proc_dump_add_section("global.callpool"); + section_added = _gf_true; + gf_proc_dump_write("callpool_address", "%p", call_pool); + gf_proc_dump_write("callpool.cnt", "%d", call_pool->cnt); - list_for_each_entry (trav, &call_pool->all_frames, all_frames) { - gf_proc_dump_add_section("global.callpool.stack.%d",i); - gf_proc_dump_call_stack(trav, "global.callpool.stack.%d", i); - i++; - } - UNLOCK (&(call_pool->lock)); + list_for_each_entry(trav, &call_pool->all_frames, all_frames) + { + gf_proc_dump_add_section("global.callpool.stack.%d", i); + gf_proc_dump_call_stack(trav, "global.callpool.stack.%d", i); + i++; + } + UNLOCK(&(call_pool->lock)); - ret = 0; + ret = 0; out: - if (ret) { - if (_gf_false == section_added) - gf_proc_dump_add_section("global.callpool"); - gf_proc_dump_write("Unable to dump the callpool", - "(Lock acquisition failed) %p", - call_pool); - } - return; + if (ret) { + if (_gf_false == section_added) + gf_proc_dump_add_section("global.callpool"); + gf_proc_dump_write("Unable to dump the callpool", + "(Lock acquisition failed) %p", call_pool); + } + return; } void -gf_proc_dump_call_frame_to_dict (call_frame_t *call_frame, - char *prefix, dict_t *dict) +gf_proc_dump_call_frame_to_dict(call_frame_t *call_frame, char *prefix, + dict_t *dict) { - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - char msg[GF_DUMP_MAX_BUF_LEN] = {0,}; - call_frame_t tmp_frame = {0,}; + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + char msg[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + call_frame_t tmp_frame = { + 0, + }; + + if (!call_frame || !dict) + return; + + ret = TRY_LOCK(&call_frame->lock); + if (ret) + return; + memcpy(&tmp_frame, call_frame, sizeof(tmp_frame)); + UNLOCK(&call_frame->lock); + + snprintf(key, sizeof(key), "%s.refcount", prefix); + ret = dict_set_int32(dict, key, tmp_frame.ref_count); + if (ret) + return; + + snprintf(key, sizeof(key), "%s.translator", prefix); + ret = dict_set_dynstr(dict, key, gf_strdup(tmp_frame.this->name)); + if (ret) + return; + + snprintf(key, sizeof(key), "%s.complete", prefix); + ret = dict_set_int32(dict, key, tmp_frame.complete); + if (ret) + return; - if (!call_frame || !dict) - return; + if (tmp_frame.root->ctx->measure_latency) { + snprintf(key, sizeof(key), "%s.timings", prefix); + snprintf(msg, sizeof(msg), + "%ld.%" GF_PRI_SNSECONDS " -> %ld.%" GF_PRI_SNSECONDS, + tmp_frame.begin.tv_sec, tmp_frame.begin.tv_nsec, + tmp_frame.end.tv_sec, tmp_frame.end.tv_nsec); + ret = dict_set_str(dict, key, msg); + if (ret) + return; + } - ret = TRY_LOCK (&call_frame->lock); + if (tmp_frame.parent) { + snprintf(key, sizeof(key), "%s.parent", prefix); + ret = dict_set_dynstr(dict, key, + gf_strdup(tmp_frame.parent->this->name)); if (ret) - return; - memcpy (&tmp_frame, call_frame, sizeof (tmp_frame)); - UNLOCK (&call_frame->lock); + return; + } - snprintf (key, sizeof (key), "%s.refcount", prefix); - ret = dict_set_int32 (dict, key, tmp_frame.ref_count); + if (tmp_frame.wind_from) { + snprintf(key, sizeof(key), "%s.windfrom", prefix); + ret = dict_set_dynstr(dict, key, gf_strdup(tmp_frame.wind_from)); if (ret) - return; + return; + } - snprintf (key, sizeof (key), "%s.translator", prefix); - ret = dict_set_dynstr (dict, key, gf_strdup (tmp_frame.this->name)); + if (tmp_frame.wind_to) { + snprintf(key, sizeof(key), "%s.windto", prefix); + ret = dict_set_dynstr(dict, key, gf_strdup(tmp_frame.wind_to)); if (ret) - return; + return; + } - snprintf (key, sizeof (key), "%s.complete", prefix); - ret = dict_set_int32 (dict, key, tmp_frame.complete); + if (tmp_frame.unwind_from) { + snprintf(key, sizeof(key), "%s.unwindfrom", prefix); + ret = dict_set_dynstr(dict, key, gf_strdup(tmp_frame.unwind_from)); if (ret) - return; - - if (tmp_frame.root->ctx->measure_latency) { - snprintf (key, sizeof (key), "%s.timings", prefix); - snprintf (msg, sizeof (msg), "%ld.%"GF_PRI_SNSECONDS - " -> %ld.%"GF_PRI_SNSECONDS, - tmp_frame.begin.tv_sec, tmp_frame.begin.tv_nsec, - tmp_frame.end.tv_sec, tmp_frame.end.tv_nsec); - ret = dict_set_str (dict, key, msg); - if (ret) - return; - } - - if (tmp_frame.parent) { - snprintf (key, sizeof (key), "%s.parent", prefix); - ret = dict_set_dynstr (dict, key, - gf_strdup (tmp_frame.parent->this->name)); - if (ret) - return; - } - - if (tmp_frame.wind_from) { - snprintf (key, sizeof (key), "%s.windfrom", prefix); - ret = dict_set_dynstr (dict, key, - gf_strdup (tmp_frame.wind_from)); - if (ret) - return; - } - - if (tmp_frame.wind_to) { - snprintf (key, sizeof (key), "%s.windto", prefix); - ret = dict_set_dynstr (dict, key, - gf_strdup (tmp_frame.wind_to)); - if (ret) - return; - } - - if (tmp_frame.unwind_from) { - snprintf (key, sizeof (key), "%s.unwindfrom", prefix); - ret = dict_set_dynstr (dict, key, - gf_strdup (tmp_frame.unwind_from)); - if (ret) - return; - } - - if (tmp_frame.unwind_to) { - snprintf (key, sizeof (key), "%s.unwind_to", prefix); - ret = dict_set_dynstr (dict, key, - gf_strdup (tmp_frame.unwind_to)); - } + return; + } - return; + if (tmp_frame.unwind_to) { + snprintf(key, sizeof(key), "%s.unwind_to", prefix); + ret = dict_set_dynstr(dict, key, gf_strdup(tmp_frame.unwind_to)); + } + + return; } void -gf_proc_dump_call_stack_to_dict (call_stack_t *call_stack, - char *prefix, dict_t *dict) +gf_proc_dump_call_stack_to_dict(call_stack_t *call_stack, char *prefix, + dict_t *dict) { - int ret = -1; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - call_frame_t *trav = NULL; - int i = 0; - int count = 0; - - if (!call_stack || !dict) - return; - - count = call_frames_count (call_stack); - snprintf (key, sizeof (key), "%s.uid", prefix); - ret = dict_set_int32 (dict, key, call_stack->uid); - if (ret) - return; - - snprintf (key, sizeof (key), "%s.gid", prefix); - ret = dict_set_int32 (dict, key, call_stack->gid); - if (ret) - return; + int ret = -1; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + call_frame_t *trav = NULL; + int i = 0; + int count = 0; + + if (!call_stack || !dict) + return; - snprintf (key, sizeof (key), "%s.pid", prefix); - ret = dict_set_int32 (dict, key, call_stack->pid); - if (ret) - return; + count = call_frames_count(call_stack); + snprintf(key, sizeof(key), "%s.uid", prefix); + ret = dict_set_int32(dict, key, call_stack->uid); + if (ret) + return; - snprintf (key, sizeof (key), "%s.unique", prefix); - ret = dict_set_uint64 (dict, key, call_stack->unique); - if (ret) - return; + snprintf(key, sizeof(key), "%s.gid", prefix); + ret = dict_set_int32(dict, key, call_stack->gid); + if (ret) + return; - snprintf (key, sizeof (key), "%s.op", prefix); - if (call_stack->type == GF_OP_TYPE_FOP) - ret = dict_set_str (dict, key, - (char *)gf_fop_list[call_stack->op]); - else - ret = dict_set_str (dict, key, "other"); + snprintf(key, sizeof(key), "%s.pid", prefix); + ret = dict_set_int32(dict, key, call_stack->pid); + if (ret) + return; - if (ret) - return; + snprintf(key, sizeof(key), "%s.unique", prefix); + ret = dict_set_uint64(dict, key, call_stack->unique); + if (ret) + return; - snprintf (key, sizeof (key), "%s.type", prefix); - ret = dict_set_int32 (dict, key, call_stack->type); - if (ret) - return; + snprintf(key, sizeof(key), "%s.op", prefix); + if (call_stack->type == GF_OP_TYPE_FOP) + ret = dict_set_str(dict, key, (char *)gf_fop_list[call_stack->op]); + else + ret = dict_set_str(dict, key, "other"); - snprintf (key, sizeof (key), "%s.count", prefix); - ret = dict_set_int32 (dict, key, count); - if (ret) - return; + if (ret) + return; - list_for_each_entry (trav, &call_stack->myframes, frames) { - snprintf (key, sizeof (key), "%s.frame%d", - prefix, i); - gf_proc_dump_call_frame_to_dict (trav, key, dict); - i++; - } + snprintf(key, sizeof(key), "%s.type", prefix); + ret = dict_set_int32(dict, key, call_stack->type); + if (ret) + return; + snprintf(key, sizeof(key), "%s.count", prefix); + ret = dict_set_int32(dict, key, count); + if (ret) return; + + list_for_each_entry(trav, &call_stack->myframes, frames) + { + snprintf(key, sizeof(key), "%s.frame%d", prefix, i); + gf_proc_dump_call_frame_to_dict(trav, key, dict); + i++; + } + + return; } void -gf_proc_dump_pending_frames_to_dict (call_pool_t *call_pool, dict_t *dict) +gf_proc_dump_pending_frames_to_dict(call_pool_t *call_pool, dict_t *dict) { - int ret = -1; - call_stack_t *trav = NULL; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - int i = 0; - - if (!call_pool || !dict) - return; - - ret = TRY_LOCK (&call_pool->lock); - if (ret) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, - LG_MSG_LOCK_FAILURE, "Unable to dump call " - "pool to dict."); - return; - } - - ret = dict_set_int32 (dict, "callpool.count", call_pool->cnt); - if (ret) - goto out; + int ret = -1; + call_stack_t *trav = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + int i = 0; + + if (!call_pool || !dict) + return; + + ret = TRY_LOCK(&call_pool->lock); + if (ret) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_LOCK_FAILURE, + "Unable to dump call " + "pool to dict."); + return; + } + + ret = dict_set_int32(dict, "callpool.count", call_pool->cnt); + if (ret) + goto out; - list_for_each_entry (trav, &call_pool->all_frames, all_frames) { - snprintf (key, sizeof (key), "callpool.stack%d", i); - gf_proc_dump_call_stack_to_dict (trav, key, dict); - i++; - } + list_for_each_entry(trav, &call_pool->all_frames, all_frames) + { + snprintf(key, sizeof(key), "callpool.stack%d", i); + gf_proc_dump_call_stack_to_dict(trav, key, dict); + i++; + } out: - UNLOCK (&call_pool->lock); + UNLOCK(&call_pool->lock); - return; + return; } gf_boolean_t -__is_fuse_call (call_frame_t *frame) +__is_fuse_call(call_frame_t *frame) { - gf_boolean_t is_fuse_call = _gf_false; - GF_ASSERT (frame); - GF_ASSERT (frame->root); + gf_boolean_t is_fuse_call = _gf_false; + GF_ASSERT(frame); + GF_ASSERT(frame->root); - if (NFS_PID != frame->root->pid) - is_fuse_call = _gf_true; - return is_fuse_call; + if (NFS_PID != frame->root->pid) + is_fuse_call = _gf_true; + return is_fuse_call; } diff --git a/libglusterfs/src/statedump.c b/libglusterfs/src/statedump.c index 057499eef68..422fb05ede6 100644 --- a/libglusterfs/src/statedump.c +++ b/libglusterfs/src/statedump.c @@ -17,7 +17,6 @@ #include "common-utils.h" #include "syscall.h" - #ifdef HAVE_MALLOC_H #include <malloc.h> #endif /* MALLOC_H */ @@ -26,1035 +25,1006 @@ 'deadlock' with statedump. This is because statedump happens inside a signal handler and cannot afford to block on a lock.*/ #ifdef gf_log -# undef gf_log +#undef gf_log #endif -#define GF_PROC_DUMP_IS_OPTION_ENABLED(opt) \ - (dump_options.dump_##opt == _gf_true) +#define GF_PROC_DUMP_IS_OPTION_ENABLED(opt) \ + (dump_options.dump_##opt == _gf_true) -#define GF_PROC_DUMP_IS_XL_OPTION_ENABLED(opt) \ - (dump_options.xl_options.dump_##opt == _gf_true) +#define GF_PROC_DUMP_IS_XL_OPTION_ENABLED(opt) \ + (dump_options.xl_options.dump_##opt == _gf_true) extern xlator_t global_xlator; -static pthread_mutex_t gf_proc_dump_mutex; +static pthread_mutex_t gf_proc_dump_mutex; static int gf_dump_fd = -1; gf_dump_options_t dump_options; static strfd_t *gf_dump_strfd = NULL; static void -gf_proc_dump_lock (void) +gf_proc_dump_lock(void) { - pthread_mutex_lock (&gf_proc_dump_mutex); + pthread_mutex_lock(&gf_proc_dump_mutex); } - static void -gf_proc_dump_unlock (void) +gf_proc_dump_unlock(void) { - pthread_mutex_unlock (&gf_proc_dump_mutex); + pthread_mutex_unlock(&gf_proc_dump_mutex); } static int -gf_proc_dump_open (char *tmpname) +gf_proc_dump_open(char *tmpname) { - int dump_fd = -1; + int dump_fd = -1; - mode_t mask = umask(S_IRWXG | S_IRWXO); - dump_fd = mkstemp (tmpname); - umask(mask); - if (dump_fd < 0) - return -1; + mode_t mask = umask(S_IRWXG | S_IRWXO); + dump_fd = mkstemp(tmpname); + umask(mask); + if (dump_fd < 0) + return -1; - gf_dump_fd = dump_fd; - return 0; + gf_dump_fd = dump_fd; + return 0; } static void -gf_proc_dump_close (void) +gf_proc_dump_close(void) { - sys_close (gf_dump_fd); - gf_dump_fd = -1; + sys_close(gf_dump_fd); + gf_dump_fd = -1; } static int -gf_proc_dump_set_path (char *dump_options_file) +gf_proc_dump_set_path(char *dump_options_file) { - int ret = -1; - FILE *fp = NULL; - char buf[256]; - char *key = NULL, *value = NULL; - char *saveptr = NULL; - - fp = fopen (dump_options_file, "r"); - if (!fp) - goto out; - - ret = fscanf (fp, "%s", buf); - - while (ret != EOF) { - key = strtok_r (buf, "=", &saveptr); - if (!key) { - ret = fscanf (fp, "%s", buf); - continue; - } - - value = strtok_r (NULL, "=", &saveptr); - - if (!value) { - ret = fscanf (fp, "%s", buf); - continue; - } - if (!strcmp (key, "path")) { - dump_options.dump_path = gf_strdup (value); - break; - } + int ret = -1; + FILE *fp = NULL; + char buf[256]; + char *key = NULL, *value = NULL; + char *saveptr = NULL; + + fp = fopen(dump_options_file, "r"); + if (!fp) + goto out; + + ret = fscanf(fp, "%s", buf); + + while (ret != EOF) { + key = strtok_r(buf, "=", &saveptr); + if (!key) { + ret = fscanf(fp, "%s", buf); + continue; } + value = strtok_r(NULL, "=", &saveptr); + + if (!value) { + ret = fscanf(fp, "%s", buf); + continue; + } + if (!strcmp(key, "path")) { + dump_options.dump_path = gf_strdup(value); + break; + } + } + out: - if (fp) - fclose (fp); - return ret; + if (fp) + fclose(fp); + return ret; } static int -gf_proc_dump_add_section_fd (char *key, va_list ap) +gf_proc_dump_add_section_fd(char *key, va_list ap) { + char buf[GF_DUMP_MAX_BUF_LEN]; + int len; - char buf[GF_DUMP_MAX_BUF_LEN]; - int len; + GF_ASSERT(key); - GF_ASSERT(key); - - len = snprintf (buf, GF_DUMP_MAX_BUF_LEN, "\n["); - len += vsnprintf (buf + len, - GF_DUMP_MAX_BUF_LEN - len, key, ap); - len += snprintf (buf + len, - GF_DUMP_MAX_BUF_LEN - len, "]\n"); - return sys_write (gf_dump_fd, buf, len); + len = snprintf(buf, GF_DUMP_MAX_BUF_LEN, "\n["); + len += vsnprintf(buf + len, GF_DUMP_MAX_BUF_LEN - len, key, ap); + len += snprintf(buf + len, GF_DUMP_MAX_BUF_LEN - len, "]\n"); + return sys_write(gf_dump_fd, buf, len); } - static int -gf_proc_dump_add_section_strfd (char *key, va_list ap) +gf_proc_dump_add_section_strfd(char *key, va_list ap) { - int ret = 0; + int ret = 0; - ret += strprintf (gf_dump_strfd, "["); - ret += strvprintf (gf_dump_strfd, key, ap); - ret += strprintf (gf_dump_strfd, "]\n"); + ret += strprintf(gf_dump_strfd, "["); + ret += strvprintf(gf_dump_strfd, key, ap); + ret += strprintf(gf_dump_strfd, "]\n"); - return ret; + return ret; } - int -gf_proc_dump_add_section (char *key, ...) +gf_proc_dump_add_section(char *key, ...) { - va_list ap; - int ret = 0; + va_list ap; + int ret = 0; - va_start (ap, key); - if (gf_dump_strfd) - ret = gf_proc_dump_add_section_strfd (key, ap); - else - ret = gf_proc_dump_add_section_fd (key, ap); - va_end (ap); + va_start(ap, key); + if (gf_dump_strfd) + ret = gf_proc_dump_add_section_strfd(key, ap); + else + ret = gf_proc_dump_add_section_fd(key, ap); + va_end(ap); - return ret; + return ret; } - static int -gf_proc_dump_write_fd (char *key, char *value, va_list ap) +gf_proc_dump_write_fd(char *key, char *value, va_list ap) { + char buf[GF_DUMP_MAX_BUF_LEN]; + int len = 0; - char buf[GF_DUMP_MAX_BUF_LEN]; - int len = 0; - - GF_ASSERT (key); + GF_ASSERT(key); - len = snprintf (buf, GF_DUMP_MAX_BUF_LEN, "%s=", key); - len += vsnprintf (buf + len, GF_DUMP_MAX_BUF_LEN - len, value, ap); + len = snprintf(buf, GF_DUMP_MAX_BUF_LEN, "%s=", key); + len += vsnprintf(buf + len, GF_DUMP_MAX_BUF_LEN - len, value, ap); - len += snprintf (buf + len, GF_DUMP_MAX_BUF_LEN - len, "\n"); - return sys_write (gf_dump_fd, buf, len); + len += snprintf(buf + len, GF_DUMP_MAX_BUF_LEN - len, "\n"); + return sys_write(gf_dump_fd, buf, len); } - static int -gf_proc_dump_write_strfd (char *key, char *value, va_list ap) +gf_proc_dump_write_strfd(char *key, char *value, va_list ap) { - int ret = 0; + int ret = 0; - ret += strprintf (gf_dump_strfd, "%s = ", key); - ret += strvprintf (gf_dump_strfd, value, ap); - ret += strprintf (gf_dump_strfd, "\n"); + ret += strprintf(gf_dump_strfd, "%s = ", key); + ret += strvprintf(gf_dump_strfd, value, ap); + ret += strprintf(gf_dump_strfd, "\n"); - return ret; + return ret; } - int -gf_proc_dump_write (char *key, char *value, ...) +gf_proc_dump_write(char *key, char *value, ...) { - int ret = 0; - va_list ap; + int ret = 0; + va_list ap; - va_start (ap, value); - if (gf_dump_strfd) - ret = gf_proc_dump_write_strfd (key, value, ap); - else - ret = gf_proc_dump_write_fd (key, value, ap); - va_end (ap); + va_start(ap, value); + if (gf_dump_strfd) + ret = gf_proc_dump_write_strfd(key, value, ap); + else + ret = gf_proc_dump_write_fd(key, value, ap); + va_end(ap); - return ret; + return ret; } - static void -gf_proc_dump_xlator_mem_info (xlator_t *xl) +gf_proc_dump_xlator_mem_info(xlator_t *xl) { - int i = 0; - - if (!xl) - return; - - if (!xl->mem_acct) - return; - - gf_proc_dump_add_section ("%s.%s - Memory usage", xl->type, xl->name); - gf_proc_dump_write ("num_types", "%d", xl->mem_acct->num_types); - - for (i = 0; i < xl->mem_acct->num_types; i++) { - if (xl->mem_acct->rec[i].num_allocs == 0) - continue; - - gf_proc_dump_add_section ("%s.%s - usage-type %s memusage", - xl->type, xl->name, - xl->mem_acct->rec[i].typestr); - gf_proc_dump_write ("size", "%u", xl->mem_acct->rec[i].size); - gf_proc_dump_write ("num_allocs", "%u", - xl->mem_acct->rec[i].num_allocs); - gf_proc_dump_write ("max_size", "%u", - xl->mem_acct->rec[i].max_size); - gf_proc_dump_write ("max_num_allocs", "%u", - xl->mem_acct->rec[i].max_num_allocs); - gf_proc_dump_write ("total_allocs", "%u", - xl->mem_acct->rec[i].total_allocs); - } + int i = 0; + + if (!xl) + return; + if (!xl->mem_acct) return; + + gf_proc_dump_add_section("%s.%s - Memory usage", xl->type, xl->name); + gf_proc_dump_write("num_types", "%d", xl->mem_acct->num_types); + + for (i = 0; i < xl->mem_acct->num_types; i++) { + if (xl->mem_acct->rec[i].num_allocs == 0) + continue; + + gf_proc_dump_add_section("%s.%s - usage-type %s memusage", xl->type, + xl->name, xl->mem_acct->rec[i].typestr); + gf_proc_dump_write("size", "%u", xl->mem_acct->rec[i].size); + gf_proc_dump_write("num_allocs", "%u", xl->mem_acct->rec[i].num_allocs); + gf_proc_dump_write("max_size", "%u", xl->mem_acct->rec[i].max_size); + gf_proc_dump_write("max_num_allocs", "%u", + xl->mem_acct->rec[i].max_num_allocs); + gf_proc_dump_write("total_allocs", "%u", + xl->mem_acct->rec[i].total_allocs); + } + + return; } static void -gf_proc_dump_xlator_mem_info_only_in_use (xlator_t *xl) +gf_proc_dump_xlator_mem_info_only_in_use(xlator_t *xl) { - int i = 0; - - if (!xl) - return; - - if (!xl->mem_acct) - return; - - gf_proc_dump_add_section ("%s.%s - Memory usage", xl->type, xl->name); - gf_proc_dump_write ("num_types", "%d", xl->mem_acct->num_types); - - for (i = 0; i < xl->mem_acct->num_types; i++) { - if (!xl->mem_acct->rec[i].size) - continue; - - gf_proc_dump_add_section ("%s.%s - usage-type %d", xl->type, - xl->name,i); - - gf_proc_dump_write ("size", "%u", - xl->mem_acct->rec[i].size); - gf_proc_dump_write ("max_size", "%u", - xl->mem_acct->rec[i].max_size); - gf_proc_dump_write ("num_allocs", "%u", - xl->mem_acct->rec[i].num_allocs); - gf_proc_dump_write ("max_num_allocs", "%u", - xl->mem_acct->rec[i].max_num_allocs); - gf_proc_dump_write ("total_allocs", "%u", - xl->mem_acct->rec[i].total_allocs); - } + int i = 0; + if (!xl) + return; + + if (!xl->mem_acct) return; -} + gf_proc_dump_add_section("%s.%s - Memory usage", xl->type, xl->name); + gf_proc_dump_write("num_types", "%d", xl->mem_acct->num_types); + for (i = 0; i < xl->mem_acct->num_types; i++) { + if (!xl->mem_acct->rec[i].size) + continue; + + gf_proc_dump_add_section("%s.%s - usage-type %d", xl->type, xl->name, + i); + + gf_proc_dump_write("size", "%u", xl->mem_acct->rec[i].size); + gf_proc_dump_write("max_size", "%u", xl->mem_acct->rec[i].max_size); + gf_proc_dump_write("num_allocs", "%u", xl->mem_acct->rec[i].num_allocs); + gf_proc_dump_write("max_num_allocs", "%u", + xl->mem_acct->rec[i].max_num_allocs); + gf_proc_dump_write("total_allocs", "%u", + xl->mem_acct->rec[i].total_allocs); + } + + return; +} /* Currently this dumps only mallinfo. More can be built on here */ void -gf_proc_dump_mem_info () +gf_proc_dump_mem_info() { #ifdef HAVE_MALLOC_STATS - struct mallinfo info; - - memset (&info, 0, sizeof (struct mallinfo)); - info = mallinfo (); - - gf_proc_dump_add_section ("mallinfo"); - gf_proc_dump_write ("mallinfo_arena", "%d", info.arena); - gf_proc_dump_write ("mallinfo_ordblks", "%d", info.ordblks); - gf_proc_dump_write ("mallinfo_smblks", "%d", info.smblks); - gf_proc_dump_write ("mallinfo_hblks", "%d", info.hblks); - gf_proc_dump_write ("mallinfo_hblkhd", "%d", info.hblkhd); - gf_proc_dump_write ("mallinfo_usmblks", "%d", info.usmblks); - gf_proc_dump_write ("mallinfo_fsmblks", "%d", info.fsmblks); - gf_proc_dump_write ("mallinfo_uordblks", "%d", info.uordblks); - gf_proc_dump_write ("mallinfo_fordblks", "%d", info.fordblks); - gf_proc_dump_write ("mallinfo_keepcost", "%d", info.keepcost); + struct mallinfo info; + + memset(&info, 0, sizeof(struct mallinfo)); + info = mallinfo(); + + gf_proc_dump_add_section("mallinfo"); + gf_proc_dump_write("mallinfo_arena", "%d", info.arena); + gf_proc_dump_write("mallinfo_ordblks", "%d", info.ordblks); + gf_proc_dump_write("mallinfo_smblks", "%d", info.smblks); + gf_proc_dump_write("mallinfo_hblks", "%d", info.hblks); + gf_proc_dump_write("mallinfo_hblkhd", "%d", info.hblkhd); + gf_proc_dump_write("mallinfo_usmblks", "%d", info.usmblks); + gf_proc_dump_write("mallinfo_fsmblks", "%d", info.fsmblks); + gf_proc_dump_write("mallinfo_uordblks", "%d", info.uordblks); + gf_proc_dump_write("mallinfo_fordblks", "%d", info.fordblks); + gf_proc_dump_write("mallinfo_keepcost", "%d", info.keepcost); #endif - gf_proc_dump_xlator_mem_info(&global_xlator); - + gf_proc_dump_xlator_mem_info(&global_xlator); } void -gf_proc_dump_mem_info_to_dict (dict_t *dict) +gf_proc_dump_mem_info_to_dict(dict_t *dict) { - if (!dict) - return; + if (!dict) + return; #ifdef HAVE_MALLOC_STATS - struct mallinfo info; - int ret = -1; + struct mallinfo info; + int ret = -1; - memset (&info, 0, sizeof(struct mallinfo)); - info = mallinfo (); + memset(&info, 0, sizeof(struct mallinfo)); + info = mallinfo(); - ret = dict_set_int32 (dict, "mallinfo.arena", info.arena); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.arena", info.arena); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.ordblks", info.ordblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.ordblks", info.ordblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.smblks", info.smblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.smblks", info.smblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.hblks", info.hblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.hblks", info.hblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.hblkhd", info.hblkhd); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.hblkhd", info.hblkhd); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.usmblks", info.usmblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.usmblks", info.usmblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.fsmblks", info.fsmblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.fsmblks", info.fsmblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.uordblks", info.uordblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.uordblks", info.uordblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.fordblks", info.fordblks); - if (ret) - return; + ret = dict_set_int32(dict, "mallinfo.fordblks", info.fordblks); + if (ret) + return; - ret = dict_set_int32 (dict, "mallinfo.keepcost", info.keepcost); - if (ret) - return; -#endif + ret = dict_set_int32(dict, "mallinfo.keepcost", info.keepcost); + if (ret) return; +#endif + return; } void -gf_proc_dump_mempool_info (glusterfs_ctx_t *ctx) +gf_proc_dump_mempool_info(glusterfs_ctx_t *ctx) { - struct mem_pool *pool = NULL; + struct mem_pool *pool = NULL; - gf_proc_dump_add_section ("mempool"); + gf_proc_dump_add_section("mempool"); #if defined(OLD_MEM_POOLS) - list_for_each_entry (pool, &ctx->mempool_list, global_list) { - gf_proc_dump_write ("-----", "-----"); - gf_proc_dump_write ("pool-name", "%s", pool->name); - gf_proc_dump_write ("hot-count", "%d", pool->hot_count); - gf_proc_dump_write ("cold-count", "%d", pool->cold_count); - gf_proc_dump_write ("padded_sizeof", "%lu", - pool->padded_sizeof_type); - gf_proc_dump_write ("alloc-count", "%"PRIu64, pool->alloc_count); - gf_proc_dump_write ("max-alloc", "%d", pool->max_alloc); - - gf_proc_dump_write ("pool-misses", "%"PRIu64, pool->pool_misses); - gf_proc_dump_write ("cur-stdalloc", "%d", pool->curr_stdalloc); - gf_proc_dump_write ("max-stdalloc", "%d", pool->max_stdalloc); - } + list_for_each_entry(pool, &ctx->mempool_list, global_list) + { + gf_proc_dump_write("-----", "-----"); + gf_proc_dump_write("pool-name", "%s", pool->name); + gf_proc_dump_write("hot-count", "%d", pool->hot_count); + gf_proc_dump_write("cold-count", "%d", pool->cold_count); + gf_proc_dump_write("padded_sizeof", "%lu", pool->padded_sizeof_type); + gf_proc_dump_write("alloc-count", "%" PRIu64, pool->alloc_count); + gf_proc_dump_write("max-alloc", "%d", pool->max_alloc); + + gf_proc_dump_write("pool-misses", "%" PRIu64, pool->pool_misses); + gf_proc_dump_write("cur-stdalloc", "%d", pool->curr_stdalloc); + gf_proc_dump_write("max-stdalloc", "%d", pool->max_stdalloc); + } #else - LOCK (&ctx->lock); + LOCK(&ctx->lock); + { + list_for_each_entry(pool, &ctx->mempool_list, owner) { - list_for_each_entry (pool, &ctx->mempool_list, owner) { - int64_t active = GF_ATOMIC_GET (pool->active); - - gf_proc_dump_write ("-----", "-----"); - gf_proc_dump_write ("pool-name", "%s", pool->name); - gf_proc_dump_write ("active-count", "%"GF_PRI_ATOMIC, active); - gf_proc_dump_write ("sizeof-type", "%d", pool->sizeof_type); - gf_proc_dump_write ("padded-sizeof", "%lu", 1 << pool->pool->power_of_two); - gf_proc_dump_write ("size", "%lu", (1 << pool->pool->power_of_two) * active); - gf_proc_dump_write ("shared-pool", "%p", pool->pool); - } + int64_t active = GF_ATOMIC_GET(pool->active); + + gf_proc_dump_write("-----", "-----"); + gf_proc_dump_write("pool-name", "%s", pool->name); + gf_proc_dump_write("active-count", "%" GF_PRI_ATOMIC, active); + gf_proc_dump_write("sizeof-type", "%d", pool->sizeof_type); + gf_proc_dump_write("padded-sizeof", "%lu", + 1 << pool->pool->power_of_two); + gf_proc_dump_write("size", "%lu", + (1 << pool->pool->power_of_two) * active); + gf_proc_dump_write("shared-pool", "%p", pool->pool); } - UNLOCK (&ctx->lock); + } + UNLOCK(&ctx->lock); - /* TODO: details of (struct mem_pool_shared) pool->pool */ + /* TODO: details of (struct mem_pool_shared) pool->pool */ #endif } void -gf_proc_dump_mempool_info_to_dict (glusterfs_ctx_t *ctx, dict_t *dict) +gf_proc_dump_mempool_info_to_dict(glusterfs_ctx_t *ctx, dict_t *dict) { #if defined(OLD_MEM_POOLS) - struct mem_pool *pool = NULL; - char key[GF_DUMP_MAX_BUF_LEN] = {0,}; - int count = 0; - int ret = -1; - - if (!ctx || !dict) - return; - - list_for_each_entry (pool, &ctx->mempool_list, global_list) { - snprintf (key, sizeof (key), "pool%d.name", count); - ret = dict_set_str (dict, key, pool->name); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.hotcount", count); - ret = dict_set_int32 (dict, key, pool->hot_count); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.coldcount", count); - ret = dict_set_int32 (dict, key, pool->cold_count); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.paddedsizeof", count); - ret = dict_set_uint64 (dict, key, pool->padded_sizeof_type); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.alloccount", count); - ret = dict_set_uint64 (dict, key, pool->alloc_count); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.max_alloc", count); - ret = dict_set_int32 (dict, key, pool->max_alloc); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.max-stdalloc", count); - ret = dict_set_int32 (dict, key, pool->max_stdalloc); - if (ret) - return; - - snprintf (key, sizeof (key), "pool%d.pool-misses", count); - ret = dict_set_uint64 (dict, key, pool->pool_misses); - if (ret) - return; - count++; - } - ret = dict_set_int32 (dict, "mempool-count", count); + struct mem_pool *pool = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = { + 0, + }; + int count = 0; + int ret = -1; + + if (!ctx || !dict) + return; + + list_for_each_entry(pool, &ctx->mempool_list, global_list) + { + snprintf(key, sizeof(key), "pool%d.name", count); + ret = dict_set_str(dict, key, pool->name); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.hotcount", count); + ret = dict_set_int32(dict, key, pool->hot_count); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.coldcount", count); + ret = dict_set_int32(dict, key, pool->cold_count); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.paddedsizeof", count); + ret = dict_set_uint64(dict, key, pool->padded_sizeof_type); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.alloccount", count); + ret = dict_set_uint64(dict, key, pool->alloc_count); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.max_alloc", count); + ret = dict_set_int32(dict, key, pool->max_alloc); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.max-stdalloc", count); + ret = dict_set_int32(dict, key, pool->max_stdalloc); + if (ret) + return; + + snprintf(key, sizeof(key), "pool%d.pool-misses", count); + ret = dict_set_uint64(dict, key, pool->pool_misses); + if (ret) + return; + count++; + } + ret = dict_set_int32(dict, "mempool-count", count); #endif } -void gf_proc_dump_latency_info (xlator_t *xl); +void +gf_proc_dump_latency_info(xlator_t *xl); void -gf_proc_dump_dict_info (glusterfs_ctx_t *ctx) +gf_proc_dump_dict_info(glusterfs_ctx_t *ctx) { - uint64_t total_dicts = 0; - uint64_t total_pairs = 0; - - total_dicts = GF_ATOMIC_GET (ctx->stats.total_dicts_used); - total_pairs = GF_ATOMIC_GET (ctx->stats.total_pairs_used); - - gf_proc_dump_write ("max-pairs-per-dict", "%u", - GF_ATOMIC_GET (ctx->stats.max_dict_pairs)); - gf_proc_dump_write ("total-pairs-used", "%lu", total_pairs); - gf_proc_dump_write ("total-dicts-used", "%lu", total_dicts); - gf_proc_dump_write ("average-pairs-per-dict", "%lu", - (total_pairs / total_dicts)); + uint64_t total_dicts = 0; + uint64_t total_pairs = 0; + + total_dicts = GF_ATOMIC_GET(ctx->stats.total_dicts_used); + total_pairs = GF_ATOMIC_GET(ctx->stats.total_pairs_used); + + gf_proc_dump_write("max-pairs-per-dict", "%u", + GF_ATOMIC_GET(ctx->stats.max_dict_pairs)); + gf_proc_dump_write("total-pairs-used", "%lu", total_pairs); + gf_proc_dump_write("total-dicts-used", "%lu", total_dicts); + gf_proc_dump_write("average-pairs-per-dict", "%lu", + (total_pairs / total_dicts)); } static void -gf_proc_dump_single_xlator_info (xlator_t *trav) +gf_proc_dump_single_xlator_info(xlator_t *trav) { - glusterfs_ctx_t *ctx = trav->ctx; - char itable_key[1024] = {0,}; + glusterfs_ctx_t *ctx = trav->ctx; + char itable_key[1024] = { + 0, + }; + if (trav->cleanup_starting) + return; - if (trav->cleanup_starting) - return; - - if (ctx->measure_latency) - gf_proc_dump_latency_info (trav); + if (ctx->measure_latency) + gf_proc_dump_latency_info(trav); - gf_proc_dump_xlator_mem_info(trav); + gf_proc_dump_xlator_mem_info(trav); - if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED (inode) && - (trav->itable)) { - snprintf (itable_key, sizeof (itable_key), "%d.%s.itable", - ctx->graph_id, trav->name); - } + if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED(inode) && (trav->itable)) { + snprintf(itable_key, sizeof(itable_key), "%d.%s.itable", ctx->graph_id, + trav->name); + } - if (!trav->dumpops) { - return; - } + if (!trav->dumpops) { + return; + } - if (trav->dumpops->priv && - GF_PROC_DUMP_IS_XL_OPTION_ENABLED (priv)) - trav->dumpops->priv (trav); + if (trav->dumpops->priv && GF_PROC_DUMP_IS_XL_OPTION_ENABLED(priv)) + trav->dumpops->priv(trav); - if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED (inode) && - (trav->dumpops->inode)) - trav->dumpops->inode (trav); - if (trav->dumpops->fd && - GF_PROC_DUMP_IS_XL_OPTION_ENABLED (fd)) - trav->dumpops->fd (trav); + if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED(inode) && (trav->dumpops->inode)) + trav->dumpops->inode(trav); + if (trav->dumpops->fd && GF_PROC_DUMP_IS_XL_OPTION_ENABLED(fd)) + trav->dumpops->fd(trav); - if (trav->dumpops->history && - GF_PROC_DUMP_IS_XL_OPTION_ENABLED (history)) - trav->dumpops->history (trav); + if (trav->dumpops->history && GF_PROC_DUMP_IS_XL_OPTION_ENABLED(history)) + trav->dumpops->history(trav); } static void -gf_proc_dump_per_xlator_info (xlator_t *top) +gf_proc_dump_per_xlator_info(xlator_t *top) { - xlator_t *trav = top; + xlator_t *trav = top; - while (trav && !trav->cleanup_starting) { - gf_proc_dump_single_xlator_info (trav); - trav = trav->next; - } + while (trav && !trav->cleanup_starting) { + gf_proc_dump_single_xlator_info(trav); + trav = trav->next; + } } - - void -gf_proc_dump_xlator_info (xlator_t *top, gf_boolean_t brick_mux) +gf_proc_dump_xlator_info(xlator_t *top, gf_boolean_t brick_mux) { - xlator_t *trav = NULL; - xlator_list_t **trav_p = NULL; - - if (!top) - return; - - trav = top; - gf_proc_dump_per_xlator_info (trav); - - if (brick_mux) { - trav_p = &top->children; - while (*trav_p) { - trav = (*trav_p)->xlator; - gf_proc_dump_per_xlator_info (trav); - trav_p = &(*trav_p)->next; - } - } + xlator_t *trav = NULL; + xlator_list_t **trav_p = NULL; + if (!top) return; + + trav = top; + gf_proc_dump_per_xlator_info(trav); + + if (brick_mux) { + trav_p = &top->children; + while (*trav_p) { + trav = (*trav_p)->xlator; + gf_proc_dump_per_xlator_info(trav); + trav_p = &(*trav_p)->next; + } + } + + return; } static void -gf_proc_dump_oldgraph_xlator_info (xlator_t *top) +gf_proc_dump_oldgraph_xlator_info(xlator_t *top) { - xlator_t *trav = NULL; + xlator_t *trav = NULL; - if (!top) - return; + if (!top) + return; - trav = top; - while (trav) { - gf_proc_dump_xlator_mem_info_only_in_use (trav); + trav = top; + while (trav) { + gf_proc_dump_xlator_mem_info_only_in_use(trav); - if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED (inode) && - (trav->itable)) { - /*TODO: dump inode table info if necessary by - printing the graph id (taken by glusterfs_cbtx_t) - in the key - */ - } + if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED(inode) && (trav->itable)) { + /*TODO: dump inode table info if necessary by + printing the graph id (taken by glusterfs_cbtx_t) + in the key + */ + } - if (!trav->dumpops) { - trav = trav->next; - continue; - } + if (!trav->dumpops) { + trav = trav->next; + continue; + } - if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED (inode) && - (trav->dumpops->inode)) - trav->dumpops->inode (trav); + if (GF_PROC_DUMP_IS_XL_OPTION_ENABLED(inode) && (trav->dumpops->inode)) + trav->dumpops->inode(trav); - if (trav->dumpops->fd && - GF_PROC_DUMP_IS_XL_OPTION_ENABLED (fd)) - trav->dumpops->fd (trav); + if (trav->dumpops->fd && GF_PROC_DUMP_IS_XL_OPTION_ENABLED(fd)) + trav->dumpops->fd(trav); - trav = trav->next; - } + trav = trav->next; + } - return; + return; } static int -gf_proc_dump_enable_all_options () +gf_proc_dump_enable_all_options() { - - GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inodectx, - _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fdctx, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_history, - _gf_true); - - return 0; + GF_PROC_DUMP_SET_OPTION(dump_options.dump_mem, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.dump_iobuf, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.dump_callpool, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_priv, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_inode, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_fd, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_inodectx, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_fdctx, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_history, _gf_true); + + return 0; } gf_boolean_t -is_gf_proc_dump_all_disabled () +is_gf_proc_dump_all_disabled() { - gf_boolean_t all_disabled = _gf_true; - - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.dump_mem, all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.dump_iobuf, all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.dump_callpool, all_disabled, - out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.xl_options.dump_priv, - all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.xl_options.dump_inode, - all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.xl_options.dump_fd, - all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.xl_options.dump_inodectx, - all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.xl_options.dump_fdctx, - all_disabled, out); - GF_CHECK_DUMP_OPTION_ENABLED (dump_options.xl_options.dump_history, - all_disabled, out); + gf_boolean_t all_disabled = _gf_true; + + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.dump_mem, all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.dump_iobuf, all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.dump_callpool, all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.xl_options.dump_priv, + all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.xl_options.dump_inode, + all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.xl_options.dump_fd, all_disabled, + out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.xl_options.dump_inodectx, + all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.xl_options.dump_fdctx, + all_disabled, out); + GF_CHECK_DUMP_OPTION_ENABLED(dump_options.xl_options.dump_history, + all_disabled, out); out: - return all_disabled; + return all_disabled; } /* These options are dumped by default if glusterdump.options file exists and it is emtpty */ static int -gf_proc_dump_enable_default_options () +gf_proc_dump_enable_default_options() { - GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_true); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.dump_mem, _gf_true); + GF_PROC_DUMP_SET_OPTION(dump_options.dump_callpool, _gf_true); - return 0; + return 0; } static int -gf_proc_dump_disable_all_options () +gf_proc_dump_disable_all_options() { - - GF_PROC_DUMP_SET_OPTION (dump_options.dump_mem, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_iobuf, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.dump_callpool, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_priv, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inode, - _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fd, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_inodectx, - _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_fdctx, _gf_false); - GF_PROC_DUMP_SET_OPTION (dump_options.xl_options.dump_history, - _gf_false); - return 0; + GF_PROC_DUMP_SET_OPTION(dump_options.dump_mem, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.dump_iobuf, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.dump_callpool, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_priv, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_inode, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_fd, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_inodectx, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_fdctx, _gf_false); + GF_PROC_DUMP_SET_OPTION(dump_options.xl_options.dump_history, _gf_false); + return 0; } static int -gf_proc_dump_parse_set_option (char *key, char *value) +gf_proc_dump_parse_set_option(char *key, char *value) { - gf_boolean_t *opt_key = NULL; - gf_boolean_t opt_value = _gf_false; - char buf[GF_DUMP_MAX_BUF_LEN]; - int ret = -1; - int len; - - if (!strcasecmp (key, "all")) { - (void)gf_proc_dump_enable_all_options (); - return 0; - } else if (!strcasecmp (key, "mem")) { - opt_key = &dump_options.dump_mem; - } else if (!strcasecmp (key, "iobuf")) { - opt_key = &dump_options.dump_iobuf; - } else if (!strcasecmp (key, "callpool")) { - opt_key = &dump_options.dump_callpool; - } else if (!strcasecmp (key, "priv")) { - opt_key = &dump_options.xl_options.dump_priv; - } else if (!strcasecmp (key, "fd")) { - opt_key = &dump_options.xl_options.dump_fd; - } else if (!strcasecmp (key, "inode")) { - opt_key = &dump_options.xl_options.dump_inode; - } else if (!strcasecmp (key, "inodectx")) { - opt_key = &dump_options.xl_options.dump_inodectx; - } else if (!strcasecmp (key, "fdctx")) { - opt_key = &dump_options.xl_options.dump_fdctx; - } else if (!strcasecmp (key, "history")) { - opt_key = &dump_options.xl_options.dump_history; - } - - if (!opt_key) { - //None of dump options match the key, return back - len = snprintf (buf, sizeof (buf), "[Warning]:None of the options " - "matched key : %s\n", key); - if (len < 0) - ret = -1; - else { - ret = sys_write (gf_dump_fd, buf, len); - if (ret >= 0) - ret = -1; - } - goto out; + gf_boolean_t *opt_key = NULL; + gf_boolean_t opt_value = _gf_false; + char buf[GF_DUMP_MAX_BUF_LEN]; + int ret = -1; + int len; + + if (!strcasecmp(key, "all")) { + (void)gf_proc_dump_enable_all_options(); + return 0; + } else if (!strcasecmp(key, "mem")) { + opt_key = &dump_options.dump_mem; + } else if (!strcasecmp(key, "iobuf")) { + opt_key = &dump_options.dump_iobuf; + } else if (!strcasecmp(key, "callpool")) { + opt_key = &dump_options.dump_callpool; + } else if (!strcasecmp(key, "priv")) { + opt_key = &dump_options.xl_options.dump_priv; + } else if (!strcasecmp(key, "fd")) { + opt_key = &dump_options.xl_options.dump_fd; + } else if (!strcasecmp(key, "inode")) { + opt_key = &dump_options.xl_options.dump_inode; + } else if (!strcasecmp(key, "inodectx")) { + opt_key = &dump_options.xl_options.dump_inodectx; + } else if (!strcasecmp(key, "fdctx")) { + opt_key = &dump_options.xl_options.dump_fdctx; + } else if (!strcasecmp(key, "history")) { + opt_key = &dump_options.xl_options.dump_history; + } + + if (!opt_key) { + // None of dump options match the key, return back + len = snprintf(buf, sizeof(buf), + "[Warning]:None of the options " + "matched key : %s\n", + key); + if (len < 0) + ret = -1; + else { + ret = sys_write(gf_dump_fd, buf, len); + if (ret >= 0) + ret = -1; } + goto out; + } - opt_value = (strncasecmp (value, "yes", 3) ? - _gf_false: _gf_true); + opt_value = (strncasecmp(value, "yes", 3) ? _gf_false : _gf_true); - GF_PROC_DUMP_SET_OPTION (*opt_key, opt_value); + GF_PROC_DUMP_SET_OPTION(*opt_key, opt_value); - ret = 0; + ret = 0; out: - return ret; + return ret; } static int -gf_proc_dump_options_init () +gf_proc_dump_options_init() { - int ret = -1; - FILE *fp = NULL; - char buf[256]; - char *key = NULL, *value = NULL; - char *saveptr = NULL; - char dump_option_file[PATH_MAX]; - - /* glusterd will create a file glusterdump.<pid>.options and - sets the statedump options for the process and the file is removed - after the statedump is taken. Direct issue of SIGUSR1 does not have - mechanism for considering the statedump options. So to have a way - of configuring the statedump of all the glusterfs processes through - both cli command and SIGUSR1, glusterdump.options file is searched - and the options mentioned in it are given the higher priority. - */ - snprintf (dump_option_file, sizeof (dump_option_file), - DEFAULT_VAR_RUN_DIRECTORY - "/glusterdump.options"); - fp = fopen (dump_option_file, "r"); - if (!fp) { - snprintf (dump_option_file, sizeof (dump_option_file), - DEFAULT_VAR_RUN_DIRECTORY - "/glusterdump.%d.options", getpid ()); - - fp = fopen (dump_option_file, "r"); + int ret = -1; + FILE *fp = NULL; + char buf[256]; + char *key = NULL, *value = NULL; + char *saveptr = NULL; + char dump_option_file[PATH_MAX]; + + /* glusterd will create a file glusterdump.<pid>.options and + sets the statedump options for the process and the file is removed + after the statedump is taken. Direct issue of SIGUSR1 does not have + mechanism for considering the statedump options. So to have a way + of configuring the statedump of all the glusterfs processes through + both cli command and SIGUSR1, glusterdump.options file is searched + and the options mentioned in it are given the higher priority. + */ + snprintf(dump_option_file, sizeof(dump_option_file), + DEFAULT_VAR_RUN_DIRECTORY "/glusterdump.options"); + fp = fopen(dump_option_file, "r"); + if (!fp) { + snprintf(dump_option_file, sizeof(dump_option_file), + DEFAULT_VAR_RUN_DIRECTORY "/glusterdump.%d.options", getpid()); + + fp = fopen(dump_option_file, "r"); - if (!fp) { - //ENOENT, return success - (void) gf_proc_dump_enable_all_options (); - return 0; - } + if (!fp) { + // ENOENT, return success + (void)gf_proc_dump_enable_all_options(); + return 0; } + } - (void) gf_proc_dump_disable_all_options (); - - // swallow the errors if setting statedump file path is failed. - ret = gf_proc_dump_set_path (dump_option_file); + (void)gf_proc_dump_disable_all_options(); - ret = fscanf (fp, "%s", buf); + // swallow the errors if setting statedump file path is failed. + ret = gf_proc_dump_set_path(dump_option_file); - while (ret != EOF) { - key = strtok_r (buf, "=", &saveptr); - if (!key) { - ret = fscanf (fp, "%s", buf); - continue; - } + ret = fscanf(fp, "%s", buf); - value = strtok_r (NULL, "=", &saveptr); + while (ret != EOF) { + key = strtok_r(buf, "=", &saveptr); + if (!key) { + ret = fscanf(fp, "%s", buf); + continue; + } - if (!value) { - ret = fscanf (fp, "%s", buf); - continue; - } + value = strtok_r(NULL, "=", &saveptr); - gf_proc_dump_parse_set_option (key, value); + if (!value) { + ret = fscanf(fp, "%s", buf); + continue; } - if (is_gf_proc_dump_all_disabled ()) - (void) gf_proc_dump_enable_default_options (); + gf_proc_dump_parse_set_option(key, value); + } - if (fp) - fclose (fp); + if (is_gf_proc_dump_all_disabled()) + (void)gf_proc_dump_enable_default_options(); - return 0; + if (fp) + fclose(fp); + + return 0; } void -gf_proc_dump_info (int signum, glusterfs_ctx_t *ctx) +gf_proc_dump_info(int signum, glusterfs_ctx_t *ctx) { - int i = 0; - int ret = -1; - glusterfs_graph_t *trav = NULL; - char brick_name[PATH_MAX] = {0,}; - char timestr[256] = {0,}; - char sign_string[512] = {0,}; - char tmp_dump_name[PATH_MAX] = {0,}; - char path[PATH_MAX] = {0,}; - struct timeval tv = {0,}; - gf_boolean_t is_brick_mux = _gf_false; - xlator_t *top = NULL; - xlator_list_t **trav_p = NULL; - int brick_count = 0; - int len = 0; - - gf_proc_dump_lock (); - - if (!ctx) - goto out; - - if (ctx) { - top = ctx->active->first; - for (trav_p = &top->children; *trav_p; - trav_p = &(*trav_p)->next) { - brick_count++; - } - - if (brick_count > 1) - is_brick_mux = _gf_true; - } - - if (ctx->cmd_args.brick_name) { - GF_REMOVE_SLASH_FROM_PATH (ctx->cmd_args.brick_name, brick_name); - } else - snprintf(brick_name, sizeof (brick_name), "glusterdump"); - - ret = gf_proc_dump_options_init (); - if (ret < 0) - goto out; - - ret = snprintf (path, sizeof (path), "%s/%s.%d.dump.%"PRIu64, - ((dump_options.dump_path != NULL) - ? dump_options.dump_path - : ((ctx->statedump_path != NULL) - ? ctx->statedump_path - : DEFAULT_VAR_RUN_DIRECTORY)), - brick_name, getpid(), (uint64_t) time (NULL)); - if ((ret < 0) || (ret >= sizeof(path))) { - goto out; - } - - snprintf (tmp_dump_name, PATH_MAX, "%s/dumpXXXXXX", - ((dump_options.dump_path != NULL)?dump_options.dump_path: - ((ctx->statedump_path != NULL)?ctx->statedump_path: - DEFAULT_VAR_RUN_DIRECTORY))); - - ret = gf_proc_dump_open (tmp_dump_name); - if (ret < 0) - goto out; - - //continue even though gettimeofday() has failed - ret = gettimeofday (&tv, NULL); - if (0 == ret) { - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - len = strlen (timestr); - snprintf (timestr + len, - sizeof timestr - len, - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - } - - len = snprintf (sign_string, sizeof (sign_string), "DUMP-START-TIME: %s\n", - timestr); - - //swallow the errors of write for start and end marker - ret = sys_write (gf_dump_fd, sign_string, len); - - memset (timestr, 0, sizeof (timestr)); - - if (GF_PROC_DUMP_IS_OPTION_ENABLED (mem)) { - gf_proc_dump_mem_info (); - gf_proc_dump_mempool_info (ctx); - } - - if (GF_PROC_DUMP_IS_OPTION_ENABLED (iobuf)) - iobuf_stats_dump (ctx->iobuf_pool); - if (GF_PROC_DUMP_IS_OPTION_ENABLED (callpool)) - gf_proc_dump_pending_frames (ctx->pool); - - /* dictionary stats */ - gf_proc_dump_add_section ("dict"); - gf_proc_dump_dict_info (ctx); - - if (ctx->master) { - gf_proc_dump_add_section ("fuse"); - gf_proc_dump_single_xlator_info (ctx->master); + int i = 0; + int ret = -1; + glusterfs_graph_t *trav = NULL; + char brick_name[PATH_MAX] = { + 0, + }; + char timestr[256] = { + 0, + }; + char sign_string[512] = { + 0, + }; + char tmp_dump_name[PATH_MAX] = { + 0, + }; + char path[PATH_MAX] = { + 0, + }; + struct timeval tv = { + 0, + }; + gf_boolean_t is_brick_mux = _gf_false; + xlator_t *top = NULL; + xlator_list_t **trav_p = NULL; + int brick_count = 0; + int len = 0; + + gf_proc_dump_lock(); + + if (!ctx) + goto out; + + if (ctx) { + top = ctx->active->first; + for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) { + brick_count++; } - if (ctx->active) { - gf_proc_dump_add_section ("active graph - %d", ctx->graph_id); - gf_proc_dump_xlator_info (ctx->active->top, is_brick_mux); - } - - i = 0; - list_for_each_entry (trav, &ctx->graphs, list) { - if (trav == ctx->active) - continue; - - gf_proc_dump_add_section ("oldgraph[%d]", i); - - gf_proc_dump_oldgraph_xlator_info (trav->top); - i++; - } - - ret = gettimeofday (&tv, NULL); - if (0 == ret) { - gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); - len = strlen (timestr); - snprintf (timestr + len, - sizeof timestr - len, - ".%"GF_PRI_SUSECONDS, tv.tv_usec); - } - - len = snprintf (sign_string, sizeof (sign_string), "\nDUMP-END-TIME: %s", - timestr); - ret = sys_write (gf_dump_fd, sign_string, len); - - if (gf_dump_fd != -1) - gf_proc_dump_close (); - sys_rename (tmp_dump_name, path); + if (brick_count > 1) + is_brick_mux = _gf_true; + } + + if (ctx->cmd_args.brick_name) { + GF_REMOVE_SLASH_FROM_PATH(ctx->cmd_args.brick_name, brick_name); + } else + snprintf(brick_name, sizeof(brick_name), "glusterdump"); + + ret = gf_proc_dump_options_init(); + if (ret < 0) + goto out; + + ret = snprintf( + path, sizeof(path), "%s/%s.%d.dump.%" PRIu64, + ((dump_options.dump_path != NULL) + ? dump_options.dump_path + : ((ctx->statedump_path != NULL) ? ctx->statedump_path + : DEFAULT_VAR_RUN_DIRECTORY)), + brick_name, getpid(), (uint64_t)time(NULL)); + if ((ret < 0) || (ret >= sizeof(path))) { + goto out; + } + + snprintf( + tmp_dump_name, PATH_MAX, "%s/dumpXXXXXX", + ((dump_options.dump_path != NULL) + ? dump_options.dump_path + : ((ctx->statedump_path != NULL) ? ctx->statedump_path + : DEFAULT_VAR_RUN_DIRECTORY))); + + ret = gf_proc_dump_open(tmp_dump_name); + if (ret < 0) + goto out; + + // continue even though gettimeofday() has failed + ret = gettimeofday(&tv, NULL); + if (0 == ret) { + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + len = strlen(timestr); + snprintf(timestr + len, sizeof timestr - len, ".%" GF_PRI_SUSECONDS, + tv.tv_usec); + } + + len = snprintf(sign_string, sizeof(sign_string), "DUMP-START-TIME: %s\n", + timestr); + + // swallow the errors of write for start and end marker + ret = sys_write(gf_dump_fd, sign_string, len); + + memset(timestr, 0, sizeof(timestr)); + + if (GF_PROC_DUMP_IS_OPTION_ENABLED(mem)) { + gf_proc_dump_mem_info(); + gf_proc_dump_mempool_info(ctx); + } + + if (GF_PROC_DUMP_IS_OPTION_ENABLED(iobuf)) + iobuf_stats_dump(ctx->iobuf_pool); + if (GF_PROC_DUMP_IS_OPTION_ENABLED(callpool)) + gf_proc_dump_pending_frames(ctx->pool); + + /* dictionary stats */ + gf_proc_dump_add_section("dict"); + gf_proc_dump_dict_info(ctx); + + if (ctx->master) { + gf_proc_dump_add_section("fuse"); + gf_proc_dump_single_xlator_info(ctx->master); + } + + if (ctx->active) { + gf_proc_dump_add_section("active graph - %d", ctx->graph_id); + gf_proc_dump_xlator_info(ctx->active->top, is_brick_mux); + } + + i = 0; + list_for_each_entry(trav, &ctx->graphs, list) + { + if (trav == ctx->active) + continue; + + gf_proc_dump_add_section("oldgraph[%d]", i); + + gf_proc_dump_oldgraph_xlator_info(trav->top); + i++; + } + + ret = gettimeofday(&tv, NULL); + if (0 == ret) { + gf_time_fmt(timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); + len = strlen(timestr); + snprintf(timestr + len, sizeof timestr - len, ".%" GF_PRI_SUSECONDS, + tv.tv_usec); + } + + len = snprintf(sign_string, sizeof(sign_string), "\nDUMP-END-TIME: %s", + timestr); + ret = sys_write(gf_dump_fd, sign_string, len); + + if (gf_dump_fd != -1) + gf_proc_dump_close(); + sys_rename(tmp_dump_name, path); out: - GF_FREE (dump_options.dump_path); - dump_options.dump_path = NULL; - gf_proc_dump_unlock (); + GF_FREE(dump_options.dump_path); + dump_options.dump_path = NULL; + gf_proc_dump_unlock(); - return; + return; } - void -gf_proc_dump_fini (void) +gf_proc_dump_fini(void) { - pthread_mutex_destroy (&gf_proc_dump_mutex); + pthread_mutex_destroy(&gf_proc_dump_mutex); } - void -gf_proc_dump_init () +gf_proc_dump_init() { - pthread_mutex_init (&gf_proc_dump_mutex, NULL); + pthread_mutex_init(&gf_proc_dump_mutex, NULL); - return; + return; } - void -gf_proc_dump_cleanup (void) +gf_proc_dump_cleanup(void) { - pthread_mutex_destroy (&gf_proc_dump_mutex); + pthread_mutex_destroy(&gf_proc_dump_mutex); } - void -gf_proc_dump_xlator_private (xlator_t *this, strfd_t *strfd) +gf_proc_dump_xlator_private(xlator_t *this, strfd_t *strfd) { - gf_proc_dump_lock (); - { - gf_dump_strfd = strfd; + gf_proc_dump_lock(); + { + gf_dump_strfd = strfd; - if (this->dumpops && this->dumpops->priv) - this->dumpops->priv (this); + if (this->dumpops && this->dumpops->priv) + this->dumpops->priv(this); - gf_dump_strfd = NULL; - } - gf_proc_dump_unlock (); + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock(); } - void -gf_proc_dump_mallinfo (strfd_t *strfd) +gf_proc_dump_mallinfo(strfd_t *strfd) { - gf_proc_dump_lock (); - { - gf_dump_strfd = strfd; + gf_proc_dump_lock(); + { + gf_dump_strfd = strfd; - gf_proc_dump_mem_info (); + gf_proc_dump_mem_info(); - gf_dump_strfd = NULL; - } - gf_proc_dump_unlock (); + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock(); } - void -gf_proc_dump_xlator_history (xlator_t *this, strfd_t *strfd) +gf_proc_dump_xlator_history(xlator_t *this, strfd_t *strfd) { - gf_proc_dump_lock (); - { - gf_dump_strfd = strfd; + gf_proc_dump_lock(); + { + gf_dump_strfd = strfd; - if (this->dumpops && this->dumpops->history) - this->dumpops->history (this); + if (this->dumpops && this->dumpops->history) + this->dumpops->history(this); - gf_dump_strfd = NULL; - } - gf_proc_dump_unlock (); + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock(); } - void -gf_proc_dump_xlator_itable (xlator_t *this, strfd_t *strfd) +gf_proc_dump_xlator_itable(xlator_t *this, strfd_t *strfd) { - gf_proc_dump_lock (); - { - gf_dump_strfd = strfd; - + gf_proc_dump_lock(); + { + gf_dump_strfd = strfd; - gf_dump_strfd = NULL; - } - gf_proc_dump_unlock (); + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock(); } - void -gf_proc_dump_xlator_meminfo (xlator_t *this, strfd_t *strfd) +gf_proc_dump_xlator_meminfo(xlator_t *this, strfd_t *strfd) { - gf_proc_dump_lock (); - { - gf_dump_strfd = strfd; + gf_proc_dump_lock(); + { + gf_dump_strfd = strfd; - gf_proc_dump_xlator_mem_info (this); + gf_proc_dump_xlator_mem_info(this); - gf_dump_strfd = NULL; - } - gf_proc_dump_unlock (); + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock(); } - void -gf_proc_dump_xlator_profile (xlator_t *this, strfd_t *strfd) +gf_proc_dump_xlator_profile(xlator_t *this, strfd_t *strfd) { - gf_proc_dump_lock (); - { - gf_dump_strfd = strfd; + gf_proc_dump_lock(); + { + gf_dump_strfd = strfd; - gf_proc_dump_latency_info (this); + gf_proc_dump_latency_info(this); - gf_dump_strfd = NULL; - } - gf_proc_dump_unlock (); + gf_dump_strfd = NULL; + } + gf_proc_dump_unlock(); } diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c index 5172982149f..39ca3ec1c74 100644 --- a/libglusterfs/src/store.c +++ b/libglusterfs/src/store.c @@ -18,725 +18,734 @@ #include "syscall.h" #include "libglusterfs-messages.h" - int32_t -gf_store_mkdir (char *path) +gf_store_mkdir(char *path) { - int32_t ret = -1; + int32_t ret = -1; - ret = mkdir_p (path, 0777, _gf_true); + ret = mkdir_p(path, 0777, _gf_true); - if ((-1 == ret) && (EEXIST != errno)) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, "mkdir()" - " failed on path %s.", path); - } else { - ret = 0; - } + if ((-1 == ret) && (EEXIST != errno)) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "mkdir()" + " failed on path %s.", + path); + } else { + ret = 0; + } - return ret; + return ret; } int32_t -gf_store_handle_create_on_absence (gf_store_handle_t **shandle, - char *path) +gf_store_handle_create_on_absence(gf_store_handle_t **shandle, char *path) { - GF_ASSERT (shandle); - int32_t ret = 0; + GF_ASSERT(shandle); + int32_t ret = 0; - if (*shandle == NULL) { - ret = gf_store_handle_new (path, shandle); + if (*shandle == NULL) { + ret = gf_store_handle_new(path, shandle); - if (ret) { - gf_msg ("", GF_LOG_ERROR, 0, - LG_MSG_STORE_HANDLE_CREATE_FAILED, "Unable to" - " create store handle for path: %s", path); - } + if (ret) { + gf_msg("", GF_LOG_ERROR, 0, LG_MSG_STORE_HANDLE_CREATE_FAILED, + "Unable to" + " create store handle for path: %s", + path); } - return ret; + } + return ret; } int32_t -gf_store_mkstemp (gf_store_handle_t *shandle) +gf_store_mkstemp(gf_store_handle_t *shandle) { - char tmppath[PATH_MAX] = {0,}; - - GF_VALIDATE_OR_GOTO ("store", shandle, out); - GF_VALIDATE_OR_GOTO ("store", shandle->path, out); - - snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); - shandle->tmp_fd = open (tmppath, O_RDWR | O_CREAT | O_TRUNC, 0600); - if (shandle->tmp_fd < 0) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Failed to open %s.", tmppath); - } + char tmppath[PATH_MAX] = { + 0, + }; + + GF_VALIDATE_OR_GOTO("store", shandle, out); + GF_VALIDATE_OR_GOTO("store", shandle->path, out); + + snprintf(tmppath, sizeof(tmppath), "%s.tmp", shandle->path); + shandle->tmp_fd = open(tmppath, O_RDWR | O_CREAT | O_TRUNC, 0600); + if (shandle->tmp_fd < 0) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Failed to open %s.", tmppath); + } out: - return shandle->tmp_fd; + return shandle->tmp_fd; } int -gf_store_sync_direntry (char *path) +gf_store_sync_direntry(char *path) { - int ret = -1; - int dirfd = -1; - char *dir = NULL; - char *pdir = NULL; - xlator_t *this = NULL; - - this = THIS; - - dir = gf_strdup (path); - if (!dir) - goto out; - - pdir = dirname (dir); - dirfd = open (pdir, O_RDONLY); - if (dirfd == -1) { - gf_msg (this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, - "Failed to open directory %s.", pdir); - goto out; - } - - ret = sys_fsync (dirfd); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, - LG_MSG_DIR_OP_FAILED, "Failed to fsync %s.", pdir); - goto out; - } - - ret = 0; + int ret = -1; + int dirfd = -1; + char *dir = NULL; + char *pdir = NULL; + xlator_t *this = NULL; + + this = THIS; + + dir = gf_strdup(path); + if (!dir) + goto out; + + pdir = dirname(dir); + dirfd = open(pdir, O_RDONLY); + if (dirfd == -1) { + gf_msg(this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "Failed to open directory %s.", pdir); + goto out; + } + + ret = sys_fsync(dirfd); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "Failed to fsync %s.", pdir); + goto out; + } + + ret = 0; out: - if (dirfd >= 0) { - ret = sys_close (dirfd); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, errno, - LG_MSG_DIR_OP_FAILED, "Failed to close %s", pdir); - } + if (dirfd >= 0) { + ret = sys_close(dirfd); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "Failed to close %s", pdir); } + } - if (dir) - GF_FREE (dir); + if (dir) + GF_FREE(dir); - return ret; + return ret; } int32_t -gf_store_rename_tmppath (gf_store_handle_t *shandle) +gf_store_rename_tmppath(gf_store_handle_t *shandle) { - int32_t ret = -1; - char tmppath[PATH_MAX] = {0,}; - - GF_VALIDATE_OR_GOTO ("store", shandle, out); - GF_VALIDATE_OR_GOTO ("store", shandle->path, out); - - ret = sys_fsync (shandle->tmp_fd); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Failed to fsync %s", shandle->path); - goto out; - } - snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); - ret = sys_rename (tmppath, shandle->path); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Failed to rename %s to %s", tmppath, - shandle->path); - goto out; - } - - ret = gf_store_sync_direntry (tmppath); + int32_t ret = -1; + char tmppath[PATH_MAX] = { + 0, + }; + + GF_VALIDATE_OR_GOTO("store", shandle, out); + GF_VALIDATE_OR_GOTO("store", shandle->path, out); + + ret = sys_fsync(shandle->tmp_fd); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Failed to fsync %s", shandle->path); + goto out; + } + snprintf(tmppath, sizeof(tmppath), "%s.tmp", shandle->path); + ret = sys_rename(tmppath, shandle->path); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Failed to rename %s to %s", tmppath, shandle->path); + goto out; + } + + ret = gf_store_sync_direntry(tmppath); out: - if (shandle && shandle->tmp_fd >= 0) { - sys_close (shandle->tmp_fd); - shandle->tmp_fd = -1; - } - return ret; + if (shandle && shandle->tmp_fd >= 0) { + sys_close(shandle->tmp_fd); + shandle->tmp_fd = -1; + } + return ret; } int32_t -gf_store_unlink_tmppath (gf_store_handle_t *shandle) +gf_store_unlink_tmppath(gf_store_handle_t *shandle) { - int32_t ret = -1; - char tmppath[PATH_MAX] = {0,}; - - GF_VALIDATE_OR_GOTO ("store", shandle, out); - GF_VALIDATE_OR_GOTO ("store", shandle->path, out); - - snprintf (tmppath, sizeof (tmppath), "%s.tmp", shandle->path); - ret = sys_unlink (tmppath); - if (ret && (errno != ENOENT)) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Failed to mv %s to %s", tmppath, - shandle->path); - } else { - ret = 0; - } + int32_t ret = -1; + char tmppath[PATH_MAX] = { + 0, + }; + + GF_VALIDATE_OR_GOTO("store", shandle, out); + GF_VALIDATE_OR_GOTO("store", shandle->path, out); + + snprintf(tmppath, sizeof(tmppath), "%s.tmp", shandle->path); + ret = sys_unlink(tmppath); + if (ret && (errno != ENOENT)) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Failed to mv %s to %s", tmppath, shandle->path); + } else { + ret = 0; + } out: - if (shandle && shandle->tmp_fd >= 0) { - sys_close (shandle->tmp_fd); - shandle->tmp_fd = -1; - } - return ret; + if (shandle && shandle->tmp_fd >= 0) { + sys_close(shandle->tmp_fd); + shandle->tmp_fd = -1; + } + return ret; } int -gf_store_read_and_tokenize (FILE *file, char *str, int size, char **iter_key, - char **iter_val, gf_store_op_errno_t *store_errno) +gf_store_read_and_tokenize(FILE *file, char *str, int size, char **iter_key, + char **iter_val, gf_store_op_errno_t *store_errno) { - int32_t ret = -1; - char *savetok = NULL; - char *key = NULL; - char *value = NULL; - char *temp = NULL; - size_t str_len = 0; - - GF_ASSERT (file); - GF_ASSERT (str); - GF_ASSERT (iter_key); - GF_ASSERT (iter_val); - GF_ASSERT (store_errno); + int32_t ret = -1; + char *savetok = NULL; + char *key = NULL; + char *value = NULL; + char *temp = NULL; + size_t str_len = 0; + + GF_ASSERT(file); + GF_ASSERT(str); + GF_ASSERT(iter_key); + GF_ASSERT(iter_val); + GF_ASSERT(store_errno); retry: - temp = fgets (str, size, file); - if (temp == NULL || feof (file)) { - ret = -1; - *store_errno = GD_STORE_EOF; - goto out; - } - - if (strcmp (str, "\n") == 0) - goto retry; - - str_len = strlen(str); - str[str_len - 1] = '\0'; - /* Truncate the "\n", as fgets stores "\n" in str */ - - key = strtok_r (str, "=", &savetok); - if (!key) { - ret = -1; - *store_errno = GD_STORE_KEY_NULL; - goto out; - } - - value = strtok_r (NULL, "", &savetok); - if (!value) { - ret = -1; - *store_errno = GD_STORE_VALUE_NULL; - goto out; - } - - *iter_key = key; - *iter_val = value; - *store_errno = GD_STORE_SUCCESS; - ret = 0; + temp = fgets(str, size, file); + if (temp == NULL || feof(file)) { + ret = -1; + *store_errno = GD_STORE_EOF; + goto out; + } + + if (strcmp(str, "\n") == 0) + goto retry; + + str_len = strlen(str); + str[str_len - 1] = '\0'; + /* Truncate the "\n", as fgets stores "\n" in str */ + + key = strtok_r(str, "=", &savetok); + if (!key) { + ret = -1; + *store_errno = GD_STORE_KEY_NULL; + goto out; + } + + value = strtok_r(NULL, "", &savetok); + if (!value) { + ret = -1; + *store_errno = GD_STORE_VALUE_NULL; + goto out; + } + + *iter_key = key; + *iter_val = value; + *store_errno = GD_STORE_SUCCESS; + ret = 0; out: - return ret; + return ret; } int32_t -gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value) +gf_store_retrieve_value(gf_store_handle_t *handle, char *key, char **value) { - int32_t ret = -1; - char *scan_str = NULL; - char *iter_key = NULL; - char *iter_val = NULL; - char *free_str = NULL; - struct stat st = {0,}; - gf_store_op_errno_t store_errno = GD_STORE_SUCCESS; - - GF_ASSERT (handle); - - if (handle->locked == F_ULOCK) - /* no locking is used handle->fd gets closed() after usage */ - handle->fd = open (handle->path, O_RDWR); - else - /* handle->fd is valid already, kept open for lockf() */ - sys_lseek (handle->fd, 0, SEEK_SET); - - if (handle->fd == -1) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Unable to open file %s", handle->path); - goto out; - } + int32_t ret = -1; + char *scan_str = NULL; + char *iter_key = NULL; + char *iter_val = NULL; + char *free_str = NULL; + struct stat st = { + 0, + }; + gf_store_op_errno_t store_errno = GD_STORE_SUCCESS; + + GF_ASSERT(handle); + + if (handle->locked == F_ULOCK) + /* no locking is used handle->fd gets closed() after usage */ + handle->fd = open(handle->path, O_RDWR); + else + /* handle->fd is valid already, kept open for lockf() */ + sys_lseek(handle->fd, 0, SEEK_SET); + + if (handle->fd == -1) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Unable to open file %s", handle->path); + goto out; + } + if (!handle->read) { + int duped_fd = dup(handle->fd); + + if (duped_fd >= 0) + handle->read = fdopen(duped_fd, "r"); if (!handle->read) { - int duped_fd = dup(handle->fd); - - if (duped_fd >= 0) - handle->read = fdopen (duped_fd, "r"); - if (!handle->read) { - if (duped_fd != -1) - sys_close (duped_fd); - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Unable to open file %s", handle->path); - goto out; - } - } else { - fseek (handle->read, 0, SEEK_SET); - } - ret = sys_fstat (handle->fd, &st); + if (duped_fd != -1) + sys_close(duped_fd); + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Unable to open file %s", handle->path); + goto out; + } + } else { + fseek(handle->read, 0, SEEK_SET); + } + ret = sys_fstat(handle->fd, &st); + if (ret < 0) { + gf_msg("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "stat on file %s failed", handle->path); + ret = -1; + store_errno = GD_STORE_STAT_FAILED; + goto out; + } + + /* "st.st_size + 1" is used as we are fetching each + * line of a file using fgets, fgets will append "\0" + * to the end of the string + */ + scan_str = GF_CALLOC(1, st.st_size + 1, gf_common_mt_char); + + if (scan_str == NULL) { + ret = -1; + store_errno = GD_STORE_ENOMEM; + goto out; + } + + free_str = scan_str; + + do { + ret = gf_store_read_and_tokenize(handle->read, scan_str, st.st_size + 1, + &iter_key, &iter_val, &store_errno); if (ret < 0) { - gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, - "stat on file %s failed", handle->path); - ret = -1; - store_errno = GD_STORE_STAT_FAILED; - goto out; + gf_msg_trace("", 0, + "error while reading key '%s': " + "%s", + key, gf_store_strerror(store_errno)); + goto out; } - /* "st.st_size + 1" is used as we are fetching each - * line of a file using fgets, fgets will append "\0" - * to the end of the string - */ - scan_str = GF_CALLOC (1, st.st_size + 1, - gf_common_mt_char); - - if (scan_str == NULL) { - ret = -1; - store_errno = GD_STORE_ENOMEM; - goto out; - } + gf_msg_trace("", 0, "key %s read", iter_key); - free_str = scan_str; - - do { - ret = gf_store_read_and_tokenize (handle->read, scan_str, - st.st_size + 1, - &iter_key, &iter_val, - &store_errno); - if (ret < 0) { - gf_msg_trace ("", 0, "error while reading key '%s': " - "%s", key, - gf_store_strerror (store_errno)); - goto out; - } - - gf_msg_trace ("", 0, "key %s read", iter_key); - - if (!strcmp (key, iter_key)) { - gf_msg_debug ("", 0, "key %s found", key); - ret = 0; - if (iter_val) - *value = gf_strdup (iter_val); - goto out; - } - } while (1); -out: - if (handle->read) { - fclose (handle->read); - handle->read = NULL; + if (!strcmp(key, iter_key)) { + gf_msg_debug("", 0, "key %s found", key); + ret = 0; + if (iter_val) + *value = gf_strdup(iter_val); + goto out; } + } while (1); +out: + if (handle->read) { + fclose(handle->read); + handle->read = NULL; + } - if (handle->fd > 0 && handle->locked == F_ULOCK) { - /* only invalidate handle->fd if not locked */ - sys_close (handle->fd); - } + if (handle->fd > 0 && handle->locked == F_ULOCK) { + /* only invalidate handle->fd if not locked */ + sys_close(handle->fd); + } - GF_FREE (free_str); + GF_FREE(free_str); - return ret; + return ret; } int32_t -gf_store_save_value (int fd, char *key, char *value) +gf_store_save_value(int fd, char *key, char *value) { - int32_t ret = -1; - int dup_fd = -1; - FILE *fp = NULL; - - GF_ASSERT (fd > 0); - GF_ASSERT (key); - GF_ASSERT (value); - - dup_fd = dup (fd); - if (dup_fd == -1) - goto out; - - fp = fdopen (dup_fd, "a+"); - if (fp == NULL) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, - LG_MSG_FILE_OP_FAILED, "fdopen failed."); - ret = -1; - goto out; - } - - ret = fprintf (fp, "%s=%s\n", key, value); - if (ret < 0) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, - "Unable to store key: %s, value: %s.", - key, value); - ret = -1; - goto out; - } - - ret = fflush (fp); - if (ret) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, - "fflush failed."); - ret = -1; - goto out; - } - - ret = 0; + int32_t ret = -1; + int dup_fd = -1; + FILE *fp = NULL; + + GF_ASSERT(fd > 0); + GF_ASSERT(key); + GF_ASSERT(value); + + dup_fd = dup(fd); + if (dup_fd == -1) + goto out; + + fp = fdopen(dup_fd, "a+"); + if (fp == NULL) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "fdopen failed."); + ret = -1; + goto out; + } + + ret = fprintf(fp, "%s=%s\n", key, value); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "Unable to store key: %s, value: %s.", key, value); + ret = -1; + goto out; + } + + ret = fflush(fp); + if (ret) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "fflush failed."); + ret = -1; + goto out; + } + + ret = 0; out: - if (fp) - fclose (fp); + if (fp) + fclose(fp); - gf_msg_debug (THIS->name, 0, "returning: %d", ret); - return ret; + gf_msg_debug(THIS->name, 0, "returning: %d", ret); + return ret; } int32_t -gf_store_handle_new (const char *path, gf_store_handle_t **handle) +gf_store_handle_new(const char *path, gf_store_handle_t **handle) { - int32_t ret = -1; - gf_store_handle_t *shandle = NULL; - int fd = -1; - char *spath = NULL; - - shandle = GF_CALLOC (1, sizeof (*shandle), gf_common_mt_store_handle_t); - if (!shandle) - goto out; - - spath = gf_strdup (path); - if (!spath) - goto out; - - fd = open (path, O_RDWR | O_CREAT | O_APPEND, 0600); - if (fd < 0) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Failed to open file: %s.", path); - goto out; - } - - ret = gf_store_sync_direntry (spath); - if (ret) - goto out; - - shandle->path = spath; - shandle->locked = F_ULOCK; - *handle = shandle; - shandle->tmp_fd = -1; - - ret = 0; + int32_t ret = -1; + gf_store_handle_t *shandle = NULL; + int fd = -1; + char *spath = NULL; + + shandle = GF_CALLOC(1, sizeof(*shandle), gf_common_mt_store_handle_t); + if (!shandle) + goto out; + + spath = gf_strdup(path); + if (!spath) + goto out; + + fd = open(path, O_RDWR | O_CREAT | O_APPEND, 0600); + if (fd < 0) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Failed to open file: %s.", path); + goto out; + } + + ret = gf_store_sync_direntry(spath); + if (ret) + goto out; + + shandle->path = spath; + shandle->locked = F_ULOCK; + *handle = shandle; + shandle->tmp_fd = -1; + + ret = 0; out: - if (fd >= 0) - sys_close (fd); + if (fd >= 0) + sys_close(fd); - if (ret < 0) { - GF_FREE (spath); - GF_FREE (shandle); - } + if (ret < 0) { + GF_FREE(spath); + GF_FREE(shandle); + } - gf_msg_debug ("", 0, "Returning %d", ret); - return ret; + gf_msg_debug("", 0, "Returning %d", ret); + return ret; } int -gf_store_handle_retrieve (char *path, gf_store_handle_t **handle) +gf_store_handle_retrieve(char *path, gf_store_handle_t **handle) { - int32_t ret = -1; - struct stat statbuf = {0}; - - ret = sys_stat (path, &statbuf); - if (ret) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_PATH_NOT_FOUND, "Path " - "corresponding to %s.", path); - goto out; - } - ret = gf_store_handle_new (path, handle); + int32_t ret = -1; + struct stat statbuf = {0}; + + ret = sys_stat(path, &statbuf); + if (ret) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_PATH_NOT_FOUND, + "Path " + "corresponding to %s.", + path); + goto out; + } + ret = gf_store_handle_new(path, handle); out: - gf_msg_debug ("", 0, "Returning %d", ret); - return ret; + gf_msg_debug("", 0, "Returning %d", ret); + return ret; } int32_t -gf_store_handle_destroy (gf_store_handle_t *handle) +gf_store_handle_destroy(gf_store_handle_t *handle) { - int32_t ret = -1; + int32_t ret = -1; - if (!handle) { - ret = 0; - goto out; - } + if (!handle) { + ret = 0; + goto out; + } - GF_FREE (handle->path); + GF_FREE(handle->path); - GF_FREE (handle); + GF_FREE(handle); - ret = 0; + ret = 0; out: - gf_msg_debug ("", 0, "Returning %d", ret); + gf_msg_debug("", 0, "Returning %d", ret); - return ret; + return ret; } int32_t -gf_store_iter_new (gf_store_handle_t *shandle, gf_store_iter_t **iter) +gf_store_iter_new(gf_store_handle_t *shandle, gf_store_iter_t **iter) { - int32_t ret = -1; - FILE *fp = NULL; - gf_store_iter_t *tmp_iter = NULL; - - GF_ASSERT (shandle); - GF_ASSERT (iter); - - fp = fopen (shandle->path, "r"); - if (!fp) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Unable to open file %s", shandle->path); - goto out; - } + int32_t ret = -1; + FILE *fp = NULL; + gf_store_iter_t *tmp_iter = NULL; - tmp_iter = GF_CALLOC (1, sizeof (*tmp_iter), - gf_common_mt_store_iter_t); - if (!tmp_iter) - goto out; + GF_ASSERT(shandle); + GF_ASSERT(iter); - if (snprintf (tmp_iter->filepath, sizeof (tmp_iter->filepath), "%s", - shandle->path) >= sizeof (tmp_iter->filepath)) - goto out; + fp = fopen(shandle->path, "r"); + if (!fp) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Unable to open file %s", shandle->path); + goto out; + } - tmp_iter->file = fp; + tmp_iter = GF_CALLOC(1, sizeof(*tmp_iter), gf_common_mt_store_iter_t); + if (!tmp_iter) + goto out; - *iter = tmp_iter; - tmp_iter = NULL; - ret = 0; + if (snprintf(tmp_iter->filepath, sizeof(tmp_iter->filepath), "%s", + shandle->path) >= sizeof(tmp_iter->filepath)) + goto out; + + tmp_iter->file = fp; + + *iter = tmp_iter; + tmp_iter = NULL; + ret = 0; out: - if (ret && fp) - fclose (fp); + if (ret && fp) + fclose(fp); - GF_FREE (tmp_iter); + GF_FREE(tmp_iter); - gf_msg_debug ("", 0, "Returning with %d", ret); - return ret; + gf_msg_debug("", 0, "Returning with %d", ret); + return ret; } int32_t -gf_store_validate_key_value (char *storepath, char *key, char *val, - gf_store_op_errno_t *op_errno) +gf_store_validate_key_value(char *storepath, char *key, char *val, + gf_store_op_errno_t *op_errno) { - int ret = 0; - - GF_ASSERT (op_errno); - GF_ASSERT (storepath); - - if ((key == NULL) && (val == NULL)) { - ret = -1; - gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Glusterd " - "store may be corrupted, Invalid key and value (null)" - " in %s", storepath); - *op_errno = GD_STORE_KEY_VALUE_NULL; - } else if (key == NULL) { - ret = -1; - gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Glusterd " - "store may be corrupted, Invalid key (null) in %s", - storepath); - *op_errno = GD_STORE_KEY_NULL; - } else if (val == NULL) { - ret = -1; - gf_msg ("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "Glusterd " - "store may be corrupted, Invalid value (null) for key" - " %s in %s", key, storepath); - *op_errno = GD_STORE_VALUE_NULL; - } else { - ret = 0; - *op_errno = GD_STORE_SUCCESS; - } + int ret = 0; + + GF_ASSERT(op_errno); + GF_ASSERT(storepath); + + if ((key == NULL) && (val == NULL)) { + ret = -1; + gf_msg("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Glusterd " + "store may be corrupted, Invalid key and value (null)" + " in %s", + storepath); + *op_errno = GD_STORE_KEY_VALUE_NULL; + } else if (key == NULL) { + ret = -1; + gf_msg("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Glusterd " + "store may be corrupted, Invalid key (null) in %s", + storepath); + *op_errno = GD_STORE_KEY_NULL; + } else if (val == NULL) { + ret = -1; + gf_msg("", GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, + "Glusterd " + "store may be corrupted, Invalid value (null) for key" + " %s in %s", + key, storepath); + *op_errno = GD_STORE_VALUE_NULL; + } else { + ret = 0; + *op_errno = GD_STORE_SUCCESS; + } - return ret; + return ret; } int32_t -gf_store_iter_get_next (gf_store_iter_t *iter, char **key, char **value, - gf_store_op_errno_t *op_errno) +gf_store_iter_get_next(gf_store_iter_t *iter, char **key, char **value, + gf_store_op_errno_t *op_errno) { - int32_t ret = -1; - char *scan_str = NULL; - char *iter_key = NULL; - char *iter_val = NULL; - struct stat st = {0,}; - gf_store_op_errno_t store_errno = GD_STORE_SUCCESS; - - GF_ASSERT (iter); - GF_ASSERT (key); - GF_ASSERT (value); - - ret = sys_stat (iter->filepath, &st); - if (ret < 0) { - gf_msg ("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, - "stat on file failed"); - ret = -1; - store_errno = GD_STORE_STAT_FAILED; - goto out; - } - - /* "st.st_size + 1" is used as we are fetching each - * line of a file using fgets, fgets will append "\0" - * to the end of the string - */ - scan_str = GF_CALLOC (1, st.st_size + 1, - gf_common_mt_char); - if (!scan_str) { - ret = -1; - store_errno = GD_STORE_ENOMEM; - goto out; - } - - ret = gf_store_read_and_tokenize (iter->file, scan_str, - st.st_size + 1, - &iter_key, &iter_val, - &store_errno); - if (ret < 0) { - goto out; - } - - ret = gf_store_validate_key_value (iter->filepath, iter_key, - iter_val, &store_errno); - if (ret) - goto out; - - *key = gf_strdup (iter_key); - if (!*key) { - ret = -1; - store_errno = GD_STORE_ENOMEM; - goto out; - } - *value = gf_strdup (iter_val); - if (!*value) { - ret = -1; - store_errno = GD_STORE_ENOMEM; - goto out; - } - ret = 0; + int32_t ret = -1; + char *scan_str = NULL; + char *iter_key = NULL; + char *iter_val = NULL; + struct stat st = { + 0, + }; + gf_store_op_errno_t store_errno = GD_STORE_SUCCESS; + + GF_ASSERT(iter); + GF_ASSERT(key); + GF_ASSERT(value); + + ret = sys_stat(iter->filepath, &st); + if (ret < 0) { + gf_msg("", GF_LOG_WARNING, errno, LG_MSG_FILE_OP_FAILED, + "stat on file failed"); + ret = -1; + store_errno = GD_STORE_STAT_FAILED; + goto out; + } + + /* "st.st_size + 1" is used as we are fetching each + * line of a file using fgets, fgets will append "\0" + * to the end of the string + */ + scan_str = GF_CALLOC(1, st.st_size + 1, gf_common_mt_char); + if (!scan_str) { + ret = -1; + store_errno = GD_STORE_ENOMEM; + goto out; + } + + ret = gf_store_read_and_tokenize(iter->file, scan_str, st.st_size + 1, + &iter_key, &iter_val, &store_errno); + if (ret < 0) { + goto out; + } + + ret = gf_store_validate_key_value(iter->filepath, iter_key, iter_val, + &store_errno); + if (ret) + goto out; + + *key = gf_strdup(iter_key); + if (!*key) { + ret = -1; + store_errno = GD_STORE_ENOMEM; + goto out; + } + *value = gf_strdup(iter_val); + if (!*value) { + ret = -1; + store_errno = GD_STORE_ENOMEM; + goto out; + } + ret = 0; out: - GF_FREE (scan_str); - if (ret) { - GF_FREE (*key); - GF_FREE (*value); - *key = NULL; - *value = NULL; - } - if (op_errno) - *op_errno = store_errno; - - gf_msg_debug ("", 0, "Returning with %d", ret); - return ret; + GF_FREE(scan_str); + if (ret) { + GF_FREE(*key); + GF_FREE(*value); + *key = NULL; + *value = NULL; + } + if (op_errno) + *op_errno = store_errno; + + gf_msg_debug("", 0, "Returning with %d", ret); + return ret; } int32_t -gf_store_iter_get_matching (gf_store_iter_t *iter, char *key, char **value) +gf_store_iter_get_matching(gf_store_iter_t *iter, char *key, char **value) { - int32_t ret = -1; - char *tmp_key = NULL; - char *tmp_value = NULL; - - ret = gf_store_iter_get_next (iter, &tmp_key, &tmp_value, NULL); - while (!ret) { - if (!strncmp (key, tmp_key, strlen (key))){ - *value = tmp_value; - GF_FREE (tmp_key); - goto out; - } - GF_FREE (tmp_key); - tmp_key = NULL; - GF_FREE (tmp_value); - tmp_value = NULL; - ret = gf_store_iter_get_next (iter, &tmp_key, &tmp_value, - NULL); - } + int32_t ret = -1; + char *tmp_key = NULL; + char *tmp_value = NULL; + + ret = gf_store_iter_get_next(iter, &tmp_key, &tmp_value, NULL); + while (!ret) { + if (!strncmp(key, tmp_key, strlen(key))) { + *value = tmp_value; + GF_FREE(tmp_key); + goto out; + } + GF_FREE(tmp_key); + tmp_key = NULL; + GF_FREE(tmp_value); + tmp_value = NULL; + ret = gf_store_iter_get_next(iter, &tmp_key, &tmp_value, NULL); + } out: - return ret; + return ret; } int32_t -gf_store_iter_destroy (gf_store_iter_t *iter) +gf_store_iter_destroy(gf_store_iter_t *iter) { - int32_t ret = -1; - - if (!iter) - return 0; - - /* gf_store_iter_new will not return a valid iter object with iter->file - * being NULL*/ - ret = fclose (iter->file); - if (ret) - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, "Unable" - " to close file: %s, ret: %d" , - iter->filepath, ret); - - GF_FREE (iter); - return ret; + int32_t ret = -1; + + if (!iter) + return 0; + + /* gf_store_iter_new will not return a valid iter object with iter->file + * being NULL*/ + ret = fclose(iter->file); + if (ret) + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Unable" + " to close file: %s, ret: %d", + iter->filepath, ret); + + GF_FREE(iter); + return ret; } -char* -gf_store_strerror (gf_store_op_errno_t op_errno) +char * +gf_store_strerror(gf_store_op_errno_t op_errno) { - switch (op_errno) { + switch (op_errno) { case GD_STORE_SUCCESS: - return "Success"; + return "Success"; case GD_STORE_KEY_NULL: - return "Invalid Key"; + return "Invalid Key"; case GD_STORE_VALUE_NULL: - return "Invalid Value"; + return "Invalid Value"; case GD_STORE_KEY_VALUE_NULL: - return "Invalid Key and Value"; + return "Invalid Key and Value"; case GD_STORE_EOF: - return "No data"; + return "No data"; case GD_STORE_ENOMEM: - return "No memory"; + return "No memory"; default: - return "Invalid errno"; - } + return "Invalid errno"; + } } int -gf_store_lock (gf_store_handle_t *sh) +gf_store_lock(gf_store_handle_t *sh) { - int ret; - - GF_ASSERT (sh); - GF_ASSERT (sh->path); - GF_ASSERT (sh->locked == F_ULOCK); - - sh->fd = open (sh->path, O_RDWR); - if (sh->fd == -1) { - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, - "Failed to open '%s'", sh->path); - return -1; - } - - ret = lockf (sh->fd, F_LOCK, 0); - if (ret) - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_LOCK_FAILED, - "Failed to gain lock on '%s'", sh->path); - else - /* sh->locked is protected by the lockf(sh->fd) above */ - sh->locked = F_LOCK; - - return ret; + int ret; + + GF_ASSERT(sh); + GF_ASSERT(sh->path); + GF_ASSERT(sh->locked == F_ULOCK); + + sh->fd = open(sh->path, O_RDWR); + if (sh->fd == -1) { + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_FILE_OP_FAILED, + "Failed to open '%s'", sh->path); + return -1; + } + + ret = lockf(sh->fd, F_LOCK, 0); + if (ret) + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_LOCK_FAILED, + "Failed to gain lock on '%s'", sh->path); + else + /* sh->locked is protected by the lockf(sh->fd) above */ + sh->locked = F_LOCK; + + return ret; } void -gf_store_unlock (gf_store_handle_t *sh) +gf_store_unlock(gf_store_handle_t *sh) { - GF_ASSERT (sh); - GF_ASSERT (sh->locked == F_LOCK); + GF_ASSERT(sh); + GF_ASSERT(sh->locked == F_LOCK); - sh->locked = F_ULOCK; + sh->locked = F_ULOCK; - /* does not matter if this fails, locks are released on close anyway */ - if (lockf (sh->fd, F_ULOCK, 0) == -1) - gf_msg ("", GF_LOG_ERROR, errno, LG_MSG_UNLOCK_FAILED, - "Failed to release lock on '%s'", sh->path); + /* does not matter if this fails, locks are released on close anyway */ + if (lockf(sh->fd, F_ULOCK, 0) == -1) + gf_msg("", GF_LOG_ERROR, errno, LG_MSG_UNLOCK_FAILED, + "Failed to release lock on '%s'", sh->path); - sys_close (sh->fd); + sys_close(sh->fd); } int -gf_store_locked_local (gf_store_handle_t *sh) +gf_store_locked_local(gf_store_handle_t *sh) { - GF_ASSERT (sh); + GF_ASSERT(sh); - return (sh->locked == F_LOCK); + return (sh->locked == F_LOCK); } diff --git a/libglusterfs/src/strfd.c b/libglusterfs/src/strfd.c index 002d48629bc..ad66b622361 100644 --- a/libglusterfs/src/strfd.c +++ b/libglusterfs/src/strfd.c @@ -16,77 +16,78 @@ #include "common-utils.h" strfd_t * -strfd_open () +strfd_open() { - strfd_t *strfd = NULL; + strfd_t *strfd = NULL; - strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t); + strfd = GF_CALLOC(1, sizeof(*strfd), gf_common_mt_strfd_t); - return strfd; + return strfd; } int -strvprintf (strfd_t *strfd, const char *fmt, va_list ap) +strvprintf(strfd_t *strfd, const char *fmt, va_list ap) { - char *str = NULL; - int size = 0; - - size = vasprintf (&str, fmt, ap); - - if (size < 0) - return size; - - if (!strfd->alloc_size) { - strfd->data = GF_CALLOC (max(size + 1, 4096), 1, - gf_common_mt_strfd_data_t); - if (!strfd->data) { - free (str); /* NOT GF_FREE */ - return -1; - } - strfd->alloc_size = max(size + 1, 4096); - } + char *str = NULL; + int size = 0; + + size = vasprintf(&str, fmt, ap); + + if (size < 0) + return size; - if (strfd->alloc_size <= (strfd->size + size)) { - char *tmp_ptr = NULL; - int new_size = max ((strfd->alloc_size * 2), - gf_roundup_next_power_of_two (strfd->size + size + 1)); - tmp_ptr = GF_REALLOC (strfd->data, new_size); - if (!tmp_ptr) { - free (str); /* NOT GF_FREE */ - return -1; - } - strfd->alloc_size = new_size; - strfd->data = tmp_ptr; + if (!strfd->alloc_size) { + strfd->data = GF_CALLOC(max(size + 1, 4096), 1, + gf_common_mt_strfd_data_t); + if (!strfd->data) { + free(str); /* NOT GF_FREE */ + return -1; + } + strfd->alloc_size = max(size + 1, 4096); + } + + if (strfd->alloc_size <= (strfd->size + size)) { + char *tmp_ptr = NULL; + int new_size = max( + (strfd->alloc_size * 2), + gf_roundup_next_power_of_two(strfd->size + size + 1)); + tmp_ptr = GF_REALLOC(strfd->data, new_size); + if (!tmp_ptr) { + free(str); /* NOT GF_FREE */ + return -1; } + strfd->alloc_size = new_size; + strfd->data = tmp_ptr; + } - /* Copy the trailing '\0', but do not account for it in ->size. - This allows safe use of strfd->data as a string. */ - memcpy (strfd->data + strfd->size, str, size + 1); - strfd->size += size; + /* Copy the trailing '\0', but do not account for it in ->size. + This allows safe use of strfd->data as a string. */ + memcpy(strfd->data + strfd->size, str, size + 1); + strfd->size += size; - free (str); /* NOT GF_FREE */ + free(str); /* NOT GF_FREE */ - return size; + return size; } int -strprintf (strfd_t *strfd, const char *fmt, ...) +strprintf(strfd_t *strfd, const char *fmt, ...) { - int ret = 0; - va_list ap; + int ret = 0; + va_list ap; - va_start (ap, fmt); - ret = strvprintf (strfd, fmt, ap); - va_end (ap); + va_start(ap, fmt); + ret = strvprintf(strfd, fmt, ap); + va_end(ap); - return ret; + return ret; } int -strfd_close (strfd_t *strfd) +strfd_close(strfd_t *strfd) { - GF_FREE (strfd->data); - GF_FREE (strfd); + GF_FREE(strfd->data); + GF_FREE(strfd); - return 0; + return 0; } diff --git a/libglusterfs/src/syncop-utils.c b/libglusterfs/src/syncop-utils.c index 1ccda55e4c5..d2a71698745 100644 --- a/libglusterfs/src/syncop-utils.c +++ b/libglusterfs/src/syncop-utils.c @@ -14,39 +14,38 @@ #include "libglusterfs-messages.h" struct syncop_dir_scan_data { - xlator_t *subvol; - loc_t *parent; - void *data; - gf_dirent_t *q; - gf_dirent_t *entry; - pthread_cond_t *cond; - pthread_mutex_t *mut; - syncop_dir_scan_fn_t fn; - uint32_t *jobs_running; - uint32_t *qlen; - int32_t *retval; + xlator_t *subvol; + loc_t *parent; + void *data; + gf_dirent_t *q; + gf_dirent_t *entry; + pthread_cond_t *cond; + pthread_mutex_t *mut; + syncop_dir_scan_fn_t fn; + uint32_t *jobs_running; + uint32_t *qlen; + int32_t *retval; }; int -syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid) +syncop_dirfd(xlator_t *subvol, loc_t *loc, fd_t **fd, int pid) { - int ret = 0; - fd_t *dirfd = NULL; - - if (!fd) - return -EINVAL; - - dirfd = fd_create (loc->inode, pid); - if (!dirfd) { - gf_msg (subvol->name, GF_LOG_ERROR, errno, - LG_MSG_FD_CREATE_FAILED, "fd_create of %s", - uuid_utoa (loc->gfid)); - ret = -errno; - goto out; - } - - ret = syncop_opendir (subvol, loc, dirfd, NULL, NULL); - if (ret) { + int ret = 0; + fd_t *dirfd = NULL; + + if (!fd) + return -EINVAL; + + dirfd = fd_create(loc->inode, pid); + if (!dirfd) { + gf_msg(subvol->name, GF_LOG_ERROR, errno, LG_MSG_FD_CREATE_FAILED, + "fd_create of %s", uuid_utoa(loc->gfid)); + ret = -errno; + goto out; + } + + ret = syncop_opendir(subvol, loc, dirfd, NULL, NULL); + if (ret) { /* * On Linux, if the brick was not updated, opendir will * fail. We therefore use backward compatible code @@ -57,93 +56,95 @@ syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid) * to provide backward-compatibility. */ #ifdef GF_LINUX_HOST_OS - fd_unref (dirfd); - dirfd = fd_anonymous (loc->inode); - if (!dirfd) { - gf_msg (subvol->name, GF_LOG_ERROR, errno, - LG_MSG_FD_ANONYMOUS_FAILED, "fd_anonymous of " - "%s", uuid_utoa (loc->gfid)); - ret = -errno; - goto out; - } - ret = 0; -#else /* GF_LINUX_HOST_OS */ - fd_unref (dirfd); - gf_msg (subvol->name, GF_LOG_ERROR, errno, - LG_MSG_DIR_OP_FAILED, "opendir of %s", - uuid_utoa (loc->gfid)); - goto out; -#endif /* GF_LINUX_HOST_OS */ - } else { - fd_bind (dirfd); + fd_unref(dirfd); + dirfd = fd_anonymous(loc->inode); + if (!dirfd) { + gf_msg(subvol->name, GF_LOG_ERROR, errno, + LG_MSG_FD_ANONYMOUS_FAILED, + "fd_anonymous of " + "%s", + uuid_utoa(loc->gfid)); + ret = -errno; + goto out; } + ret = 0; +#else /* GF_LINUX_HOST_OS */ + fd_unref(dirfd); + gf_msg(subvol->name, GF_LOG_ERROR, errno, LG_MSG_DIR_OP_FAILED, + "opendir of %s", uuid_utoa(loc->gfid)); + goto out; +#endif /* GF_LINUX_HOST_OS */ + } else { + fd_bind(dirfd); + } out: - if (ret == 0) - *fd = dirfd; - return ret; + if (ret == 0) + *fd = dirfd; + return ret; } int -syncop_ftw (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, - void *data)) +syncop_ftw(xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn)(xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, + void *data)) { - loc_t child_loc = {0, }; - fd_t *fd = NULL; - uint64_t offset = 0; - gf_dirent_t *entry = NULL; - int ret = 0; - gf_dirent_t entries; - - ret = syncop_dirfd (subvol, loc, &fd, pid); - if (ret) - goto out; + loc_t child_loc = { + 0, + }; + fd_t *fd = NULL; + uint64_t offset = 0; + gf_dirent_t *entry = NULL; + int ret = 0; + gf_dirent_t entries; + + ret = syncop_dirfd(subvol, loc, &fd, pid); + if (ret) + goto out; + + INIT_LIST_HEAD(&entries.list); + + while ((ret = syncop_readdirp(subvol, fd, 131072, offset, &entries, NULL, + NULL))) { + if (ret < 0) + break; + + if (ret > 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } + list_for_each_entry(entry, &entries.list, list) + { + offset = entry->d_off; - INIT_LIST_HEAD (&entries.list); + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) + continue; - while ((ret = syncop_readdirp (subvol, fd, 131072, offset, &entries, - NULL, NULL))) { - if (ret < 0) - break; + gf_link_inode_from_dirent(NULL, fd->inode, entry); - if (ret > 0) { - /* If the entries are only '.', and '..' then ret - * value will be non-zero. so set it to zero here. */ - ret = 0; - } - list_for_each_entry (entry, &entries.list, list) { - offset = entry->d_off; - - if (!strcmp (entry->d_name, ".") || - !strcmp (entry->d_name, "..")) - continue; - - gf_link_inode_from_dirent (NULL, fd->inode, entry); - - ret = fn (subvol, entry, loc, data); - if (ret) - break; - - if (entry->d_stat.ia_type == IA_IFDIR) { - child_loc.inode = inode_ref (entry->inode); - gf_uuid_copy (child_loc.gfid, entry->inode->gfid); - ret = syncop_ftw (subvol, &child_loc, - pid, data, fn); - loc_wipe (&child_loc); - if (ret) - break; - } - } + ret = fn(subvol, entry, loc, data); + if (ret) + break; - gf_dirent_free (&entries); + if (entry->d_stat.ia_type == IA_IFDIR) { + child_loc.inode = inode_ref(entry->inode); + gf_uuid_copy(child_loc.gfid, entry->inode->gfid); + ret = syncop_ftw(subvol, &child_loc, pid, data, fn); + loc_wipe(&child_loc); if (ret) - break; + break; + } } + gf_dirent_free(&entries); + if (ret) + break; + } + out: - if (fd) - fd_unref (fd); - return ret; + if (fd) + fd_unref(fd); + return ret; } /** @@ -156,402 +157,399 @@ out: * syncop_ftw. */ int -syncop_ftw_throttle (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, - loc_t *parent, void *data), - int count, int sleep_time) +syncop_ftw_throttle(xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn)(xlator_t *subvol, gf_dirent_t *entry, + loc_t *parent, void *data), + int count, int sleep_time) { - loc_t child_loc = {0, }; - fd_t *fd = NULL; - uint64_t offset = 0; - gf_dirent_t *entry = NULL; - int ret = 0; - gf_dirent_t entries; - int tmp = 0; - - if (sleep_time <= 0) { - ret = syncop_ftw (subvol, loc, pid, data, fn); - goto out; - } + loc_t child_loc = { + 0, + }; + fd_t *fd = NULL; + uint64_t offset = 0; + gf_dirent_t *entry = NULL; + int ret = 0; + gf_dirent_t entries; + int tmp = 0; + + if (sleep_time <= 0) { + ret = syncop_ftw(subvol, loc, pid, data, fn); + goto out; + } + + ret = syncop_dirfd(subvol, loc, &fd, pid); + if (ret) + goto out; + + INIT_LIST_HEAD(&entries.list); + + while ((ret = syncop_readdirp(subvol, fd, 131072, offset, &entries, NULL, + NULL))) { + if (ret < 0) + break; - ret = syncop_dirfd (subvol, loc, &fd, pid); - if (ret) - goto out; + if (ret > 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } - INIT_LIST_HEAD (&entries.list); + tmp = 0; - while ((ret = syncop_readdirp (subvol, fd, 131072, offset, &entries, - NULL, NULL))) { - if (ret < 0) - break; + list_for_each_entry(entry, &entries.list, list) + { + offset = entry->d_off; - if (ret > 0) { - /* If the entries are only '.', and '..' then ret - * value will be non-zero. so set it to zero here. */ - ret = 0; - } + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) + continue; + if (++tmp >= count) { tmp = 0; + sleep(sleep_time); + } - list_for_each_entry (entry, &entries.list, list) { - offset = entry->d_off; - - if (!strcmp (entry->d_name, ".") || - !strcmp (entry->d_name, "..")) - continue; - - if (++tmp >= count) { - tmp = 0; - sleep (sleep_time); - } - - gf_link_inode_from_dirent (NULL, fd->inode, entry); - - ret = fn (subvol, entry, loc, data); - if (ret) - continue; - - if (entry->d_stat.ia_type == IA_IFDIR) { - child_loc.inode = inode_ref (entry->inode); - gf_uuid_copy (child_loc.gfid, entry->inode->gfid); - ret = syncop_ftw_throttle (subvol, &child_loc, - pid, data, fn, count, - sleep_time); - loc_wipe (&child_loc); - if (ret) - continue; - } - } + gf_link_inode_from_dirent(NULL, fd->inode, entry); + + ret = fn(subvol, entry, loc, data); + if (ret) + continue; - gf_dirent_free (&entries); + if (entry->d_stat.ia_type == IA_IFDIR) { + child_loc.inode = inode_ref(entry->inode); + gf_uuid_copy(child_loc.gfid, entry->inode->gfid); + ret = syncop_ftw_throttle(subvol, &child_loc, pid, data, fn, + count, sleep_time); + loc_wipe(&child_loc); if (ret) - break; + continue; + } } + gf_dirent_free(&entries); + if (ret) + break; + } + out: - if (fd) - fd_unref (fd); - return ret; + if (fd) + fd_unref(fd); + return ret; } static void -_scan_data_destroy (struct syncop_dir_scan_data *data) +_scan_data_destroy(struct syncop_dir_scan_data *data) { - GF_FREE (data); + GF_FREE(data); } static int -_dir_scan_job_fn_cbk (int ret, call_frame_t *frame, void *opaque) +_dir_scan_job_fn_cbk(int ret, call_frame_t *frame, void *opaque) { - struct syncop_dir_scan_data *scan_data = opaque; + struct syncop_dir_scan_data *scan_data = opaque; - _scan_data_destroy (scan_data); - return 0; + _scan_data_destroy(scan_data); + return 0; } static int -_dir_scan_job_fn (void *data) +_dir_scan_job_fn(void *data) { - struct syncop_dir_scan_data *scan_data = data; - gf_dirent_t *entry = NULL; - int ret = 0; - - entry = scan_data->entry; - scan_data->entry = NULL; - do { - ret = scan_data->fn (scan_data->subvol, entry, - scan_data->parent, - scan_data->data); - gf_dirent_entry_free (entry); - entry = NULL; - pthread_mutex_lock (scan_data->mut); - { - if (ret) - *scan_data->retval |= ret; - if (list_empty (&scan_data->q->list)) { - (*scan_data->jobs_running)--; - pthread_cond_broadcast (scan_data->cond); - } else { - entry = list_first_entry (&scan_data->q->list, - typeof (*scan_data->q), list); - list_del_init (&entry->list); - (*scan_data->qlen)--; - } - } - pthread_mutex_unlock (scan_data->mut); - } while (entry); + struct syncop_dir_scan_data *scan_data = data; + gf_dirent_t *entry = NULL; + int ret = 0; + + entry = scan_data->entry; + scan_data->entry = NULL; + do { + ret = scan_data->fn(scan_data->subvol, entry, scan_data->parent, + scan_data->data); + gf_dirent_entry_free(entry); + entry = NULL; + pthread_mutex_lock(scan_data->mut); + { + if (ret) + *scan_data->retval |= ret; + if (list_empty(&scan_data->q->list)) { + (*scan_data->jobs_running)--; + pthread_cond_broadcast(scan_data->cond); + } else { + entry = list_first_entry(&scan_data->q->list, + typeof(*scan_data->q), list); + list_del_init(&entry->list); + (*scan_data->qlen)--; + } + } + pthread_mutex_unlock(scan_data->mut); + } while (entry); - return ret; + return ret; } static int -_run_dir_scan_task (call_frame_t *frame, xlator_t *subvol, loc_t *parent, - gf_dirent_t *q, gf_dirent_t *entry, int *retval, - pthread_mutex_t *mut, pthread_cond_t *cond, - uint32_t *jobs_running, uint32_t *qlen, - syncop_dir_scan_fn_t fn, void *data) +_run_dir_scan_task(call_frame_t *frame, xlator_t *subvol, loc_t *parent, + gf_dirent_t *q, gf_dirent_t *entry, int *retval, + pthread_mutex_t *mut, pthread_cond_t *cond, + uint32_t *jobs_running, uint32_t *qlen, + syncop_dir_scan_fn_t fn, void *data) { - int ret = 0; - struct syncop_dir_scan_data *scan_data = NULL; - - - scan_data = GF_CALLOC (1, sizeof (struct syncop_dir_scan_data), - gf_common_mt_scan_data); - if (!scan_data) { - ret = -ENOMEM; - goto out; - } - - scan_data->subvol = subvol; - scan_data->parent = parent; - scan_data->data = data; - scan_data->mut = mut; - scan_data->cond = cond; - scan_data->fn = fn; - scan_data->jobs_running = jobs_running; - scan_data->entry = entry; - scan_data->q = q; - scan_data->qlen = qlen; - scan_data->retval = retval; - - ret = synctask_new (subvol->ctx->env, _dir_scan_job_fn, - _dir_scan_job_fn_cbk, frame, scan_data); + int ret = 0; + struct syncop_dir_scan_data *scan_data = NULL; + + scan_data = GF_CALLOC(1, sizeof(struct syncop_dir_scan_data), + gf_common_mt_scan_data); + if (!scan_data) { + ret = -ENOMEM; + goto out; + } + + scan_data->subvol = subvol; + scan_data->parent = parent; + scan_data->data = data; + scan_data->mut = mut; + scan_data->cond = cond; + scan_data->fn = fn; + scan_data->jobs_running = jobs_running; + scan_data->entry = entry; + scan_data->q = q; + scan_data->qlen = qlen; + scan_data->retval = retval; + + ret = synctask_new(subvol->ctx->env, _dir_scan_job_fn, _dir_scan_job_fn_cbk, + frame, scan_data); out: - if (ret < 0) { - gf_dirent_entry_free (entry); - _scan_data_destroy (scan_data); - pthread_mutex_lock (mut); - { - *jobs_running = *jobs_running - 1; - } - pthread_mutex_unlock (mut); - /*No need to cond-broadcast*/ + if (ret < 0) { + gf_dirent_entry_free(entry); + _scan_data_destroy(scan_data); + pthread_mutex_lock(mut); + { + *jobs_running = *jobs_running - 1; } - return ret; + pthread_mutex_unlock(mut); + /*No need to cond-broadcast*/ + } + return ret; } int -syncop_mt_dir_scan (call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid, - void *data, syncop_dir_scan_fn_t fn, dict_t *xdata, - uint32_t max_jobs, uint32_t max_qlen) +syncop_mt_dir_scan(call_frame_t *frame, xlator_t *subvol, loc_t *loc, int pid, + void *data, syncop_dir_scan_fn_t fn, dict_t *xdata, + uint32_t max_jobs, uint32_t max_qlen) { - fd_t *fd = NULL; - uint64_t offset = 0; - gf_dirent_t *last = NULL; - int ret = 0; - int retval = 0; - gf_dirent_t q; - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; - uint32_t jobs_running = 0; - uint32_t qlen = 0; - pthread_cond_t cond; - pthread_mutex_t mut; - gf_boolean_t cond_init = _gf_false; - gf_boolean_t mut_init = _gf_false; - gf_dirent_t entries; - - /*For this functionality to be implemented in general, we need - * synccond_t infra which doesn't block the executing thread. Until then - * return failures inside synctask if they use this.*/ - if (synctask_get()) - return -ENOTSUP; - - if (max_jobs == 0) - return -EINVAL; - - /*Code becomes simpler this way. cond_wait just on qlength. - * Little bit of cheating*/ - if (max_qlen == 0) - max_qlen = 1; - - ret = syncop_dirfd (subvol, loc, &fd, pid); - if (ret) - goto out; + fd_t *fd = NULL; + uint64_t offset = 0; + gf_dirent_t *last = NULL; + int ret = 0; + int retval = 0; + gf_dirent_t q; + gf_dirent_t *entry = NULL; + gf_dirent_t *tmp = NULL; + uint32_t jobs_running = 0; + uint32_t qlen = 0; + pthread_cond_t cond; + pthread_mutex_t mut; + gf_boolean_t cond_init = _gf_false; + gf_boolean_t mut_init = _gf_false; + gf_dirent_t entries; + + /*For this functionality to be implemented in general, we need + * synccond_t infra which doesn't block the executing thread. Until then + * return failures inside synctask if they use this.*/ + if (synctask_get()) + return -ENOTSUP; + + if (max_jobs == 0) + return -EINVAL; + + /*Code becomes simpler this way. cond_wait just on qlength. + * Little bit of cheating*/ + if (max_qlen == 0) + max_qlen = 1; + + ret = syncop_dirfd(subvol, loc, &fd, pid); + if (ret) + goto out; + + INIT_LIST_HEAD(&entries.list); + INIT_LIST_HEAD(&q.list); + ret = pthread_mutex_init(&mut, NULL); + if (ret) + goto out; + mut_init = _gf_true; + + ret = pthread_cond_init(&cond, NULL); + if (ret) + goto out; + cond_init = _gf_true; + + while ((ret = syncop_readdir(subvol, fd, 131072, offset, &entries, xdata, + NULL))) { + if (ret < 0) + break; - INIT_LIST_HEAD (&entries.list); - INIT_LIST_HEAD (&q.list); - ret = pthread_mutex_init (&mut, NULL); - if (ret) - goto out; - mut_init = _gf_true; + if (ret > 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } - ret = pthread_cond_init (&cond, NULL); - if (ret) - goto out; - cond_init = _gf_true; + last = list_last_entry(&entries.list, typeof(*last), list); + offset = last->d_off; - while ((ret = syncop_readdir (subvol, fd, 131072, offset, &entries, - xdata, NULL))) { - if (ret < 0) - break; + list_for_each_entry_safe(entry, tmp, &entries.list, list) + { + list_del_init(&entry->list); + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) { + gf_dirent_entry_free(entry); + continue; + } - if (ret > 0) { - /* If the entries are only '.', and '..' then ret - * value will be non-zero. so set it to zero here. */ - ret = 0; - } + if (entry->d_type == IA_IFDIR) { + ret = fn(subvol, entry, loc, data); + gf_dirent_entry_free(entry); + if (ret) + goto out; + continue; + } + + if (retval) /*Any jobs failed?*/ + goto out; - last = list_last_entry (&entries.list, typeof (*last), list); - offset = last->d_off; - - list_for_each_entry_safe (entry, tmp, &entries.list, list) { - list_del_init (&entry->list); - if (!strcmp (entry->d_name, ".") || - !strcmp (entry->d_name, "..")) { - gf_dirent_entry_free (entry); - continue; - } - - if (entry->d_type == IA_IFDIR) { - ret = fn (subvol, entry, loc, data); - gf_dirent_entry_free (entry); - if (ret) - goto out; - continue; - } - - if (retval) /*Any jobs failed?*/ - goto out; - - pthread_mutex_lock (&mut); - { - while (qlen == max_qlen) - pthread_cond_wait (&cond, &mut); - if (max_jobs == jobs_running) { - list_add_tail (&entry->list, &q.list); - qlen++; - entry = NULL; - } else { - jobs_running++; - } - } - pthread_mutex_unlock (&mut); - - - if (!entry) - continue; - - ret = _run_dir_scan_task (frame, subvol, loc, &q, entry, - &retval, &mut, &cond, - &jobs_running, &qlen, fn, data); - if (ret) - goto out; + pthread_mutex_lock(&mut); + { + while (qlen == max_qlen) + pthread_cond_wait(&cond, &mut); + if (max_jobs == jobs_running) { + list_add_tail(&entry->list, &q.list); + qlen++; + entry = NULL; + } else { + jobs_running++; } + } + pthread_mutex_unlock(&mut); + + if (!entry) + continue; + + ret = _run_dir_scan_task(frame, subvol, loc, &q, entry, &retval, + &mut, &cond, &jobs_running, &qlen, fn, + data); + if (ret) + goto out; } + } out: - if (fd) - fd_unref (fd); - if (mut_init && cond_init) { - pthread_mutex_lock (&mut); - { - while (jobs_running) - pthread_cond_wait (&cond, &mut); - } - pthread_mutex_unlock (&mut); - gf_dirent_free (&q); - gf_dirent_free (&entries); + if (fd) + fd_unref(fd); + if (mut_init && cond_init) { + pthread_mutex_lock(&mut); + { + while (jobs_running) + pthread_cond_wait(&cond, &mut); } - - if (mut_init) - pthread_mutex_destroy (&mut); - if (cond_init) - pthread_cond_destroy (&cond); - return ret|retval; + pthread_mutex_unlock(&mut); + gf_dirent_free(&q); + gf_dirent_free(&entries); + } + + if (mut_init) + pthread_mutex_destroy(&mut); + if (cond_init) + pthread_cond_destroy(&cond); + return ret | retval; } int -syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data, - int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, - void *data)) +syncop_dir_scan(xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn)(xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, + void *data)) { - fd_t *fd = NULL; - uint64_t offset = 0; - gf_dirent_t *entry = NULL; - int ret = 0; - gf_dirent_t entries; + fd_t *fd = NULL; + uint64_t offset = 0; + gf_dirent_t *entry = NULL; + int ret = 0; + gf_dirent_t entries; - ret = syncop_dirfd (subvol, loc, &fd, pid); - if (ret) - goto out; + ret = syncop_dirfd(subvol, loc, &fd, pid); + if (ret) + goto out; - INIT_LIST_HEAD (&entries.list); + INIT_LIST_HEAD(&entries.list); - while ((ret = syncop_readdir (subvol, fd, 131072, offset, &entries, - NULL, NULL))) { - if (ret < 0) - break; + while ((ret = syncop_readdir(subvol, fd, 131072, offset, &entries, NULL, + NULL))) { + if (ret < 0) + break; - if (ret > 0) { - /* If the entries are only '.', and '..' then ret - * value will be non-zero. so set it to zero here. */ - ret = 0; - } + if (ret > 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } - list_for_each_entry (entry, &entries.list, list) { - offset = entry->d_off; + list_for_each_entry(entry, &entries.list, list) + { + offset = entry->d_off; - if (!strcmp (entry->d_name, ".") || - !strcmp (entry->d_name, "..")) - continue; + if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) + continue; - ret = fn (subvol, entry, loc, data); - if (ret) - break; - } - gf_dirent_free (&entries); - if (ret) - break; + ret = fn(subvol, entry, loc, data); + if (ret) + break; } + gf_dirent_free(&entries); + if (ret) + break; + } out: - if (fd) - fd_unref (fd); - return ret; + if (fd) + fd_unref(fd); + return ret; } int -syncop_is_subvol_local (xlator_t *this, loc_t *loc, gf_boolean_t *is_local) +syncop_is_subvol_local(xlator_t *this, loc_t *loc, gf_boolean_t *is_local) { - char *pathinfo = NULL; - dict_t *xattr = NULL; - int ret = 0; + char *pathinfo = NULL; + dict_t *xattr = NULL; + int ret = 0; - if (!this || !this->type || !is_local) - return -EINVAL; + if (!this || !this->type || !is_local) + return -EINVAL; - if (strcmp (this->type, "protocol/client") != 0) - return -EINVAL; + if (strcmp(this->type, "protocol/client") != 0) + return -EINVAL; - *is_local = _gf_false; + *is_local = _gf_false; - ret = syncop_getxattr (this, loc, &xattr, GF_XATTR_PATHINFO_KEY, NULL, - NULL); - if (ret < 0) { - ret = -1; - goto out; - } + ret = syncop_getxattr(this, loc, &xattr, GF_XATTR_PATHINFO_KEY, NULL, NULL); + if (ret < 0) { + ret = -1; + goto out; + } - if (!xattr) { - ret = -EINVAL; - goto out; - } + if (!xattr) { + ret = -EINVAL; + goto out; + } - ret = dict_get_str (xattr, GF_XATTR_PATHINFO_KEY, &pathinfo); - if (ret) - goto out; + ret = dict_get_str(xattr, GF_XATTR_PATHINFO_KEY, &pathinfo); + if (ret) + goto out; - ret = glusterfs_is_local_pathinfo (pathinfo, is_local); + ret = glusterfs_is_local_pathinfo(pathinfo, is_local); - gf_msg_debug (this->name, 0, "subvol %s is %slocal", - this->name, *is_local ? "" : "not "); + gf_msg_debug(this->name, 0, "subvol %s is %slocal", this->name, + *is_local ? "" : "not "); out: - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - return ret; + return ret; } /** @@ -565,109 +563,112 @@ out: **/ int -syncop_gfid_to_path_hard (inode_table_t *itable, xlator_t *subvol, uuid_t gfid, - inode_t *inode, char **path_p, - gf_boolean_t hard_resolve) +syncop_gfid_to_path_hard(inode_table_t *itable, xlator_t *subvol, uuid_t gfid, + inode_t *inode, char **path_p, + gf_boolean_t hard_resolve) { - int ret = 0; - char *path = NULL; - loc_t loc = {0,}; - dict_t *xattr = NULL; - - gf_uuid_copy (loc.gfid, gfid); - - if (!inode) - loc.inode = inode_new (itable); - else - loc.inode = inode_ref (inode); - - if (!hard_resolve) - ret = syncop_getxattr (subvol, &loc, &xattr, GFID_TO_PATH_KEY, - NULL, NULL); - else - ret = syncop_getxattr (subvol, &loc, &xattr, - GFID2PATH_VIRT_XATTR_KEY, NULL, NULL); - - if (ret < 0) - goto out; - - - /* - * posix will do dict_set_dynstr for GFID_TO_PATH_KEY i.e. - * for in memory search for the path. And for on disk xattr - * fetching of the path for the key GFID2PATH_VIRT_XATTR_KEY - * it uses dict_set_dynptr. So, for GFID2PATH_VIRT_XATTR_KEY - * use dict_get_ptr to avoid dict complaining about type - * mismatch (i.e. str vs ptr) - */ - if (!hard_resolve) - ret = dict_get_str (xattr, GFID_TO_PATH_KEY, &path); - else - ret = dict_get_ptr (xattr, GFID2PATH_VIRT_XATTR_KEY, - (void **)&path); - - if (ret || !path) { - ret = -EINVAL; - goto out; - } - - if (path_p) { - *path_p = gf_strdup (path); - if (!*path_p) { - ret = -ENOMEM; - goto out; - } + int ret = 0; + char *path = NULL; + loc_t loc = { + 0, + }; + dict_t *xattr = NULL; + + gf_uuid_copy(loc.gfid, gfid); + + if (!inode) + loc.inode = inode_new(itable); + else + loc.inode = inode_ref(inode); + + if (!hard_resolve) + ret = syncop_getxattr(subvol, &loc, &xattr, GFID_TO_PATH_KEY, NULL, + NULL); + else + ret = syncop_getxattr(subvol, &loc, &xattr, GFID2PATH_VIRT_XATTR_KEY, + NULL, NULL); + + if (ret < 0) + goto out; + + /* + * posix will do dict_set_dynstr for GFID_TO_PATH_KEY i.e. + * for in memory search for the path. And for on disk xattr + * fetching of the path for the key GFID2PATH_VIRT_XATTR_KEY + * it uses dict_set_dynptr. So, for GFID2PATH_VIRT_XATTR_KEY + * use dict_get_ptr to avoid dict complaining about type + * mismatch (i.e. str vs ptr) + */ + if (!hard_resolve) + ret = dict_get_str(xattr, GFID_TO_PATH_KEY, &path); + else + ret = dict_get_ptr(xattr, GFID2PATH_VIRT_XATTR_KEY, (void **)&path); + + if (ret || !path) { + ret = -EINVAL; + goto out; + } + + if (path_p) { + *path_p = gf_strdup(path); + if (!*path_p) { + ret = -ENOMEM; + goto out; } + } - ret = 0; + ret = 0; out: - if (xattr) - dict_unref (xattr); - loc_wipe (&loc); + if (xattr) + dict_unref(xattr); + loc_wipe(&loc); - return ret; + return ret; } int -syncop_gfid_to_path (inode_table_t *itable, xlator_t *subvol, uuid_t gfid, - char **path_p) +syncop_gfid_to_path(inode_table_t *itable, xlator_t *subvol, uuid_t gfid, + char **path_p) { - return syncop_gfid_to_path_hard (itable, subvol, gfid, NULL, path_p, - _gf_false); + return syncop_gfid_to_path_hard(itable, subvol, gfid, NULL, path_p, + _gf_false); } int -syncop_inode_find (xlator_t *this, xlator_t *subvol, - uuid_t gfid, inode_t **inode, - dict_t *xdata, dict_t **rsp_dict) +syncop_inode_find(xlator_t *this, xlator_t *subvol, uuid_t gfid, + inode_t **inode, dict_t *xdata, dict_t **rsp_dict) { - int ret = 0; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - *inode = NULL; - - *inode = inode_find (this->itable, gfid); - if (*inode) - goto out; - - loc.inode = inode_new (this->itable); - if (!loc.inode) { - ret = -ENOMEM; - goto out; - } - gf_uuid_copy (loc.gfid, gfid); - - ret = syncop_lookup (subvol, &loc, &iatt, NULL, xdata, rsp_dict); - if (ret < 0) - goto out; - - *inode = inode_link (loc.inode, NULL, NULL, &iatt); - if (!*inode) { - ret = -ENOMEM; - goto out; - } + int ret = 0; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + *inode = NULL; + + *inode = inode_find(this->itable, gfid); + if (*inode) + goto out; + + loc.inode = inode_new(this->itable); + if (!loc.inode) { + ret = -ENOMEM; + goto out; + } + gf_uuid_copy(loc.gfid, gfid); + + ret = syncop_lookup(subvol, &loc, &iatt, NULL, xdata, rsp_dict); + if (ret < 0) + goto out; + + *inode = inode_link(loc.inode, NULL, NULL, &iatt); + if (!*inode) { + ret = -ENOMEM; + goto out; + } out: - loc_wipe (&loc); - return ret; + loc_wipe(&loc); + return ret; } diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 8323dd71a10..ec646425d74 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -12,2758 +12,2742 @@ #include "libglusterfs-messages.h" int -syncopctx_setfsuid (void *uid) -{ - struct syncopctx *opctx = NULL; - int ret = 0; - - /* In args check */ - if (!uid) { - 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; - } - } +syncopctx_setfsuid(void *uid) +{ + struct syncopctx *opctx = NULL; + int ret = 0; + + /* In args check */ + if (!uid) { + 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 && uid) { - opctx->uid = *(uid_t *)uid; - opctx->valid |= SYNCOPCTX_UID; - } + if (opctx && uid) { + opctx->uid = *(uid_t *)uid; + opctx->valid |= SYNCOPCTX_UID; + } - return ret; + return ret; } int -syncopctx_setfsgid (void *gid) +syncopctx_setfsgid(void *gid) { - struct syncopctx *opctx = NULL; - int ret = 0; + struct syncopctx *opctx = NULL; + int ret = 0; - /* In args check */ - if (!gid) { - ret = -1; - errno = EINVAL; - goto out; - } + /* In args check */ + if (!gid) { + ret = -1; + errno = EINVAL; + goto out; + } - opctx = syncopctx_getctx (); + 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; - } + /* 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; - } - } + ret = syncopctx_setctx(opctx); + if (ret != 0) { + GF_FREE(opctx); + opctx = NULL; + goto out; + } + } out: - if (opctx && gid) { - opctx->gid = *(gid_t *)gid; - opctx->valid |= SYNCOPCTX_GID; - } - - return ret; -} - -int -syncopctx_setfsgroups (int count, const void *groups) -{ - struct syncopctx *opctx = NULL; - gid_t *tmpgroups = NULL; - int ret = 0; - - /* In args check */ - if (count != 0 && !groups) { - 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; - } - } - - /* resize internal groups as required */ - if (count && opctx->grpsize < count) { - if (opctx->groups) { - tmpgroups = GF_REALLOC (opctx->groups, - (sizeof (gid_t) * count)); - /* NOTE: Not really required to zero the reallocation, - * as ngrps controls the validity of data, - * making a note irrespective */ - if (tmpgroups == NULL) { - opctx->grpsize = 0; - GF_FREE (opctx->groups); - opctx->groups = NULL; - ret = -1; - goto out; - } - } - else { - tmpgroups = GF_CALLOC (count, sizeof (gid_t), - gf_common_mt_syncopctx); - if (tmpgroups == NULL) { - opctx->grpsize = 0; - ret = -1; - goto out; - } - } - - opctx->groups = tmpgroups; - opctx->grpsize = count; - } - - /* copy out the groups passed */ - if (count) - memcpy (opctx->groups, groups, (sizeof (gid_t) * count)); - - /* set/reset the ngrps, this is where reset of groups is handled */ - opctx->ngrps = count; - opctx->valid |= SYNCOPCTX_GROUPS; + if (opctx && gid) { + opctx->gid = *(gid_t *)gid; + opctx->valid |= SYNCOPCTX_GID; + } + + return ret; +} + +int +syncopctx_setfsgroups(int count, const void *groups) +{ + struct syncopctx *opctx = NULL; + gid_t *tmpgroups = NULL; + int ret = 0; + + /* In args check */ + if (count != 0 && !groups) { + 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; + } + } + + /* resize internal groups as required */ + if (count && opctx->grpsize < count) { + if (opctx->groups) { + tmpgroups = GF_REALLOC(opctx->groups, (sizeof(gid_t) * count)); + /* NOTE: Not really required to zero the reallocation, + * as ngrps controls the validity of data, + * making a note irrespective */ + if (tmpgroups == NULL) { + opctx->grpsize = 0; + GF_FREE(opctx->groups); + opctx->groups = NULL; + ret = -1; + goto out; + } + } else { + tmpgroups = GF_CALLOC(count, sizeof(gid_t), gf_common_mt_syncopctx); + if (tmpgroups == NULL) { + opctx->grpsize = 0; + ret = -1; + goto out; + } + } + + opctx->groups = tmpgroups; + opctx->grpsize = count; + } + + /* copy out the groups passed */ + if (count) + memcpy(opctx->groups, groups, (sizeof(gid_t) * count)); + + /* set/reset the ngrps, this is where reset of groups is handled */ + opctx->ngrps = count; + opctx->valid |= SYNCOPCTX_GROUPS; out: - return ret; + return ret; } int -syncopctx_setfspid (void *pid) +syncopctx_setfspid(void *pid) { - struct syncopctx *opctx = NULL; - int ret = 0; + struct syncopctx *opctx = NULL; + int ret = 0; - /* In args check */ - if (!pid) { - ret = -1; - errno = EINVAL; - goto out; - } + /* In args check */ + if (!pid) { + ret = -1; + errno = EINVAL; + goto out; + } - opctx = syncopctx_getctx (); + 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; - } + /* 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; - } - } + 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; - } + if (opctx && pid) { + opctx->pid = *(pid_t *)pid; + opctx->valid |= SYNCOPCTX_PID; + } - return ret; + return ret; } int -syncopctx_setfslkowner (gf_lkowner_t *lk_owner) +syncopctx_setfslkowner(gf_lkowner_t *lk_owner) { - struct syncopctx *opctx = NULL; - int ret = 0; + struct syncopctx *opctx = NULL; + int ret = 0; - /* In args check */ - if (!lk_owner) { - ret = -1; - errno = EINVAL; - goto out; - } + /* In args check */ + if (!lk_owner) { + ret = -1; + errno = EINVAL; + goto out; + } - opctx = syncopctx_getctx (); + opctx = syncopctx_getctx(); - /* alloc for this thread the first time */ + /* alloc for this thread the first time */ + if (!opctx) { + opctx = GF_CALLOC(1, sizeof(*opctx), gf_common_mt_syncopctx); if (!opctx) { - opctx = GF_CALLOC (1, sizeof (*opctx), gf_common_mt_syncopctx); - if (!opctx) { - ret = -1; - goto out; - } + ret = -1; + goto out; + } - ret = syncopctx_setctx (opctx); - if (ret != 0) { - GF_FREE (opctx); - opctx = NULL; - goto out; - } + ret = syncopctx_setctx(opctx); + if (ret != 0) { + GF_FREE(opctx); + opctx = NULL; + goto out; } + } out: - if (opctx && lk_owner) { - opctx->lk_owner = *lk_owner; - opctx->valid |= SYNCOPCTX_LKOWNER; - } + if (opctx && lk_owner) { + opctx->lk_owner = *lk_owner; + opctx->valid |= SYNCOPCTX_LKOWNER; + } - return ret; + return ret; } static void -__run (struct synctask *task) +__run(struct synctask *task) { - struct syncenv *env = NULL; + struct syncenv *env = NULL; - env = task->env; + env = task->env; - list_del_init (&task->all_tasks); - switch (task->state) { + list_del_init(&task->all_tasks); + switch (task->state) { case SYNCTASK_INIT: case SYNCTASK_SUSPEND: - break; + break; case SYNCTASK_RUN: - gf_msg_debug (task->xl->name, 0, "re-running already running" - " task"); - env->runcount--; - break; + gf_msg_debug(task->xl->name, 0, + "re-running already running" + " task"); + env->runcount--; + break; case SYNCTASK_WAIT: - env->waitcount--; - break; + env->waitcount--; + break; case SYNCTASK_DONE: - gf_msg (task->xl->name, GF_LOG_WARNING, 0, - LG_MSG_COMPLETED_TASK, "running completed task"); - return; - case SYNCTASK_ZOMBIE: - gf_msg (task->xl->name, GF_LOG_WARNING, 0, - LG_MSG_WAKE_UP_ZOMBIE, "attempted to wake up " - "zombie!!"); - return; - } + gf_msg(task->xl->name, GF_LOG_WARNING, 0, LG_MSG_COMPLETED_TASK, + "running completed task"); + return; + case SYNCTASK_ZOMBIE: + gf_msg(task->xl->name, GF_LOG_WARNING, 0, LG_MSG_WAKE_UP_ZOMBIE, + "attempted to wake up " + "zombie!!"); + return; + } - list_add_tail (&task->all_tasks, &env->runq); - env->runcount++; - task->state = SYNCTASK_RUN; + list_add_tail(&task->all_tasks, &env->runq); + env->runcount++; + task->state = SYNCTASK_RUN; } - static void -__wait (struct synctask *task) +__wait(struct synctask *task) { - struct syncenv *env = NULL; + struct syncenv *env = NULL; - env = task->env; + env = task->env; - list_del_init (&task->all_tasks); - switch (task->state) { + list_del_init(&task->all_tasks); + switch (task->state) { case SYNCTASK_INIT: case SYNCTASK_SUSPEND: - break; + break; case SYNCTASK_RUN: - env->runcount--; - break; + env->runcount--; + break; case SYNCTASK_WAIT: - gf_msg (task->xl->name, GF_LOG_WARNING, 0, - LG_MSG_REWAITING_TASK, "re-waiting already waiting " - "task"); - env->waitcount--; - break; + gf_msg(task->xl->name, GF_LOG_WARNING, 0, LG_MSG_REWAITING_TASK, + "re-waiting already waiting " + "task"); + env->waitcount--; + break; case SYNCTASK_DONE: - gf_msg (task->xl->name, GF_LOG_WARNING, 0, - LG_MSG_COMPLETED_TASK, - "running completed task"); - return; - case SYNCTASK_ZOMBIE: - gf_msg (task->xl->name, GF_LOG_WARNING, 0, - LG_MSG_SLEEP_ZOMBIE, - "attempted to sleep a zombie!!"); - return; - } + gf_msg(task->xl->name, GF_LOG_WARNING, 0, LG_MSG_COMPLETED_TASK, + "running completed task"); + return; + case SYNCTASK_ZOMBIE: + gf_msg(task->xl->name, GF_LOG_WARNING, 0, LG_MSG_SLEEP_ZOMBIE, + "attempted to sleep a zombie!!"); + return; + } - list_add_tail (&task->all_tasks, &env->waitq); - env->waitcount++; - task->state = SYNCTASK_WAIT; + list_add_tail(&task->all_tasks, &env->waitq); + env->waitcount++; + task->state = SYNCTASK_WAIT; } - void -synctask_yield (struct synctask *task) +synctask_yield(struct synctask *task) { - xlator_t *oldTHIS = THIS; + xlator_t *oldTHIS = THIS; #if defined(__NetBSD__) && defined(_UC_TLSBASE) - /* Preserve pthread private pointer through swapcontex() */ - task->proc->sched.uc_flags &= ~_UC_TLSBASE; + /* Preserve pthread private pointer through swapcontex() */ + task->proc->sched.uc_flags &= ~_UC_TLSBASE; #endif - if (task->state != SYNCTASK_DONE) { - task->state = SYNCTASK_SUSPEND; - (void) gf_backtrace_save (task->btbuf); - } - if (swapcontext (&task->ctx, &task->proc->sched) < 0) { - gf_msg ("syncop", GF_LOG_ERROR, errno, - LG_MSG_SWAPCONTEXT_FAILED, "swapcontext failed"); - } + if (task->state != SYNCTASK_DONE) { + task->state = SYNCTASK_SUSPEND; + (void)gf_backtrace_save(task->btbuf); + } + if (swapcontext(&task->ctx, &task->proc->sched) < 0) { + gf_msg("syncop", GF_LOG_ERROR, errno, LG_MSG_SWAPCONTEXT_FAILED, + "swapcontext failed"); + } - THIS = oldTHIS; + THIS = oldTHIS; } - void -synctask_wake (struct synctask *task) +synctask_wake(struct synctask *task) { - struct syncenv *env = NULL; + struct syncenv *env = NULL; - env = task->env; + env = task->env; - pthread_mutex_lock (&env->mutex); - { - task->woken = 1; + pthread_mutex_lock(&env->mutex); + { + task->woken = 1; - if (task->slept) - __run (task); + if (task->slept) + __run(task); - pthread_cond_broadcast (&env->cond); - } - pthread_mutex_unlock (&env->mutex); + pthread_cond_broadcast(&env->cond); + } + pthread_mutex_unlock(&env->mutex); } void -synctask_wrap (void) +synctask_wrap(void) { - struct synctask *task = NULL; + struct synctask *task = NULL; - /* Do not trust the pointer received. It may be - wrong and can lead to crashes. */ + /* Do not trust the pointer received. It may be + wrong and can lead to crashes. */ - task = synctask_get (); - task->ret = task->syncfn (task->opaque); - if (task->synccbk) - task->synccbk (task->ret, task->frame, task->opaque); + task = synctask_get(); + task->ret = task->syncfn(task->opaque); + if (task->synccbk) + task->synccbk(task->ret, task->frame, task->opaque); - task->state = SYNCTASK_DONE; + task->state = SYNCTASK_DONE; - synctask_yield (task); + synctask_yield(task); } - void -synctask_destroy (struct synctask *task) +synctask_destroy(struct synctask *task) { - if (!task) - return; + if (!task) + return; - GF_FREE (task->stack); + GF_FREE(task->stack); - if (task->opframe) - STACK_DESTROY (task->opframe->root); + if (task->opframe) + STACK_DESTROY(task->opframe->root); - if (task->synccbk == NULL) { - pthread_mutex_destroy (&task->mutex); - pthread_cond_destroy (&task->cond); - } + if (task->synccbk == NULL) { + pthread_mutex_destroy(&task->mutex); + pthread_cond_destroy(&task->cond); + } - GF_FREE (task); + GF_FREE(task); } - void -synctask_done (struct synctask *task) +synctask_done(struct synctask *task) { - if (task->synccbk) { - synctask_destroy (task); - return; - } + if (task->synccbk) { + synctask_destroy(task); + return; + } - pthread_mutex_lock (&task->mutex); - { - task->state = SYNCTASK_ZOMBIE; - task->done = 1; - pthread_cond_broadcast (&task->cond); - } - pthread_mutex_unlock (&task->mutex); + pthread_mutex_lock(&task->mutex); + { + task->state = SYNCTASK_ZOMBIE; + task->done = 1; + pthread_cond_broadcast(&task->cond); + } + pthread_mutex_unlock(&task->mutex); } - int -synctask_setid (struct synctask *task, uid_t uid, gid_t gid) +synctask_setid(struct synctask *task, uid_t uid, gid_t gid) { - if (!task) - return -1; + if (!task) + return -1; - if (uid != -1) - task->uid = uid; + if (uid != -1) + task->uid = uid; - if (gid != -1) - task->gid = gid; + if (gid != -1) + task->gid = gid; - return 0; + return 0; } - struct synctask * -synctask_create (struct syncenv *env, size_t stacksize, synctask_fn_t fn, - synctask_cbk_t cbk, call_frame_t *frame, void *opaque) +synctask_create(struct syncenv *env, size_t stacksize, synctask_fn_t fn, + synctask_cbk_t cbk, call_frame_t *frame, void *opaque) { - struct synctask *newtask = NULL; - xlator_t *this = THIS; - int destroymode = 0; - - VALIDATE_OR_GOTO (env, err); - VALIDATE_OR_GOTO (fn, err); - - /* Check if the syncenv is in destroymode i.e. destroy is SET. - * If YES, then don't allow any new synctasks on it. Return NULL. - */ - pthread_mutex_lock (&env->mutex); - { - destroymode = env->destroy; - } - pthread_mutex_unlock (&env->mutex); - - /* syncenv is in DESTROY mode, return from here */ - if (destroymode) - return NULL; - - newtask = GF_CALLOC (1, sizeof (*newtask), gf_common_mt_synctask); - if (!newtask) - return NULL; - - newtask->frame = frame; - if (!frame) { - newtask->opframe = create_frame (this, this->ctx->pool); - if (!newtask->opframe) - goto err; - set_lk_owner_from_ptr (&newtask->opframe->root->lk_owner, - newtask->opframe->root); - } else { - newtask->opframe = copy_frame (frame); - } - if (!newtask->opframe) - goto err; - newtask->env = env; - newtask->xl = this; - newtask->syncfn = fn; - newtask->synccbk = cbk; - newtask->opaque = opaque; - - /* default to the uid/gid of the passed frame */ - newtask->uid = newtask->opframe->root->uid; - newtask->gid = newtask->opframe->root->gid; - - INIT_LIST_HEAD (&newtask->all_tasks); - INIT_LIST_HEAD (&newtask->waitq); - - if (getcontext (&newtask->ctx) < 0) { - gf_msg ("syncop", GF_LOG_ERROR, errno, - LG_MSG_GETCONTEXT_FAILED, "getcontext failed"); - goto err; - } + struct synctask *newtask = NULL; + xlator_t *this = THIS; + int destroymode = 0; - if (stacksize <= 0) { - newtask->stack = GF_CALLOC (1, env->stacksize, - gf_common_mt_syncstack); - newtask->ctx.uc_stack.ss_size = env->stacksize; - } else { - newtask->stack = GF_CALLOC (1, stacksize, - gf_common_mt_syncstack); - newtask->ctx.uc_stack.ss_size = stacksize; - } - - if (!newtask->stack) { - goto err; - } - - newtask->ctx.uc_stack.ss_sp = newtask->stack; - - makecontext (&newtask->ctx, (void (*)(void)) synctask_wrap, 0); - - newtask->state = SYNCTASK_INIT; + VALIDATE_OR_GOTO(env, err); + VALIDATE_OR_GOTO(fn, err); - newtask->slept = 1; + /* Check if the syncenv is in destroymode i.e. destroy is SET. + * If YES, then don't allow any new synctasks on it. Return NULL. + */ + pthread_mutex_lock(&env->mutex); + { + destroymode = env->destroy; + } + pthread_mutex_unlock(&env->mutex); - if (!cbk) { - pthread_mutex_init (&newtask->mutex, NULL); - pthread_cond_init (&newtask->cond, NULL); - newtask->done = 0; - } + /* syncenv is in DESTROY mode, return from here */ + if (destroymode) + return NULL; - synctask_wake (newtask); - /* - * Make sure someone's there to execute anything we just put on the - * run queue. - */ - syncenv_scale(env); + newtask = GF_CALLOC(1, sizeof(*newtask), gf_common_mt_synctask); + if (!newtask) + return NULL; - return newtask; + newtask->frame = frame; + if (!frame) { + newtask->opframe = create_frame(this, this->ctx->pool); + if (!newtask->opframe) + goto err; + set_lk_owner_from_ptr(&newtask->opframe->root->lk_owner, + newtask->opframe->root); + } else { + newtask->opframe = copy_frame(frame); + } + if (!newtask->opframe) + goto err; + newtask->env = env; + newtask->xl = this; + newtask->syncfn = fn; + newtask->synccbk = cbk; + newtask->opaque = opaque; + + /* default to the uid/gid of the passed frame */ + newtask->uid = newtask->opframe->root->uid; + newtask->gid = newtask->opframe->root->gid; + + INIT_LIST_HEAD(&newtask->all_tasks); + INIT_LIST_HEAD(&newtask->waitq); + + if (getcontext(&newtask->ctx) < 0) { + gf_msg("syncop", GF_LOG_ERROR, errno, LG_MSG_GETCONTEXT_FAILED, + "getcontext failed"); + goto err; + } + + if (stacksize <= 0) { + newtask->stack = GF_CALLOC(1, env->stacksize, gf_common_mt_syncstack); + newtask->ctx.uc_stack.ss_size = env->stacksize; + } else { + newtask->stack = GF_CALLOC(1, stacksize, gf_common_mt_syncstack); + newtask->ctx.uc_stack.ss_size = stacksize; + } + + if (!newtask->stack) { + goto err; + } + + newtask->ctx.uc_stack.ss_sp = newtask->stack; + + makecontext(&newtask->ctx, (void (*)(void))synctask_wrap, 0); + + newtask->state = SYNCTASK_INIT; + + newtask->slept = 1; + + if (!cbk) { + pthread_mutex_init(&newtask->mutex, NULL); + pthread_cond_init(&newtask->cond, NULL); + newtask->done = 0; + } + + synctask_wake(newtask); + /* + * Make sure someone's there to execute anything we just put on the + * run queue. + */ + syncenv_scale(env); + + return newtask; err: - if (newtask) { - GF_FREE (newtask->stack); - if (newtask->opframe) - STACK_DESTROY (newtask->opframe->root); - GF_FREE (newtask); - } + if (newtask) { + GF_FREE(newtask->stack); + if (newtask->opframe) + STACK_DESTROY(newtask->opframe->root); + GF_FREE(newtask); + } - return NULL; + return NULL; } - int -synctask_join (struct synctask *task) +synctask_join(struct synctask *task) { - int ret = 0; + int ret = 0; - pthread_mutex_lock (&task->mutex); - { - while (!task->done) - pthread_cond_wait (&task->cond, &task->mutex); - } - pthread_mutex_unlock (&task->mutex); + pthread_mutex_lock(&task->mutex); + { + while (!task->done) + pthread_cond_wait(&task->cond, &task->mutex); + } + pthread_mutex_unlock(&task->mutex); - ret = task->ret; + ret = task->ret; - synctask_destroy (task); + synctask_destroy(task); - return ret; + return ret; } - int -synctask_new1 (struct syncenv *env, size_t stacksize, synctask_fn_t fn, - synctask_cbk_t cbk, call_frame_t *frame, void *opaque) +synctask_new1(struct syncenv *env, size_t stacksize, synctask_fn_t fn, + synctask_cbk_t cbk, call_frame_t *frame, void *opaque) { - struct synctask *newtask = NULL; - int ret = 0; + struct synctask *newtask = NULL; + int ret = 0; - newtask = synctask_create (env, stacksize, fn, cbk, frame, opaque); - if (!newtask) - return -1; + newtask = synctask_create(env, stacksize, fn, cbk, frame, opaque); + if (!newtask) + return -1; - if (!cbk) - ret = synctask_join (newtask); + if (!cbk) + ret = synctask_join(newtask); - return ret; + return ret; } - int -synctask_new (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, - call_frame_t *frame, void *opaque) +synctask_new(struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, + call_frame_t *frame, void *opaque) { - return synctask_new1 (env, 0, fn, cbk, frame, opaque); + return synctask_new1(env, 0, fn, cbk, frame, opaque); } struct synctask * -syncenv_task (struct syncproc *proc) -{ - struct syncenv *env = NULL; - struct synctask *task = NULL; - struct timespec sleep_till = {0, }; - int ret = 0; - - env = proc->env; - - pthread_mutex_lock (&env->mutex); - { - while (list_empty (&env->runq)) { - sleep_till.tv_sec = time (NULL) + SYNCPROC_IDLE_TIME; - ret = pthread_cond_timedwait (&env->cond, &env->mutex, - &sleep_till); - if (!list_empty (&env->runq)) - break; - /* If either of the conditions are met then exit - * the current thread: - * 1. syncenv has to scale down(procs > procmin) - * 2. syncenv is in destroy mode and no tasks in - * either waitq or runq. - * - * At any point in time, a task can be either in runq, - * or in executing state or in the waitq. Once the - * destroy mode is set, no new synctask creates will - * be allowed, but whatever in waitq or runq should be - * allowed to finish before exiting any of the syncenv - * processor threads. - */ - if (((ret == ETIMEDOUT) && (env->procs > env->procmin)) - || (env->destroy && list_empty (&env->waitq))) { - task = NULL; - env->procs--; - memset (proc, 0, sizeof (*proc)); - pthread_cond_broadcast (&env->cond); - goto unlock; - } - } +syncenv_task(struct syncproc *proc) +{ + struct syncenv *env = NULL; + struct synctask *task = NULL; + struct timespec sleep_till = { + 0, + }; + int ret = 0; + + env = proc->env; + + pthread_mutex_lock(&env->mutex); + { + while (list_empty(&env->runq)) { + sleep_till.tv_sec = time(NULL) + SYNCPROC_IDLE_TIME; + ret = pthread_cond_timedwait(&env->cond, &env->mutex, &sleep_till); + if (!list_empty(&env->runq)) + break; + /* If either of the conditions are met then exit + * the current thread: + * 1. syncenv has to scale down(procs > procmin) + * 2. syncenv is in destroy mode and no tasks in + * either waitq or runq. + * + * At any point in time, a task can be either in runq, + * or in executing state or in the waitq. Once the + * destroy mode is set, no new synctask creates will + * be allowed, but whatever in waitq or runq should be + * allowed to finish before exiting any of the syncenv + * processor threads. + */ + if (((ret == ETIMEDOUT) && (env->procs > env->procmin)) || + (env->destroy && list_empty(&env->waitq))) { + task = NULL; + env->procs--; + memset(proc, 0, sizeof(*proc)); + pthread_cond_broadcast(&env->cond); + goto unlock; + } + } - task = list_entry (env->runq.next, struct synctask, all_tasks); + task = list_entry(env->runq.next, struct synctask, all_tasks); - list_del_init (&task->all_tasks); - env->runcount--; + list_del_init(&task->all_tasks); + env->runcount--; - task->woken = 0; - task->slept = 0; + task->woken = 0; + task->slept = 0; - task->proc = proc; - } + task->proc = proc; + } unlock: - pthread_mutex_unlock (&env->mutex); + pthread_mutex_unlock(&env->mutex); - return task; + return task; } - void -synctask_switchto (struct synctask *task) +synctask_switchto(struct synctask *task) { - struct syncenv *env = NULL; + struct syncenv *env = NULL; - env = task->env; + env = task->env; - synctask_set (task); - THIS = task->xl; + synctask_set(task); + THIS = task->xl; #if defined(__NetBSD__) && defined(_UC_TLSBASE) - /* Preserve pthread private pointer through swapcontex() */ - task->ctx.uc_flags &= ~_UC_TLSBASE; + /* Preserve pthread private pointer through swapcontex() */ + task->ctx.uc_flags &= ~_UC_TLSBASE; #endif - if (swapcontext (&task->proc->sched, &task->ctx) < 0) { - gf_msg ("syncop", GF_LOG_ERROR, errno, - LG_MSG_SWAPCONTEXT_FAILED, "swapcontext failed"); - } + if (swapcontext(&task->proc->sched, &task->ctx) < 0) { + gf_msg("syncop", GF_LOG_ERROR, errno, LG_MSG_SWAPCONTEXT_FAILED, + "swapcontext failed"); + } - if (task->state == SYNCTASK_DONE) { - synctask_done (task); - return; - } + if (task->state == SYNCTASK_DONE) { + synctask_done(task); + return; + } - pthread_mutex_lock (&env->mutex); - { - if (task->woken) { - __run (task); - } else { - task->slept = 1; - __wait (task); - } + pthread_mutex_lock(&env->mutex); + { + if (task->woken) { + __run(task); + } else { + task->slept = 1; + __wait(task); } - pthread_mutex_unlock (&env->mutex); + } + pthread_mutex_unlock(&env->mutex); } void * -syncenv_processor (void *thdata) +syncenv_processor(void *thdata) { - struct syncenv *env = NULL; - struct syncproc *proc = NULL; - struct synctask *task = NULL; + struct syncenv *env = NULL; + struct syncproc *proc = NULL; + struct synctask *task = NULL; - proc = thdata; - env = proc->env; + proc = thdata; + env = proc->env; - for (;;) { - task = syncenv_task (proc); - if (!task) - break; + for (;;) { + task = syncenv_task(proc); + if (!task) + break; - synctask_switchto (task); + synctask_switchto(task); - syncenv_scale (env); - } + syncenv_scale(env); + } - return NULL; + return NULL; } - void -syncenv_scale (struct syncenv *env) -{ - int diff = 0; - int scale = 0; - int i = 0; - int ret = 0; - char thread_name[GF_THREAD_NAMEMAX] = {0,}; - - pthread_mutex_lock (&env->mutex); - { - if (env->procs > env->runcount) - goto unlock; - - scale = env->runcount; - if (scale > env->procmax) - scale = env->procmax; - if (scale > env->procs) - diff = scale - env->procs; - while (diff) { - diff--; - for (; (i < env->procmax); i++) { - if (env->proc[i].processor == 0) - break; - } - - env->proc[i].env = env; - snprintf (thread_name, sizeof(thread_name), - "sproc%03hx", (env->procs & 0x3ff)); - ret = gf_thread_create (&env->proc[i].processor, NULL, - syncenv_processor, - &env->proc[i], thread_name); - if (ret) - break; - env->procs++; - i++; - } +syncenv_scale(struct syncenv *env) +{ + int diff = 0; + int scale = 0; + int i = 0; + int ret = 0; + char thread_name[GF_THREAD_NAMEMAX] = { + 0, + }; + + pthread_mutex_lock(&env->mutex); + { + if (env->procs > env->runcount) + goto unlock; + + scale = env->runcount; + if (scale > env->procmax) + scale = env->procmax; + if (scale > env->procs) + diff = scale - env->procs; + while (diff) { + diff--; + for (; (i < env->procmax); i++) { + if (env->proc[i].processor == 0) + break; + } + + env->proc[i].env = env; + snprintf(thread_name, sizeof(thread_name), "sproc%03hx", + (env->procs & 0x3ff)); + ret = gf_thread_create(&env->proc[i].processor, NULL, + syncenv_processor, &env->proc[i], + thread_name); + if (ret) + break; + env->procs++; + i++; } + } unlock: - pthread_mutex_unlock (&env->mutex); + pthread_mutex_unlock(&env->mutex); } /* The syncenv threads are cleaned up in this routine. */ void -syncenv_destroy (struct syncenv *env) -{ - - if (env == NULL) - return; - - /* SET the 'destroy' in syncenv structure to prohibit any - * further synctask(s) on this syncenv which is in destroy mode. - * - * If syncenv threads are in pthread cond wait with no tasks in - * their run or wait queue, then the threads are woken up by - * broadcasting the cond variable and if destroy field is set, - * the infinite loop in syncenv_processor is broken and the - * threads return. - * - * If syncenv threads have tasks in runq or waitq, the tasks are - * completed and only then the thread returns. +syncenv_destroy(struct syncenv *env) +{ + if (env == NULL) + return; + + /* SET the 'destroy' in syncenv structure to prohibit any + * further synctask(s) on this syncenv which is in destroy mode. + * + * If syncenv threads are in pthread cond wait with no tasks in + * their run or wait queue, then the threads are woken up by + * broadcasting the cond variable and if destroy field is set, + * the infinite loop in syncenv_processor is broken and the + * threads return. + * + * If syncenv threads have tasks in runq or waitq, the tasks are + * completed and only then the thread returns. + */ + pthread_mutex_lock(&env->mutex); + { + env->destroy = 1; + /* This broadcast will wake threads in pthread_cond_wait + * in syncenv_task */ - pthread_mutex_lock (&env->mutex); - { - env->destroy = 1; - /* This broadcast will wake threads in pthread_cond_wait - * in syncenv_task - */ - pthread_cond_broadcast (&env->cond); - - /* when the syncenv_task() thread is exiting, it broadcasts to - * wake the below wait. - */ - while (env->procs != 0) { - pthread_cond_wait (&env->cond, &env->mutex); - } + pthread_cond_broadcast(&env->cond); + + /* when the syncenv_task() thread is exiting, it broadcasts to + * wake the below wait. + */ + while (env->procs != 0) { + pthread_cond_wait(&env->cond, &env->mutex); } - pthread_mutex_unlock (&env->mutex); + } + pthread_mutex_unlock(&env->mutex); - pthread_mutex_destroy (&env->mutex); - pthread_cond_destroy (&env->cond); + pthread_mutex_destroy(&env->mutex); + pthread_cond_destroy(&env->cond); - GF_FREE (env); + GF_FREE(env); - return; + return; } - struct syncenv * -syncenv_new (size_t stacksize, int procmin, int procmax) -{ - struct syncenv *newenv = NULL; - int ret = 0; - int i = 0; - char thread_name[GF_THREAD_NAMEMAX] = {0,}; - - if (!procmin || procmin < 0) - procmin = SYNCENV_PROC_MIN; - if (!procmax || procmax > SYNCENV_PROC_MAX) - procmax = SYNCENV_PROC_MAX; - - if (procmin > procmax) - return NULL; - - newenv = GF_CALLOC (1, sizeof (*newenv), gf_common_mt_syncenv); - - if (!newenv) - return NULL; - - pthread_mutex_init (&newenv->mutex, NULL); - pthread_cond_init (&newenv->cond, NULL); - - INIT_LIST_HEAD (&newenv->runq); - INIT_LIST_HEAD (&newenv->waitq); - - newenv->stacksize = SYNCENV_DEFAULT_STACKSIZE; - if (stacksize) - newenv->stacksize = stacksize; - newenv->procmin = procmin; - newenv->procmax = procmax; - - for (i = 0; i < newenv->procmin; i++) { - newenv->proc[i].env = newenv; - snprintf (thread_name, sizeof(thread_name), - "%s%d", "sproc", (newenv->procs)); - ret = gf_thread_create (&newenv->proc[i].processor, NULL, - syncenv_processor, &newenv->proc[i], - thread_name); - if (ret) - break; - newenv->procs++; - } +syncenv_new(size_t stacksize, int procmin, int procmax) +{ + struct syncenv *newenv = NULL; + int ret = 0; + int i = 0; + char thread_name[GF_THREAD_NAMEMAX] = { + 0, + }; - if (ret != 0) { - syncenv_destroy (newenv); - newenv = NULL; - } + if (!procmin || procmin < 0) + procmin = SYNCENV_PROC_MIN; + if (!procmax || procmax > SYNCENV_PROC_MAX) + procmax = SYNCENV_PROC_MAX; - return newenv; -} + if (procmin > procmax) + return NULL; + + newenv = GF_CALLOC(1, sizeof(*newenv), gf_common_mt_syncenv); + + if (!newenv) + return NULL; + + pthread_mutex_init(&newenv->mutex, NULL); + pthread_cond_init(&newenv->cond, NULL); + + INIT_LIST_HEAD(&newenv->runq); + INIT_LIST_HEAD(&newenv->waitq); + newenv->stacksize = SYNCENV_DEFAULT_STACKSIZE; + if (stacksize) + newenv->stacksize = stacksize; + newenv->procmin = procmin; + newenv->procmax = procmax; + + for (i = 0; i < newenv->procmin; i++) { + newenv->proc[i].env = newenv; + snprintf(thread_name, sizeof(thread_name), "%s%d", "sproc", + (newenv->procs)); + ret = gf_thread_create(&newenv->proc[i].processor, NULL, + syncenv_processor, &newenv->proc[i], + thread_name); + if (ret) + break; + newenv->procs++; + } + + if (ret != 0) { + syncenv_destroy(newenv); + newenv = NULL; + } + + return newenv; +} int -synclock_init (synclock_t *lock, lock_attr_t attr) +synclock_init(synclock_t *lock, lock_attr_t attr) { - if (!lock) - return -1; + if (!lock) + return -1; - pthread_cond_init (&lock->cond, 0); - lock->type = LOCK_NULL; - lock->owner = NULL; - lock->owner_tid = 0; - lock->lock = 0; - lock->attr = attr; - INIT_LIST_HEAD (&lock->waitq); + pthread_cond_init(&lock->cond, 0); + lock->type = LOCK_NULL; + lock->owner = NULL; + lock->owner_tid = 0; + lock->lock = 0; + lock->attr = attr; + INIT_LIST_HEAD(&lock->waitq); - return pthread_mutex_init (&lock->guard, 0); + return pthread_mutex_init(&lock->guard, 0); } - int -synclock_destroy (synclock_t *lock) +synclock_destroy(synclock_t *lock) { - if (!lock) - return -1; + if (!lock) + return -1; - pthread_cond_destroy (&lock->cond); - return pthread_mutex_destroy (&lock->guard); + pthread_cond_destroy(&lock->cond); + return pthread_mutex_destroy(&lock->guard); } - static int -__synclock_lock (struct synclock *lock) -{ - struct synctask *task = NULL; - - if (!lock) - return -1; - - task = synctask_get (); - - if (lock->lock && (lock->attr == SYNC_LOCK_RECURSIVE)) { - /*Recursive lock (if same owner requested for lock again then - *increment lock count and return success). - *Note:same number of unlocks required. - */ - switch (lock->type) { - case LOCK_TASK: - if (task == lock->owner) { - lock->lock++; - gf_msg_trace ("", 0, "Recursive lock called by" - " sync task.owner= %p,lock=%d", - lock->owner, lock->lock); - return 0; - } - break; - case LOCK_THREAD: - if (pthread_equal(pthread_self (), lock->owner_tid)) { - lock->lock++; - gf_msg_trace ("", 0, "Recursive lock called by" - " thread ,owner=%u lock=%d", - (unsigned int) lock->owner_tid, - lock->lock); - return 0; - } - break; - default: - gf_msg ("", GF_LOG_CRITICAL, 0, - LG_MSG_UNKNOWN_LOCK_TYPE, "unknown lock type"); - break; - } - } +__synclock_lock(struct synclock *lock) +{ + struct synctask *task = NULL; + if (!lock) + return -1; - while (lock->lock) { - if (task) { - /* called within a synctask */ - task->woken = 0; - list_add_tail (&task->waitq, &lock->waitq); - pthread_mutex_unlock (&lock->guard); - synctask_yield (task); - /* task is removed from waitq in unlock, - * under lock->guard.*/ - pthread_mutex_lock (&lock->guard); - } else { - /* called by a non-synctask */ - pthread_cond_wait (&lock->cond, &lock->guard); + task = synctask_get(); + + if (lock->lock && (lock->attr == SYNC_LOCK_RECURSIVE)) { + /*Recursive lock (if same owner requested for lock again then + *increment lock count and return success). + *Note:same number of unlocks required. + */ + switch (lock->type) { + case LOCK_TASK: + if (task == lock->owner) { + lock->lock++; + gf_msg_trace("", 0, + "Recursive lock called by" + " sync task.owner= %p,lock=%d", + lock->owner, lock->lock); + return 0; + } + break; + case LOCK_THREAD: + if (pthread_equal(pthread_self(), lock->owner_tid)) { + lock->lock++; + gf_msg_trace("", 0, + "Recursive lock called by" + " thread ,owner=%u lock=%d", + (unsigned int)lock->owner_tid, lock->lock); + return 0; } + break; + default: + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_UNKNOWN_LOCK_TYPE, + "unknown lock type"); + break; } + } + while (lock->lock) { if (task) { - lock->type = LOCK_TASK; - lock->owner = task; /* for synctask*/ - + /* called within a synctask */ + task->woken = 0; + list_add_tail(&task->waitq, &lock->waitq); + pthread_mutex_unlock(&lock->guard); + synctask_yield(task); + /* task is removed from waitq in unlock, + * under lock->guard.*/ + pthread_mutex_lock(&lock->guard); } else { - lock->type = LOCK_THREAD; - lock->owner_tid = pthread_self (); /* for non-synctask */ - + /* called by a non-synctask */ + pthread_cond_wait(&lock->cond, &lock->guard); } - lock->lock = 1; + } - return 0; -} + if (task) { + lock->type = LOCK_TASK; + lock->owner = task; /* for synctask*/ + } else { + lock->type = LOCK_THREAD; + lock->owner_tid = pthread_self(); /* for non-synctask */ + } + lock->lock = 1; + + return 0; +} int -synclock_lock (synclock_t *lock) +synclock_lock(synclock_t *lock) { - int ret = 0; + int ret = 0; - pthread_mutex_lock (&lock->guard); - { - ret = __synclock_lock (lock); - } - pthread_mutex_unlock (&lock->guard); + pthread_mutex_lock(&lock->guard); + { + ret = __synclock_lock(lock); + } + pthread_mutex_unlock(&lock->guard); - return ret; + return ret; } - int -synclock_trylock (synclock_t *lock) +synclock_trylock(synclock_t *lock) { - int ret = 0; + int ret = 0; - errno = 0; + errno = 0; - pthread_mutex_lock (&lock->guard); - { - if (lock->lock) { - errno = EBUSY; - ret = -1; - goto unlock; - } + pthread_mutex_lock(&lock->guard); + { + if (lock->lock) { + errno = EBUSY; + ret = -1; + goto unlock; + } - ret = __synclock_lock (lock); - } + ret = __synclock_lock(lock); + } unlock: - pthread_mutex_unlock (&lock->guard); + pthread_mutex_unlock(&lock->guard); - return ret; + return ret; } - static int -__synclock_unlock (synclock_t *lock) -{ - struct synctask *task = NULL; - struct synctask *curr = NULL; - - if (!lock) - return -1; - - if (lock->lock == 0) { - gf_msg ("", GF_LOG_CRITICAL, 0, LG_MSG_UNLOCK_BEFORE_LOCK, - "Unlock called before lock "); - return -1; - } - curr = synctask_get (); - /*unlock should be called by lock owner - *i.e this will not allow the lock in nonsync task and unlock - * in sync task and vice-versa - */ - switch (lock->type) { +__synclock_unlock(synclock_t *lock) +{ + struct synctask *task = NULL; + struct synctask *curr = NULL; + + if (!lock) + return -1; + + if (lock->lock == 0) { + gf_msg("", GF_LOG_CRITICAL, 0, LG_MSG_UNLOCK_BEFORE_LOCK, + "Unlock called before lock "); + return -1; + } + curr = synctask_get(); + /*unlock should be called by lock owner + *i.e this will not allow the lock in nonsync task and unlock + * in sync task and vice-versa + */ + switch (lock->type) { case LOCK_TASK: - if (curr == lock->owner) { - lock->lock--; - gf_msg_trace ("", 0, "Unlock success %p, remaining" - " locks=%d", lock->owner, lock->lock); - } else { - gf_msg ("", GF_LOG_WARNING, 0, LG_MSG_LOCK_OWNER_ERROR, - "Unlock called by %p, but lock held by %p", - curr, lock->owner); - } - - break; + if (curr == lock->owner) { + lock->lock--; + gf_msg_trace("", 0, + "Unlock success %p, remaining" + " locks=%d", + lock->owner, lock->lock); + } else { + gf_msg("", GF_LOG_WARNING, 0, LG_MSG_LOCK_OWNER_ERROR, + "Unlock called by %p, but lock held by %p", curr, + lock->owner); + } + + break; case LOCK_THREAD: - if (pthread_equal(pthread_self (), lock->owner_tid)) { - lock->lock--; - gf_msg_trace ("", 0, "Unlock success %u, remaining " - "locks=%d", - (unsigned int)lock->owner_tid, - lock->lock); - } else { - gf_msg ("", GF_LOG_WARNING, 0, LG_MSG_LOCK_OWNER_ERROR, - "Unlock called by %u, but lock held by %u", - (unsigned int) pthread_self(), - (unsigned int) lock->owner_tid); - } - - break; + if (pthread_equal(pthread_self(), lock->owner_tid)) { + lock->lock--; + gf_msg_trace("", 0, + "Unlock success %u, remaining " + "locks=%d", + (unsigned int)lock->owner_tid, lock->lock); + } else { + gf_msg("", GF_LOG_WARNING, 0, LG_MSG_LOCK_OWNER_ERROR, + "Unlock called by %u, but lock held by %u", + (unsigned int)pthread_self(), + (unsigned int)lock->owner_tid); + } + + break; default: - break; - } - - if (lock->lock > 0) { - return 0; - } - lock->type = LOCK_NULL; - lock->owner = NULL; - lock->owner_tid = 0; - lock->lock = 0; - /* There could be both synctasks and non synctasks - waiting (or none, or either). As a mid-approach - between maintaining too many waiting counters - at one extreme and a thundering herd on unlock - at the other, call a cond_signal (which wakes - one waiter) and first synctask waiter. So at - most we have two threads waking up to grab the - just released lock. - */ - pthread_cond_signal (&lock->cond); - if (!list_empty (&lock->waitq)) { - task = list_entry (lock->waitq.next, struct synctask, waitq); - list_del_init (&task->waitq); - synctask_wake (task); - } + break; + } + if (lock->lock > 0) { return 0; -} + } + lock->type = LOCK_NULL; + lock->owner = NULL; + lock->owner_tid = 0; + lock->lock = 0; + /* There could be both synctasks and non synctasks + waiting (or none, or either). As a mid-approach + between maintaining too many waiting counters + at one extreme and a thundering herd on unlock + at the other, call a cond_signal (which wakes + one waiter) and first synctask waiter. So at + most we have two threads waking up to grab the + just released lock. + */ + pthread_cond_signal(&lock->cond); + if (!list_empty(&lock->waitq)) { + task = list_entry(lock->waitq.next, struct synctask, waitq); + list_del_init(&task->waitq); + synctask_wake(task); + } + return 0; +} int -synclock_unlock (synclock_t *lock) +synclock_unlock(synclock_t *lock) { - int ret = 0; + int ret = 0; - pthread_mutex_lock (&lock->guard); - { - ret = __synclock_unlock (lock); - } - pthread_mutex_unlock (&lock->guard); + pthread_mutex_lock(&lock->guard); + { + ret = __synclock_unlock(lock); + } + pthread_mutex_unlock(&lock->guard); - return ret; + return ret; } /* Barriers */ int -syncbarrier_init (struct syncbarrier *barrier) +syncbarrier_init(struct syncbarrier *barrier) { - int ret = 0; - if (!barrier) { - errno = EINVAL; - return -1; - } + int ret = 0; + if (!barrier) { + errno = EINVAL; + return -1; + } - ret = pthread_cond_init (&barrier->cond, 0); - if (ret) { - errno = ret; - return -1; - } - barrier->count = 0; - barrier->waitfor = 0; - INIT_LIST_HEAD (&barrier->waitq); - - ret = pthread_mutex_init (&barrier->guard, 0); - if (ret) { - (void)pthread_cond_destroy (&barrier->cond); - errno = ret; - return -1; - } - barrier->initialized = _gf_true; - return 0; -} + ret = pthread_cond_init(&barrier->cond, 0); + if (ret) { + errno = ret; + return -1; + } + barrier->count = 0; + barrier->waitfor = 0; + INIT_LIST_HEAD(&barrier->waitq); + ret = pthread_mutex_init(&barrier->guard, 0); + if (ret) { + (void)pthread_cond_destroy(&barrier->cond); + errno = ret; + return -1; + } + barrier->initialized = _gf_true; + return 0; +} int -syncbarrier_destroy (struct syncbarrier *barrier) +syncbarrier_destroy(struct syncbarrier *barrier) { - int ret = 0; - int ret1 = 0; - if (!barrier) { - errno = EINVAL; - return -1; - } + int ret = 0; + int ret1 = 0; + if (!barrier) { + errno = EINVAL; + return -1; + } - if (barrier->initialized) { - ret = pthread_cond_destroy (&barrier->cond); - ret1 = pthread_mutex_destroy (&barrier->guard); - barrier->initialized = _gf_false; - } - if (ret || ret1) { - errno = ret?ret:ret1; - return -1; - } - return 0; + if (barrier->initialized) { + ret = pthread_cond_destroy(&barrier->cond); + ret1 = pthread_mutex_destroy(&barrier->guard); + barrier->initialized = _gf_false; + } + if (ret || ret1) { + errno = ret ? ret : ret1; + return -1; + } + return 0; } - static int -__syncbarrier_wait (struct syncbarrier *barrier, int waitfor) +__syncbarrier_wait(struct syncbarrier *barrier, int waitfor) { - struct synctask *task = NULL; + struct synctask *task = NULL; - if (!barrier) { - errno = EINVAL; - return -1; - } + if (!barrier) { + errno = EINVAL; + return -1; + } - task = synctask_get (); + task = synctask_get(); - while (barrier->count < waitfor) { - if (task) { - /* called within a synctask */ - list_add_tail (&task->waitq, &barrier->waitq); - pthread_mutex_unlock (&barrier->guard); - synctask_yield (task); - pthread_mutex_lock (&barrier->guard); - } else { - /* called by a non-synctask */ - pthread_cond_wait (&barrier->cond, &barrier->guard); - } - } + while (barrier->count < waitfor) { + if (task) { + /* called within a synctask */ + list_add_tail(&task->waitq, &barrier->waitq); + pthread_mutex_unlock(&barrier->guard); + synctask_yield(task); + pthread_mutex_lock(&barrier->guard); + } else { + /* called by a non-synctask */ + pthread_cond_wait(&barrier->cond, &barrier->guard); + } + } - barrier->count = 0; + barrier->count = 0; - return 0; + return 0; } - int -syncbarrier_wait (struct syncbarrier *barrier, int waitfor) +syncbarrier_wait(struct syncbarrier *barrier, int waitfor) { - int ret = 0; + int ret = 0; - pthread_mutex_lock (&barrier->guard); - { - ret = __syncbarrier_wait (barrier, waitfor); - } - pthread_mutex_unlock (&barrier->guard); + pthread_mutex_lock(&barrier->guard); + { + ret = __syncbarrier_wait(barrier, waitfor); + } + pthread_mutex_unlock(&barrier->guard); - return ret; + return ret; } - static int -__syncbarrier_wake (struct syncbarrier *barrier) +__syncbarrier_wake(struct syncbarrier *barrier) { - struct synctask *task = NULL; + struct synctask *task = NULL; - if (!barrier) { - errno = EINVAL; - return -1; - } + if (!barrier) { + errno = EINVAL; + return -1; + } - barrier->count++; - if (barrier->waitfor && (barrier->count < barrier->waitfor)) - return 0; + barrier->count++; + if (barrier->waitfor && (barrier->count < barrier->waitfor)) + return 0; - pthread_cond_signal (&barrier->cond); - if (!list_empty (&barrier->waitq)) { - task = list_entry (barrier->waitq.next, struct synctask, waitq); - list_del_init (&task->waitq); - synctask_wake (task); - } - barrier->waitfor = 0; + pthread_cond_signal(&barrier->cond); + if (!list_empty(&barrier->waitq)) { + task = list_entry(barrier->waitq.next, struct synctask, waitq); + list_del_init(&task->waitq); + synctask_wake(task); + } + barrier->waitfor = 0; - return 0; + return 0; } - int -syncbarrier_wake (struct syncbarrier *barrier) +syncbarrier_wake(struct syncbarrier *barrier) { - int ret = 0; + int ret = 0; - pthread_mutex_lock (&barrier->guard); - { - ret = __syncbarrier_wake (barrier); - } - pthread_mutex_unlock (&barrier->guard); + pthread_mutex_lock(&barrier->guard); + { + ret = __syncbarrier_wake(barrier); + } + pthread_mutex_unlock(&barrier->guard); - return ret; + return ret; } - /* FOPS */ - int -syncop_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, inode_t *inode, - struct iatt *iatt, dict_t *xdata, struct iatt *parent) +syncop_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, inode_t *inode, struct iatt *iatt, + dict_t *xdata, struct iatt *parent) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret == 0) { - args->iatt1 = *iatt; - args->iatt2 = *parent; - } + if (op_ret == 0) { + args->iatt1 = *iatt; + args->iatt2 = *parent; + } - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_lookup (xlator_t *subvol, loc_t *loc, struct iatt *iatt, - struct iatt *parent, dict_t *xdata_in, dict_t **xdata_out) +syncop_lookup(xlator_t *subvol, loc_t *loc, struct iatt *iatt, + struct iatt *parent, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_lookup_cbk, subvol->fops->lookup, - loc, xdata_in); + SYNCOP(subvol, (&args), syncop_lookup_cbk, subvol->fops->lookup, loc, + xdata_in); - if (iatt) - *iatt = args.iatt1; - if (parent) - *parent = args.iatt2; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (iatt) + *iatt = args.iatt1; + if (parent) + *parent = args.iatt2; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int32_t -syncop_readdirp_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - gf_dirent_t *entries, dict_t *xdata) -{ - struct syncargs *args = NULL; - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; - - int count = 0; - - args = cookie; - - INIT_LIST_HEAD (&args->entries.list); - - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); - - - if (op_ret >= 0) { - list_for_each_entry (entry, &entries->list, list) { - tmp = entry_copy (entry); - if (!tmp) { - args->op_ret = -1; - args->op_errno = ENOMEM; - gf_dirent_free (&(args->entries)); - break; - } - gf_msg_trace (this->name, 0, "adding entry=%s, " - "count=%d", tmp->d_name, count); - list_add_tail (&tmp->list, &(args->entries.list)); - count++; - } - } +syncop_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + struct syncargs *args = NULL; + gf_dirent_t *entry = NULL; + gf_dirent_t *tmp = NULL; - __wake (args); + int count = 0; - return 0; + args = cookie; + + INIT_LIST_HEAD(&args->entries.list); + + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); + + if (op_ret >= 0) { + list_for_each_entry(entry, &entries->list, list) + { + tmp = entry_copy(entry); + if (!tmp) { + args->op_ret = -1; + args->op_errno = ENOMEM; + gf_dirent_free(&(args->entries)); + break; + } + gf_msg_trace(this->name, 0, + "adding entry=%s, " + "count=%d", + tmp->d_name, count); + list_add_tail(&tmp->list, &(args->entries.list)); + count++; + } + } + + __wake(args); + return 0; } int -syncop_readdirp (xlator_t *subvol, - fd_t *fd, - size_t size, - off_t off, - gf_dirent_t *entries, - dict_t *xdata_in, - dict_t **xdata_out) +syncop_readdirp(xlator_t *subvol, fd_t *fd, size_t size, off_t off, + gf_dirent_t *entries, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_readdirp_cbk, subvol->fops->readdirp, - fd, size, off, xdata_in); + struct syncargs args = { + 0, + }; - if (entries) - list_splice_init (&args.entries.list, &entries->list); - else - gf_dirent_free (&args.entries); + SYNCOP(subvol, (&args), syncop_readdirp_cbk, subvol->fops->readdirp, fd, + size, off, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (entries) + list_splice_init(&args.entries.list, &entries->list); + else + gf_dirent_free(&args.entries); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int32_t -syncop_readdir_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - gf_dirent_t *entries, dict_t *xdata) -{ - struct syncargs *args = NULL; - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; - - int count = 0; - - args = cookie; - - INIT_LIST_HEAD (&args->entries.list); - - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); - - if (op_ret >= 0) { - list_for_each_entry (entry, &entries->list, list) { - tmp = entry_copy (entry); - if (!tmp) { - args->op_ret = -1; - args->op_errno = ENOMEM; - gf_dirent_free (&(args->entries)); - break; - } - gf_msg_trace (this->name, 0, "adding " - "entry=%s, count=%d", tmp->d_name, - count); - list_add_tail (&tmp->list, &(args->entries.list)); - count++; - } - } +syncop_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + struct syncargs *args = NULL; + gf_dirent_t *entry = NULL; + gf_dirent_t *tmp = NULL; - __wake (args); + int count = 0; - return 0; + args = cookie; + + INIT_LIST_HEAD(&args->entries.list); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); + + if (op_ret >= 0) { + list_for_each_entry(entry, &entries->list, list) + { + tmp = entry_copy(entry); + if (!tmp) { + args->op_ret = -1; + args->op_errno = ENOMEM; + gf_dirent_free(&(args->entries)); + break; + } + gf_msg_trace(this->name, 0, + "adding " + "entry=%s, count=%d", + tmp->d_name, count); + list_add_tail(&tmp->list, &(args->entries.list)); + count++; + } + } + + __wake(args); + + return 0; } int -syncop_readdir (xlator_t *subvol, - fd_t *fd, - size_t size, - off_t off, - gf_dirent_t *entries, - dict_t *xdata_in, - dict_t **xdata_out) +syncop_readdir(xlator_t *subvol, fd_t *fd, size_t size, off_t off, + gf_dirent_t *entries, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_readdir_cbk, subvol->fops->readdir, - fd, size, off, xdata_in); + SYNCOP(subvol, (&args), syncop_readdir_cbk, subvol->fops->readdir, fd, size, + off, xdata_in); - if (entries) - list_splice_init (&args.entries.list, &entries->list); - else - gf_dirent_free (&args.entries); + if (entries) + list_splice_init(&args.entries.list, &entries->list); + else + gf_dirent_free(&args.entries); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); - - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int32_t -syncop_opendir_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - fd_t *fd, dict_t *xdata) +syncop_opendir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_opendir (xlator_t *subvol, - loc_t *loc, - fd_t *fd, - dict_t *xdata_in, - dict_t **xdata_out) +syncop_opendir(xlator_t *subvol, loc_t *loc, fd_t *fd, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_opendir_cbk, subvol->fops->opendir, - loc, fd, xdata_in); + SYNCOP(subvol, (&args), syncop_opendir_cbk, subvol->fops->opendir, loc, fd, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); - - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_fsyncdir_cbk (call_frame_t *frame, void* cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) +syncop_fsyncdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_fsyncdir (xlator_t *subvol, fd_t *fd, int datasync, dict_t *xdata_in, - dict_t **xdata_out) +syncop_fsyncdir(xlator_t *subvol, fd_t *fd, int datasync, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_fsyncdir_cbk, subvol->fops->fsyncdir, - fd, datasync, xdata_in); + SYNCOP(subvol, (&args), syncop_fsyncdir_cbk, subvol->fops->fsyncdir, fd, + datasync, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) +syncop_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_removexattr (xlator_t *subvol, loc_t *loc, const char *name, - dict_t *xdata_in, dict_t **xdata_out) +syncop_removexattr(xlator_t *subvol, loc_t *loc, const char *name, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_removexattr_cbk, - subvol->fops->removexattr, loc, name, xdata_in); + SYNCOP(subvol, (&args), syncop_removexattr_cbk, subvol->fops->removexattr, + loc, name, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) +syncop_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_fremovexattr (xlator_t *subvol, fd_t *fd, const char *name, - dict_t *xdata_in, dict_t **xdata_out) +syncop_fremovexattr(xlator_t *subvol, fd_t *fd, const char *name, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_fremovexattr_cbk, - subvol->fops->fremovexattr, fd, name, xdata_in); + SYNCOP(subvol, (&args), syncop_fremovexattr_cbk, subvol->fops->fremovexattr, + fd, name, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) +syncop_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_setxattr (xlator_t *subvol, loc_t *loc, dict_t *dict, int32_t flags, - dict_t *xdata_in, dict_t **xdata_out) +syncop_setxattr(xlator_t *subvol, loc_t *loc, dict_t *dict, int32_t flags, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_setxattr_cbk, subvol->fops->setxattr, - loc, dict, flags, xdata_in); + SYNCOP(subvol, (&args), syncop_setxattr_cbk, subvol->fops->setxattr, loc, + dict, flags, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) +syncop_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_fsetxattr (xlator_t *subvol, fd_t *fd, dict_t *dict, int32_t flags, - dict_t *xdata_in, dict_t **xdata_out) +syncop_fsetxattr(xlator_t *subvol, fd_t *fd, dict_t *dict, int32_t flags, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_fsetxattr_cbk, subvol->fops->fsetxattr, - fd, dict, flags, xdata_in); + SYNCOP(subvol, (&args), syncop_fsetxattr_cbk, subvol->fops->fsetxattr, fd, + dict, flags, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *dict, dict_t *xdata) +syncop_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, dict_t *dict, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret >= 0) - args->xattr = dict_ref (dict); + if (op_ret >= 0) + args->xattr = dict_ref(dict); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_listxattr (xlator_t *subvol, loc_t *loc, dict_t **dict, dict_t *xdata_in, - dict_t **xdata_out) +syncop_listxattr(xlator_t *subvol, loc_t *loc, dict_t **dict, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_getxattr_cbk, subvol->fops->getxattr, - loc, NULL, xdata_in); + SYNCOP(subvol, (&args), syncop_getxattr_cbk, subvol->fops->getxattr, loc, + NULL, xdata_in); - if (dict) - *dict = args.xattr; - else if (args.xattr) - dict_unref (args.xattr); + if (dict) + *dict = args.xattr; + else if (args.xattr) + dict_unref(args.xattr); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_getxattr (xlator_t *subvol, loc_t *loc, dict_t **dict, const char *key, - dict_t *xdata_in, dict_t **xdata_out) +syncop_getxattr(xlator_t *subvol, loc_t *loc, dict_t **dict, const char *key, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_getxattr_cbk, subvol->fops->getxattr, - loc, key, xdata_in); + SYNCOP(subvol, (&args), syncop_getxattr_cbk, subvol->fops->getxattr, loc, + key, xdata_in); - if (dict) - *dict = args.xattr; - else if (args.xattr) - dict_unref (args.xattr); + if (dict) + *dict = args.xattr; + else if (args.xattr) + dict_unref(args.xattr); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_fgetxattr (xlator_t *subvol, fd_t *fd, dict_t **dict, const char *key, - dict_t *xdata_in, dict_t **xdata_out) +syncop_fgetxattr(xlator_t *subvol, fd_t *fd, dict_t **dict, const char *key, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_getxattr_cbk, subvol->fops->fgetxattr, - fd, key, xdata_in); + SYNCOP(subvol, (&args), syncop_getxattr_cbk, subvol->fops->fgetxattr, fd, + key, xdata_in); - if (dict) - *dict = args.xattr; - else if (args.xattr) - dict_unref (args.xattr); + if (dict) + *dict = args.xattr; + else if (args.xattr) + dict_unref(args.xattr); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct statvfs *buf, dict_t *xdata) +syncop_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct statvfs *buf, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret == 0) { - args->statvfs_buf = *buf; - } + if (op_ret == 0) { + args->statvfs_buf = *buf; + } - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_statfs (xlator_t *subvol, loc_t *loc, struct statvfs *buf, - dict_t *xdata_in, dict_t **xdata_out) +syncop_statfs(xlator_t *subvol, loc_t *loc, struct statvfs *buf, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_statfs_cbk, subvol->fops->statfs, - loc, xdata_in); + SYNCOP(subvol, (&args), syncop_statfs_cbk, subvol->fops->statfs, loc, + xdata_in); - if (buf) - *buf = args.statvfs_buf; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (buf) + *buf = args.statvfs_buf; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, - struct iatt *preop, struct iatt *postop, dict_t *xdata) +syncop_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iatt *preop, + struct iatt *postop, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret == 0) { - args->iatt1 = *preop; - args->iatt2 = *postop; - } + if (op_ret == 0) { + args->iatt1 = *preop; + args->iatt2 = *postop; + } - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_setattr (xlator_t *subvol, loc_t *loc, struct iatt *iatt, int valid, - struct iatt *preop, struct iatt *postop, dict_t *xdata_in, - dict_t **xdata_out) +syncop_setattr(xlator_t *subvol, loc_t *loc, struct iatt *iatt, int valid, + struct iatt *preop, struct iatt *postop, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_setattr_cbk, subvol->fops->setattr, - loc, iatt, valid, xdata_in); + SYNCOP(subvol, (&args), syncop_setattr_cbk, subvol->fops->setattr, loc, + iatt, valid, xdata_in); - if (preop) - *preop = args.iatt1; - if (postop) - *postop = args.iatt2; + if (preop) + *preop = args.iatt1; + if (postop) + *postop = args.iatt2; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_fsetattr (xlator_t *subvol, fd_t *fd, struct iatt *iatt, int valid, - struct iatt *preop, struct iatt *postop, dict_t *xdata_in, - dict_t **xdata_out) +syncop_fsetattr(xlator_t *subvol, fd_t *fd, struct iatt *iatt, int valid, + struct iatt *preop, struct iatt *postop, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_setattr_cbk, subvol->fops->fsetattr, - fd, iatt, valid, xdata_in); + SYNCOP(subvol, (&args), syncop_setattr_cbk, subvol->fops->fsetattr, fd, + iatt, valid, xdata_in); - if (preop) - *preop = args.iatt1; - if (postop) - *postop = args.iatt2; + if (preop) + *preop = args.iatt1; + if (postop) + *postop = args.iatt2; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int32_t -syncop_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) +syncop_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_open (xlator_t *subvol, loc_t *loc, int32_t flags, fd_t *fd, - dict_t *xdata_in, dict_t **xdata_out) +syncop_open(xlator_t *subvol, loc_t *loc, int32_t flags, fd_t *fd, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_open_cbk, subvol->fops->open, - loc, flags, fd, xdata_in); + struct syncargs args = { + 0, + }; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + SYNCOP(subvol, (&args), syncop_open_cbk, subvol->fops->open, loc, flags, fd, + xdata_in); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int32_t -syncop_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iovec *vector, - int32_t count, struct iatt *stbuf, struct iobref *iobref, - dict_t *xdata) +syncop_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iovec *vector, + int32_t count, struct iatt *stbuf, struct iobref *iobref, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - INIT_LIST_HEAD (&args->entries.list); + INIT_LIST_HEAD(&args->entries.list); - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (args->op_ret >= 0) { - if (iobref) - args->iobref = iobref_ref (iobref); - args->vector = iov_dup (vector, count); - args->count = count; - args->iatt1 = *stbuf; - } + if (args->op_ret >= 0) { + if (iobref) + args->iobref = iobref_ref(iobref); + args->vector = iov_dup(vector, count); + args->count = count; + args->iatt1 = *stbuf; + } - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_readv (xlator_t *subvol, fd_t *fd, size_t size, off_t off, - uint32_t flags, struct iovec **vector, int *count, - struct iobref **iobref, struct iatt *iatt, - dict_t *xdata_in, dict_t **xdata_out) +syncop_readv(xlator_t *subvol, fd_t *fd, size_t size, off_t off, uint32_t flags, + struct iovec **vector, int *count, struct iobref **iobref, + struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_readv_cbk, subvol->fops->readv, - fd, size, off, flags, xdata_in); + SYNCOP(subvol, (&args), syncop_readv_cbk, subvol->fops->readv, fd, size, + off, flags, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (iatt) - *iatt = args.iatt1; + if (iatt) + *iatt = args.iatt1; - if (args.op_ret < 0) - goto out; + if (args.op_ret < 0) + goto out; - if (vector) - *vector = args.vector; - else - GF_FREE (args.vector); + if (vector) + *vector = args.vector; + else + GF_FREE(args.vector); - if (count) - *count = args.count; + if (count) + *count = args.count; - /* Do we need a 'ref' here? */ - if (iobref) - *iobref = args.iobref; - else if (args.iobref) - iobref_unref (args.iobref); + /* Do we need a 'ref' here? */ + if (iobref) + *iobref = args.iobref; + else if (args.iobref) + iobref_unref(args.iobref); out: - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +syncop_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, struct iatt *prebuf, struct iatt *postbuf, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret >= 0) { - args->iatt1 = *prebuf; - args->iatt2 = *postbuf; - } + if (op_ret >= 0) { + args->iatt1 = *prebuf; + args->iatt2 = *postbuf; + } - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_writev (xlator_t *subvol, fd_t *fd, const struct iovec *vector, - int32_t count, off_t offset, struct iobref *iobref, - uint32_t flags, struct iatt *preiatt, struct iatt *postiatt, - dict_t *xdata_in, dict_t **xdata_out) +syncop_writev(xlator_t *subvol, fd_t *fd, const struct iovec *vector, + int32_t count, off_t offset, struct iobref *iobref, + uint32_t flags, struct iatt *preiatt, struct iatt *postiatt, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_writev_cbk, subvol->fops->writev, - fd, (struct iovec *) vector, count, offset, flags, iobref, - xdata_in); + SYNCOP(subvol, (&args), syncop_writev_cbk, subvol->fops->writev, fd, + (struct iovec *)vector, count, offset, flags, iobref, xdata_in); - if (preiatt) - *preiatt = args.iatt1; - if (postiatt) - *postiatt = args.iatt2; + if (preiatt) + *preiatt = args.iatt1; + if (postiatt) + *postiatt = args.iatt2; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } -int syncop_write (xlator_t *subvol, fd_t *fd, const char *buf, int size, - off_t offset, struct iobref *iobref, uint32_t flags, - dict_t *xdata_in, dict_t **xdata_out) +int +syncop_write(xlator_t *subvol, fd_t *fd, const char *buf, int size, + off_t offset, struct iobref *iobref, uint32_t flags, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0,}; - struct iovec vec = {0,}; + struct syncargs args = { + 0, + }; + struct iovec vec = { + 0, + }; - vec.iov_len = size; - vec.iov_base = (void *)buf; + vec.iov_len = size; + vec.iov_base = (void *)buf; - SYNCOP (subvol, (&args), syncop_writev_cbk, subvol->fops->writev, - fd, &vec, 1, offset, flags, iobref, xdata_in); + SYNCOP(subvol, (&args), syncop_writev_cbk, subvol->fops->writev, fd, &vec, + 1, offset, flags, iobref, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_close (fd_t *fd) +syncop_close(fd_t *fd) { - if (fd) - fd_unref (fd); - return 0; + if (fd) + fd_unref(fd); + return 0; } int32_t -syncop_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_create (xlator_t *subvol, loc_t *loc, int32_t flags, mode_t mode, - fd_t *fd, struct iatt *iatt, - dict_t *xdata_in, dict_t **xdata_out) +syncop_create(xlator_t *subvol, loc_t *loc, int32_t flags, mode_t mode, + fd_t *fd, struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_create_cbk, subvol->fops->create, - loc, flags, mode, 0, fd, xdata_in); + SYNCOP(subvol, (&args), syncop_create_cbk, subvol->fops->create, loc, flags, + mode, 0, fd, xdata_in); - if (iatt) - *iatt = args.iatt1; + if (iatt) + *iatt = args.iatt1; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); - - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int32_t -syncop_put_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_put_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_put (xlator_t *subvol, loc_t *loc, mode_t mode, mode_t umask, - uint32_t flags, struct iovec *vector, int32_t count, - off_t offset, struct iobref *iobref, dict_t *xattr, - struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) +syncop_put(xlator_t *subvol, loc_t *loc, mode_t mode, mode_t umask, + uint32_t flags, struct iovec *vector, int32_t count, off_t offset, + struct iobref *iobref, dict_t *xattr, struct iatt *iatt, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_put_cbk, subvol->fops->put, - loc, mode, umask, flags, (struct iovec *) vector, count, - offset, iobref, xattr, xdata_in); + SYNCOP(subvol, (&args), syncop_put_cbk, subvol->fops->put, loc, mode, umask, + flags, (struct iovec *)vector, count, offset, iobref, xattr, + xdata_in); - if (iatt) - *iatt = args.iatt1; + if (iatt) + *iatt = args.iatt1; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); - - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_unlink (xlator_t *subvol, loc_t *loc, dict_t *xdata_in, - dict_t **xdata_out) +syncop_unlink(xlator_t *subvol, loc_t *loc, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_unlink_cbk, subvol->fops->unlink, loc, - 0, xdata_in); + SYNCOP(subvol, (&args), syncop_unlink_cbk, subvol->fops->unlink, loc, 0, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, struct iatt *preparent, struct iatt *postparent, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_rmdir (xlator_t *subvol, loc_t *loc, int flags, dict_t *xdata_in, - dict_t **xdata_out) +syncop_rmdir(xlator_t *subvol, loc_t *loc, int flags, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_rmdir_cbk, subvol->fops->rmdir, loc, - flags, xdata_in); + SYNCOP(subvol, (&args), syncop_rmdir_cbk, subvol->fops->rmdir, loc, flags, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_link (xlator_t *subvol, loc_t *oldloc, loc_t *newloc, struct iatt *iatt, - dict_t *xdata_in, dict_t **xdata_out) +syncop_link(xlator_t *subvol, loc_t *oldloc, loc_t *newloc, struct iatt *iatt, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_link_cbk, subvol->fops->link, - oldloc, newloc, xdata_in); + SYNCOP(subvol, (&args), syncop_link_cbk, subvol->fops->link, oldloc, newloc, + xdata_in); - if (iatt) - *iatt = args.iatt1; + if (iatt) + *iatt = args.iatt1; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; - return args.op_ret; + return args.op_ret; } - int -syncop_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *buf, - struct iatt *preoldparent, struct iatt *postoldparent, - struct iatt *prenewparent, struct iatt *postnewparent, - dict_t *xdata) +syncop_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *buf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_rename (xlator_t *subvol, loc_t *oldloc, loc_t *newloc, - dict_t *xdata_in, dict_t **xdata_out) +syncop_rename(xlator_t *subvol, loc_t *oldloc, loc_t *newloc, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_rename_cbk, subvol->fops->rename, - oldloc, newloc, xdata_in); + SYNCOP(subvol, (&args), syncop_rename_cbk, subvol->fops->rename, oldloc, + newloc, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; - return args.op_ret; + return args.op_ret; } - int -syncop_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +syncop_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret >= 0) { - args->iatt1 = *prebuf; - args->iatt2 = *postbuf; - } + if (op_ret >= 0) { + args->iatt1 = *prebuf; + args->iatt2 = *postbuf; + } - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_ftruncate (xlator_t *subvol, fd_t *fd, off_t offset, - struct iatt *preiatt, struct iatt *postiatt, - dict_t *xdata_in, dict_t **xdata_out) +syncop_ftruncate(xlator_t *subvol, fd_t *fd, off_t offset, struct iatt *preiatt, + struct iatt *postiatt, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->ftruncate, - fd, offset, xdata_in); + SYNCOP(subvol, (&args), syncop_ftruncate_cbk, subvol->fops->ftruncate, fd, + offset, xdata_in); - if (preiatt) - *preiatt = args.iatt1; - if (postiatt) - *postiatt = args.iatt2; + if (preiatt) + *preiatt = args.iatt1; + if (postiatt) + *postiatt = args.iatt2; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_truncate (xlator_t *subvol, loc_t *loc, off_t offset, dict_t *xdata_in, - dict_t **xdata_out) +syncop_truncate(xlator_t *subvol, loc_t *loc, off_t offset, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->truncate, - loc, offset, xdata_in); + SYNCOP(subvol, (&args), syncop_ftruncate_cbk, subvol->fops->truncate, loc, + offset, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +syncop_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret >= 0) { - args->iatt1 = *prebuf; - args->iatt2 = *postbuf; - } + if (op_ret >= 0) { + args->iatt1 = *prebuf; + args->iatt2 = *postbuf; + } - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_fsync (xlator_t *subvol, fd_t *fd, int dataonly, struct iatt *preiatt, - struct iatt *postiatt, dict_t *xdata_in, dict_t **xdata_out) +syncop_fsync(xlator_t *subvol, fd_t *fd, int dataonly, struct iatt *preiatt, + struct iatt *postiatt, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_fsync_cbk, subvol->fops->fsync, - fd, dataonly, xdata_in); + struct syncargs args = { + 0, + }; - if (preiatt) - *preiatt = args.iatt1; - if (postiatt) - *postiatt = args.iatt2; + SYNCOP(subvol, (&args), syncop_fsync_cbk, subvol->fops->fsync, fd, dataonly, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (preiatt) + *preiatt = args.iatt1; + if (postiatt) + *postiatt = args.iatt2; - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +syncop_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_flush (xlator_t *subvol, fd_t *fd, dict_t *xdata_in, - dict_t **xdata_out) +syncop_flush(xlator_t *subvol, fd_t *fd, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0}; + struct syncargs args = {0}; - SYNCOP (subvol, (&args), syncop_flush_cbk, subvol->fops->flush, - fd, xdata_in); + SYNCOP(subvol, (&args), syncop_flush_cbk, subvol->fops->flush, fd, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); - - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *stbuf, - dict_t *xdata) +syncop_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *stbuf, + dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (op_ret == 0) - args->iatt1 = *stbuf; + if (op_ret == 0) + args->iatt1 = *stbuf; - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_fstat (xlator_t *subvol, fd_t *fd, struct iatt *stbuf, dict_t *xdata_in, - dict_t **xdata_out) +syncop_fstat(xlator_t *subvol, fd_t *fd, struct iatt *stbuf, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_fstat_cbk, subvol->fops->fstat, - fd, xdata_in); + struct syncargs args = { + 0, + }; - if (stbuf) - *stbuf = args.iatt1; + SYNCOP(subvol, (&args), syncop_fstat_cbk, subvol->fops->fstat, fd, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (stbuf) + *stbuf = args.iatt1; - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_stat (xlator_t *subvol, loc_t *loc, struct iatt *stbuf, dict_t *xdata_in, - dict_t **xdata_out) +syncop_stat(xlator_t *subvol, loc_t *loc, struct iatt *stbuf, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_fstat_cbk, subvol->fops->stat, - loc, xdata_in); + struct syncargs args = { + 0, + }; - if (stbuf) - *stbuf = args.iatt1; + SYNCOP(subvol, (&args), syncop_fstat_cbk, subvol->fops->stat, loc, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (stbuf) + *stbuf = args.iatt1; - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int32_t -syncop_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_symlink (xlator_t *subvol, loc_t *loc, const char *newpath, - struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) +syncop_symlink(xlator_t *subvol, loc_t *loc, const char *newpath, + struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_symlink_cbk, subvol->fops->symlink, - newpath, loc, 0, xdata_in); + struct syncargs args = { + 0, + }; - if (iatt) - *iatt = args.iatt1; + SYNCOP(subvol, (&args), syncop_symlink_cbk, subvol->fops->symlink, newpath, + loc, 0, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (iatt) + *iatt = args.iatt1; - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, const char *path, - struct iatt *stbuf, dict_t *xdata) +syncop_readlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, const char *path, + struct iatt *stbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if ((op_ret != -1) && path) - args->buffer = gf_strdup (path); + if ((op_ret != -1) && path) + args->buffer = gf_strdup(path); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_readlink (xlator_t *subvol, loc_t *loc, char **buffer, size_t size, - dict_t *xdata_in, dict_t **xdata_out) +syncop_readlink(xlator_t *subvol, loc_t *loc, char **buffer, size_t size, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_readlink_cbk, subvol->fops->readlink, - loc, size, xdata_in); + SYNCOP(subvol, (&args), syncop_readlink_cbk, subvol->fops->readlink, loc, + size, xdata_in); - if (buffer) - *buffer = args.buffer; - else GF_FREE (args.buffer); + if (buffer) + *buffer = args.buffer; + else + GF_FREE(args.buffer); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_mknod (xlator_t *subvol, loc_t *loc, mode_t mode, dev_t rdev, - struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) +syncop_mknod(xlator_t *subvol, loc_t *loc, mode_t mode, dev_t rdev, + struct iatt *iatt, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_mknod_cbk, subvol->fops->mknod, - loc, mode, rdev, 0, xdata_in); + struct syncargs args = { + 0, + }; - if (iatt) - *iatt = args.iatt1; + SYNCOP(subvol, (&args), syncop_mknod_cbk, subvol->fops->mknod, loc, mode, + rdev, 0, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (iatt) + *iatt = args.iatt1; - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, inode_t *inode, - struct iatt *buf, struct iatt *preparent, - struct iatt *postparent, dict_t *xdata) +syncop_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *buf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } - int -syncop_mkdir (xlator_t *subvol, loc_t *loc, mode_t mode, struct iatt *iatt, - dict_t *xdata_in, dict_t **xdata_out) +syncop_mkdir(xlator_t *subvol, loc_t *loc, mode_t mode, struct iatt *iatt, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_mkdir_cbk, subvol->fops->mkdir, - loc, mode, 0, xdata_in); + struct syncargs args = { + 0, + }; - if (iatt) - *iatt = args.iatt1; + SYNCOP(subvol, (&args), syncop_mkdir_cbk, subvol->fops->mkdir, loc, mode, 0, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (iatt) + *iatt = args.iatt1; - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +syncop_access_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } /* posix_acl xlator will respond in different ways for access calls from @@ -2782,659 +2766,674 @@ syncop_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, got is the mode of the access. */ int -syncop_access (xlator_t *subvol, loc_t *loc, int32_t mask, dict_t *xdata_in, - dict_t **xdata_out) +syncop_access(xlator_t *subvol, loc_t *loc, int32_t mask, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_access_cbk, subvol->fops->access, - loc, mask, xdata_in); + SYNCOP(subvol, (&args), syncop_access_cbk, subvol->fops->access, loc, mask, + xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_errno; } - int -syncop_fallocate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +syncop_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int syncop_fallocate(xlator_t *subvol, fd_t *fd, int32_t keep_size, off_t offset, - size_t len, dict_t *xdata_in, dict_t **xdata_out) + size_t len, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_fallocate_cbk, subvol->fops->fallocate, - fd, keep_size, offset, len, xdata_in); + SYNCOP(subvol, (&args), syncop_fallocate_cbk, subvol->fops->fallocate, fd, + keep_size, offset, len, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_discard_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +syncop_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int syncop_discard(xlator_t *subvol, fd_t *fd, off_t offset, size_t len, - dict_t *xdata_in, dict_t **xdata_out) + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_discard_cbk, subvol->fops->discard, - fd, offset, len, xdata_in); + SYNCOP(subvol, (&args), syncop_discard_cbk, subvol->fops->discard, fd, + offset, len, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_zerofill_cbk (call_frame_t *frame, void *cookie, xlator_t *this, +syncop_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, int op_errno, struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int syncop_zerofill(xlator_t *subvol, fd_t *fd, off_t offset, off_t len, - dict_t *xdata_in, dict_t **xdata_out) + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_zerofill_cbk, subvol->fops->zerofill, - fd, offset, len, xdata_in); + SYNCOP(subvol, (&args), syncop_zerofill_cbk, subvol->fops->zerofill, fd, + offset, len, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } - int -syncop_ipc_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *xdata) +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; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_ipc (xlator_t *subvol, int32_t op, dict_t *xdata_in, dict_t **xdata_out) +syncop_ipc(xlator_t *subvol, int32_t op, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_ipc_cbk, subvol->fops->ipc, - op, xdata_in); + 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.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; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_seek_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, off_t offset, dict_t *xdata) +syncop_seek_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, off_t offset, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - args->offset = offset; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + args->offset = offset; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_seek (xlator_t *subvol, fd_t *fd, off_t offset, gf_seek_what_t what, - dict_t *xdata_in, off_t *off) +syncop_seek(xlator_t *subvol, fd_t *fd, off_t offset, gf_seek_what_t what, + dict_t *xdata_in, off_t *off) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_seek_cbk, subvol->fops->seek, fd, - offset, what, xdata_in); + SYNCOP(subvol, (&args), syncop_seek_cbk, subvol->fops->seek, fd, offset, + what, xdata_in); - if (*off) - *off = args.offset; + if (*off) + *off = args.offset; - if (args.op_ret == -1) - return -args.op_errno; - return args.op_ret; + if (args.op_ret == -1) + return -args.op_errno; + return args.op_ret; } int -syncop_lease_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, - int op_errno, struct gf_lease *lease, dict_t *xdata) +syncop_lease_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret, + int op_errno, struct gf_lease *lease, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); - if (lease) - args->lease = *lease; + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); + if (lease) + args->lease = *lease; - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_lease (xlator_t *subvol, loc_t *loc, struct gf_lease *lease, - dict_t *xdata_in, dict_t **xdata_out) +syncop_lease(xlator_t *subvol, loc_t *loc, struct gf_lease *lease, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_lease_cbk, subvol->fops->lease, - loc, lease, xdata_in); + SYNCOP(subvol, (&args), syncop_lease_cbk, subvol->fops->lease, loc, lease, + xdata_in); - *lease = args.lease; + *lease = args.lease; - 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.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; + 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) +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) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (flock) - args->flock = *flock; - __wake (args); + if (flock) + args->flock = *flock; + __wake(args); - return 0; + return 0; } int -syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock, - dict_t *xdata_in, dict_t **xdata_out) +syncop_lk(xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_lk_cbk, subvol->fops->lk, - fd, cmd, flock, xdata_in); + SYNCOP(subvol, (&args), syncop_lk_cbk, subvol->fops->lk, fd, cmd, flock, + xdata_in); - *flock = args.flock; + *flock = args.flock; - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int32_t -syncop_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +syncop_inodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_inodelk (xlator_t *subvol, const char *volume, loc_t *loc, int32_t cmd, - struct gf_flock *lock, dict_t *xdata_in, dict_t **xdata_out) +syncop_inodelk(xlator_t *subvol, const char *volume, loc_t *loc, int32_t cmd, + struct gf_flock *lock, dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_inodelk_cbk, subvol->fops->inodelk, - volume, loc, cmd, lock, xdata_in); + SYNCOP(subvol, (&args), syncop_inodelk_cbk, subvol->fops->inodelk, volume, + loc, cmd, lock, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; - return args.op_ret; + return args.op_ret; } int32_t -syncop_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +syncop_entrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args = cookie; + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); - return 0; + __wake(args); + return 0; } int -syncop_entrylk (xlator_t *subvol, const char *volume, loc_t *loc, - const char *basename, entrylk_cmd cmd, entrylk_type type, - dict_t *xdata_in, dict_t **xdata_out) +syncop_entrylk(xlator_t *subvol, const char *volume, loc_t *loc, + const char *basename, entrylk_cmd cmd, entrylk_type type, + dict_t *xdata_in, dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_entrylk_cbk, subvol->fops->entrylk, - volume, loc, basename, cmd, type, xdata_in); + SYNCOP(subvol, (&args), syncop_entrylk_cbk, subvol->fops->entrylk, volume, + loc, basename, cmd, type, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; - return args.op_ret; + return args.op_ret; } int32_t -syncop_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *dict, - dict_t *xdata) +syncop_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) { - struct syncargs *args = NULL; - - args = cookie; + struct syncargs *args = NULL; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); - if (dict) - args->dict_out = dict_ref (dict); + args = cookie; - __wake (args); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); + if (dict) + args->dict_out = dict_ref(dict); - return 0; + __wake(args); + return 0; } int -syncop_xattrop (xlator_t *subvol, loc_t *loc, gf_xattrop_flags_t flags, - dict_t *dict, dict_t *xdata_in, dict_t **dict_out, - dict_t **xdata_out) +syncop_xattrop(xlator_t *subvol, loc_t *loc, gf_xattrop_flags_t flags, + dict_t *dict, dict_t *xdata_in, dict_t **dict_out, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_xattrop_cbk, subvol->fops->xattrop, - loc, flags, dict, xdata_in); + SYNCOP(subvol, (&args), syncop_xattrop_cbk, subvol->fops->xattrop, loc, + flags, dict, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (dict_out) - *dict_out = args.dict_out; - else if (args.dict_out) - dict_unref (args.dict_out); + if (dict_out) + *dict_out = args.dict_out; + else if (args.dict_out) + dict_unref(args.dict_out); - if (args.op_ret < 0) - return -args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; - return args.op_ret; + return args.op_ret; } int -syncop_fxattrop (xlator_t *subvol, fd_t *fd, gf_xattrop_flags_t flags, - dict_t *dict, dict_t *xdata_in, dict_t **dict_out, - dict_t **xdata_out) +syncop_fxattrop(xlator_t *subvol, fd_t *fd, gf_xattrop_flags_t flags, + dict_t *dict, dict_t *xdata_in, dict_t **dict_out, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_xattrop_cbk, subvol->fops->fxattrop, - fd, flags, dict, xdata_in); + SYNCOP(subvol, (&args), syncop_xattrop_cbk, subvol->fops->fxattrop, fd, + flags, dict, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (dict_out) - *dict_out = args.dict_out; - else if (args.dict_out) - dict_unref (args.dict_out); + if (dict_out) + *dict_out = args.dict_out; + else if (args.dict_out) + dict_unref(args.dict_out); - if (args.op_ret < 0) - return -args.op_errno; + if (args.op_ret < 0) + return -args.op_errno; - return args.op_ret; + return args.op_ret; } int32_t -syncop_getactivelk_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - lock_migration_info_t *locklist, dict_t *xdata) +syncop_getactivelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + lock_migration_info_t *locklist, dict_t *xdata) { - struct syncargs *args = NULL; - lock_migration_info_t *tmp = NULL; - lock_migration_info_t *entry = NULL; - - args = cookie; + struct syncargs *args = NULL; + lock_migration_info_t *tmp = NULL; + lock_migration_info_t *entry = NULL; - INIT_LIST_HEAD (&args->locklist.list); + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + INIT_LIST_HEAD(&args->locklist.list); - if (op_ret > 0) { - list_for_each_entry (tmp, &locklist->list, list) { - entry = GF_CALLOC (1, sizeof (lock_migration_info_t), - gf_common_mt_char); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (!entry) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, 0, - "lock mem allocation failed"); - gf_free_mig_locks (&args->locklist); + if (op_ret > 0) { + list_for_each_entry(tmp, &locklist->list, list) + { + entry = GF_CALLOC(1, sizeof(lock_migration_info_t), + gf_common_mt_char); - break; - } + if (!entry) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, 0, + "lock mem allocation failed"); + gf_free_mig_locks(&args->locklist); - INIT_LIST_HEAD (&entry->list); + break; + } - entry->flock = tmp->flock; + INIT_LIST_HEAD(&entry->list); - entry->lk_flags = tmp->lk_flags; + entry->flock = tmp->flock; - entry->client_uid = gf_strdup (tmp->client_uid); + entry->lk_flags = tmp->lk_flags; - list_add_tail (&entry->list, &args->locklist.list); + entry->client_uid = gf_strdup(tmp->client_uid); - } + list_add_tail(&entry->list, &args->locklist.list); } + } - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_getactivelk (xlator_t *subvol, loc_t *loc, - lock_migration_info_t *locklist, dict_t *xdata_in, - dict_t **xdata_out) +syncop_getactivelk(xlator_t *subvol, loc_t *loc, + lock_migration_info_t *locklist, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; - - SYNCOP (subvol, (&args), syncop_getactivelk_cbk, - subvol->fops->getactivelk, - loc, xdata_in); + struct syncargs args = { + 0, + }; - if (locklist) - list_splice_init (&args.locklist.list, &locklist->list); - else - gf_free_mig_locks (&args.locklist) ; + SYNCOP(subvol, (&args), syncop_getactivelk_cbk, subvol->fops->getactivelk, + loc, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (locklist) + list_splice_init(&args.locklist.list, &locklist->list); + else + gf_free_mig_locks(&args.locklist); - if (args.op_ret < 0) - return -args.op_errno; + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_setactivelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, dict_t *xdata) +syncop_setactivelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) { - struct syncargs *args = NULL; - - args = cookie; + struct syncargs *args = NULL; - args->op_ret = op_ret; - args->op_errno = op_errno; + args = cookie; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); - - return 0; + __wake(args); + return 0; } int -syncop_setactivelk (xlator_t *subvol, loc_t *loc, - lock_migration_info_t *locklist, dict_t *xdata_in, - dict_t **xdata_out) +syncop_setactivelk(xlator_t *subvol, loc_t *loc, + lock_migration_info_t *locklist, dict_t *xdata_in, + dict_t **xdata_out) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_setactivelk_cbk, - subvol->fops->setactivelk, - loc, locklist, xdata_in); + SYNCOP(subvol, (&args), syncop_setactivelk_cbk, subvol->fops->setactivelk, + loc, locklist, xdata_in); - if (xdata_out) - *xdata_out = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata_out) + *xdata_out = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - if (args.op_ret < 0) - return -args.op_errno; - - return args.op_ret; + if (args.op_ret < 0) + return -args.op_errno; + return args.op_ret; } int -syncop_icreate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, +syncop_icreate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + args->op_ret = op_ret; + args->op_errno = op_errno; + if (xdata) + args->xdata = dict_ref(xdata); - if (buf) - args->iatt1 = *buf; + if (buf) + args->iatt1 = *buf; - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_namelink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +syncop_namelink_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - struct syncargs *args = NULL; + struct syncargs *args = NULL; - args = cookie; + args = cookie; - args->op_ret = op_ret; - args->op_errno = op_errno; + args->op_ret = op_ret; + args->op_errno = op_errno; - if (xdata) - args->xdata = dict_ref (xdata); + if (xdata) + args->xdata = dict_ref(xdata); - __wake (args); + __wake(args); - return 0; + return 0; } int -syncop_icreate (xlator_t *subvol, loc_t *loc, mode_t mode, dict_t *xdata) +syncop_icreate(xlator_t *subvol, loc_t *loc, mode_t mode, dict_t *xdata) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_icreate_cbk, subvol->fops->icreate, - loc, mode, xdata); + SYNCOP(subvol, (&args), syncop_icreate_cbk, subvol->fops->icreate, loc, + mode, xdata); - if (xdata) - xdata = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata) + xdata = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - errno = args.op_errno; - return args.op_ret; + errno = args.op_errno; + return args.op_ret; } int -syncop_namelink (xlator_t *subvol, loc_t *loc, dict_t *xdata) +syncop_namelink(xlator_t *subvol, loc_t *loc, dict_t *xdata) { - struct syncargs args = {0, }; + struct syncargs args = { + 0, + }; - SYNCOP (subvol, (&args), syncop_namelink_cbk, subvol->fops->namelink, - loc, xdata); + SYNCOP(subvol, (&args), syncop_namelink_cbk, subvol->fops->namelink, loc, + xdata); - if (xdata) - xdata = args.xdata; - else if (args.xdata) - dict_unref (args.xdata); + if (xdata) + xdata = args.xdata; + else if (args.xdata) + dict_unref(args.xdata); - errno = args.op_errno; - return args.op_ret; + errno = args.op_errno; + return args.op_ret; } diff --git a/libglusterfs/src/syscall.c b/libglusterfs/src/syscall.c index 6a17d1ec6ca..a3bc9189257 100644 --- a/libglusterfs/src/syscall.c +++ b/libglusterfs/src/syscall.c @@ -21,776 +21,709 @@ #include <stdarg.h> #define FS_ERROR_LOG(result) \ - do { \ - gf_msg_callingfn ("FS", GF_LOG_CRITICAL, EIO, \ - LG_MSG_SYSCALL_RETURNS_WRONG, \ - "returned %zd for the syscall", \ - (ssize_t)result); \ - } while (0) - + do { \ + gf_msg_callingfn("FS", GF_LOG_CRITICAL, EIO, \ + LG_MSG_SYSCALL_RETURNS_WRONG, \ + "returned %zd for the syscall", (ssize_t)result); \ + } while (0) /* * Input to these macros is generally a function call, so capture the result * i.e. (_ret) in another variable and use that instead of using _ret again */ -#define FS_RET_CHECK(_ret, err) \ -({ \ - typeof(_ret) _result = (_ret); \ - if (_result < -1) { \ - FS_ERROR_LOG (_result); \ - _result = -1; \ - err = EIO; \ - } \ - _result; \ - }) +#define FS_RET_CHECK(_ret, err) \ + ({ \ + typeof(_ret) _result = (_ret); \ + if (_result < -1) { \ + FS_ERROR_LOG(_result); \ + _result = -1; \ + err = EIO; \ + } \ + _result; \ + }) -#define FS_RET_CHECK0(_ret, err) \ -({ \ - typeof(_ret) _result0 = (_ret); \ - if (_result0 < -1 || _result0 > 0) { \ - FS_ERROR_LOG (_result0); \ - _result0 = -1; \ - err = EIO; \ - } \ - _result0; \ -}) +#define FS_RET_CHECK0(_ret, err) \ + ({ \ + typeof(_ret) _result0 = (_ret); \ + if (_result0 < -1 || _result0 > 0) { \ + FS_ERROR_LOG(_result0); \ + _result0 = -1; \ + err = EIO; \ + } \ + _result0; \ + }) -#define FS_RET_CHECK_ERRNO(_ret, err) \ -({ \ - typeof(_ret) _result1 = (_ret); \ - if (_result1 < 0) { \ - FS_ERROR_LOG (_result1); \ - _result1 = -1; \ - err = EIO; \ - } else if (_result1 > 0) { \ - err = _result1; \ - _result1 = -1; \ - } \ - _result1; \ -}) +#define FS_RET_CHECK_ERRNO(_ret, err) \ + ({ \ + typeof(_ret) _result1 = (_ret); \ + if (_result1 < 0) { \ + FS_ERROR_LOG(_result1); \ + _result1 = -1; \ + err = EIO; \ + } else if (_result1 > 0) { \ + err = _result1; \ + _result1 = -1; \ + } \ + _result1; \ + }) int -sys_lstat (const char *path, struct stat *buf) +sys_lstat(const char *path, struct stat *buf) { - return FS_RET_CHECK0(lstat (path, buf), errno); + return FS_RET_CHECK0(lstat(path, buf), errno); } - int -sys_stat (const char *path, struct stat *buf) +sys_stat(const char *path, struct stat *buf) { - return FS_RET_CHECK0(stat (path, buf), errno); + return FS_RET_CHECK0(stat(path, buf), errno); } - int -sys_fstat (int fd, struct stat *buf) +sys_fstat(int fd, struct stat *buf) { - return FS_RET_CHECK0(fstat (fd, buf), errno); + return FS_RET_CHECK0(fstat(fd, buf), errno); } - int sys_fstatat(int dirfd, const char *pathname, struct stat *buf, int flags) { #ifdef GF_DARWIN_HOST_OS - if (fchdir(dirfd) < 0) - return -1; - if(flags & AT_SYMLINK_NOFOLLOW) - return FS_RET_CHECK0(lstat(pathname, buf), errno); - else - return FS_RET_CHECK0(stat(pathname, buf), errno); + if (fchdir(dirfd) < 0) + return -1; + if (flags & AT_SYMLINK_NOFOLLOW) + return FS_RET_CHECK0(lstat(pathname, buf), errno); + else + return FS_RET_CHECK0(stat(pathname, buf), errno); #else - return FS_RET_CHECK0(fstatat (dirfd, pathname, buf, flags), errno); + return FS_RET_CHECK0(fstatat(dirfd, pathname, buf, flags), errno); #endif } - int sys_openat(int dirfd, const char *pathname, int flags, int mode) { - int fd; + int fd; #ifdef GF_DARWIN_HOST_OS - if (fchdir(dirfd) < 0) - return -1; - fd = open (pathname, flags, mode); - /* TODO: Shouldn't we restore the old current directory */ + if (fchdir(dirfd) < 0) + return -1; + fd = open(pathname, flags, mode); + /* TODO: Shouldn't we restore the old current directory */ #else /* GF_DARWIN_HOST_OS */ - fd = openat (dirfd, pathname, flags, mode); + fd = openat(dirfd, pathname, flags, mode); #ifdef __FreeBSD__ - /* On FreeBSD S_ISVTX flag is ignored for an open() with O_CREAT set. - * We need to force the flag using fchmod(). */ - if ((fd >= 0) && - ((flags & O_CREAT) != 0) && ((mode & S_ISVTX) != 0)) { - sys_fchmod(fd, mode); - /* TODO: It's unlikely that fchmod could fail here. However, - if it fails we cannot always restore the old state - (if the file existed, we cannot recover it). We would - need many more system calls to correctly handle all - possible cases and it doesn't worth it. For now we - simply ignore the error. */ - } + /* On FreeBSD S_ISVTX flag is ignored for an open() with O_CREAT set. + * We need to force the flag using fchmod(). */ + if ((fd >= 0) && ((flags & O_CREAT) != 0) && ((mode & S_ISVTX) != 0)) { + sys_fchmod(fd, mode); + /* TODO: It's unlikely that fchmod could fail here. However, + if it fails we cannot always restore the old state + (if the file existed, we cannot recover it). We would + need many more system calls to correctly handle all + possible cases and it doesn't worth it. For now we + simply ignore the error. */ + } #endif /* __FreeBSD__ */ #endif /* !GF_DARWIN_HOST_OS */ - return FS_RET_CHECK(fd, errno); + return FS_RET_CHECK(fd, errno); } - int sys_open(const char *pathname, int flags, int mode) { - return FS_RET_CHECK(sys_openat(AT_FDCWD, pathname, flags, mode), errno); + return FS_RET_CHECK(sys_openat(AT_FDCWD, pathname, flags, mode), errno); } - DIR * -sys_opendir (const char *name) +sys_opendir(const char *name) { - return opendir (name); + return opendir(name); } -int sys_mkdirat(int dirfd, const char *pathname, mode_t mode) +int +sys_mkdirat(int dirfd, const char *pathname, mode_t mode) { #ifdef GF_DARWIN_HOST_OS - if(fchdir(dirfd) < 0) - return -1; - return FS_RET_CHECK0(mkdir(pathname, mode), errno); + if (fchdir(dirfd) < 0) + return -1; + return FS_RET_CHECK0(mkdir(pathname, mode), errno); #else - return FS_RET_CHECK0(mkdirat (dirfd, pathname, mode), errno); + return FS_RET_CHECK0(mkdirat(dirfd, pathname, mode), errno); #endif } struct dirent * -sys_readdir (DIR *dir, struct dirent *de) +sys_readdir(DIR *dir, struct dirent *de) { #if !defined(__GLIBC__) - /* - * World+Dog says glibc's readdir(3) is MT-SAFE as long as - * two threads are not accessing the same DIR; there's a - * potential buffer overflow in glibc's readdir_r(3); and - * glibc's readdir_r(3) is deprecated after version 2.22 - * with presumed eventual removal. - * Given all that, World+Dog says everyone should just use - * readdir(3). But it's unknown, unclear whether the same - * is also true for *BSD, MacOS, and, etc. - */ - struct dirent *entry = NULL; - - (void) readdir_r (dir, de, &entry); - return entry; + /* + * World+Dog says glibc's readdir(3) is MT-SAFE as long as + * two threads are not accessing the same DIR; there's a + * potential buffer overflow in glibc's readdir_r(3); and + * glibc's readdir_r(3) is deprecated after version 2.22 + * with presumed eventual removal. + * Given all that, World+Dog says everyone should just use + * readdir(3). But it's unknown, unclear whether the same + * is also true for *BSD, MacOS, and, etc. + */ + struct dirent *entry = NULL; + + (void)readdir_r(dir, de, &entry); + return entry; #else - return readdir (dir); + return readdir(dir); #endif } - ssize_t -sys_readlink (const char *path, char *buf, size_t bufsiz) +sys_readlink(const char *path, char *buf, size_t bufsiz) { - return FS_RET_CHECK(readlink (path, buf, bufsiz), errno); + return FS_RET_CHECK(readlink(path, buf, bufsiz), errno); } - int -sys_closedir (DIR *dir) +sys_closedir(DIR *dir) { - return FS_RET_CHECK0(closedir (dir), errno); + return FS_RET_CHECK0(closedir(dir), errno); } - int -sys_mknod (const char *pathname, mode_t mode, dev_t dev) +sys_mknod(const char *pathname, mode_t mode, dev_t dev) { - return FS_RET_CHECK0(mknod (pathname, mode, dev), errno); + return FS_RET_CHECK0(mknod(pathname, mode, dev), errno); } - int -sys_mkdir (const char *pathname, mode_t mode) +sys_mkdir(const char *pathname, mode_t mode) { - return FS_RET_CHECK0(mkdir (pathname, mode), errno); + return FS_RET_CHECK0(mkdir(pathname, mode), errno); } - int -sys_unlink (const char *pathname) +sys_unlink(const char *pathname) { #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK0(solaris_unlink (pathname), errno); + return FS_RET_CHECK0(solaris_unlink(pathname), errno); #endif - return FS_RET_CHECK0(unlink (pathname), errno); + return FS_RET_CHECK0(unlink(pathname), errno); } - int -sys_rmdir (const char *pathname) +sys_rmdir(const char *pathname) { - return FS_RET_CHECK0(rmdir (pathname), errno); + return FS_RET_CHECK0(rmdir(pathname), errno); } - int -sys_symlink (const char *oldpath, const char *newpath) +sys_symlink(const char *oldpath, const char *newpath) { - return FS_RET_CHECK0(symlink (oldpath, newpath), errno); + return FS_RET_CHECK0(symlink(oldpath, newpath), errno); } - int -sys_rename (const char *oldpath, const char *newpath) +sys_rename(const char *oldpath, const char *newpath) { #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK0(solaris_rename (oldpath, newpath), errno); + return FS_RET_CHECK0(solaris_rename(oldpath, newpath), errno); #endif - return FS_RET_CHECK0(rename (oldpath, newpath), errno); + return FS_RET_CHECK0(rename(oldpath, newpath), errno); } - int -sys_link (const char *oldpath, const char *newpath) +sys_link(const char *oldpath, const char *newpath) { #ifdef HAVE_LINKAT - /* - * On most systems (Linux being the notable exception), link(2) - * first resolves symlinks. If the target is a directory or - * is nonexistent, it will fail. linkat(2) operates on the - * symlink instead of its target when the AT_SYMLINK_FOLLOW - * flag is not supplied. - */ - return FS_RET_CHECK0(linkat (AT_FDCWD, oldpath, AT_FDCWD, newpath, 0), - errno); + /* + * On most systems (Linux being the notable exception), link(2) + * first resolves symlinks. If the target is a directory or + * is nonexistent, it will fail. linkat(2) operates on the + * symlink instead of its target when the AT_SYMLINK_FOLLOW + * flag is not supplied. + */ + return FS_RET_CHECK0(linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0), + errno); #else - return FS_RET_CHECK0(link (oldpath, newpath), errno); + return FS_RET_CHECK0(link(oldpath, newpath), errno); #endif } - int -sys_chmod (const char *path, mode_t mode) +sys_chmod(const char *path, mode_t mode) { - return FS_RET_CHECK0(chmod (path, mode), errno); + return FS_RET_CHECK0(chmod(path, mode), errno); } - int -sys_fchmod (int fd, mode_t mode) +sys_fchmod(int fd, mode_t mode) { - return FS_RET_CHECK0(fchmod (fd, mode), errno); + return FS_RET_CHECK0(fchmod(fd, mode), errno); } - int -sys_chown (const char *path, uid_t owner, gid_t group) +sys_chown(const char *path, uid_t owner, gid_t group) { - return FS_RET_CHECK0(chown (path, owner, group), errno); + return FS_RET_CHECK0(chown(path, owner, group), errno); } - int -sys_fchown (int fd, uid_t owner, gid_t group) +sys_fchown(int fd, uid_t owner, gid_t group) { - return FS_RET_CHECK0(fchown (fd, owner, group), errno); + return FS_RET_CHECK0(fchown(fd, owner, group), errno); } - int -sys_lchown (const char *path, uid_t owner, gid_t group) +sys_lchown(const char *path, uid_t owner, gid_t group) { - return FS_RET_CHECK0(lchown (path, owner, group), errno); + return FS_RET_CHECK0(lchown(path, owner, group), errno); } - int -sys_truncate (const char *path, off_t length) +sys_truncate(const char *path, off_t length) { - return FS_RET_CHECK0(truncate (path, length), errno); + return FS_RET_CHECK0(truncate(path, length), errno); } - int -sys_ftruncate (int fd, off_t length) +sys_ftruncate(int fd, off_t length) { - return FS_RET_CHECK0(ftruncate (fd, length), errno); + return FS_RET_CHECK0(ftruncate(fd, length), errno); } - int -sys_utimes (const char *filename, const struct timeval times[2]) +sys_utimes(const char *filename, const struct timeval times[2]) { - return FS_RET_CHECK0(utimes (filename, times), errno); + return FS_RET_CHECK0(utimes(filename, times), errno); } - #if defined(HAVE_UTIMENSAT) int -sys_utimensat (int dirfd, const char *filename, const struct timespec times[2], - int flags) +sys_utimensat(int dirfd, const char *filename, const struct timespec times[2], + int flags) { - return FS_RET_CHECK0(utimensat (dirfd, filename, times, flags), errno); + return FS_RET_CHECK0(utimensat(dirfd, filename, times, flags), errno); } #endif - int -sys_futimes (int fd, const struct timeval times[2]) +sys_futimes(int fd, const struct timeval times[2]) { - return futimes (fd, times); + return futimes(fd, times); } - int -sys_creat (const char *pathname, mode_t mode) +sys_creat(const char *pathname, mode_t mode) { - return FS_RET_CHECK(sys_open(pathname, O_CREAT | O_TRUNC | O_WRONLY, - mode), errno); + return FS_RET_CHECK(sys_open(pathname, O_CREAT | O_TRUNC | O_WRONLY, mode), + errno); } - ssize_t -sys_readv (int fd, const struct iovec *iov, int iovcnt) +sys_readv(int fd, const struct iovec *iov, int iovcnt) { - return FS_RET_CHECK(readv (fd, iov, iovcnt), errno); + return FS_RET_CHECK(readv(fd, iov, iovcnt), errno); } - ssize_t -sys_writev (int fd, const struct iovec *iov, int iovcnt) +sys_writev(int fd, const struct iovec *iov, int iovcnt) { - return FS_RET_CHECK(writev (fd, iov, iovcnt), errno); + return FS_RET_CHECK(writev(fd, iov, iovcnt), errno); } - ssize_t -sys_read (int fd, void *buf, size_t count) +sys_read(int fd, void *buf, size_t count) { - return FS_RET_CHECK(read (fd, buf, count), errno); + return FS_RET_CHECK(read(fd, buf, count), errno); } - ssize_t -sys_write (int fd, const void *buf, size_t count) +sys_write(int fd, const void *buf, size_t count) { - return FS_RET_CHECK(write (fd, buf, count), errno); + return FS_RET_CHECK(write(fd, buf, count), errno); } - ssize_t -sys_preadv (int fd, const struct iovec *iov, int iovcnt, off_t offset) +sys_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) { - return FS_RET_CHECK(preadv (fd, iov, iovcnt, offset), errno); + return FS_RET_CHECK(preadv(fd, iov, iovcnt, offset), errno); } - ssize_t -sys_pwritev (int fd, const struct iovec *iov, int iovcnt, off_t offset) +sys_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset) { - return FS_RET_CHECK(pwritev (fd, iov, iovcnt, offset), errno); + return FS_RET_CHECK(pwritev(fd, iov, iovcnt, offset), errno); } - ssize_t -sys_pread (int fd, void *buf, size_t count, off_t offset) +sys_pread(int fd, void *buf, size_t count, off_t offset) { - return FS_RET_CHECK(pread (fd, buf, count, offset), errno); + return FS_RET_CHECK(pread(fd, buf, count, offset), errno); } - ssize_t -sys_pwrite (int fd, const void *buf, size_t count, off_t offset) +sys_pwrite(int fd, const void *buf, size_t count, off_t offset) { - return FS_RET_CHECK(pwrite (fd, buf, count, offset), errno); + return FS_RET_CHECK(pwrite(fd, buf, count, offset), errno); } - off_t -sys_lseek (int fd, off_t offset, int whence) +sys_lseek(int fd, off_t offset, int whence) { - return FS_RET_CHECK(lseek (fd, offset, whence), errno); + return FS_RET_CHECK(lseek(fd, offset, whence), errno); } - int -sys_statvfs (const char *path, struct statvfs *buf) +sys_statvfs(const char *path, struct statvfs *buf) { - int ret; + int ret; - ret = statvfs (path, buf); + ret = statvfs(path, buf); #ifdef __FreeBSD__ - /* FreeBSD doesn't return the expected value in buf->f_bsize. It - * contains the optimal I/O size instead of the file system block - * size. Gluster expects that this field contains the block size. - */ - if (ret == 0) { - buf->f_bsize = buf->f_frsize; - } + /* FreeBSD doesn't return the expected value in buf->f_bsize. It + * contains the optimal I/O size instead of the file system block + * size. Gluster expects that this field contains the block size. + */ + if (ret == 0) { + buf->f_bsize = buf->f_frsize; + } #endif /* __FreeBSD__ */ - return FS_RET_CHECK0(ret, errno); + return FS_RET_CHECK0(ret, errno); } - int -sys_fstatvfs (int fd, struct statvfs *buf) +sys_fstatvfs(int fd, struct statvfs *buf) { - int ret; + int ret; - ret = fstatvfs (fd, buf); + ret = fstatvfs(fd, buf); #ifdef __FreeBSD__ - /* FreeBSD doesn't return the expected value in buf->f_bsize. It - * contains the optimal I/O size instead of the file system block - * size. Gluster expects this field to contain the block size. - */ - if (ret == 0) { - buf->f_bsize = buf->f_frsize; - } + /* FreeBSD doesn't return the expected value in buf->f_bsize. It + * contains the optimal I/O size instead of the file system block + * size. Gluster expects this field to contain the block size. + */ + if (ret == 0) { + buf->f_bsize = buf->f_frsize; + } #endif /* __FreeBSD__ */ - return FS_RET_CHECK0(ret, errno); + return FS_RET_CHECK0(ret, errno); } - int -sys_close (int fd) +sys_close(int fd) { - int ret = -1; + int ret = -1; - if (fd >= 0) - ret = close (fd); + if (fd >= 0) + ret = close(fd); - return FS_RET_CHECK0(ret, errno); + return FS_RET_CHECK0(ret, errno); } - int -sys_fsync (int fd) +sys_fsync(int fd) { - return FS_RET_CHECK0(fsync (fd), errno); + return FS_RET_CHECK0(fsync(fd), errno); } - int -sys_fdatasync (int fd) +sys_fdatasync(int fd) { #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK0(fcntl (fd, F_FULLFSYNC), errno); + return FS_RET_CHECK0(fcntl(fd, F_FULLFSYNC), errno); #elif __FreeBSD__ - return FS_RET_CHECK0(fsync (fd), errno); + return FS_RET_CHECK0(fsync(fd), errno); #else - return FS_RET_CHECK0(fdatasync (fd), errno); + return FS_RET_CHECK0(fdatasync(fd), errno); #endif } void gf_add_prefix(const char *ns, const char *key, char **newkey) { - /* if we don't have any namespace, append USER NS */ - if (strncmp(key, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && - strncmp(key, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) && - strncmp(key, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) && - strncmp(key, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) { - int ns_length = strlen(ns); - *newkey = GF_MALLOC(ns_length + strlen(key) + 10, - gf_common_mt_char); - if (!*newkey) - return; - strcpy(*newkey, ns); - strcat(*newkey, key); - } else { - *newkey = gf_strdup(key); - } + /* if we don't have any namespace, append USER NS */ + if (strncmp(key, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && + strncmp(key, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) && + strncmp(key, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) && + strncmp(key, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) { + int ns_length = strlen(ns); + *newkey = GF_MALLOC(ns_length + strlen(key) + 10, gf_common_mt_char); + if (!*newkey) + return; + strcpy(*newkey, ns); + strcat(*newkey, key); + } else { + *newkey = gf_strdup(key); + } } void gf_remove_prefix(const char *ns, const char *key, char **newkey) { - int ns_length = strlen(ns); - if (strncmp(key, ns, ns_length) == 0) { - *newkey = GF_MALLOC(-ns_length + strlen(key) + 10, - gf_common_mt_char); - if (!*newkey) - return; - strcpy(*newkey, key + ns_length); - } else { - *newkey = gf_strdup(key); - } + int ns_length = strlen(ns); + if (strncmp(key, ns, ns_length) == 0) { + *newkey = GF_MALLOC(-ns_length + strlen(key) + 10, gf_common_mt_char); + if (!*newkey) + return; + strcpy(*newkey, key + ns_length); + } else { + *newkey = gf_strdup(key); + } } int -sys_lsetxattr (const char *path, const char *name, const void *value, - size_t size, int flags) +sys_lsetxattr(const char *path, const char *name, const void *value, + size_t size, int flags) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK0(lsetxattr (path, name, value, size, flags), errno); + return FS_RET_CHECK0(lsetxattr(path, name, value, size, flags), errno); #endif #ifdef GF_BSD_HOST_OS - return FS_RET_CHECK0(extattr_set_link (path, EXTATTR_NAMESPACE_USER, - name, value, size), errno); + return FS_RET_CHECK0( + extattr_set_link(path, EXTATTR_NAMESPACE_USER, name, value, size), + errno); #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK0(solaris_setxattr (path, name, value, size, flags), - errno); + return FS_RET_CHECK0(solaris_setxattr(path, name, value, size, flags), + errno); #endif #ifdef GF_DARWIN_HOST_OS - /* OS X clients will carry other flags, which will be used on a - OS X host, but masked out on others. GF assume NOFOLLOW on Linux, - enforcing */ - return FS_RET_CHECK0(setxattr (path, name, value, size, 0, - (flags & ~XATTR_NOSECURITY) | XATTR_NOFOLLOW), - errno); + /* OS X clients will carry other flags, which will be used on a + OS X host, but masked out on others. GF assume NOFOLLOW on Linux, + enforcing */ + return FS_RET_CHECK0(setxattr(path, name, value, size, 0, + (flags & ~XATTR_NOSECURITY) | XATTR_NOFOLLOW), + errno); #endif - } - ssize_t -sys_llistxattr (const char *path, char *list, size_t size) +sys_llistxattr(const char *path, char *list, size_t size) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK(llistxattr (path, list, size), errno); + return FS_RET_CHECK(llistxattr(path, list, size), errno); #endif #ifdef GF_BSD_HOST_OS - ssize_t ret = FS_RET_CHECK(extattr_list_link (path, - EXTATTR_NAMESPACE_USER, - list, size), errno); - gf_extattr_list_reshape (list, ret); - return ret; + ssize_t ret = FS_RET_CHECK( + extattr_list_link(path, EXTATTR_NAMESPACE_USER, list, size), errno); + gf_extattr_list_reshape(list, ret); + return ret; #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK(solaris_listxattr (path, list, size), errno); + return FS_RET_CHECK(solaris_listxattr(path, list, size), errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK(listxattr (path, list, size, XATTR_NOFOLLOW), - errno); + return FS_RET_CHECK(listxattr(path, list, size, XATTR_NOFOLLOW), errno); #endif } ssize_t -sys_lgetxattr (const char *path, const char *name, void *value, size_t size) +sys_lgetxattr(const char *path, const char *name, void *value, size_t size) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK(lgetxattr (path, name, value, size), errno); + return FS_RET_CHECK(lgetxattr(path, name, value, size), errno); #endif #ifdef GF_BSD_HOST_OS - return FS_RET_CHECK(extattr_get_link (path, EXTATTR_NAMESPACE_USER, - name, value, size), errno); + return FS_RET_CHECK( + extattr_get_link(path, EXTATTR_NAMESPACE_USER, name, value, size), + errno); #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK(solaris_getxattr (path, name, value, size), errno); + return FS_RET_CHECK(solaris_getxattr(path, name, value, size), errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK(getxattr (path, name, value, size, 0, - XATTR_NOFOLLOW), errno); + return FS_RET_CHECK(getxattr(path, name, value, size, 0, XATTR_NOFOLLOW), + errno); #endif - } - ssize_t -sys_fgetxattr (int filedes, const char *name, void *value, size_t size) +sys_fgetxattr(int filedes, const char *name, void *value, size_t size) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK(fgetxattr (filedes, name, value, size), errno); + return FS_RET_CHECK(fgetxattr(filedes, name, value, size), errno); #endif #ifdef GF_BSD_HOST_OS - return FS_RET_CHECK(extattr_get_fd (filedes, EXTATTR_NAMESPACE_USER, - name, value, size), errno); + return FS_RET_CHECK( + extattr_get_fd(filedes, EXTATTR_NAMESPACE_USER, name, value, size), + errno); #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK(solaris_fgetxattr (filedes, name, value, size), - errno); + return FS_RET_CHECK(solaris_fgetxattr(filedes, name, value, size), errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK(fgetxattr (filedes, name, value, size, 0, 0), - errno); + return FS_RET_CHECK(fgetxattr(filedes, name, value, size, 0, 0), errno); #endif - } int -sys_fremovexattr (int filedes, const char *name) +sys_fremovexattr(int filedes, const char *name) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK0(fremovexattr (filedes, name), errno); + return FS_RET_CHECK0(fremovexattr(filedes, name), errno); #endif #ifdef GF_BSD_HOST_OS - return FS_RET_CHECK0(extattr_delete_fd (filedes, EXTATTR_NAMESPACE_USER, - name), errno); + return FS_RET_CHECK0( + extattr_delete_fd(filedes, EXTATTR_NAMESPACE_USER, name), errno); #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK0(solaris_fremovexattr (filedes, name), errno); + return FS_RET_CHECK0(solaris_fremovexattr(filedes, name), errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK0(fremovexattr (filedes, name, 0), errno); + return FS_RET_CHECK0(fremovexattr(filedes, name, 0), errno); #endif } - int -sys_fsetxattr (int filedes, const char *name, const void *value, - size_t size, int flags) +sys_fsetxattr(int filedes, const char *name, const void *value, size_t size, + int flags) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK0(fsetxattr (filedes, name, value, size, flags), - errno); + return FS_RET_CHECK0(fsetxattr(filedes, name, value, size, flags), errno); #endif #ifdef GF_BSD_HOST_OS - return FS_RET_CHECK0(extattr_set_fd (filedes, EXTATTR_NAMESPACE_USER, - name, value, size), errno); + return FS_RET_CHECK0( + extattr_set_fd(filedes, EXTATTR_NAMESPACE_USER, name, value, size), + errno); #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK0(solaris_fsetxattr (filedes, name, value, size, - flags), errno); + return FS_RET_CHECK0(solaris_fsetxattr(filedes, name, value, size, flags), + errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK0(fsetxattr (filedes, name, value, size, 0, - flags & ~XATTR_NOSECURITY), errno); + return FS_RET_CHECK0( + fsetxattr(filedes, name, value, size, 0, flags & ~XATTR_NOSECURITY), + errno); #endif - } - ssize_t -sys_flistxattr (int filedes, char *list, size_t size) +sys_flistxattr(int filedes, char *list, size_t size) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK(flistxattr (filedes, list, size), errno); + return FS_RET_CHECK(flistxattr(filedes, list, size), errno); #endif #ifdef GF_BSD_HOST_OS - ssize_t ret = FS_RET_CHECK (extattr_list_fd (filedes, - EXTATTR_NAMESPACE_USER, - list, size), errno); - gf_extattr_list_reshape (list, ret); - return ret; + ssize_t ret = FS_RET_CHECK( + extattr_list_fd(filedes, EXTATTR_NAMESPACE_USER, list, size), errno); + gf_extattr_list_reshape(list, ret); + return ret; #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK(solaris_flistxattr (filedes, list, size), errno); + return FS_RET_CHECK(solaris_flistxattr(filedes, list, size), errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK(flistxattr (filedes, list, size, XATTR_NOFOLLOW), - errno); + return FS_RET_CHECK(flistxattr(filedes, list, size, XATTR_NOFOLLOW), errno); #endif - } - int -sys_lremovexattr (const char *path, const char *name) +sys_lremovexattr(const char *path, const char *name) { - #if defined(GF_LINUX_HOST_OS) || defined(__NetBSD__) - return FS_RET_CHECK0(lremovexattr (path, name), errno); + return FS_RET_CHECK0(lremovexattr(path, name), errno); #endif #ifdef GF_BSD_HOST_OS - return FS_RET_CHECK0(extattr_delete_link (path, EXTATTR_NAMESPACE_USER, - name), errno); + return FS_RET_CHECK0( + extattr_delete_link(path, EXTATTR_NAMESPACE_USER, name), errno); #endif #ifdef GF_SOLARIS_HOST_OS - return FS_RET_CHECK0(solaris_removexattr (path, name), errno); + return FS_RET_CHECK0(solaris_removexattr(path, name), errno); #endif #ifdef GF_DARWIN_HOST_OS - return FS_RET_CHECK0(removexattr (path, name, XATTR_NOFOLLOW), errno); + return FS_RET_CHECK0(removexattr(path, name, XATTR_NOFOLLOW), errno); #endif - } - int -sys_access (const char *pathname, int mode) +sys_access(const char *pathname, int mode) { - return FS_RET_CHECK0(access (pathname, mode), errno); + return FS_RET_CHECK0(access(pathname, mode), errno); } - int sys_fallocate(int fd, int mode, off_t offset, off_t len) { #ifdef HAVE_FALLOCATE - return FS_RET_CHECK0(fallocate(fd, mode, offset, len), errno); + return FS_RET_CHECK0(fallocate(fd, mode, offset, len), errno); #endif #ifdef HAVE_POSIX_FALLOCATE - if (mode) { - /* keep size not supported */ - errno = EOPNOTSUPP; - return -1; - } + if (mode) { + /* keep size not supported */ + errno = EOPNOTSUPP; + return -1; + } - return FS_RET_CHECK_ERRNO(posix_fallocate(fd, offset, len), errno); + return FS_RET_CHECK_ERRNO(posix_fallocate(fd, offset, len), errno); #endif #if defined(F_ALLOCATECONTIG) && defined(GF_DARWIN_HOST_OS) - /* C conversion from C++ implementation for OSX by Mozilla Foundation */ - if (mode) { - /* keep size not supported */ - errno = EOPNOTSUPP; - return -1; - } - /* - * The F_PREALLOCATE command operates on the following structure: - * - * typedef struct fstore { - * u_int32_t fst_flags; // IN: flags word - * int fst_posmode; // IN: indicates offset field - * off_t fst_offset; // IN: start of the region - * off_t fst_length; // IN: size of the region - * off_t fst_bytesalloc; // OUT: number of bytes allocated - * } fstore_t; - * - * The flags (fst_flags) for the F_PREALLOCATE command are as follows: - * F_ALLOCATECONTIG Allocate contiguous space. - * F_ALLOCATEALL Allocate all requested space or no space at all. - * - * The position modes (fst_posmode) for the F_PREALLOCATE command - * indicate how to use the offset field. The modes are as follows: - * F_PEOFPOSMODE Allocate from the physical end of file. - * F_VOLPOSMODE Allocate from the volume offset. - * - */ - - int ret; - fstore_t store = {F_ALLOCATECONTIG, F_PEOFPOSMODE, offset, len, 0}; - ret = fcntl (fd, F_PREALLOCATE, &store); - if (ret == -1) { - store.fst_flags = F_ALLOCATEALL; - ret = fcntl (fd, F_PREALLOCATE, &store); - } - if (ret == -1) - return ret; - return FS_RET_CHECK0(ftruncate (fd, offset + len), errno); -#endif - errno = ENOSYS; + /* C conversion from C++ implementation for OSX by Mozilla Foundation */ + if (mode) { + /* keep size not supported */ + errno = EOPNOTSUPP; return -1; + } + /* + * The F_PREALLOCATE command operates on the following structure: + * + * typedef struct fstore { + * u_int32_t fst_flags; // IN: flags word + * int fst_posmode; // IN: indicates offset field + * off_t fst_offset; // IN: start of the region + * off_t fst_length; // IN: size of the region + * off_t fst_bytesalloc; // OUT: number of bytes allocated + * } fstore_t; + * + * The flags (fst_flags) for the F_PREALLOCATE command are as follows: + * F_ALLOCATECONTIG Allocate contiguous space. + * F_ALLOCATEALL Allocate all requested space or no space at all. + * + * The position modes (fst_posmode) for the F_PREALLOCATE command + * indicate how to use the offset field. The modes are as follows: + * F_PEOFPOSMODE Allocate from the physical end of file. + * F_VOLPOSMODE Allocate from the volume offset. + * + */ + + int ret; + fstore_t store = {F_ALLOCATECONTIG, F_PEOFPOSMODE, offset, len, 0}; + ret = fcntl(fd, F_PREALLOCATE, &store); + if (ret == -1) { + store.fst_flags = F_ALLOCATEALL; + ret = fcntl(fd, F_PREALLOCATE, &store); + } + if (ret == -1) + return ret; + return FS_RET_CHECK0(ftruncate(fd, offset + len), errno); +#endif + errno = ENOSYS; + return -1; } diff --git a/libglusterfs/src/throttle-tbf.c b/libglusterfs/src/throttle-tbf.c index a425166b681..9519defa37f 100644 --- a/libglusterfs/src/throttle-tbf.c +++ b/libglusterfs/src/throttle-tbf.c @@ -27,93 +27,93 @@ #include "throttle-tbf.h" typedef struct tbf_throttle { - char done; + char done; - pthread_mutex_t mutex; - pthread_cond_t cond; + pthread_mutex_t mutex; + pthread_cond_t cond; - unsigned long tokens; + unsigned long tokens; - struct list_head list; + struct list_head list; } tbf_throttle_t; static tbf_throttle_t * -tbf_init_throttle (unsigned long tokens_required) +tbf_init_throttle(unsigned long tokens_required) { - tbf_throttle_t *throttle = NULL; + tbf_throttle_t *throttle = NULL; - throttle = GF_CALLOC (1, sizeof (*throttle), - gf_common_mt_tbf_throttle_t); - if (!throttle) - return NULL; + throttle = GF_CALLOC(1, sizeof(*throttle), gf_common_mt_tbf_throttle_t); + if (!throttle) + return NULL; - throttle->done = 0; - throttle->tokens = tokens_required; - INIT_LIST_HEAD (&throttle->list); + throttle->done = 0; + throttle->tokens = tokens_required; + INIT_LIST_HEAD(&throttle->list); - (void) pthread_mutex_init (&throttle->mutex, NULL); - (void) pthread_cond_init (&throttle->cond, NULL); + (void)pthread_mutex_init(&throttle->mutex, NULL); + (void)pthread_cond_init(&throttle->cond, NULL); - return throttle; + return throttle; } void -_tbf_dispatch_queued (tbf_bucket_t *bucket) +_tbf_dispatch_queued(tbf_bucket_t *bucket) { - gf_boolean_t xcont = _gf_false; - tbf_throttle_t *tmp = NULL; - tbf_throttle_t *throttle = NULL; - - list_for_each_entry_safe (throttle, tmp, &bucket->queued, list) { - - pthread_mutex_lock (&throttle->mutex); - { - if (bucket->tokens < throttle->tokens) { - xcont = _gf_true; - goto unblock; - } - - /* this request can now be serviced */ - throttle->done = 1; - list_del_init (&throttle->list); - - bucket->tokens -= throttle->tokens; - pthread_cond_signal (&throttle->cond); - } - unblock: - pthread_mutex_unlock (&throttle->mutex); - if (xcont) - break; + gf_boolean_t xcont = _gf_false; + tbf_throttle_t *tmp = NULL; + tbf_throttle_t *throttle = NULL; + + list_for_each_entry_safe(throttle, tmp, &bucket->queued, list) + { + pthread_mutex_lock(&throttle->mutex); + { + if (bucket->tokens < throttle->tokens) { + xcont = _gf_true; + goto unblock; + } + + /* this request can now be serviced */ + throttle->done = 1; + list_del_init(&throttle->list); + + bucket->tokens -= throttle->tokens; + pthread_cond_signal(&throttle->cond); } + unblock: + pthread_mutex_unlock(&throttle->mutex); + if (xcont) + break; + } } -void *tbf_tokengenerator (void *arg) +void * +tbf_tokengenerator(void *arg) { - unsigned long tokenrate = 0; - unsigned long maxtokens = 0; - unsigned long token_gen_interval = 0; - tbf_bucket_t *bucket = arg; - - tokenrate = bucket->tokenrate; - maxtokens = bucket->maxtokens; - token_gen_interval = bucket->token_gen_interval; - - while (1) { - usleep (token_gen_interval); - - LOCK (&bucket->lock); - { - bucket->tokens += tokenrate; - if (bucket->tokens > maxtokens) - bucket->tokens = maxtokens; - - if (!list_empty (&bucket->queued)) - _tbf_dispatch_queued (bucket); - } - UNLOCK (&bucket->lock); + unsigned long tokenrate = 0; + unsigned long maxtokens = 0; + unsigned long token_gen_interval = 0; + tbf_bucket_t *bucket = arg; + + tokenrate = bucket->tokenrate; + maxtokens = bucket->maxtokens; + token_gen_interval = bucket->token_gen_interval; + + while (1) { + usleep(token_gen_interval); + + LOCK(&bucket->lock); + { + bucket->tokens += tokenrate; + if (bucket->tokens > maxtokens) + bucket->tokens = maxtokens; + + if (!list_empty(&bucket->queued)) + _tbf_dispatch_queued(bucket); } + UNLOCK(&bucket->lock); + } - return NULL; + return NULL; } /** @@ -122,170 +122,169 @@ void *tbf_tokengenerator (void *arg) * updated _after_ all the required variables are initialized. */ static int32_t -tbf_init_bucket (tbf_t *tbf, tbf_opspec_t *spec) +tbf_init_bucket(tbf_t *tbf, tbf_opspec_t *spec) { - int ret = 0; - tbf_bucket_t *curr = NULL; - tbf_bucket_t **bucket = NULL; + int ret = 0; + tbf_bucket_t *curr = NULL; + tbf_bucket_t **bucket = NULL; - GF_ASSERT (spec->op >= TBF_OP_MIN); - GF_ASSERT (spec->op <= TBF_OP_MAX); + GF_ASSERT(spec->op >= TBF_OP_MIN); + GF_ASSERT(spec->op <= TBF_OP_MAX); - /* no rate? no throttling. */ - if (!spec->rate) - return 0; + /* no rate? no throttling. */ + if (!spec->rate) + return 0; - bucket = tbf->bucket + spec->op; + bucket = tbf->bucket + spec->op; - curr = GF_CALLOC (1, sizeof (*curr), gf_common_mt_tbf_bucket_t); - if (!curr) - goto error_return; + curr = GF_CALLOC(1, sizeof(*curr), gf_common_mt_tbf_bucket_t); + if (!curr) + goto error_return; - LOCK_INIT (&curr->lock); - INIT_LIST_HEAD (&curr->queued); + LOCK_INIT(&curr->lock); + INIT_LIST_HEAD(&curr->queued); - curr->tokens = 0; - curr->tokenrate = spec->rate; - curr->maxtokens = spec->maxlimit; - curr->token_gen_interval = spec->token_gen_interval; + curr->tokens = 0; + curr->tokenrate = spec->rate; + curr->maxtokens = spec->maxlimit; + curr->token_gen_interval = spec->token_gen_interval; - ret = gf_thread_create (&curr->tokener, - NULL, tbf_tokengenerator, curr, "tbfclock"); - if (ret != 0) - goto freemem; + ret = gf_thread_create(&curr->tokener, NULL, tbf_tokengenerator, curr, + "tbfclock"); + if (ret != 0) + goto freemem; - *bucket = curr; - return 0; + *bucket = curr; + return 0; - freemem: - LOCK_DESTROY (&curr->lock); - GF_FREE (curr); - error_return: - return -1; +freemem: + LOCK_DESTROY(&curr->lock); + GF_FREE(curr); +error_return: + return -1; } -#define TBF_ALLOC_SIZE \ - (sizeof (tbf_t) + (TBF_OP_MAX * sizeof (tbf_bucket_t))) +#define TBF_ALLOC_SIZE (sizeof(tbf_t) + (TBF_OP_MAX * sizeof(tbf_bucket_t))) tbf_t * -tbf_init (tbf_opspec_t *tbfspec, unsigned int count) +tbf_init(tbf_opspec_t *tbfspec, unsigned int count) { - int32_t i = 0; - int32_t ret = 0; - tbf_t *tbf = NULL; - tbf_opspec_t *opspec = NULL; - - tbf = GF_CALLOC (1, TBF_ALLOC_SIZE, gf_common_mt_tbf_t); - if (!tbf) - goto error_return; - - tbf->bucket = (tbf_bucket_t **) ((char *)tbf + sizeof (*tbf)); - for (i = 0; i < TBF_OP_MAX; i++) { - *(tbf->bucket + i) = NULL; - } + int32_t i = 0; + int32_t ret = 0; + tbf_t *tbf = NULL; + tbf_opspec_t *opspec = NULL; - for (i = 0; i < count; i++) { - opspec = tbfspec + i; + tbf = GF_CALLOC(1, TBF_ALLOC_SIZE, gf_common_mt_tbf_t); + if (!tbf) + goto error_return; - ret = tbf_init_bucket (tbf, opspec); - if (ret) - break; - } + tbf->bucket = (tbf_bucket_t **)((char *)tbf + sizeof(*tbf)); + for (i = 0; i < TBF_OP_MAX; i++) { + *(tbf->bucket + i) = NULL; + } + for (i = 0; i < count; i++) { + opspec = tbfspec + i; + + ret = tbf_init_bucket(tbf, opspec); if (ret) - goto error_return; + break; + } - return tbf; + if (ret) + goto error_return; - error_return: - return NULL; + return tbf; + +error_return: + return NULL; } static void -tbf_mod_bucket (tbf_bucket_t *bucket, tbf_opspec_t *spec) +tbf_mod_bucket(tbf_bucket_t *bucket, tbf_opspec_t *spec) { - LOCK (&bucket->lock); - { - bucket->tokens = 0; - bucket->tokenrate = spec->rate; - bucket->maxtokens = spec->maxlimit; - } - UNLOCK (&bucket->lock); - - /* next token tick would unqueue pending operations */ + LOCK(&bucket->lock); + { + bucket->tokens = 0; + bucket->tokenrate = spec->rate; + bucket->maxtokens = spec->maxlimit; + } + UNLOCK(&bucket->lock); + + /* next token tick would unqueue pending operations */ } int -tbf_mod (tbf_t *tbf, tbf_opspec_t *tbfspec) +tbf_mod(tbf_t *tbf, tbf_opspec_t *tbfspec) { - int ret = 0; - tbf_bucket_t *bucket = NULL; - tbf_ops_t op = TBF_OP_MIN; + int ret = 0; + tbf_bucket_t *bucket = NULL; + tbf_ops_t op = TBF_OP_MIN; - if (!tbf || !tbfspec) - return -1; + if (!tbf || !tbfspec) + return -1; - op = tbfspec->op; + op = tbfspec->op; - GF_ASSERT (op >= TBF_OP_MIN); - GF_ASSERT (op <= TBF_OP_MAX); + GF_ASSERT(op >= TBF_OP_MIN); + GF_ASSERT(op <= TBF_OP_MAX); - bucket = *(tbf->bucket + op); - if (bucket) { - tbf_mod_bucket (bucket, tbfspec); - } else { - ret = tbf_init_bucket (tbf, tbfspec); - } + bucket = *(tbf->bucket + op); + if (bucket) { + tbf_mod_bucket(bucket, tbfspec); + } else { + ret = tbf_init_bucket(tbf, tbfspec); + } - return ret; + return ret; } void -tbf_throttle (tbf_t *tbf, tbf_ops_t op, unsigned long tokens_requested) +tbf_throttle(tbf_t *tbf, tbf_ops_t op, unsigned long tokens_requested) { - char waitq = 0; - tbf_bucket_t *bucket = NULL; - tbf_throttle_t *throttle = NULL; - - GF_ASSERT (op >= TBF_OP_MIN); - GF_ASSERT (op <= TBF_OP_MAX); - - bucket = *(tbf->bucket + op); - if (!bucket) - return; + char waitq = 0; + tbf_bucket_t *bucket = NULL; + tbf_throttle_t *throttle = NULL; + + GF_ASSERT(op >= TBF_OP_MIN); + GF_ASSERT(op <= TBF_OP_MAX); + + bucket = *(tbf->bucket + op); + if (!bucket) + return; + + LOCK(&bucket->lock); + { + /** + * if there are enough tokens in the bucket there is no need + * to throttle the request: therefore, consume the required + * number of tokens and continue. + */ + if (tokens_requested <= bucket->tokens) { + bucket->tokens -= tokens_requested; + } else { + throttle = tbf_init_throttle(tokens_requested); + if (!throttle) /* let it slip through for now.. */ + goto unblock; - LOCK (&bucket->lock); - { - /** - * if there are enough tokens in the bucket there is no need - * to throttle the request: therefore, consume the required - * number of tokens and continue. - */ - if (tokens_requested <= bucket->tokens) { - bucket->tokens -= tokens_requested; - } else { - throttle = tbf_init_throttle (tokens_requested); - if (!throttle) /* let it slip through for now.. */ - goto unblock; - - waitq = 1; - pthread_mutex_lock (&throttle->mutex); - list_add_tail (&throttle->list, &bucket->queued); - } + waitq = 1; + pthread_mutex_lock(&throttle->mutex); + list_add_tail(&throttle->list, &bucket->queued); } - unblock: - UNLOCK (&bucket->lock); + } +unblock: + UNLOCK(&bucket->lock); - if (waitq) { - while (!throttle->done) { - pthread_cond_wait (&throttle->cond, &throttle->mutex); - } + if (waitq) { + while (!throttle->done) { + pthread_cond_wait(&throttle->cond, &throttle->mutex); + } - pthread_mutex_unlock (&throttle->mutex); + pthread_mutex_unlock(&throttle->mutex); - pthread_mutex_destroy (&throttle->mutex); - pthread_cond_destroy (&throttle->cond); + pthread_mutex_destroy(&throttle->mutex); + pthread_cond_destroy(&throttle->cond); - GF_FREE (throttle); - } + GF_FREE(throttle); + } } diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c index 68ac7b0edff..88a28a9bd16 100644 --- a/libglusterfs/src/timer.c +++ b/libglusterfs/src/timer.c @@ -17,265 +17,255 @@ /* fwd decl */ static gf_timer_registry_t * -gf_timer_registry_init (glusterfs_ctx_t *); +gf_timer_registry_init(glusterfs_ctx_t *); gf_timer_t * -gf_timer_call_after (glusterfs_ctx_t *ctx, - struct timespec delta, - gf_timer_cbk_t callbk, - void *data) +gf_timer_call_after(glusterfs_ctx_t *ctx, struct timespec delta, + gf_timer_cbk_t callbk, void *data) { - gf_timer_registry_t *reg = NULL; - gf_timer_t *event = NULL; - gf_timer_t *trav = NULL; - uint64_t at = 0; - - if ((ctx == NULL) || (ctx->cleanup_started)) - { - gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "Either ctx is NULL or" - " ctx cleanup started"); - return NULL; - } + gf_timer_registry_t *reg = NULL; + gf_timer_t *event = NULL; + gf_timer_t *trav = NULL; + uint64_t at = 0; + + if ((ctx == NULL) || (ctx->cleanup_started)) { + gf_msg_callingfn("timer", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "Either ctx is NULL or" + " ctx cleanup started"); + return NULL; + } - reg = gf_timer_registry_init (ctx); + reg = gf_timer_registry_init(ctx); - if (!reg) { - gf_msg_callingfn ("timer", GF_LOG_ERROR, 0, - LG_MSG_TIMER_REGISTER_ERROR, "!reg"); - return NULL; - } + if (!reg) { + gf_msg_callingfn("timer", GF_LOG_ERROR, 0, LG_MSG_TIMER_REGISTER_ERROR, + "!reg"); + return NULL; + } - event = GF_CALLOC (1, sizeof (*event), gf_common_mt_gf_timer_t); - if (!event) { - return NULL; - } - timespec_now (&event->at); - timespec_adjust_delta (&event->at, delta); - at = TS (event->at); - event->callbk = callbk; - event->data = data; - event->xl = THIS; - LOCK (®->lock); + event = GF_CALLOC(1, sizeof(*event), gf_common_mt_gf_timer_t); + if (!event) { + return NULL; + } + timespec_now(&event->at); + timespec_adjust_delta(&event->at, delta); + at = TS(event->at); + event->callbk = callbk; + event->data = data; + event->xl = THIS; + LOCK(®->lock); + { + list_for_each_entry_reverse(trav, ®->active, list) { - list_for_each_entry_reverse (trav, ®->active, list) { - if (TS (trav->at) < at) - break; - } - list_add (&event->list, &trav->list); + if (TS(trav->at) < at) + break; } - UNLOCK (®->lock); - return event; + list_add(&event->list, &trav->list); + } + UNLOCK(®->lock); + return event; } - int32_t -gf_timer_call_cancel (glusterfs_ctx_t *ctx, - gf_timer_t *event) +gf_timer_call_cancel(glusterfs_ctx_t *ctx, gf_timer_t *event) { - gf_timer_registry_t *reg = NULL; - gf_boolean_t fired = _gf_false; - - if (ctx == NULL || event == NULL) - { - gf_msg_callingfn ("timer", GF_LOG_ERROR, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return 0; - } - - if (ctx->cleanup_started) { - gf_msg_callingfn ("timer", GF_LOG_INFO, 0, - LG_MSG_CTX_CLEANUP_STARTED, - "ctx cleanup started"); - return 0; - } - - LOCK (&ctx->lock); - { - reg = ctx->timer; - } - UNLOCK (&ctx->lock); - - if (!reg) { - /* This can happen when cleanup may have just started and - * gf_timer_registry_destroy() sets ctx->timer to NULL. - * Just bail out as success as gf_timer_proc() takes - * care of cleaning up the events. - */ - return 0; - } - - LOCK (®->lock); - { - fired = event->fired; - if (fired) - goto unlock; - list_del (&event->list); - } + gf_timer_registry_t *reg = NULL; + gf_boolean_t fired = _gf_false; + + if (ctx == NULL || event == NULL) { + gf_msg_callingfn("timer", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); + return 0; + } + + if (ctx->cleanup_started) { + gf_msg_callingfn("timer", GF_LOG_INFO, 0, LG_MSG_CTX_CLEANUP_STARTED, + "ctx cleanup started"); + return 0; + } + + LOCK(&ctx->lock); + { + reg = ctx->timer; + } + UNLOCK(&ctx->lock); + + if (!reg) { + /* This can happen when cleanup may have just started and + * gf_timer_registry_destroy() sets ctx->timer to NULL. + * Just bail out as success as gf_timer_proc() takes + * care of cleaning up the events. + */ + return 0; + } + + LOCK(®->lock); + { + fired = event->fired; + if (fired) + goto unlock; + list_del(&event->list); + } unlock: - UNLOCK (®->lock); + UNLOCK(®->lock); - if (!fired) { - GF_FREE (event); - return 0; - } - return -1; + if (!fired) { + GF_FREE(event); + return 0; + } + return -1; } - static void * -gf_timer_proc (void *data) +gf_timer_proc(void *data) { - gf_timer_registry_t *reg = data; - struct timespec sleepts; - gf_timer_t *event = NULL; - gf_timer_t *tmp = NULL; - xlator_t *old_THIS = NULL; - - while (!reg->fin) { - uint64_t now; - struct timespec now_ts; - - timespec_now (&now_ts); - now = TS (now_ts); - while (1) { - uint64_t at; - char need_cbk = 0; - - /* - * This will be overridden with a shorter interval if - * there's an event scheduled sooner. That makes the - * system more responsive in most cases, but doesn't - * include the case where a timer is added while we're - * asleep. It's tempting to use pthread_cond_timedwait, - * with the caveat that we'd be relying on system time - * instead of monotonic time. That's a mess when the - * system time is adjusted. Another alternative might - * be to use pthread_kill, but that will remain TBD for - * now. - */ - sleepts.tv_sec = 1; - sleepts.tv_nsec = 0; - - LOCK (®->lock); - { - /* - * Using list_for_each and then always breaking - * after the first iteration might seem strange, - * but (unlike alternatives) is independent of - * the underlying list implementation. - */ - list_for_each_entry_safe (event, - tmp, ®->active, list) { - at = TS (event->at); - if (now >= at) { - need_cbk = 1; - event->fired = _gf_true; - list_del (&event->list); - } else { - uint64_t diff = now - at; - - if (diff < 1000000000) { - sleepts.tv_sec = 0; - sleepts.tv_nsec = diff; - } - } - break; - } - } - UNLOCK (®->lock); - if (need_cbk) { - old_THIS = NULL; - if (event->xl) { - old_THIS = THIS; - THIS = event->xl; - } - event->callbk (event->data); - GF_FREE (event); - if (old_THIS) { - THIS = old_THIS; - } - } else { - break; + gf_timer_registry_t *reg = data; + struct timespec sleepts; + gf_timer_t *event = NULL; + gf_timer_t *tmp = NULL; + xlator_t *old_THIS = NULL; + + while (!reg->fin) { + uint64_t now; + struct timespec now_ts; + + timespec_now(&now_ts); + now = TS(now_ts); + while (1) { + uint64_t at; + char need_cbk = 0; + + /* + * This will be overridden with a shorter interval if + * there's an event scheduled sooner. That makes the + * system more responsive in most cases, but doesn't + * include the case where a timer is added while we're + * asleep. It's tempting to use pthread_cond_timedwait, + * with the caveat that we'd be relying on system time + * instead of monotonic time. That's a mess when the + * system time is adjusted. Another alternative might + * be to use pthread_kill, but that will remain TBD for + * now. + */ + sleepts.tv_sec = 1; + sleepts.tv_nsec = 0; + + LOCK(®->lock); + { + /* + * Using list_for_each and then always breaking + * after the first iteration might seem strange, + * but (unlike alternatives) is independent of + * the underlying list implementation. + */ + list_for_each_entry_safe(event, tmp, ®->active, list) + { + at = TS(event->at); + if (now >= at) { + need_cbk = 1; + event->fired = _gf_true; + list_del(&event->list); + } else { + uint64_t diff = now - at; + + if (diff < 1000000000) { + sleepts.tv_sec = 0; + sleepts.tv_nsec = diff; } + } + break; + } + } + UNLOCK(®->lock); + if (need_cbk) { + old_THIS = NULL; + if (event->xl) { + old_THIS = THIS; + THIS = event->xl; } - nanosleep (&sleepts, NULL); + event->callbk(event->data); + GF_FREE(event); + if (old_THIS) { + THIS = old_THIS; + } + } else { + break; + } } - - LOCK (®->lock); + nanosleep(&sleepts, NULL); + } + + LOCK(®->lock); + { + /* Do not call gf_timer_call_cancel(), + * it will lead to deadlock + */ + list_for_each_entry_safe(event, tmp, ®->active, list) { - /* Do not call gf_timer_call_cancel(), - * it will lead to deadlock - */ - list_for_each_entry_safe (event, tmp, ®->active, list) { - list_del (&event->list); - GF_FREE (event); - } + list_del(&event->list); + GF_FREE(event); } - UNLOCK (®->lock); - LOCK_DESTROY (®->lock); + } + UNLOCK(®->lock); + LOCK_DESTROY(®->lock); - return NULL; + return NULL; } - static gf_timer_registry_t * -gf_timer_registry_init (glusterfs_ctx_t *ctx) +gf_timer_registry_init(glusterfs_ctx_t *ctx) { - gf_timer_registry_t *reg = NULL; - int ret = -1; - - LOCK (&ctx->lock); - { - reg = ctx->timer; - if (reg) { - UNLOCK (&ctx->lock); - goto out; - } - reg = GF_CALLOC (1, sizeof (*reg), - gf_common_mt_gf_timer_registry_t); - if (!reg) { - UNLOCK (&ctx->lock); - goto out; - } - ctx->timer = reg; - LOCK_INIT (®->lock); - INIT_LIST_HEAD (®->active); + gf_timer_registry_t *reg = NULL; + int ret = -1; + + LOCK(&ctx->lock); + { + reg = ctx->timer; + if (reg) { + UNLOCK(&ctx->lock); + goto out; } - UNLOCK (&ctx->lock); - ret = gf_thread_create (®->th, NULL, gf_timer_proc, reg, "timer"); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, ret, - LG_MSG_PTHREAD_FAILED, - "Thread creation failed"); + reg = GF_CALLOC(1, sizeof(*reg), gf_common_mt_gf_timer_registry_t); + if (!reg) { + UNLOCK(&ctx->lock); + goto out; } + ctx->timer = reg; + LOCK_INIT(®->lock); + INIT_LIST_HEAD(®->active); + } + UNLOCK(&ctx->lock); + ret = gf_thread_create(®->th, NULL, gf_timer_proc, reg, "timer"); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, ret, LG_MSG_PTHREAD_FAILED, + "Thread creation failed"); + } out: - return reg; + return reg; } - void -gf_timer_registry_destroy (glusterfs_ctx_t *ctx) +gf_timer_registry_destroy(glusterfs_ctx_t *ctx) { - pthread_t thr_id; - gf_timer_registry_t *reg = NULL; - - if (ctx == NULL) - return; - - LOCK (&ctx->lock); - { - reg = ctx->timer; - ctx->timer = NULL; - } - UNLOCK (&ctx->lock); - - if (!reg) - return; - - thr_id = reg->th; - reg->fin = 1; - pthread_join (thr_id, NULL); - GF_FREE (reg); + pthread_t thr_id; + gf_timer_registry_t *reg = NULL; + + if (ctx == NULL) + return; + + LOCK(&ctx->lock); + { + reg = ctx->timer; + ctx->timer = NULL; + } + UNLOCK(&ctx->lock); + + if (!reg) + return; + + thr_id = reg->th; + reg->fin = 1; + pthread_join(thr_id, NULL); + GF_FREE(reg); } diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c index 932a18c0103..d17506662ac 100644 --- a/libglusterfs/src/timespec.c +++ b/libglusterfs/src/timespec.c @@ -24,65 +24,69 @@ static mach_timebase_info_data_t gf_timebase; #include "libglusterfs-messages.h" #include "common-utils.h" -void timespec_now (struct timespec *ts) +void +timespec_now(struct timespec *ts) { -#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || defined GF_BSD_HOST_OS - if (0 == clock_gettime(CLOCK_MONOTONIC, ts)) { - /* All good */ - return; - } +#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || \ + defined GF_BSD_HOST_OS + if (0 == clock_gettime(CLOCK_MONOTONIC, ts)) { + /* All good */ + return; + } - /* Fall back, but there is hope in gettimeofday() syscall */ - struct timeval tv; - if (0 == gettimeofday(&tv, NULL)) { - /* Again, all good */ - TIMEVAL_TO_TIMESPEC(&tv, ts); - return; - } + /* Fall back, but there is hope in gettimeofday() syscall */ + struct timeval tv; + if (0 == gettimeofday(&tv, NULL)) { + /* Again, all good */ + TIMEVAL_TO_TIMESPEC(&tv, ts); + return; + } - /* If control hits here, there is surely a problem, - mainly because, as per man page too, these syscalls - shouldn't fail. Best way is to ABORT, because it is - not right */ - GF_ABORT ("gettimeofday() failed!!"); + /* If control hits here, there is surely a problem, + mainly because, as per man page too, these syscalls + shouldn't fail. Best way is to ABORT, because it is + not right */ + GF_ABORT("gettimeofday() failed!!"); #elif defined GF_DARWIN_HOST_OS - uint64_t time = mach_absolute_time(); - static double scaling = 0.0; + uint64_t time = mach_absolute_time(); + static double scaling = 0.0; - if (mach_timebase_info(&gf_timebase) != KERN_SUCCESS) { - gf_timebase.numer = 1; - gf_timebase.denom = 1; - } - if (gf_timebase.denom == 0) { - gf_timebase.numer = 1; - gf_timebase.denom = 1; - } + if (mach_timebase_info(&gf_timebase) != KERN_SUCCESS) { + gf_timebase.numer = 1; + gf_timebase.denom = 1; + } + if (gf_timebase.denom == 0) { + gf_timebase.numer = 1; + gf_timebase.denom = 1; + } - scaling = (double) gf_timebase.numer / (double) gf_timebase.denom; - time *= scaling; + scaling = (double)gf_timebase.numer / (double)gf_timebase.denom; + time *= scaling; - ts->tv_sec = (time * NANO); - ts->tv_nsec = (time - (ts->tv_sec * GIGA)); + ts->tv_sec = (time * NANO); + ts->tv_nsec = (time - (ts->tv_sec * GIGA)); #endif /* Platform verification */ } -void timespec_adjust_delta (struct timespec *ts, struct timespec delta) +void +timespec_adjust_delta(struct timespec *ts, struct timespec delta) { - ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000); - ts->tv_sec += ((ts->tv_nsec + delta.tv_nsec) / 1000000000); - ts->tv_sec += delta.tv_sec; + ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000); + ts->tv_sec += ((ts->tv_nsec + delta.tv_nsec) / 1000000000); + ts->tv_sec += delta.tv_sec; } -void timespec_sub (const struct timespec *begin, const struct timespec *end, - struct timespec *res) +void +timespec_sub(const struct timespec *begin, const struct timespec *end, + struct timespec *res) { - if (end->tv_nsec < begin->tv_nsec) { - res->tv_sec = end->tv_sec - begin->tv_sec - 1; - res->tv_nsec = end->tv_nsec + 1000000000 - begin->tv_nsec; - } else { - res->tv_sec = end->tv_sec - begin->tv_sec; - res->tv_nsec = end->tv_nsec - begin->tv_nsec; - } + if (end->tv_nsec < begin->tv_nsec) { + res->tv_sec = end->tv_sec - begin->tv_sec - 1; + res->tv_nsec = end->tv_nsec + 1000000000 - begin->tv_nsec; + } else { + res->tv_sec = end->tv_sec - begin->tv_sec; + res->tv_nsec = end->tv_nsec - begin->tv_nsec; + } } diff --git a/libglusterfs/src/trie.c b/libglusterfs/src/trie.c index f96bbebf6d3..4f01bcfe0da 100644 --- a/libglusterfs/src/trie.c +++ b/libglusterfs/src/trie.c @@ -17,371 +17,352 @@ #include "trie.h" #define DISTANCE_EDIT 1 -#define DISTANCE_INS 1 -#define DISTANCE_DEL 1 - +#define DISTANCE_INS 1 +#define DISTANCE_DEL 1 struct trienode { - char id; - char eow; - int depth; - void *data; - struct trie *trie; - struct trienode *parent; - struct trienode *subnodes[255]; + char id; + char eow; + int depth; + void *data; + struct trie *trie; + struct trienode *parent; + struct trienode *subnodes[255]; }; struct trie { - struct trienode root; - int nodecnt; - size_t len; + struct trienode root; + int nodecnt; + size_t len; }; - trie_t * -trie_new () +trie_new() { - trie_t *trie = NULL; + trie_t *trie = NULL; - trie = GF_CALLOC (1, sizeof (*trie), gf_common_mt_trie_trie); - if (!trie) - return NULL; + trie = GF_CALLOC(1, sizeof(*trie), gf_common_mt_trie_trie); + if (!trie) + return NULL; - trie->root.trie = trie; + trie->root.trie = trie; - return trie; + return trie; } - static trienode_t * -trie_subnode (trienode_t *node, int id) +trie_subnode(trienode_t *node, int id) { - trienode_t *subnode = NULL; - - subnode = node->subnodes[id]; - if (!subnode) { - subnode = GF_CALLOC (1, sizeof (*subnode), - gf_common_mt_trie_node); - if (!subnode) - return NULL; - - subnode->id = id; - subnode->depth = node->depth + 1; - node->subnodes[id] = subnode; - subnode->parent = node; - subnode->trie = node->trie; - node->trie->nodecnt++; - } - - return subnode; + trienode_t *subnode = NULL; + + subnode = node->subnodes[id]; + if (!subnode) { + subnode = GF_CALLOC(1, sizeof(*subnode), gf_common_mt_trie_node); + if (!subnode) + return NULL; + + subnode->id = id; + subnode->depth = node->depth + 1; + node->subnodes[id] = subnode; + subnode->parent = node; + subnode->trie = node->trie; + node->trie->nodecnt++; + } + + return subnode; } - int -trie_add (trie_t *trie, const char *dword) +trie_add(trie_t *trie, const char *dword) { - trienode_t *node = NULL; - int i = 0; - char id = 0; - trienode_t *subnode = NULL; + trienode_t *node = NULL; + int i = 0; + char id = 0; + trienode_t *subnode = NULL; - node = &trie->root; + node = &trie->root; - for (i = 0; i < strlen (dword); i++) { - id = dword[i]; + for (i = 0; i < strlen(dword); i++) { + id = dword[i]; - subnode = trie_subnode (node, id); - if (!subnode) - return -1; - node = subnode; - } + subnode = trie_subnode(node, id); + if (!subnode) + return -1; + node = subnode; + } - node->eow = 1; + node->eow = 1; - return 0; + return 0; } static void -trienode_free (trienode_t *node) +trienode_free(trienode_t *node) { - trienode_t *trav = NULL; - int i = 0; + trienode_t *trav = NULL; + int i = 0; - for (i = 0; i < 255; i++) { - trav = node->subnodes[i]; + for (i = 0; i < 255; i++) { + trav = node->subnodes[i]; - if (trav) - trienode_free (trav); - } + if (trav) + trienode_free(trav); + } - GF_FREE (node->data); - GF_FREE (node); + GF_FREE(node->data); + GF_FREE(node); } - void -trie_destroy (trie_t *trie) +trie_destroy(trie_t *trie) { - trienode_free ((trienode_t *)trie); + trienode_free((trienode_t *)trie); } - void -trie_destroy_bynode (trienode_t *node) +trie_destroy_bynode(trienode_t *node) { - trie_destroy (node->trie); + trie_destroy(node->trie); } - static int -trienode_walk (trienode_t *node, int (*fn)(trienode_t *node, void *data), - void *data, int eowonly) +trienode_walk(trienode_t *node, int (*fn)(trienode_t *node, void *data), + void *data, int eowonly) { - trienode_t *trav = NULL; - int i = 0; - int cret = 0; - int ret = 0; - - if (!eowonly || node->eow) - ret = fn (node, data); - - if (ret) - goto out; - - for (i = 0; i < 255; i++) { - trav = node->subnodes[i]; - if (!trav) - continue; - - cret = trienode_walk (trav, fn, data, eowonly); - if (cret < 0) { - ret = cret; - goto out; - } - ret += cret; + trienode_t *trav = NULL; + int i = 0; + int cret = 0; + int ret = 0; + + if (!eowonly || node->eow) + ret = fn(node, data); + + if (ret) + goto out; + + for (i = 0; i < 255; i++) { + trav = node->subnodes[i]; + if (!trav) + continue; + + cret = trienode_walk(trav, fn, data, eowonly); + if (cret < 0) { + ret = cret; + goto out; } + ret += cret; + } out: - return ret; + return ret; } - static int -trie_walk (trie_t *trie, int (*fn)(trienode_t *node, void *data), - void *data, int eowonly) +trie_walk(trie_t *trie, int (*fn)(trienode_t *node, void *data), void *data, + int eowonly) { - return trienode_walk (&trie->root, fn, data, eowonly); + return trienode_walk(&trie->root, fn, data, eowonly); } - static void -print_node (trienode_t *node, char **buf) +print_node(trienode_t *node, char **buf) { - if (!node->parent) - return; + if (!node->parent) + return; - if (node->parent) { - print_node (node->parent, buf); - *(*buf)++ = node->id; - } + if (node->parent) { + print_node(node->parent, buf); + *(*buf)++ = node->id; + } } - int -trienode_get_word (trienode_t *node, char **bufp) +trienode_get_word(trienode_t *node, char **bufp) { - char *buf = NULL; + char *buf = NULL; - buf = GF_CALLOC (1, node->depth + 1, gf_common_mt_trie_buf); - if (!buf) - return -1; - *bufp = buf; + buf = GF_CALLOC(1, node->depth + 1, gf_common_mt_trie_buf); + if (!buf) + return -1; + *bufp = buf; - print_node (node, &buf); + print_node(node, &buf); - return 0; + return 0; } - static int -calc_dist (trienode_t *node, void *data) +calc_dist(trienode_t *node, void *data) { - const char *word = NULL; - int i = 0; - int *row = NULL; - int *uprow = NULL; - int distu = 0; - int distl = 0; - int distul = 0; - - word = data; - - node->data = GF_CALLOC (node->trie->len, sizeof (int), - gf_common_mt_trie_data); - if (!node->data) - return -1; - row = node->data; - - if (!node->parent) { - for (i = 0; i < node->trie->len; i++) - row[i] = i+1; - - return 0; - } + const char *word = NULL; + int i = 0; + int *row = NULL; + int *uprow = NULL; + int distu = 0; + int distl = 0; + int distul = 0; + + word = data; + + node->data = GF_CALLOC(node->trie->len, sizeof(int), + gf_common_mt_trie_data); + if (!node->data) + return -1; + row = node->data; + + if (!node->parent) { + for (i = 0; i < node->trie->len; i++) + row[i] = i + 1; - uprow = node->parent->data; + return 0; + } - distu = node->depth; /* up node */ - distul = node->parent->depth; /* up-left node */ + uprow = node->parent->data; - for (i = 0; i < node->trie->len; i++) { - distl = uprow[i]; /* left node */ + distu = node->depth; /* up node */ + distul = node->parent->depth; /* up-left node */ - if (word[i] == node->id) - row[i] = distul; - else - row[i] = min ((distul + DISTANCE_EDIT), - min ((distu + DISTANCE_DEL), - (distl + DISTANCE_INS))); + for (i = 0; i < node->trie->len; i++) { + distl = uprow[i]; /* left node */ - distu = row[i]; - distul = distl; - } + if (word[i] == node->id) + row[i] = distul; + else + row[i] = min((distul + DISTANCE_EDIT), + min((distu + DISTANCE_DEL), (distl + DISTANCE_INS))); - return 0; -} + distu = row[i]; + distul = distl; + } + return 0; +} int -trienode_get_dist (trienode_t *node) +trienode_get_dist(trienode_t *node) { - int *row = NULL; + int *row = NULL; - row = node->data; + row = node->data; - return row[node->trie->len - 1]; + return row[node->trie->len - 1]; } - struct trienodevec_w { - struct trienodevec *vec; - const char *word; + struct trienodevec *vec; + const char *word; }; - static void -trienodevec_clear (struct trienodevec *nodevec) +trienodevec_clear(struct trienodevec *nodevec) { - memset(nodevec->nodes, 0, sizeof (*nodevec->nodes) * nodevec->cnt); + memset(nodevec->nodes, 0, sizeof(*nodevec->nodes) * nodevec->cnt); } - static int -collect_closest (trienode_t *node, void *data) +collect_closest(trienode_t *node, void *data) { - struct trienodevec_w *nodevec_w = NULL; - struct trienodevec *nodevec = NULL; - int dist = 0; - int i = 0; - - nodevec_w = data; - nodevec = nodevec_w->vec; - - if (calc_dist (node, (void *)nodevec_w->word)) - return -1; - - if (!node->eow || !nodevec->cnt) - return 0; - - dist = trienode_get_dist (node); - - /* - * I thought that when descending further after some dictionary word dw, - * if we see that child's distance is bigger than it was for dw, then we - * can prune this branch, as it can contain only worse nodes. - * - * This conjecture fails, see eg: - * - * d("AB", "B") = 1; - * d("AB", "BA") = 2; - * d("AB", "BAB") = 1; - * - * -- if both "B" and "BAB" are in dict., then pruning at "BA" * would - * miss "BAB". - * - * (example courtesy of Richard Bann <richardbann at gmail.com>) - - if (node->parent->eow && dist > trienode_get_dist (node->parent)) - return 1; - - */ - - if (nodevec->nodes[0] && - dist < trienode_get_dist (nodevec->nodes[0])) { - /* improving over the findings so far */ - trienodevec_clear (nodevec); - nodevec->nodes[0] = node; - } else if (!nodevec->nodes[0] || - dist == trienode_get_dist (nodevec->nodes[0])) { - /* as good as the best so far, add if there is free space */ - for (i = 0; i < nodevec->cnt; i++) { - if (!nodevec->nodes[i]) { - nodevec->nodes[i] = node; - break; - } - } - } + struct trienodevec_w *nodevec_w = NULL; + struct trienodevec *nodevec = NULL; + int dist = 0; + int i = 0; + + nodevec_w = data; + nodevec = nodevec_w->vec; + if (calc_dist(node, (void *)nodevec_w->word)) + return -1; + + if (!node->eow || !nodevec->cnt) return 0; -} + dist = trienode_get_dist(node); + + /* + * I thought that when descending further after some dictionary word dw, + * if we see that child's distance is bigger than it was for dw, then we + * can prune this branch, as it can contain only worse nodes. + * + * This conjecture fails, see eg: + * + * d("AB", "B") = 1; + * d("AB", "BA") = 2; + * d("AB", "BAB") = 1; + * + * -- if both "B" and "BAB" are in dict., then pruning at "BA" * would + * miss "BAB". + * + * (example courtesy of Richard Bann <richardbann at gmail.com>) + + if (node->parent->eow && dist > trienode_get_dist (node->parent)) + return 1; + + */ + + if (nodevec->nodes[0] && dist < trienode_get_dist(nodevec->nodes[0])) { + /* improving over the findings so far */ + trienodevec_clear(nodevec); + nodevec->nodes[0] = node; + } else if (!nodevec->nodes[0] || + dist == trienode_get_dist(nodevec->nodes[0])) { + /* as good as the best so far, add if there is free space */ + for (i = 0; i < nodevec->cnt; i++) { + if (!nodevec->nodes[i]) { + nodevec->nodes[i] = node; + break; + } + } + } + + return 0; +} int -trie_measure (trie_t *trie, const char *word, trienode_t **nodes, - int nodecnt) +trie_measure(trie_t *trie, const char *word, trienode_t **nodes, int nodecnt) { - struct trienodevec nodevec = {0,}; + struct trienodevec nodevec = { + 0, + }; - nodevec.nodes = nodes; - nodevec.cnt = nodecnt; + nodevec.nodes = nodes; + nodevec.cnt = nodecnt; - return trie_measure_vec (trie, word, &nodevec); + return trie_measure_vec(trie, word, &nodevec); } - int -trie_measure_vec (trie_t *trie, const char *word, struct trienodevec *nodevec) +trie_measure_vec(trie_t *trie, const char *word, struct trienodevec *nodevec) { - struct trienodevec_w nodevec_w = {0,}; - int ret = 0; + struct trienodevec_w nodevec_w = { + 0, + }; + int ret = 0; - trie->len = strlen (word); + trie->len = strlen(word); - trienodevec_clear (nodevec); - nodevec_w.vec = nodevec; - nodevec_w.word = word; + trienodevec_clear(nodevec); + nodevec_w.vec = nodevec; + nodevec_w.word = word; - ret = trie_walk (trie, collect_closest, &nodevec_w, 0); - if (ret > 0) - ret = 0; + ret = trie_walk(trie, collect_closest, &nodevec_w, 0); + if (ret > 0) + ret = 0; - return ret; + return ret; } - static int -trienode_reset (trienode_t *node, void *data) +trienode_reset(trienode_t *node, void *data) { - GF_FREE (node->data); + GF_FREE(node->data); - return 0; + return 0; } - void -trie_reset_search (trie_t *trie) +trie_reset_search(trie_t *trie) { - trie->len = 0; + trie->len = 0; - trie_walk (trie, trienode_reset, NULL, 0); + trie_walk(trie, trienode_reset, NULL, 0); } diff --git a/libglusterfs/src/unittest/global_mock.c b/libglusterfs/src/unittest/global_mock.c index afdadc4e868..52156847d81 100644 --- a/libglusterfs/src/unittest/global_mock.c +++ b/libglusterfs/src/unittest/global_mock.c @@ -18,7 +18,8 @@ #include <cmocka.h> -xlator_t **__glusterfs_this_location () +xlator_t ** +__glusterfs_this_location() { return ((xlator_t **)(uintptr_t)mock()); } diff --git a/libglusterfs/src/unittest/log_mock.c b/libglusterfs/src/unittest/log_mock.c index c03ff524612..d342de31067 100644 --- a/libglusterfs/src/unittest/log_mock.c +++ b/libglusterfs/src/unittest/log_mock.c @@ -18,33 +18,35 @@ #include <cmocka.h> -int _gf_log (const char *domain, const char *file, - const char *function, int32_t line, gf_loglevel_t level, - const char *fmt, ...) +int +_gf_log(const char *domain, const char *file, const char *function, + int32_t line, gf_loglevel_t level, const char *fmt, ...) { return 0; } -int _gf_log_callingfn (const char *domain, const char *file, - const char *function, int32_t line, gf_loglevel_t level, - const char *fmt, ...) +int +_gf_log_callingfn(const char *domain, const char *file, const char *function, + int32_t line, gf_loglevel_t level, const char *fmt, ...) { return 0; } -int _gf_log_nomem (const char *domain, const char *file, - const char *function, int line, gf_loglevel_t level, - size_t size) +int +_gf_log_nomem(const char *domain, const char *file, const char *function, + int line, gf_loglevel_t level, size_t size) { return 0; } -int _gf_msg_nomem (const char *domain, const char *file, - const char *function, int line, gf_loglevel_t level, - size_t size) +int +_gf_msg_nomem(const char *domain, const char *file, const char *function, + int line, gf_loglevel_t level, size_t size) { - return 0; + return 0; } void -gf_log_globals_init (void *data, gf_loglevel_t level) {} +gf_log_globals_init(void *data, gf_loglevel_t level) +{ +} diff --git a/libglusterfs/src/unittest/mem_pool_unittest.c b/libglusterfs/src/unittest/mem_pool_unittest.c index 00c7688637f..32137b95bb0 100644 --- a/libglusterfs/src/unittest/mem_pool_unittest.c +++ b/libglusterfs/src/unittest/mem_pool_unittest.c @@ -21,10 +21,10 @@ #include <cmocka.h> #ifndef assert_ptr_equal -#define assert_ptr_equal(a, b) \ - _assert_int_equal(cast_ptr_to_largest_integral_type(a), \ - cast_ptr_to_largest_integral_type(b), \ - __FILE__, __LINE__) +#define assert_ptr_equal(a, b) \ + _assert_int_equal(cast_ptr_to_largest_integral_type(a), \ + cast_ptr_to_largest_integral_type(b), __FILE__, \ + __LINE__) #endif /* @@ -42,8 +42,8 @@ typedef struct __attribute__((packed)) { * Prototypes to private functions */ int -gf_mem_set_acct_info (xlator_t *xl, char **alloc_ptr, size_t size, - uint32_t type, const char *typestr); +gf_mem_set_acct_info(xlator_t *xl, char **alloc_ptr, size_t size, uint32_t type, + const char *typestr); /* * Helper functions @@ -59,16 +59,16 @@ helper_xlator_init(uint32_t num_types) xl = test_calloc(1, sizeof(xlator_t)); assert_non_null(xl); xl->mem_acct->num_types = num_types; - xl->mem_acct = test_calloc (sizeof(struct mem_acct) - + sizeof(struct mem_acct_rec) * num_types); + xl->mem_acct = test_calloc(sizeof(struct mem_acct) + + sizeof(struct mem_acct_rec) * num_types); assert_non_null(xl->mem_acct); xl->ctx = test_calloc(1, sizeof(glusterfs_ctx_t)); assert_non_null(xl->ctx); for (i = 0; i < num_types; i++) { - ret = LOCK_INIT(&(xl->mem_acct->rec[i].lock)); - assert_int_equal(ret, 0); + ret = LOCK_INIT(&(xl->mem_acct->rec[i].lock)); + assert_int_equal(ret, 0); } ENSURE(num_types == xl->mem_acct->num_types); @@ -83,8 +83,8 @@ helper_xlator_destroy(xlator_t *xl) int i, ret; for (i = 0; i < xl->mem_acct->num_types; i++) { - ret = LOCK_DESTROY(&(xl->mem_acct->rec[i].lock)); - assert_int_equal(ret, 0); + ret = LOCK_DESTROY(&(xl->mem_acct->rec[i].lock)); + assert_int_equal(ret, 0); } free(xl->mem_acct->rec); @@ -94,20 +94,16 @@ helper_xlator_destroy(xlator_t *xl) } static void -helper_check_memory_headers( char *mem, - xlator_t *xl, - size_t size, - uint32_t type) +helper_check_memory_headers(char *mem, xlator_t *xl, size_t size, uint32_t type) { mem_header_t *p; - p = (mem_header_t *)mem, - assert_int_equal(p->type, type); + p = (mem_header_t *)mem, assert_int_equal(p->type, type); assert_int_equal(p->size, size); assert_true(p->xl == xl); assert_int_equal(p->header_magic, GF_MEM_HEADER_MAGIC); - assert_true(*(uint32_t *)(mem+sizeof(mem_header_t)+size) == GF_MEM_TRAILER_MAGIC); - + assert_true(*(uint32_t *)(mem + sizeof(mem_header_t) + size) == + GF_MEM_TRAILER_MAGIC); } /* @@ -116,7 +112,7 @@ helper_check_memory_headers( char *mem, static void test_gf_mem_acct_enable_set(void **state) { - (void) state; + (void)state; glusterfs_ctx_t test_ctx; expect_assert_failure(gf_mem_acct_enable_set(NULL)); @@ -143,14 +139,16 @@ test_gf_mem_set_acct_info_asserts(void **state) size = 8196; type = 0; - // Check xl is NULL - expect_assert_failure(gf_mem_set_acct_info(NULL, &alloc_ptr, size, type, "")); + expect_assert_failure( + gf_mem_set_acct_info(NULL, &alloc_ptr, size, type, "")); // Check xl->mem_acct = NULL - expect_assert_failure(gf_mem_set_acct_info(&xltest, &alloc_ptr, 0, type, "")); + expect_assert_failure( + gf_mem_set_acct_info(&xltest, &alloc_ptr, 0, type, "")); // Check type <= xl->mem_acct->num_types type = 100; - expect_assert_failure(gf_mem_set_acct_info(&xltest, &alloc_ptr, 0, type, "")); + expect_assert_failure( + gf_mem_set_acct_info(&xltest, &alloc_ptr, 0, type, "")); // Check alloc is NULL assert_int_equal(-1, gf_mem_set_acct_info(&xltest, NULL, size, type, "")); @@ -189,7 +187,7 @@ test_gf_mem_set_acct_info_memory(void **state) alloc_ptr = temp_ptr; gf_mem_set_acct_info(xl, &alloc_ptr, size, type, typestr); - //Check values + // Check values assert_ptr_equal(typestr, xl->mem_acct->rec[type].typestr); assert_int_equal(xl->mem_acct->rec[type].size, size); assert_int_equal(xl->mem_acct->rec[type].num_allocs, 1); @@ -420,10 +418,10 @@ test_gf_realloc_mem_acct_enabled(void **state) // not to the realloc + the malloc. // Is this a bug? // - assert_int_equal(xl->mem_acct->rec[type].size, size+1024); + assert_int_equal(xl->mem_acct->rec[type].size, size + 1024); assert_int_equal(xl->mem_acct->rec[type].num_allocs, 2); assert_int_equal(xl->mem_acct->rec[type].total_allocs, 2); - assert_int_equal(xl->mem_acct->rec[type].max_size, size+1024); + assert_int_equal(xl->mem_acct->rec[type].max_size, size + 1024); assert_int_equal(xl->mem_acct->rec[type].max_num_allocs, 2); // Check memory @@ -465,7 +463,9 @@ test_gf_realloc_ptr(void **state) helper_xlator_destroy(xl); } -int main(void) { +int +main(void) +{ const struct CMUnitTest libglusterfs_mem_pool_tests[] = { cmocka_unit_test(test_gf_mem_acct_enable_set), cmocka_unit_test(test_gf_mem_set_acct_info_asserts), diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index d3c134ba903..6975fbbd15f 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -15,605 +15,599 @@ #include "defaults.h" #include "libglusterfs-messages.h" -#define SET_DEFAULT_FOP(fn) do { \ - if (!xl->fops->fn) \ - xl->fops->fn = default_##fn; \ - if (!xl->pass_through_fops->fn) \ - xl->pass_through_fops->fn = default_##fn; \ - } while (0) - -#define SET_DEFAULT_CBK(fn) do { \ - if (!xl->cbks->fn) \ - xl->cbks->fn = default_##fn; \ - } while (0) +#define SET_DEFAULT_FOP(fn) \ + do { \ + if (!xl->fops->fn) \ + xl->fops->fn = default_##fn; \ + if (!xl->pass_through_fops->fn) \ + xl->pass_through_fops->fn = default_##fn; \ + } while (0) + +#define SET_DEFAULT_CBK(fn) \ + do { \ + if (!xl->cbks->fn) \ + xl->cbks->fn = default_##fn; \ + } while (0) pthread_mutex_t xlator_init_mutex = PTHREAD_MUTEX_INITIALIZER; void -xlator_init_lock (void) +xlator_init_lock(void) { - (void) pthread_mutex_lock (&xlator_init_mutex); + (void)pthread_mutex_lock(&xlator_init_mutex); } - void -xlator_init_unlock (void) +xlator_init_unlock(void) { - (void) pthread_mutex_unlock (&xlator_init_mutex); + (void)pthread_mutex_unlock(&xlator_init_mutex); } -static struct xlator_cbks default_cbks = { }; +static struct xlator_cbks default_cbks = {}; struct volume_options default_options[] = { - { .key = {NULL} }, + {.key = {NULL}}, }; static void -fill_defaults (xlator_t *xl) +fill_defaults(xlator_t *xl) { - if (xl == NULL) { - gf_msg_callingfn ("xlator", GF_LOG_WARNING, EINVAL, - LG_MSG_INVALID_ARG, "invalid argument"); - return; - } - - if (!xl->pass_through_fops) - xl->pass_through_fops = default_fops; - - SET_DEFAULT_FOP (create); - SET_DEFAULT_FOP (open); - SET_DEFAULT_FOP (stat); - SET_DEFAULT_FOP (readlink); - SET_DEFAULT_FOP (mknod); - SET_DEFAULT_FOP (mkdir); - SET_DEFAULT_FOP (unlink); - SET_DEFAULT_FOP (rmdir); - SET_DEFAULT_FOP (symlink); - SET_DEFAULT_FOP (rename); - SET_DEFAULT_FOP (link); - SET_DEFAULT_FOP (truncate); - SET_DEFAULT_FOP (readv); - SET_DEFAULT_FOP (writev); - SET_DEFAULT_FOP (statfs); - SET_DEFAULT_FOP (flush); - SET_DEFAULT_FOP (fsync); - SET_DEFAULT_FOP (setxattr); - SET_DEFAULT_FOP (getxattr); - SET_DEFAULT_FOP (fsetxattr); - SET_DEFAULT_FOP (fgetxattr); - SET_DEFAULT_FOP (removexattr); - SET_DEFAULT_FOP (fremovexattr); - SET_DEFAULT_FOP (opendir); - SET_DEFAULT_FOP (readdir); - SET_DEFAULT_FOP (readdirp); - SET_DEFAULT_FOP (fsyncdir); - SET_DEFAULT_FOP (access); - SET_DEFAULT_FOP (ftruncate); - SET_DEFAULT_FOP (fstat); - SET_DEFAULT_FOP (lk); - SET_DEFAULT_FOP (inodelk); - SET_DEFAULT_FOP (finodelk); - SET_DEFAULT_FOP (entrylk); - SET_DEFAULT_FOP (fentrylk); - SET_DEFAULT_FOP (lookup); - SET_DEFAULT_FOP (rchecksum); - SET_DEFAULT_FOP (xattrop); - SET_DEFAULT_FOP (fxattrop); - SET_DEFAULT_FOP (setattr); - SET_DEFAULT_FOP (fsetattr); - SET_DEFAULT_FOP (fallocate); - SET_DEFAULT_FOP (discard); - SET_DEFAULT_FOP (zerofill); - SET_DEFAULT_FOP (ipc); - SET_DEFAULT_FOP (seek); - SET_DEFAULT_FOP (lease); - SET_DEFAULT_FOP (getactivelk); - SET_DEFAULT_FOP (setactivelk); - SET_DEFAULT_FOP (put); - - SET_DEFAULT_FOP (getspec); - SET_DEFAULT_FOP (icreate); - SET_DEFAULT_FOP (namelink); - - if (!xl->cbks) - xl->cbks = &default_cbks; - - SET_DEFAULT_CBK (release); - SET_DEFAULT_CBK (releasedir); - SET_DEFAULT_CBK (forget); - - if (!xl->fini) - xl->fini = default_fini; - - if (!xl->notify) - xl->notify = default_notify; - - if (!xl->mem_acct_init) - xl->mem_acct_init = default_mem_acct_init; - + if (xl == NULL) { + gf_msg_callingfn("xlator", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, + "invalid argument"); return; + } + + if (!xl->pass_through_fops) + xl->pass_through_fops = default_fops; + + SET_DEFAULT_FOP(create); + SET_DEFAULT_FOP(open); + SET_DEFAULT_FOP(stat); + SET_DEFAULT_FOP(readlink); + SET_DEFAULT_FOP(mknod); + SET_DEFAULT_FOP(mkdir); + SET_DEFAULT_FOP(unlink); + SET_DEFAULT_FOP(rmdir); + SET_DEFAULT_FOP(symlink); + SET_DEFAULT_FOP(rename); + SET_DEFAULT_FOP(link); + SET_DEFAULT_FOP(truncate); + SET_DEFAULT_FOP(readv); + SET_DEFAULT_FOP(writev); + SET_DEFAULT_FOP(statfs); + SET_DEFAULT_FOP(flush); + SET_DEFAULT_FOP(fsync); + SET_DEFAULT_FOP(setxattr); + SET_DEFAULT_FOP(getxattr); + SET_DEFAULT_FOP(fsetxattr); + SET_DEFAULT_FOP(fgetxattr); + SET_DEFAULT_FOP(removexattr); + SET_DEFAULT_FOP(fremovexattr); + SET_DEFAULT_FOP(opendir); + SET_DEFAULT_FOP(readdir); + SET_DEFAULT_FOP(readdirp); + SET_DEFAULT_FOP(fsyncdir); + SET_DEFAULT_FOP(access); + SET_DEFAULT_FOP(ftruncate); + SET_DEFAULT_FOP(fstat); + SET_DEFAULT_FOP(lk); + SET_DEFAULT_FOP(inodelk); + SET_DEFAULT_FOP(finodelk); + SET_DEFAULT_FOP(entrylk); + SET_DEFAULT_FOP(fentrylk); + SET_DEFAULT_FOP(lookup); + SET_DEFAULT_FOP(rchecksum); + SET_DEFAULT_FOP(xattrop); + SET_DEFAULT_FOP(fxattrop); + SET_DEFAULT_FOP(setattr); + SET_DEFAULT_FOP(fsetattr); + SET_DEFAULT_FOP(fallocate); + SET_DEFAULT_FOP(discard); + SET_DEFAULT_FOP(zerofill); + SET_DEFAULT_FOP(ipc); + SET_DEFAULT_FOP(seek); + SET_DEFAULT_FOP(lease); + SET_DEFAULT_FOP(getactivelk); + SET_DEFAULT_FOP(setactivelk); + SET_DEFAULT_FOP(put); + + SET_DEFAULT_FOP(getspec); + SET_DEFAULT_FOP(icreate); + SET_DEFAULT_FOP(namelink); + + if (!xl->cbks) + xl->cbks = &default_cbks; + + SET_DEFAULT_CBK(release); + SET_DEFAULT_CBK(releasedir); + SET_DEFAULT_CBK(forget); + + if (!xl->fini) + xl->fini = default_fini; + + if (!xl->notify) + xl->notify = default_notify; + + if (!xl->mem_acct_init) + xl->mem_acct_init = default_mem_acct_init; + + return; } - int -xlator_set_type_virtual (xlator_t *xl, const char *type) +xlator_set_type_virtual(xlator_t *xl, const char *type) { - GF_VALIDATE_OR_GOTO ("xlator", xl, out); - GF_VALIDATE_OR_GOTO ("xlator", type, out); + GF_VALIDATE_OR_GOTO("xlator", xl, out); + GF_VALIDATE_OR_GOTO("xlator", type, out); - xl->type = gf_strdup (type); + xl->type = gf_strdup(type); - if (xl->type) - return 0; + if (xl->type) + return 0; out: - return -1; + return -1; } - int -xlator_volopt_dynload (char *xlator_type, void **dl_handle, - volume_opt_list_t *opt_list) +xlator_volopt_dynload(char *xlator_type, void **dl_handle, + volume_opt_list_t *opt_list) { - int ret = -1; - char *name = NULL; - void *handle = NULL; - xlator_api_t *xlapi = NULL; - - GF_VALIDATE_OR_GOTO ("xlator", xlator_type, out); - - /* socket.so doesn't fall under the default xlator directory, hence we - * need this check */ - if (!strstr(xlator_type, "rpc-transport")) - ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xlator_type); - else - ret = gf_asprintf (&name, "%s/%s.so", XLATORPARENTDIR, xlator_type); - if (-1 == ret) { - goto out; - } - - ret = -1; - - gf_msg_trace ("xlator", 0, "attempt to load file %s", name); - - handle = dlopen (name, RTLD_NOW); - if (!handle) { - gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED, - "%s", dlerror ()); - goto out; - } - - /* check new struct first, and then check this */ - xlapi = dlsym (handle, "xlator_api"); - if (!xlapi) { - gf_msg ("xlator", GF_LOG_DEBUG, 0, LG_MSG_DLSYM_ERROR, - "dlsym(xlator_api) on %s. " - "Fall back to old symbols", dlerror ()); - /* This case is not an error for now, so allow it - to fall back to old methods. */ - opt_list->given_opt = dlsym (handle, "options"); - if (!opt_list->given_opt) { - dlerror (); - gf_msg ("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED, - "Failed to load xlator opt table"); - goto out; - } - } else { - opt_list->given_opt = xlapi->options; - if (!opt_list->given_opt) { - gf_msg ("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED, - "Failed to load xlator options table"); - goto out; - } - } - - *dl_handle = handle; - handle = NULL; - - ret = 0; - out: - GF_FREE (name); - if (handle) - dlclose (handle); - - gf_msg_debug ("xlator", 0, "Returning %d", ret); - return ret; + int ret = -1; + char *name = NULL; + void *handle = NULL; + xlator_api_t *xlapi = NULL; + + GF_VALIDATE_OR_GOTO("xlator", xlator_type, out); + + /* socket.so doesn't fall under the default xlator directory, hence we + * need this check */ + if (!strstr(xlator_type, "rpc-transport")) + ret = gf_asprintf(&name, "%s/%s.so", XLATORDIR, xlator_type); + else + ret = gf_asprintf(&name, "%s/%s.so", XLATORPARENTDIR, xlator_type); + if (-1 == ret) { + goto out; + } + + ret = -1; + + gf_msg_trace("xlator", 0, "attempt to load file %s", name); + + handle = dlopen(name, RTLD_NOW); + if (!handle) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED, "%s", + dlerror()); + goto out; + } + + /* check new struct first, and then check this */ + xlapi = dlsym(handle, "xlator_api"); + if (!xlapi) { + gf_msg("xlator", GF_LOG_DEBUG, 0, LG_MSG_DLSYM_ERROR, + "dlsym(xlator_api) on %s. " + "Fall back to old symbols", + dlerror()); + /* This case is not an error for now, so allow it + to fall back to old methods. */ + opt_list->given_opt = dlsym(handle, "options"); + if (!opt_list->given_opt) { + dlerror(); + gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED, + "Failed to load xlator opt table"); + goto out; + } + } else { + opt_list->given_opt = xlapi->options; + if (!opt_list->given_opt) { + gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED, + "Failed to load xlator options table"); + goto out; + } + } + + *dl_handle = handle; + handle = NULL; + + ret = 0; +out: + GF_FREE(name); + if (handle) + dlclose(handle); + gf_msg_debug("xlator", 0, "Returning %d", ret); + return ret; } -int xlator_dynload_oldway (xlator_t *xl) +int +xlator_dynload_oldway(xlator_t *xl) { - int i = 0; - int ret = -1; - void *handle = NULL; - volume_opt_list_t *vol_opt = NULL; - class_methods_t *vtbl = NULL; - - handle = xl->dlhandle; - - xl->fops = dlsym (handle, "fops"); - if (!xl->fops) { - gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, - "dlsym(fops) on %s", dlerror ()); - goto out; - } - - xl->cbks = dlsym (handle, "cbks"); - if (!xl->cbks) { - gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, - "dlsym(cbks) on %s", dlerror ()); - goto out; - } - - /* - * If class_methods exists, its contents override any definitions of - * init or fini for that translator. Otherwise, we fall back to the - * older method of looking for init and fini directly. - */ - vtbl = dlsym(handle,"class_methods"); - if (vtbl) { - xl->init = vtbl->init; - xl->fini = vtbl->fini; - xl->reconfigure = vtbl->reconfigure; - xl->notify = vtbl->notify; - } - else { - if (!(*VOID(&xl->init) = dlsym (handle, "init"))) { - gf_msg ("xlator", GF_LOG_WARNING, 0, - LG_MSG_DLSYM_ERROR, "dlsym(init) on %s", - dlerror ()); - goto out; - } - - if (!(*VOID(&(xl->fini)) = dlsym (handle, "fini"))) { - gf_msg ("xlator", GF_LOG_WARNING, 0, - LG_MSG_DLSYM_ERROR, "dlsym(fini) on %s", - dlerror ()); - goto out; - } - if (!(*VOID(&(xl->reconfigure)) = dlsym (handle, - "reconfigure"))) { - gf_msg_trace ("xlator", 0, "dlsym(reconfigure) on %s " - "-- neglecting", dlerror()); - } - if (!(*VOID(&(xl->notify)) = dlsym (handle, "notify"))) { - gf_msg_trace ("xlator", 0, "dlsym(notify) on %s -- " - "neglecting", dlerror ()); - } - - } - - if (!(xl->dumpops = dlsym (handle, "dumpops"))) { - gf_msg_trace ("xlator", 0, "dlsym(dumpops) on %s -- " - "neglecting", dlerror ()); - } - - if (!(*VOID(&(xl->mem_acct_init)) = dlsym (handle, "mem_acct_init"))) { - gf_msg_trace (xl->name, 0, "dlsym(mem_acct_init) on %s -- " - "neglecting", dlerror ()); - } - - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - - if (!vol_opt) { - goto out; - } - - if (!(vol_opt->given_opt = dlsym (handle, "options"))) { - gf_msg_trace (xl->name, 0, "Strict option validation not " - "enforced -- neglecting (%s)", dlerror ()); - } - INIT_LIST_HEAD (&vol_opt->list); - list_add_tail (&vol_opt->list, &xl->volume_options); - - /* make sure 'min' is set to high value, so it would be - properly set later */ - for (i = 0; i < GF_FOP_MAXVALUE; i++) { - xl->stats.interval.latencies[i].min = 0xffffffff; - } - - ret = 0; + int i = 0; + int ret = -1; + void *handle = NULL; + volume_opt_list_t *vol_opt = NULL; + class_methods_t *vtbl = NULL; + + handle = xl->dlhandle; + + xl->fops = dlsym(handle, "fops"); + if (!xl->fops) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, + "dlsym(fops) on %s", dlerror()); + goto out; + } + + xl->cbks = dlsym(handle, "cbks"); + if (!xl->cbks) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, + "dlsym(cbks) on %s", dlerror()); + goto out; + } + + /* + * If class_methods exists, its contents override any definitions of + * init or fini for that translator. Otherwise, we fall back to the + * older method of looking for init and fini directly. + */ + vtbl = dlsym(handle, "class_methods"); + if (vtbl) { + xl->init = vtbl->init; + xl->fini = vtbl->fini; + xl->reconfigure = vtbl->reconfigure; + xl->notify = vtbl->notify; + } else { + if (!(*VOID(&xl->init) = dlsym(handle, "init"))) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, + "dlsym(init) on %s", dlerror()); + goto out; + } + + if (!(*VOID(&(xl->fini)) = dlsym(handle, "fini"))) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, + "dlsym(fini) on %s", dlerror()); + goto out; + } + if (!(*VOID(&(xl->reconfigure)) = dlsym(handle, "reconfigure"))) { + gf_msg_trace("xlator", 0, + "dlsym(reconfigure) on %s " + "-- neglecting", + dlerror()); + } + if (!(*VOID(&(xl->notify)) = dlsym(handle, "notify"))) { + gf_msg_trace("xlator", 0, + "dlsym(notify) on %s -- " + "neglecting", + dlerror()); + } + } + + if (!(xl->dumpops = dlsym(handle, "dumpops"))) { + gf_msg_trace("xlator", 0, + "dlsym(dumpops) on %s -- " + "neglecting", + dlerror()); + } + + if (!(*VOID(&(xl->mem_acct_init)) = dlsym(handle, "mem_acct_init"))) { + gf_msg_trace(xl->name, 0, + "dlsym(mem_acct_init) on %s -- " + "neglecting", + dlerror()); + } + + vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + + if (!vol_opt) { + goto out; + } + + if (!(vol_opt->given_opt = dlsym(handle, "options"))) { + gf_msg_trace(xl->name, 0, + "Strict option validation not " + "enforced -- neglecting (%s)", + dlerror()); + } + INIT_LIST_HEAD(&vol_opt->list); + list_add_tail(&vol_opt->list, &xl->volume_options); + + /* make sure 'min' is set to high value, so it would be + properly set later */ + for (i = 0; i < GF_FOP_MAXVALUE; i++) { + xl->stats.interval.latencies[i].min = 0xffffffff; + } + + ret = 0; out: - return ret; + return ret; } -int xlator_dynload_newway (xlator_t *xl) +int +xlator_dynload_newway(xlator_t *xl) { - int ret = -1; - void *handle = NULL; - volume_opt_list_t *vol_opt = NULL; - xlator_api_t *xlapi = NULL; - - handle = xl->dlhandle; - - xlapi = dlsym (handle, "xlator_api"); - if (!xlapi) { - gf_msg ("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR, - "dlsym(xlator_api) on %s. " - "Fall back to old symbols", dlerror ()); - /* This case is not an error for now, so allow it - to fall back to old methods. */ - ret = 1; - goto out; - } - - xl->fops = xlapi->fops; - if (!xl->fops) { - gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, - "%s: struct missing (fops)", xl->name); - goto out; - } - - xl->cbks = xlapi->cbks; - if (!xl->cbks) { - gf_msg_trace ("xlator", 0, "%s: struct missing (cbks)", - xl->name); - } + int ret = -1; + void *handle = NULL; + volume_opt_list_t *vol_opt = NULL; + xlator_api_t *xlapi = NULL; + + handle = xl->dlhandle; + + xlapi = dlsym(handle, "xlator_api"); + if (!xlapi) { + gf_msg("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR, + "dlsym(xlator_api) on %s. " + "Fall back to old symbols", + dlerror()); + /* This case is not an error for now, so allow it + to fall back to old methods. */ + ret = 1; + goto out; + } + + xl->fops = xlapi->fops; + if (!xl->fops) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, + "%s: struct missing (fops)", xl->name); + goto out; + } + + xl->cbks = xlapi->cbks; + if (!xl->cbks) { + gf_msg_trace("xlator", 0, "%s: struct missing (cbks)", xl->name); + } + + xl->init = xlapi->init; + if (!xl->init) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, + "%s: method missing (init)", xl->name); + goto out; + } + + xl->fini = xlapi->fini; + if (!xl->fini) { + gf_msg_trace("xlator", 0, "%s: method missing (fini)", xl->name); + } + + xl->reconfigure = xlapi->reconfigure; + if (!xl->reconfigure) { + gf_msg_trace("xlator", 0, "%s: method missing (reconfigure)", xl->name); + } + xl->notify = xlapi->notify; + if (!xl->notify) { + gf_msg_trace("xlator", 0, "%s: method missing (notify)", xl->name); + } + xl->dumpops = xlapi->dumpops; + if (!xl->dumpops) { + gf_msg_trace("xlator", 0, "%s: method missing (dumpops)", xl->name); + } + xl->mem_acct_init = xlapi->mem_acct_init; + if (!xl->mem_acct_init) { + gf_msg_trace("xlator", 0, "%s: method missing (mem_acct_init)", + xl->name); + } + + xl->dump_metrics = xlapi->dump_metrics; + if (!xl->dump_metrics) { + gf_msg_trace("xlator", 0, "%s: method missing (dump_metrics)", + xl->name); + } + + xl->pass_through_fops = xlapi->pass_through_fops; + if (!xl->pass_through_fops) { + gf_msg_trace("xlator", 0, + "%s: method missing (pass_through_fops), " + "falling back to default", + xl->name); + } + + vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + if (!vol_opt) { + goto out; + } + + vol_opt->given_opt = xlapi->options; + if (!vol_opt->given_opt) { + gf_msg("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR, + "%s: options not provided, using default", xl->name); + vol_opt->given_opt = default_options; + } + + INIT_LIST_HEAD(&vol_opt->list); + list_add_tail(&vol_opt->list, &xl->volume_options); + + xl->id = xlapi->xlator_id; + xl->flags = xlapi->flags; + xl->identifier = xlapi->identifier; + xl->category = xlapi->category; + + memcpy(xl->op_version, xlapi->op_version, + sizeof(uint32_t) * GF_MAX_RELEASES); + + ret = 0; +out: + return ret; +} - xl->init = xlapi->init; - if (!xl->init) { - gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR, - "%s: method missing (init)", xl->name); - goto out; - } +int +xlator_dynload(xlator_t *xl) +{ + int ret = -1; + char *name = NULL; + void *handle = NULL; - xl->fini = xlapi->fini; - if (!xl->fini) { - gf_msg_trace ("xlator", 0, "%s: method missing (fini)", - xl->name); - } + GF_VALIDATE_OR_GOTO("xlator", xl, out); - xl->reconfigure = xlapi->reconfigure; - if (!xl->reconfigure) { - gf_msg_trace ("xlator", 0, "%s: method missing (reconfigure)", - xl->name); - } - xl->notify = xlapi->notify; - if (!xl->notify) { - gf_msg_trace ("xlator", 0, "%s: method missing (notify)", - xl->name); - } - xl->dumpops = xlapi->dumpops; - if (!xl->dumpops) { - gf_msg_trace ("xlator", 0, "%s: method missing (dumpops)", - xl->name); - } - xl->mem_acct_init = xlapi->mem_acct_init; - if (!xl->mem_acct_init) { - gf_msg_trace ("xlator", 0, "%s: method missing (mem_acct_init)", - xl->name); - } + INIT_LIST_HEAD(&xl->volume_options); - xl->dump_metrics = xlapi->dump_metrics; - if (!xl->dump_metrics) { - gf_msg_trace ("xlator", 0, "%s: method missing (dump_metrics)", - xl->name); - } + ret = gf_asprintf(&name, "%s/%s.so", XLATORDIR, xl->type); + if (-1 == ret) { + goto out; + } - xl->pass_through_fops = xlapi->pass_through_fops; - if (!xl->pass_through_fops) { - gf_msg_trace ("xlator", 0, "%s: method missing (pass_through_fops), " - "falling back to default", - xl->name); - } + ret = -1; - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - if (!vol_opt) { - goto out; - } + gf_msg_trace("xlator", 0, "attempt to load file %s", name); - vol_opt->given_opt = xlapi->options; - if (!vol_opt->given_opt) { - gf_msg ("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR, - "%s: options not provided, using default", xl->name); - vol_opt->given_opt = default_options; - } + handle = dlopen(name, RTLD_NOW); + if (!handle) { + gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED, "%s", + dlerror()); + goto out; + } + xl->dlhandle = handle; - INIT_LIST_HEAD (&vol_opt->list); - list_add_tail (&vol_opt->list, &xl->volume_options); + ret = xlator_dynload_newway(xl); + if (-1 == ret) + goto out; + if (1 == ret) { + /* it means we don't find the new symbol in xlator code */ + ret = xlator_dynload_oldway(xl); + if (-1 == ret) + goto out; + } - xl->id = xlapi->xlator_id; - xl->flags = xlapi->flags; - xl->identifier = xlapi->identifier; - xl->category = xlapi->category; + fill_defaults(xl); - memcpy (xl->op_version, xlapi->op_version, - sizeof (uint32_t) * GF_MAX_RELEASES); + ret = 0; - ret = 0; out: - return ret; + GF_FREE(name); + return ret; } - int -xlator_dynload (xlator_t *xl) +xlator_set_type(xlator_t *xl, const char *type) { - int ret = -1; - char *name = NULL; - void *handle = NULL; - - GF_VALIDATE_OR_GOTO ("xlator", xl, out); - - INIT_LIST_HEAD (&xl->volume_options); + int ret = 0; - ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xl->type); - if (-1 == ret) { - goto out; - } - - ret = -1; + /* Handle 'global' translator differently */ + if (!strncmp(GF_GLOBAL_XLATOR_NAME, type, SLEN(GF_GLOBAL_XLATOR_NAME))) { + volume_opt_list_t *vol_opt = NULL; - gf_msg_trace ("xlator", 0, "attempt to load file %s", name); + /* set the required values from Global xlator */ + xl->type = gf_strdup(GF_GLOBAL_XLATOR_NAME); + xl->cbks = global_xlator.cbks; + xl->fops = global_xlator.fops; + xl->init = global_xlator.init; + xl->fini = global_xlator.fini; + xl->reconfigure = global_xlator.reconfigure; - handle = dlopen (name, RTLD_NOW); - if (!handle) { - gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED, - "%s", dlerror ()); - goto out; + vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t), + gf_common_mt_volume_opt_list_t); + if (!vol_opt) { + ret = -1; + goto out; } - xl->dlhandle = handle; - ret = xlator_dynload_newway (xl); - if (-1 == ret) - goto out; - if (1 == ret) { - /* it means we don't find the new symbol in xlator code */ - ret = xlator_dynload_oldway (xl); - if (-1 == ret) - goto out; - } + vol_opt->given_opt = global_xl_options; - fill_defaults (xl); + INIT_LIST_HEAD(&xl->volume_options); + INIT_LIST_HEAD(&vol_opt->list); + list_add_tail(&vol_opt->list, &xl->volume_options); + fill_defaults(xl); ret = 0; + goto out; + } + ret = xlator_set_type_virtual(xl, type); + if (!ret) + ret = xlator_dynload(xl); out: - GF_FREE (name); - return ret; -} - - -int -xlator_set_type (xlator_t *xl, const char *type) -{ - int ret = 0; - - /* Handle 'global' translator differently */ - if (!strncmp (GF_GLOBAL_XLATOR_NAME, type, - SLEN (GF_GLOBAL_XLATOR_NAME))) { - volume_opt_list_t *vol_opt = NULL; - - /* set the required values from Global xlator */ - xl->type = gf_strdup (GF_GLOBAL_XLATOR_NAME); - xl->cbks = global_xlator.cbks; - xl->fops = global_xlator.fops; - xl->init = global_xlator.init; - xl->fini = global_xlator.fini; - xl->reconfigure = global_xlator.reconfigure; - - vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), - gf_common_mt_volume_opt_list_t); - if (!vol_opt) { - ret = -1; - goto out; - } - - vol_opt->given_opt = global_xl_options; - - INIT_LIST_HEAD (&xl->volume_options); - INIT_LIST_HEAD (&vol_opt->list); - list_add_tail (&vol_opt->list, &xl->volume_options); - - fill_defaults(xl); - ret = 0; - goto out; - } - - ret = xlator_set_type_virtual (xl, type); - if (!ret) - ret = xlator_dynload (xl); -out: - return ret; + return ret; } void -xlator_set_inode_lru_limit (xlator_t *this, void *data) +xlator_set_inode_lru_limit(xlator_t *this, void *data) { - int inode_lru_limit = 0; - - if (this->itable) { - if (!data) { - gf_msg (this->name, GF_LOG_WARNING, 0, - LG_MSG_INVALID_ENTRY, "input data is NULL. " - "Cannot update the lru limit of the inode" - " table. Continuing with older value"); - goto out; - } - inode_lru_limit = *(int *)data; - inode_table_set_lru_limit (this->itable, inode_lru_limit); + int inode_lru_limit = 0; + + if (this->itable) { + if (!data) { + gf_msg(this->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY, + "input data is NULL. " + "Cannot update the lru limit of the inode" + " table. Continuing with older value"); + goto out; } + inode_lru_limit = *(int *)data; + inode_table_set_lru_limit(this->itable, inode_lru_limit); + } out: - return; + return; } void -xlator_foreach (xlator_t *this, - void (*fn)(xlator_t *each, - void *data), - void *data) +xlator_foreach(xlator_t *this, void (*fn)(xlator_t *each, void *data), + void *data) { - xlator_t *first = NULL; - xlator_t *old_THIS = NULL; + xlator_t *first = NULL; + xlator_t *old_THIS = NULL; - GF_VALIDATE_OR_GOTO ("xlator", this, out); - GF_VALIDATE_OR_GOTO ("xlator", fn, out); + GF_VALIDATE_OR_GOTO("xlator", this, out); + GF_VALIDATE_OR_GOTO("xlator", fn, out); - first = this; + first = this; - while (first->prev) - first = first->prev; + while (first->prev) + first = first->prev; - while (first) { - old_THIS = THIS; - THIS = first; + while (first) { + old_THIS = THIS; + THIS = first; - fn (first, data); + fn(first, data); - THIS = old_THIS; - first = first->next; - } + THIS = old_THIS; + first = first->next; + } out: - return; + return; } - void -xlator_foreach_depth_first (xlator_t *this, - void (*fn)(xlator_t *each, void *data), - void *data) +xlator_foreach_depth_first(xlator_t *this, + void (*fn)(xlator_t *each, void *data), void *data) { - xlator_list_t *subv = NULL; + xlator_list_t *subv = NULL; - subv = this->children; + subv = this->children; - while (subv) { - xlator_foreach_depth_first (subv->xlator, fn, data); - subv = subv->next; - } + while (subv) { + xlator_foreach_depth_first(subv->xlator, fn, data); + subv = subv->next; + } - fn (this, data); + fn(this, data); } - xlator_t * -xlator_search_by_name (xlator_t *any, const char *name) +xlator_search_by_name(xlator_t *any, const char *name) { - xlator_t *search = NULL; + xlator_t *search = NULL; - GF_VALIDATE_OR_GOTO ("xlator", any, out); - GF_VALIDATE_OR_GOTO ("xlator", name, out); + GF_VALIDATE_OR_GOTO("xlator", any, out); + GF_VALIDATE_OR_GOTO("xlator", name, out); - search = any; + search = any; - while (search->prev) - search = search->prev; + while (search->prev) + search = search->prev; - while (search) { - if (!strcmp (search->name, name)) - break; - search = search->next; - } + while (search) { + if (!strcmp(search->name, name)) + break; + search = search->next; + } out: - return search; + return search; } - /* * With brick multiplexing, we sort of have multiple graphs, so * xlator_search_by_name might not find what we want. Also, the translator @@ -623,294 +617,289 @@ out: * search instead of a linear search works around both problems. */ static xlator_t * -get_xlator_by_name_or_type (xlator_t *this, char *target, int is_name) +get_xlator_by_name_or_type(xlator_t *this, char *target, int is_name) { - xlator_list_t *trav; - xlator_t *child_xl; - char *value; - - for (trav = this->children; trav; trav = trav->next) { - value = is_name ? trav->xlator->name : trav->xlator->type; - if (!strcmp(value, target) && !trav->xlator->cleanup_starting) { - return trav->xlator; - } - child_xl = get_xlator_by_name_or_type (trav->xlator, target, - is_name); - if (child_xl) { - /* - * If the xlator we're looking for is somewhere down - * the stack, get_xlator_by_name expects to get a - * pointer to the top of its subtree (child of "this") - * while get_xlator_by_type expects a pointer to what - * we actually found. Handle both cases here. - * - * TBD: rename the functions and fix callers to better - * reflect the difference in semantics. - */ - return is_name ? trav->xlator : child_xl; - } - } - - return NULL; + xlator_list_t *trav; + xlator_t *child_xl; + char *value; + + for (trav = this->children; trav; trav = trav->next) { + value = is_name ? trav->xlator->name : trav->xlator->type; + if (!strcmp(value, target) && !trav->xlator->cleanup_starting) { + return trav->xlator; + } + child_xl = get_xlator_by_name_or_type(trav->xlator, target, is_name); + if (child_xl) { + /* + * If the xlator we're looking for is somewhere down + * the stack, get_xlator_by_name expects to get a + * pointer to the top of its subtree (child of "this") + * while get_xlator_by_type expects a pointer to what + * we actually found. Handle both cases here. + * + * TBD: rename the functions and fix callers to better + * reflect the difference in semantics. + */ + return is_name ? trav->xlator : child_xl; + } + } + + return NULL; } xlator_t * -get_xlator_by_name (xlator_t *this, char *target) +get_xlator_by_name(xlator_t *this, char *target) { - return get_xlator_by_name_or_type (this, target, 1); + return get_xlator_by_name_or_type(this, target, 1); } xlator_t * -get_xlator_by_type (xlator_t *this, char *target) +get_xlator_by_type(xlator_t *this, char *target) { - return get_xlator_by_name_or_type (this, target, 0); + return get_xlator_by_name_or_type(this, target, 0); } static int __xlator_init(xlator_t *xl) { - xlator_t *old_THIS = NULL; - int ret = 0; - int fop_idx = 0; + xlator_t *old_THIS = NULL; + int ret = 0; + int fop_idx = 0; - old_THIS = THIS; - THIS = xl; + old_THIS = THIS; + THIS = xl; - /* initialize the metrics related locks */ - for (fop_idx = 0; fop_idx < GF_FOP_MAXVALUE; fop_idx++) { - GF_ATOMIC_INIT (xl->stats.total.metrics[fop_idx].fop, 0); - GF_ATOMIC_INIT (xl->stats.total.metrics[fop_idx].cbk, 0); + /* initialize the metrics related locks */ + for (fop_idx = 0; fop_idx < GF_FOP_MAXVALUE; fop_idx++) { + GF_ATOMIC_INIT(xl->stats.total.metrics[fop_idx].fop, 0); + GF_ATOMIC_INIT(xl->stats.total.metrics[fop_idx].cbk, 0); - GF_ATOMIC_INIT (xl->stats.interval.metrics[fop_idx].fop, 0); - GF_ATOMIC_INIT (xl->stats.interval.metrics[fop_idx].cbk, 0); - } - GF_ATOMIC_INIT (xl->stats.total.count, 0); - GF_ATOMIC_INIT (xl->stats.interval.count, 0); + GF_ATOMIC_INIT(xl->stats.interval.metrics[fop_idx].fop, 0); + GF_ATOMIC_INIT(xl->stats.interval.metrics[fop_idx].cbk, 0); + } + GF_ATOMIC_INIT(xl->stats.total.count, 0); + GF_ATOMIC_INIT(xl->stats.interval.count, 0); - xlator_init_lock (); - ret = xl->init (xl); - xlator_init_unlock (); + xlator_init_lock(); + ret = xl->init(xl); + xlator_init_unlock(); - THIS = old_THIS; + THIS = old_THIS; - return ret; + return ret; } - int -xlator_init (xlator_t *xl) +xlator_init(xlator_t *xl) { - int32_t ret = -1; - - GF_VALIDATE_OR_GOTO ("xlator", xl, out); - - if (xl->mem_acct_init) - xl->mem_acct_init (xl); - - xl->instance_name = NULL; - if (!xl->init) { - gf_msg (xl->name, GF_LOG_WARNING, 0, LG_MSG_INIT_FAILED, - "No init() found"); - goto out; - } - - ret = __xlator_init (xl); - - if (ret) { - gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, - "Initialization of volume '%s' failed," - " review your volfile again", xl->name); - goto out; - } - - xl->init_succeeded = 1; - /*xl->cleanup_starting = 0; - xl->call_cleanup = 0; - */ - ret = 0; + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO("xlator", xl, out); + + if (xl->mem_acct_init) + xl->mem_acct_init(xl); + + xl->instance_name = NULL; + if (!xl->init) { + gf_msg(xl->name, GF_LOG_WARNING, 0, LG_MSG_INIT_FAILED, + "No init() found"); + goto out; + } + + ret = __xlator_init(xl); + + if (ret) { + gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR, + "Initialization of volume '%s' failed," + " review your volfile again", + xl->name); + goto out; + } + + xl->init_succeeded = 1; + /*xl->cleanup_starting = 0; + xl->call_cleanup = 0; + */ + ret = 0; out: - return ret; + return ret; } - static void -xlator_fini_rec (xlator_t *xl) +xlator_fini_rec(xlator_t *xl) { - xlator_list_t *trav = NULL; - xlator_t *old_THIS = NULL; + xlator_list_t *trav = NULL; + xlator_t *old_THIS = NULL; - GF_VALIDATE_OR_GOTO ("xlator", xl, out); + GF_VALIDATE_OR_GOTO("xlator", xl, out); - trav = xl->children; + trav = xl->children; - while (trav) { - if (!trav->xlator->init_succeeded) { - break; - } - - xlator_fini_rec (trav->xlator); - gf_msg_debug (trav->xlator->name, 0, "fini done"); - trav = trav->next; + while (trav) { + if (!trav->xlator->init_succeeded) { + break; } - if (xl->init_succeeded) { - if (xl->fini) { - old_THIS = THIS; - THIS = xl; + xlator_fini_rec(trav->xlator); + gf_msg_debug(trav->xlator->name, 0, "fini done"); + trav = trav->next; + } + + if (xl->init_succeeded) { + if (xl->fini) { + old_THIS = THIS; + THIS = xl; - xl->fini (xl); + xl->fini(xl); - if (xl->local_pool) - mem_pool_destroy (xl->local_pool); + if (xl->local_pool) + mem_pool_destroy(xl->local_pool); - THIS = old_THIS; - } else { - gf_msg_debug (xl->name, 0, "No fini() found"); - } - xl->init_succeeded = 0; + THIS = old_THIS; + } else { + gf_msg_debug(xl->name, 0, "No fini() found"); } + xl->init_succeeded = 0; + } out: - return; + return; } - int -xlator_notify (xlator_t *xl, int event, void *data, ...) +xlator_notify(xlator_t *xl, int event, void *data, ...) { - xlator_t *old_THIS = NULL; - int ret = 0; + xlator_t *old_THIS = NULL; + int ret = 0; - old_THIS = THIS; - THIS = xl; + old_THIS = THIS; + THIS = xl; - ret = xl->notify (xl, event, data); + ret = xl->notify(xl, event, data); - THIS = old_THIS; + THIS = old_THIS; - return ret; + return ret; } - int -xlator_mem_acct_init (xlator_t *xl, int num_types) +xlator_mem_acct_init(xlator_t *xl, int num_types) { - int i = 0; - int ret = 0; + int i = 0; + int ret = 0; - if (!xl) - return -1; - - if (!xl->ctx) - return -1; + if (!xl) + return -1; - if (!xl->ctx->mem_acct_enable) - return 0; + if (!xl->ctx) + return -1; + if (!xl->ctx->mem_acct_enable) + return 0; - xl->mem_acct = MALLOC (sizeof(struct mem_acct) - + sizeof(struct mem_acct_rec) * num_types); + xl->mem_acct = MALLOC(sizeof(struct mem_acct) + + sizeof(struct mem_acct_rec) * num_types); - if (!xl->mem_acct) { - return -1; - } + if (!xl->mem_acct) { + return -1; + } - xl->mem_acct->num_types = num_types; - GF_ATOMIC_INIT (xl->mem_acct->refcnt, 1); + xl->mem_acct->num_types = num_types; + GF_ATOMIC_INIT(xl->mem_acct->refcnt, 1); - for (i = 0; i < num_types; i++) { - memset (&xl->mem_acct->rec[i], 0, sizeof(struct mem_acct_rec)); - ret = LOCK_INIT(&(xl->mem_acct->rec[i].lock)); - if (ret) { - fprintf(stderr, "Unable to lock..errno : %d",errno); - } + for (i = 0; i < num_types; i++) { + memset(&xl->mem_acct->rec[i], 0, sizeof(struct mem_acct_rec)); + ret = LOCK_INIT(&(xl->mem_acct->rec[i].lock)); + if (ret) { + fprintf(stderr, "Unable to lock..errno : %d", errno); + } #ifdef DEBUG - INIT_LIST_HEAD(&(xl->mem_acct->rec[i].obj_list)); + INIT_LIST_HEAD(&(xl->mem_acct->rec[i].obj_list)); #endif - } + } - return 0; + return 0; } - void -xlator_tree_fini (xlator_t *xl) +xlator_tree_fini(xlator_t *xl) { - xlator_t *top = NULL; + xlator_t *top = NULL; - GF_VALIDATE_OR_GOTO ("xlator", xl, out); + GF_VALIDATE_OR_GOTO("xlator", xl, out); - top = xl; - xlator_fini_rec (top); + top = xl; + xlator_fini_rec(top); out: - return; + return; } int -xlator_list_destroy (xlator_list_t *list) +xlator_list_destroy(xlator_list_t *list) { - xlator_list_t *next = NULL; + xlator_list_t *next = NULL; - while (list) { - next = list->next; - GF_FREE (list); - list = next; - } + while (list) { + next = list->next; + GF_FREE(list); + list = next; + } - return 0; + return 0; } int -xlator_memrec_free (xlator_t *xl) +xlator_memrec_free(xlator_t *xl) { - uint32_t i = 0; - struct mem_acct *mem_acct = NULL; + uint32_t i = 0; + struct mem_acct *mem_acct = NULL; - if (!xl) { - return 0; + if (!xl) { + return 0; + } + mem_acct = xl->mem_acct; + + if (mem_acct) { + for (i = 0; i < mem_acct->num_types; i++) { + LOCK_DESTROY(&(mem_acct->rec[i].lock)); } - mem_acct = xl->mem_acct; - - if (mem_acct) { - for (i = 0; i < mem_acct->num_types; i++) { - LOCK_DESTROY (&(mem_acct->rec[i].lock)); - } - if (GF_ATOMIC_DEC (mem_acct->refcnt) == 0) { - FREE (mem_acct); - xl->mem_acct = NULL; - } + if (GF_ATOMIC_DEC(mem_acct->refcnt) == 0) { + FREE(mem_acct); + xl->mem_acct = NULL; } + } - return 0; + return 0; } static int -xlator_members_free (xlator_t *xl) +xlator_members_free(xlator_t *xl) { - volume_opt_list_t *vol_opt = NULL; - volume_opt_list_t *tmp = NULL; + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp = NULL; - if (!xl) - return 0; + if (!xl) + return 0; - GF_FREE (xl->name); - GF_FREE (xl->type); - if (!(xl->ctx && xl->ctx->cmd_args.valgrind) && xl->dlhandle) - dlclose (xl->dlhandle); - if (xl->options) - dict_unref (xl->options); + GF_FREE(xl->name); + GF_FREE(xl->type); + if (!(xl->ctx && xl->ctx->cmd_args.valgrind) && xl->dlhandle) + dlclose(xl->dlhandle); + if (xl->options) + dict_unref(xl->options); - xlator_list_destroy (xl->children); + xlator_list_destroy(xl->children); - xlator_list_destroy (xl->parents); + xlator_list_destroy(xl->parents); - list_for_each_entry_safe (vol_opt, tmp, &xl->volume_options, list) { - list_del_init (&vol_opt->list); - GF_FREE (vol_opt); - } + list_for_each_entry_safe(vol_opt, tmp, &xl->volume_options, list) + { + list_del_init(&vol_opt->list); + GF_FREE(vol_opt); + } - return 0; + return 0; } /* This function destroys all the xlator members except for the @@ -939,609 +928,606 @@ xlator_members_free (xlator_t *xl) */ int -xlator_tree_free_members (xlator_t *tree) +xlator_tree_free_members(xlator_t *tree) { - xlator_t *trav = tree; - xlator_t *prev = tree; + xlator_t *trav = tree; + xlator_t *prev = tree; - if (!tree) { - gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND, - "Translator tree not found"); - return -1; - } + if (!tree) { + gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND, + "Translator tree not found"); + return -1; + } - while (prev) { - trav = prev->next; - xlator_members_free (prev); - prev = trav; - } + while (prev) { + trav = prev->next; + xlator_members_free(prev); + prev = trav; + } - return 0; + return 0; } int -xlator_tree_free_memacct (xlator_t *tree) +xlator_tree_free_memacct(xlator_t *tree) { - xlator_t *trav = tree; - xlator_t *prev = tree; + xlator_t *trav = tree; + xlator_t *prev = tree; - if (!tree) { - gf_msg ("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND, - "Translator tree not found"); - return -1; - } + if (!tree) { + gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND, + "Translator tree not found"); + return -1; + } - while (prev) { - trav = prev->next; - xlator_memrec_free (prev); - GF_FREE (prev); - prev = trav; - } + while (prev) { + trav = prev->next; + xlator_memrec_free(prev); + GF_FREE(prev); + prev = trav; + } - return 0; + return 0; } static int -xlator_mem_free (xlator_t *xl) +xlator_mem_free(xlator_t *xl) { - volume_opt_list_t *vol_opt = NULL; - volume_opt_list_t *tmp = NULL; + volume_opt_list_t *vol_opt = NULL; + volume_opt_list_t *tmp = NULL; - if (!xl) - return 0; + if (!xl) + return 0; - if (xl->options) { - dict_ref (xl->options); - dict_unref (xl->options); - xl->options = NULL; - } + if (xl->options) { + dict_ref(xl->options); + dict_unref(xl->options); + xl->options = NULL; + } - list_for_each_entry_safe (vol_opt, tmp, &xl->volume_options, list) { - list_del_init (&vol_opt->list); - GF_FREE (vol_opt); - } + list_for_each_entry_safe(vol_opt, tmp, &xl->volume_options, list) + { + list_del_init(&vol_opt->list); + GF_FREE(vol_opt); + } - xlator_memrec_free (xl); + xlator_memrec_free(xl); - return 0; + return 0; } static void -xlator_call_fini (xlator_t *this) { - if (!this || this->cleanup_starting) - return; - this->cleanup_starting = 1; - this->call_cleanup = 1; - xlator_call_fini (this->next); - this->fini (this); +xlator_call_fini(xlator_t *this) +{ + if (!this || this->cleanup_starting) + return; + this->cleanup_starting = 1; + this->call_cleanup = 1; + xlator_call_fini(this->next); + this->fini(this); } void -xlator_mem_cleanup (xlator_t *this) { - xlator_list_t *list = this->children; - xlator_t *trav = list->xlator; - inode_table_t *inode_table = NULL; - xlator_t *prev = trav; - glusterfs_ctx_t *ctx = NULL; - xlator_list_t **trav_p = NULL; - xlator_t *top = NULL; - xlator_t *victim = NULL; - - - if (this->call_cleanup || !this->ctx) - return; - - this->call_cleanup = 1; - ctx = this->ctx; - - xlator_call_fini (trav); - - while (prev) { - trav = prev->next; - xlator_mem_free (prev); - prev = trav; - } - - inode_table = this->itable; - if (inode_table) { - inode_table_destroy (inode_table); - this->itable = NULL; - } - - if (this->fini) { - this->fini (this); - } +xlator_mem_cleanup(xlator_t *this) +{ + xlator_list_t *list = this->children; + xlator_t *trav = list->xlator; + inode_table_t *inode_table = NULL; + xlator_t *prev = trav; + glusterfs_ctx_t *ctx = NULL; + xlator_list_t **trav_p = NULL; + xlator_t *top = NULL; + xlator_t *victim = NULL; + + if (this->call_cleanup || !this->ctx) + return; - xlator_mem_free (this); - - if (ctx->active) { - top = ctx->active->first; - LOCK (&ctx->volfile_lock); - /* TODO here we have leak for xlator node in a graph */ - for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) { - victim = (*trav_p)->xlator; - if (victim->call_cleanup && !strcmp (victim->name, this->name)) { - (*trav_p) = (*trav_p)->next; - break; - } - } - /* TODO Sometime brick xlator is not moved from graph so followed below - approach to move brick xlator from a graph, will move specific brick - xlator from graph only while inode table and mem_acct are cleaned up - */ - trav_p = &top->children; - while (*trav_p) { - victim = (*trav_p)->xlator; - if (victim->call_cleanup && !victim->itable && !victim->mem_acct) { - (*trav_p) = (*trav_p)->next; - } else { - trav_p = &(*trav_p)->next; - } - } - UNLOCK (&ctx->volfile_lock); - } + this->call_cleanup = 1; + ctx = this->ctx; + + xlator_call_fini(trav); + + while (prev) { + trav = prev->next; + xlator_mem_free(prev); + prev = trav; + } + + inode_table = this->itable; + if (inode_table) { + inode_table_destroy(inode_table); + this->itable = NULL; + } + + if (this->fini) { + this->fini(this); + } + + xlator_mem_free(this); + + if (ctx->active) { + top = ctx->active->first; + LOCK(&ctx->volfile_lock); + /* TODO here we have leak for xlator node in a graph */ + for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) { + victim = (*trav_p)->xlator; + if (victim->call_cleanup && !strcmp(victim->name, this->name)) { + (*trav_p) = (*trav_p)->next; + break; + } + } + /* TODO Sometime brick xlator is not moved from graph so followed below + approach to move brick xlator from a graph, will move specific brick + xlator from graph only while inode table and mem_acct are cleaned up + */ + trav_p = &top->children; + while (*trav_p) { + victim = (*trav_p)->xlator; + if (victim->call_cleanup && !victim->itable && !victim->mem_acct) { + (*trav_p) = (*trav_p)->next; + } else { + trav_p = &(*trav_p)->next; + } + } + UNLOCK(&ctx->volfile_lock); + } } void -loc_wipe (loc_t *loc) +loc_wipe(loc_t *loc) { - if (loc->inode) { - inode_unref (loc->inode); - loc->inode = NULL; - } - if (loc->path) { - GF_FREE ((char *)loc->path); - loc->path = NULL; - } - - if (loc->parent) { - inode_unref (loc->parent); - loc->parent = NULL; - } - - memset (loc, 0, sizeof (*loc)); + if (loc->inode) { + inode_unref(loc->inode); + loc->inode = NULL; + } + if (loc->path) { + GF_FREE((char *)loc->path); + loc->path = NULL; + } + + if (loc->parent) { + inode_unref(loc->parent); + loc->parent = NULL; + } + + memset(loc, 0, sizeof(*loc)); } int -loc_path (loc_t *loc, const char *bname) +loc_path(loc_t *loc, const char *bname) { - int ret = 0; + int ret = 0; - if (loc->path) - goto out; + if (loc->path) + goto out; - ret = -1; + ret = -1; - if (bname && !strlen (bname)) - bname = NULL; + if (bname && !strlen(bname)) + bname = NULL; - if (!bname) - goto inode_path; + if (!bname) + goto inode_path; - if (loc->parent && !gf_uuid_is_null (loc->parent->gfid)) { - ret = inode_path (loc->parent, bname, (char**)&loc->path); - } else if (!gf_uuid_is_null (loc->pargfid)) { - ret = gf_asprintf ((char**)&loc->path, INODE_PATH_FMT"/%s", - uuid_utoa (loc->pargfid), bname); - } + if (loc->parent && !gf_uuid_is_null(loc->parent->gfid)) { + ret = inode_path(loc->parent, bname, (char **)&loc->path); + } else if (!gf_uuid_is_null(loc->pargfid)) { + ret = gf_asprintf((char **)&loc->path, INODE_PATH_FMT "/%s", + uuid_utoa(loc->pargfid), bname); + } - if (loc->path) - goto out; + if (loc->path) + goto out; inode_path: - if (loc->inode && !gf_uuid_is_null (loc->inode->gfid)) { - ret = inode_path (loc->inode, NULL, (char **)&loc->path); - } else if (!gf_uuid_is_null (loc->gfid)) { - ret = gf_asprintf ((char**)&loc->path, INODE_PATH_FMT, - uuid_utoa (loc->gfid)); - } + if (loc->inode && !gf_uuid_is_null(loc->inode->gfid)) { + ret = inode_path(loc->inode, NULL, (char **)&loc->path); + } else if (!gf_uuid_is_null(loc->gfid)) { + ret = gf_asprintf((char **)&loc->path, INODE_PATH_FMT, + uuid_utoa(loc->gfid)); + } out: - return ret; + return ret; } void -loc_gfid (loc_t *loc, uuid_t gfid) +loc_gfid(loc_t *loc, uuid_t gfid) { - if (!gfid) - goto out; - gf_uuid_clear (gfid); - - if (!loc) - goto out; - else if (!gf_uuid_is_null (loc->gfid)) - gf_uuid_copy (gfid, loc->gfid); - else if (loc->inode && (!gf_uuid_is_null (loc->inode->gfid))) - gf_uuid_copy (gfid, loc->inode->gfid); + if (!gfid) + goto out; + gf_uuid_clear(gfid); + + if (!loc) + goto out; + else if (!gf_uuid_is_null(loc->gfid)) + gf_uuid_copy(gfid, loc->gfid); + else if (loc->inode && (!gf_uuid_is_null(loc->inode->gfid))) + gf_uuid_copy(gfid, loc->inode->gfid); out: - return; + return; } void -loc_pargfid (loc_t *loc, uuid_t gfid) +loc_pargfid(loc_t *loc, uuid_t gfid) { - if (!gfid) - goto out; - gf_uuid_clear (gfid); - - if (!loc) - goto out; - else if (!gf_uuid_is_null (loc->pargfid)) - gf_uuid_copy (gfid, loc->pargfid); - else if (loc->parent && (!gf_uuid_is_null (loc->parent->gfid))) - gf_uuid_copy (gfid, loc->parent->gfid); + if (!gfid) + goto out; + gf_uuid_clear(gfid); + + if (!loc) + goto out; + else if (!gf_uuid_is_null(loc->pargfid)) + gf_uuid_copy(gfid, loc->pargfid); + else if (loc->parent && (!gf_uuid_is_null(loc->parent->gfid))) + gf_uuid_copy(gfid, loc->parent->gfid); out: - return; + return; } -char* -loc_gfid_utoa (loc_t *loc) +char * +loc_gfid_utoa(loc_t *loc) { - uuid_t gfid = {0, }; - loc_gfid (loc, gfid); - return uuid_utoa (gfid); + uuid_t gfid = { + 0, + }; + loc_gfid(loc, gfid); + return uuid_utoa(gfid); } int -loc_touchup (loc_t *loc, const char *name) +loc_touchup(loc_t *loc, const char *name) { - char *path = NULL; - int ret = 0; - - if (loc->path) - goto out; - - if (loc->parent && name && strlen (name)) { - ret = inode_path (loc->parent, name, &path); - if (path) /*Guaranteed to have trailing '/' */ - loc->name = strrchr (path, '/') + 1; - - if (gf_uuid_is_null (loc->pargfid)) - gf_uuid_copy (loc->pargfid, loc->parent->gfid); - } else if (loc->inode) { - ret = inode_path (loc->inode, 0, &path); - if (gf_uuid_is_null (loc->gfid)) - gf_uuid_copy (loc->gfid, loc->inode->gfid); - } - - if (ret < 0 || !path) { - ret = -ENOMEM; - goto out; - } - - loc->path = path; - ret = 0; + char *path = NULL; + int ret = 0; + + if (loc->path) + goto out; + + if (loc->parent && name && strlen(name)) { + ret = inode_path(loc->parent, name, &path); + if (path) /*Guaranteed to have trailing '/' */ + loc->name = strrchr(path, '/') + 1; + + if (gf_uuid_is_null(loc->pargfid)) + gf_uuid_copy(loc->pargfid, loc->parent->gfid); + } else if (loc->inode) { + ret = inode_path(loc->inode, 0, &path); + if (gf_uuid_is_null(loc->gfid)) + gf_uuid_copy(loc->gfid, loc->inode->gfid); + } + + if (ret < 0 || !path) { + ret = -ENOMEM; + goto out; + } + + loc->path = path; + ret = 0; out: - return ret; + return ret; } int -loc_copy_overload_parent (loc_t *dst, loc_t *src, inode_t *parent) +loc_copy_overload_parent(loc_t *dst, loc_t *src, inode_t *parent) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("xlator", dst, err); - GF_VALIDATE_OR_GOTO ("xlator", src, err); - GF_VALIDATE_OR_GOTO ("xlator", parent, err); + GF_VALIDATE_OR_GOTO("xlator", dst, err); + GF_VALIDATE_OR_GOTO("xlator", src, err); + GF_VALIDATE_OR_GOTO("xlator", parent, err); - gf_uuid_copy (dst->gfid, src->gfid); - gf_uuid_copy (dst->pargfid, parent->gfid); + gf_uuid_copy(dst->gfid, src->gfid); + gf_uuid_copy(dst->pargfid, parent->gfid); - if (src->inode) - dst->inode = inode_ref (src->inode); + if (src->inode) + dst->inode = inode_ref(src->inode); - if (parent) - dst->parent = inode_ref (parent); + if (parent) + dst->parent = inode_ref(parent); - if (src->path) { - dst->path = gf_strdup (src->path); + if (src->path) { + dst->path = gf_strdup(src->path); - if (!dst->path) - goto out; + if (!dst->path) + goto out; - if (src->name) - dst->name = strrchr (dst->path, '/'); - if (dst->name) - dst->name++; - } else if (src->name) { - dst->name = src->name; - } + if (src->name) + dst->name = strrchr(dst->path, '/'); + if (dst->name) + dst->name++; + } else if (src->name) { + dst->name = src->name; + } - ret = 0; + ret = 0; out: - if (ret == -1) - loc_wipe (dst); + if (ret == -1) + loc_wipe(dst); err: - return ret; + return ret; } int -loc_copy (loc_t *dst, loc_t *src) +loc_copy(loc_t *dst, loc_t *src) { - int ret = -1; + int ret = -1; - GF_VALIDATE_OR_GOTO ("xlator", dst, err); - GF_VALIDATE_OR_GOTO ("xlator", src, err); + GF_VALIDATE_OR_GOTO("xlator", dst, err); + GF_VALIDATE_OR_GOTO("xlator", src, err); - if (!gf_uuid_is_null (src->gfid)) - gf_uuid_copy (dst->gfid, src->gfid); - else if (src->inode && !gf_uuid_is_null (src->inode->gfid)) - gf_uuid_copy (dst->gfid, src->inode->gfid); + if (!gf_uuid_is_null(src->gfid)) + gf_uuid_copy(dst->gfid, src->gfid); + else if (src->inode && !gf_uuid_is_null(src->inode->gfid)) + gf_uuid_copy(dst->gfid, src->inode->gfid); - gf_uuid_copy (dst->pargfid, src->pargfid); + gf_uuid_copy(dst->pargfid, src->pargfid); - if (src->inode) - dst->inode = inode_ref (src->inode); + if (src->inode) + dst->inode = inode_ref(src->inode); - if (src->parent) - dst->parent = inode_ref (src->parent); + if (src->parent) + dst->parent = inode_ref(src->parent); - if (src->path) { - dst->path = gf_strdup (src->path); + if (src->path) { + dst->path = gf_strdup(src->path); - if (!dst->path) - goto out; + if (!dst->path) + goto out; - if (src->name) - dst->name = strrchr (dst->path, '/'); - if (dst->name) - dst->name++; - } else if (src->name) { - dst->name = src->name; - } + if (src->name) + dst->name = strrchr(dst->path, '/'); + if (dst->name) + dst->name++; + } else if (src->name) { + dst->name = src->name; + } - ret = 0; + ret = 0; out: - if (ret == -1) - loc_wipe (dst); + if (ret == -1) + loc_wipe(dst); err: - return ret; + return ret; } gf_boolean_t -loc_is_root (loc_t *loc) +loc_is_root(loc_t *loc) { - if (loc && __is_root_gfid (loc->gfid)) { - return _gf_true; - } else if (loc && loc->inode && __is_root_gfid (loc->inode->gfid)) { - return _gf_true; - } + if (loc && __is_root_gfid(loc->gfid)) { + return _gf_true; + } else if (loc && loc->inode && __is_root_gfid(loc->inode->gfid)) { + return _gf_true; + } - return _gf_false; + return _gf_false; } int32_t -loc_build_child (loc_t *child, loc_t *parent, char *name) +loc_build_child(loc_t *child, loc_t *parent, char *name) { - int32_t ret = -1; + int32_t ret = -1; - GF_VALIDATE_OR_GOTO ("xlator", child, out); - GF_VALIDATE_OR_GOTO ("xlator", parent, out); - GF_VALIDATE_OR_GOTO ("xlator", name, out); + GF_VALIDATE_OR_GOTO("xlator", child, out); + GF_VALIDATE_OR_GOTO("xlator", parent, out); + GF_VALIDATE_OR_GOTO("xlator", name, out); - loc_gfid (parent, child->pargfid); + loc_gfid(parent, child->pargfid); - if (strcmp (parent->path, "/") == 0) - ret = gf_asprintf ((char **)&child->path, "/%s", name); - else - ret = gf_asprintf ((char **)&child->path, "%s/%s", parent->path, - name); + if (strcmp(parent->path, "/") == 0) + ret = gf_asprintf((char **)&child->path, "/%s", name); + else + ret = gf_asprintf((char **)&child->path, "%s/%s", parent->path, name); - if (ret < 0 || !child->path) { - ret = -1; - goto out; - } + if (ret < 0 || !child->path) { + ret = -1; + goto out; + } - child->name = strrchr (child->path, '/') + 1; + child->name = strrchr(child->path, '/') + 1; - child->parent = inode_ref (parent->inode); - child->inode = inode_new (parent->inode->table); + child->parent = inode_ref(parent->inode); + child->inode = inode_new(parent->inode->table); - if (!child->inode) { - ret = -1; - goto out; - } + if (!child->inode) { + ret = -1; + goto out; + } - ret = 0; + ret = 0; out: - if ((ret < 0) && child) - loc_wipe (child); + if ((ret < 0) && child) + loc_wipe(child); - return ret; + return ret; } - gf_boolean_t -loc_is_nameless (loc_t *loc) +loc_is_nameless(loc_t *loc) { - gf_boolean_t ret = _gf_false; + gf_boolean_t ret = _gf_false; - GF_VALIDATE_OR_GOTO ("xlator", loc, out); + GF_VALIDATE_OR_GOTO("xlator", loc, out); - if ((!loc->parent && gf_uuid_is_null (loc->pargfid)) || !loc->name) - ret = _gf_true; + if ((!loc->parent && gf_uuid_is_null(loc->pargfid)) || !loc->name) + ret = _gf_true; out: - return ret; + return ret; } - int -xlator_destroy (xlator_t *xl) +xlator_destroy(xlator_t *xl) { - if (!xl) - return 0; + if (!xl) + return 0; - xlator_members_free (xl); - xlator_memrec_free (xl); - GF_FREE (xl); + xlator_members_free(xl); + xlator_memrec_free(xl); + GF_FREE(xl); - return 0; + return 0; } - int -is_gf_log_command (xlator_t *this, const char *name, char *value) +is_gf_log_command(xlator_t *this, const char *name, char *value) { - xlator_t *trav = NULL; - char key[1024] = {0,}; - int ret = -1; - int log_level = -1; - gf_boolean_t syslog_flag = 0; - glusterfs_ctx_t *ctx = NULL; - - if (!strcmp ("trusted.glusterfs.syslog", name)) { - ret = gf_string2boolean (value, &syslog_flag); - if (ret) { - ret = EOPNOTSUPP; - goto out; - } - if (syslog_flag) - gf_log_enable_syslog (); - else - gf_log_disable_syslog (); - - goto out; - } - - if (fnmatch ("trusted.glusterfs*set-log-level", name, FNM_NOESCAPE)) - goto out; - - log_level = glusterd_check_log_level (value); - if (log_level == -1) { - ret = EOPNOTSUPP; - goto out; - } - - /* Some crude way to change the log-level of process */ - if (!strcmp (name, "trusted.glusterfs.set-log-level")) { - gf_msg ("glusterfs", gf_log_get_loglevel(), 0, - LG_MSG_SET_LOG_LEVEL, - "setting log level to %d (old-value=%d)", - log_level, gf_log_get_loglevel()); - gf_log_set_loglevel (this->ctx, log_level); - ret = 0; - goto out; - } - - if (!strcmp (name, "trusted.glusterfs.fuse.set-log-level")) { - /* */ - gf_msg (this->name, gf_log_get_xl_loglevel (this), 0, - LG_MSG_SET_LOG_LEVEL, - "setting log level to %d (old-value=%d)", - log_level, gf_log_get_xl_loglevel (this)); - gf_log_set_xl_loglevel (this, log_level); - ret = 0; - goto out; - } - - ctx = this->ctx; - if (!ctx) - goto out; - if (!ctx->active) - goto out; - trav = ctx->active->top; - - while (trav) { - snprintf (key, 1024, "trusted.glusterfs.%s.set-log-level", - trav->name); - if (fnmatch (name, key, FNM_NOESCAPE) == 0) { - gf_msg (trav->name, gf_log_get_xl_loglevel (trav), 0, - LG_MSG_SET_LOG_LEVEL, - "setting log level to %d (old-value=%d)", - log_level, gf_log_get_xl_loglevel (trav)); - gf_log_set_xl_loglevel (trav, log_level); - ret = 0; - } - trav = trav->next; + xlator_t *trav = NULL; + char key[1024] = { + 0, + }; + int ret = -1; + int log_level = -1; + gf_boolean_t syslog_flag = 0; + glusterfs_ctx_t *ctx = NULL; + + if (!strcmp("trusted.glusterfs.syslog", name)) { + ret = gf_string2boolean(value, &syslog_flag); + if (ret) { + ret = EOPNOTSUPP; + goto out; } + if (syslog_flag) + gf_log_enable_syslog(); + else + gf_log_disable_syslog(); + + goto out; + } + + if (fnmatch("trusted.glusterfs*set-log-level", name, FNM_NOESCAPE)) + goto out; + + log_level = glusterd_check_log_level(value); + if (log_level == -1) { + ret = EOPNOTSUPP; + goto out; + } + + /* Some crude way to change the log-level of process */ + if (!strcmp(name, "trusted.glusterfs.set-log-level")) { + gf_msg("glusterfs", gf_log_get_loglevel(), 0, LG_MSG_SET_LOG_LEVEL, + "setting log level to %d (old-value=%d)", log_level, + gf_log_get_loglevel()); + gf_log_set_loglevel(this->ctx, log_level); + ret = 0; + goto out; + } + + if (!strcmp(name, "trusted.glusterfs.fuse.set-log-level")) { + /* */ + gf_msg(this->name, gf_log_get_xl_loglevel(this), 0, + LG_MSG_SET_LOG_LEVEL, "setting log level to %d (old-value=%d)", + log_level, gf_log_get_xl_loglevel(this)); + gf_log_set_xl_loglevel(this, log_level); + ret = 0; + goto out; + } + + ctx = this->ctx; + if (!ctx) + goto out; + if (!ctx->active) + goto out; + trav = ctx->active->top; + + while (trav) { + snprintf(key, 1024, "trusted.glusterfs.%s.set-log-level", trav->name); + if (fnmatch(name, key, FNM_NOESCAPE) == 0) { + gf_msg(trav->name, gf_log_get_xl_loglevel(trav), 0, + LG_MSG_SET_LOG_LEVEL, + "setting log level to %d (old-value=%d)", log_level, + gf_log_get_xl_loglevel(trav)); + gf_log_set_xl_loglevel(trav, log_level); + ret = 0; + } + trav = trav->next; + } out: - return ret; + return ret; } - int -glusterd_check_log_level (const char *value) +glusterd_check_log_level(const char *value) { - int log_level = -1; - - if (!strcasecmp (value, "CRITICAL")) { - log_level = GF_LOG_CRITICAL; - } else if (!strcasecmp (value, "ERROR")) { - log_level = GF_LOG_ERROR; - } else if (!strcasecmp (value, "WARNING")) { - log_level = GF_LOG_WARNING; - } else if (!strcasecmp (value, "INFO")) { - log_level = GF_LOG_INFO; - } else if (!strcasecmp (value, "DEBUG")) { - log_level = GF_LOG_DEBUG; - } else if (!strcasecmp (value, "TRACE")) { - log_level = GF_LOG_TRACE; - } else if (!strcasecmp (value, "NONE")) { - log_level = GF_LOG_NONE; - } - - if (log_level == -1) - gf_msg (THIS->name, GF_LOG_ERROR, 0, LG_MSG_INIT_FAILED, - "Invalid log-level. possible values are " - "DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); - - return log_level; + int log_level = -1; + + if (!strcasecmp(value, "CRITICAL")) { + log_level = GF_LOG_CRITICAL; + } else if (!strcasecmp(value, "ERROR")) { + log_level = GF_LOG_ERROR; + } else if (!strcasecmp(value, "WARNING")) { + log_level = GF_LOG_WARNING; + } else if (!strcasecmp(value, "INFO")) { + log_level = GF_LOG_INFO; + } else if (!strcasecmp(value, "DEBUG")) { + log_level = GF_LOG_DEBUG; + } else if (!strcasecmp(value, "TRACE")) { + log_level = GF_LOG_TRACE; + } else if (!strcasecmp(value, "NONE")) { + log_level = GF_LOG_NONE; + } + + if (log_level == -1) + gf_msg(THIS->name, GF_LOG_ERROR, 0, LG_MSG_INIT_FAILED, + "Invalid log-level. possible values are " + "DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE"); + + return log_level; } int -xlator_subvolume_count (xlator_t *this) +xlator_subvolume_count(xlator_t *this) { - int i = 0; - xlator_list_t *list = NULL; + int i = 0; + xlator_list_t *list = NULL; - for (list = this->children; list; list = list->next) - i++; - return i; + for (list = this->children; list; list = list->next) + i++; + return i; } static int -_copy_opt_to_child (dict_t *options, char *key, data_t *value, void *data) +_copy_opt_to_child(dict_t *options, char *key, data_t *value, void *data) { - xlator_t *child = data; + xlator_t *child = data; - gf_log (__func__, GF_LOG_DEBUG, - "copying %s to child %s", key, child->name); - dict_set (child->options, key, value); + gf_log(__func__, GF_LOG_DEBUG, "copying %s to child %s", key, child->name); + dict_set(child->options, key, value); - return 0; + return 0; } int -copy_opts_to_child (xlator_t *src, xlator_t *dst, char *glob) +copy_opts_to_child(xlator_t *src, xlator_t *dst, char *glob) { - return dict_foreach_fnmatch (src->options, glob, - _copy_opt_to_child, dst); + return dict_foreach_fnmatch(src->options, glob, _copy_opt_to_child, dst); } int -glusterfs_delete_volfile_checksum (glusterfs_ctx_t *ctx, - const char *volfile_id) { - - gf_volfile_t *volfile_tmp = NULL; - gf_volfile_t *volfile_obj = NULL; - - list_for_each_entry (volfile_tmp, &ctx->volfile_list, - volfile_list) { - if (!strcmp (volfile_id, volfile_tmp->vol_id)) { - list_del_init (&volfile_tmp->volfile_list); - volfile_obj = volfile_tmp; - break; - } - } - - if (volfile_obj) { - GF_FREE (volfile_obj); - } else { - gf_log (THIS->name, GF_LOG_ERROR, "failed to get volfile " - "checksum for volfile id %s.", volfile_id); - } - - return 0; +glusterfs_delete_volfile_checksum(glusterfs_ctx_t *ctx, const char *volfile_id) +{ + gf_volfile_t *volfile_tmp = NULL; + gf_volfile_t *volfile_obj = NULL; + + list_for_each_entry(volfile_tmp, &ctx->volfile_list, volfile_list) + { + if (!strcmp(volfile_id, volfile_tmp->vol_id)) { + list_del_init(&volfile_tmp->volfile_list); + volfile_obj = volfile_tmp; + break; + } + } + + if (volfile_obj) { + GF_FREE(volfile_obj); + } else { + gf_log(THIS->name, GF_LOG_ERROR, + "failed to get volfile " + "checksum for volfile id %s.", + volfile_id); + } + + return 0; } |