diff options
Diffstat (limited to 'libglusterfs/src/syncop.c')
| -rw-r--r-- | libglusterfs/src/syncop.c | 1104 |
1 files changed, 885 insertions, 219 deletions
diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 4acac5f8..d2c8381a 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2013 Red Hat, Inc. <http://www.redhat.com> This file is part of GlusterFS. - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H @@ -24,22 +15,6 @@ #include "syncop.h" -call_frame_t * -syncop_create_frame () -{ - struct synctask *task = NULL; - call_frame_t *frame = NULL; - - task = synctask_get (); - - if (task) { - frame = task->frame; - } - - return (call_frame_t *)frame; -} - - static void __run (struct synctask *task) { @@ -48,26 +23,31 @@ __run (struct synctask *task) env = task->env; list_del_init (&task->all_tasks); - switch (task->state) { - case SYNCTASK_INIT: - break; - case SYNCTASK_RUN: - gf_log (task->xl->name, GF_LOG_WARNING, - "re-running already running task"); - env->runcount--; - break; - case SYNCTASK_WAIT: - env->waitcount--; - break; - case SYNCTASK_DONE: + switch (task->state) { + case SYNCTASK_INIT: + case SYNCTASK_SUSPEND: + break; + case SYNCTASK_RUN: + gf_log (task->xl->name, GF_LOG_DEBUG, + "re-running already running task"); + env->runcount--; + break; + case SYNCTASK_WAIT: + env->waitcount--; + break; + case SYNCTASK_DONE: + gf_log (task->xl->name, GF_LOG_WARNING, + "running completed task"); + return; + case SYNCTASK_ZOMBIE: gf_log (task->xl->name, GF_LOG_WARNING, - "running completed task"); - break; - } + "attempted to wake up zombie!!"); + return; + } list_add_tail (&task->all_tasks, &env->runq); - env->runcount++; - task->state = SYNCTASK_RUN; + env->runcount++; + task->state = SYNCTASK_RUN; } @@ -79,36 +59,52 @@ __wait (struct synctask *task) env = task->env; list_del_init (&task->all_tasks); - switch (task->state) { - case SYNCTASK_INIT: - break; - case SYNCTASK_RUN: - env->runcount--; - break; - case SYNCTASK_WAIT: - gf_log (task->xl->name, GF_LOG_WARNING, - "re-waiting already waiting task"); - env->waitcount--; - break; - case SYNCTASK_DONE: + switch (task->state) { + case SYNCTASK_INIT: + case SYNCTASK_SUSPEND: + break; + case SYNCTASK_RUN: + env->runcount--; + break; + case SYNCTASK_WAIT: + gf_log (task->xl->name, GF_LOG_WARNING, + "re-waiting already waiting task"); + env->waitcount--; + break; + case SYNCTASK_DONE: + gf_log (task->xl->name, GF_LOG_WARNING, + "running completed task"); + return; + case SYNCTASK_ZOMBIE: gf_log (task->xl->name, GF_LOG_WARNING, - "running completed task"); - break; - } + "attempted to sleep a zombie!!"); + return; + } list_add_tail (&task->all_tasks, &env->waitq); - env->waitcount++; - task->state = SYNCTASK_WAIT; + env->waitcount++; + task->state = SYNCTASK_WAIT; } void synctask_yield (struct synctask *task) { + xlator_t *oldTHIS = THIS; + +#if defined(__NetBSD__) && defined(_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; if (swapcontext (&task->ctx, &task->proc->sched) < 0) { gf_log ("syncop", GF_LOG_ERROR, "swapcontext failed (%s)", strerror (errno)); } + + THIS = oldTHIS; } @@ -125,13 +121,12 @@ synctask_wake (struct synctask *task) if (task->slept) __run (task); + + pthread_cond_broadcast (&env->cond); } pthread_mutex_unlock (&env->mutex); - - pthread_cond_broadcast (&env->cond); } - void synctask_wrap (struct synctask *old_task) { @@ -142,8 +137,8 @@ synctask_wrap (struct synctask *old_task) task = synctask_get (); task->ret = task->syncfn (task->opaque); - if (task->synccbk) - task->synccbk (task->ret, task->frame, task->opaque); + if (task->synccbk) + task->synccbk (task->ret, task->frame, task->opaque); task->state = SYNCTASK_DONE; @@ -157,12 +152,15 @@ synctask_destroy (struct synctask *task) if (!task) return; - if (task->stack) - FREE (task->stack); + FREE (task->stack); - pthread_mutex_destroy (&task->mutex); + if (task->opframe) + STACK_DESTROY (task->opframe->root); - pthread_cond_destroy (&task->cond); + if (task->synccbk == NULL) { + pthread_mutex_destroy (&task->mutex); + pthread_cond_destroy (&task->cond); + } FREE (task); } @@ -171,44 +169,71 @@ synctask_destroy (struct synctask *task) void 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->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_new (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, - call_frame_t *frame, void *opaque) +synctask_setid (struct synctask *task, uid_t uid, gid_t gid) +{ + if (!task) + return -1; + + if (uid != -1) + task->uid = uid; + + if (gid != -1) + task->gid = gid; + + return 0; +} + + +struct synctask * +synctask_create (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, + call_frame_t *frame, void *opaque) { struct synctask *newtask = NULL; xlator_t *this = THIS; - int ret = 0; VALIDATE_OR_GOTO (env, err); VALIDATE_OR_GOTO (fn, err); - VALIDATE_OR_GOTO (frame, err); newtask = CALLOC (1, sizeof (*newtask)); if (!newtask) - return -ENOMEM; + return NULL; + newtask->frame = frame; + if (!frame) { + newtask->opframe = create_frame (this, this->ctx->pool); + } else { + newtask->opframe = copy_frame (frame); + } + if (!newtask->opframe) + goto err; newtask->env = env; newtask->xl = this; newtask->syncfn = fn; - newtask->synccbk = cbk; + newtask->synccbk = cbk; newtask->opaque = opaque; - newtask->frame = frame; + + /* 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_log ("syncop", GF_LOG_ERROR, @@ -227,65 +252,114 @@ synctask_new (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, newtask->ctx.uc_stack.ss_sp = newtask->stack; newtask->ctx.uc_stack.ss_size = env->stacksize; - makecontext (&newtask->ctx, (void *) synctask_wrap, 2, newtask); + makecontext (&newtask->ctx, (void (*)(void)) synctask_wrap, 2, newtask); - newtask->state = SYNCTASK_INIT; + newtask->state = SYNCTASK_INIT; newtask->slept = 1; - if (!cbk) { - pthread_mutex_init (&newtask->mutex, NULL); - pthread_cond_init (&newtask->cond, NULL); - newtask->done = 0; - } + 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); - if (!cbk) { - pthread_mutex_lock (&newtask->mutex); - { - while (!newtask->done) { - pthread_cond_wait (&newtask->cond, &newtask->mutex); - } - } - pthread_mutex_unlock (&newtask->mutex); + return newtask; +err: + if (newtask) { + FREE (newtask->stack); + if (newtask->opframe) + STACK_DESTROY (newtask->opframe->root); + FREE (newtask); + } + + return NULL; +} - ret = newtask->ret; - synctask_destroy (newtask); +int +synctask_join (struct synctask *task) +{ + int ret = 0; + + pthread_mutex_lock (&task->mutex); + { + while (!task->done) + pthread_cond_wait (&task->cond, &task->mutex); } + pthread_mutex_unlock (&task->mutex); + + ret = task->ret; + + synctask_destroy (task); + + return ret; +} + + +int +synctask_new (struct syncenv *env, synctask_fn_t fn, synctask_cbk_t cbk, + call_frame_t *frame, void *opaque) +{ + struct synctask *newtask = NULL; + int ret = 0; + + newtask = synctask_create (env, fn, cbk, frame, opaque); + if (!newtask) + return -1; + + if (!cbk) + ret = synctask_join (newtask); return ret; -err: - if (newtask) { - if (newtask->stack) - FREE (newtask->stack); - FREE (newtask); - } - return -1; } struct synctask * syncenv_task (struct syncproc *proc) { - struct syncenv *env = NULL; + struct syncenv *env = NULL; struct synctask *task = NULL; + struct timespec sleep_till = {0, }; + int ret = 0; - env = proc->env; + env = proc->env; pthread_mutex_lock (&env->mutex); { - while (list_empty (&env->runq)) - pthread_cond_wait (&env->cond, &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 ((ret == ETIMEDOUT) && + (env->procs > env->procmin)) { + task = NULL; + env->procs--; + memset (proc, 0, sizeof (*proc)); + goto unlock; + } + } task = list_entry (env->runq.next, struct synctask, all_tasks); list_del_init (&task->all_tasks); - env->runcount--; + env->runcount--; + + task->woken = 0; + task->slept = 0; - task->proc = proc; + task->proc = proc; } +unlock: pthread_mutex_unlock (&env->mutex); return task; @@ -302,8 +376,10 @@ synctask_switchto (struct synctask *task) synctask_set (task); THIS = task->xl; - task->woken = 0; - task->slept = 0; +#if defined(__NetBSD__) && defined(_UC_TLSBASE) + /* Preserve pthread private pointer through swapcontex() */ + task->ctx.uc_flags &= ~_UC_TLSBASE; +#endif if (swapcontext (&task->proc->sched, &task->ctx) < 0) { gf_log ("syncop", GF_LOG_ERROR, @@ -327,7 +403,6 @@ synctask_switchto (struct synctask *task) pthread_mutex_unlock (&env->mutex); } - void * syncenv_processor (void *thdata) { @@ -340,10 +415,12 @@ syncenv_processor (void *thdata) for (;;) { task = syncenv_task (proc); + if (!task) + break; synctask_switchto (task); - syncenv_scale (env); + syncenv_scale (env); } return NULL; @@ -353,27 +430,39 @@ syncenv_processor (void *thdata) void syncenv_scale (struct syncenv *env) { - int thmax = 0; - int i = 0; - int ret = 0; + int diff = 0; + int scale = 0; + int i = 0; + int ret = 0; - pthread_mutex_lock (&env->mutex); - { - if (env->procs > env->runcount) - goto unlock; - - thmax = max (env->runcount, SYNCENV_PROC_MAX); - for (i = env->procs; i < thmax; i++) { - env->proc[i].env = env; - ret = pthread_create (&env->proc[i].processor, NULL, - syncenv_processor, &env->proc[i]); - if (ret) - break; - env->procs++; - } - } + 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; + ret = pthread_create (&env->proc[i].processor, NULL, + syncenv_processor, &env->proc[i]); + if (ret) + break; + env->procs++; + i++; + } + } unlock: - pthread_mutex_unlock (&env->mutex); + pthread_mutex_unlock (&env->mutex); } @@ -385,12 +474,20 @@ syncenv_destroy (struct syncenv *env) struct syncenv * -syncenv_new (size_t stacksize) +syncenv_new (size_t stacksize, int procmin, int procmax) { struct syncenv *newenv = NULL; int ret = 0; int i = 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 = CALLOC (1, sizeof (*newenv)); if (!newenv) @@ -405,8 +502,10 @@ syncenv_new (size_t stacksize) newenv->stacksize = SYNCENV_DEFAULT_STACKSIZE; if (stacksize) newenv->stacksize = stacksize; + newenv->procmin = procmin; + newenv->procmax = procmax; - for (i = 0; i < SYNCENV_PROC_MIN; i++) { + for (i = 0; i < newenv->procmin; i++) { newenv->proc[i].env = newenv; ret = pthread_create (&newenv->proc[i].processor, NULL, syncenv_processor, &newenv->proc[i]); @@ -422,13 +521,275 @@ syncenv_new (size_t stacksize) } +int +synclock_init (synclock_t *lock) +{ + if (!lock) + return -1; + + pthread_cond_init (&lock->cond, 0); + lock->lock = 0; + INIT_LIST_HEAD (&lock->waitq); + + return pthread_mutex_init (&lock->guard, 0); +} + + +int +synclock_destroy (synclock_t *lock) +{ + if (!lock) + return -1; + + 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 (); + + while (lock->lock) { + if (task) { + /* called within a synctask */ + 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); + } + } + + lock->lock = _gf_true; + lock->owner = task; + + return 0; +} + + +int +synclock_lock (synclock_t *lock) +{ + int ret = 0; + + pthread_mutex_lock (&lock->guard); + { + ret = __synclock_lock (lock); + } + pthread_mutex_unlock (&lock->guard); + + return ret; +} + + +int +synclock_trylock (synclock_t *lock) +{ + int ret = 0; + + errno = 0; + + pthread_mutex_lock (&lock->guard); + { + if (lock->lock) { + errno = EBUSY; + ret = -1; + goto unlock; + } + + ret = __synclock_lock (lock); + } +unlock: + pthread_mutex_unlock (&lock->guard); + + return ret; +} + + +static int +__synclock_unlock (synclock_t *lock) +{ + struct synctask *task = NULL; + struct synctask *curr = NULL; + + if (!lock) + return -1; + + curr = synctask_get (); + + if (lock->owner != curr) { + /* warn ? */ + } + + lock->lock = _gf_false; + + /* 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) +{ + int ret = 0; + + pthread_mutex_lock (&lock->guard); + { + ret = __synclock_unlock (lock); + } + pthread_mutex_unlock (&lock->guard); + + return ret; +} + +/* Barriers */ + +int +syncbarrier_init (struct syncbarrier *barrier) +{ + if (!barrier) { + errno = EINVAL; + return -1; + } + + pthread_cond_init (&barrier->cond, 0); + barrier->count = 0; + INIT_LIST_HEAD (&barrier->waitq); + + return pthread_mutex_init (&barrier->guard, 0); +} + + +int +syncbarrier_destroy (struct syncbarrier *barrier) +{ + if (!barrier) { + errno = EINVAL; + return -1; + } + + pthread_cond_destroy (&barrier->cond); + return pthread_mutex_destroy (&barrier->guard); +} + + +static int +__syncbarrier_wait (struct syncbarrier *barrier, int waitfor) +{ + struct synctask *task = NULL; + + if (!barrier) { + errno = EINVAL; + return -1; + } + + 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); + } + } + + barrier->count = 0; + + return 0; +} + + +int +syncbarrier_wait (struct syncbarrier *barrier, int waitfor) +{ + int ret = 0; + + pthread_mutex_lock (&barrier->guard); + { + ret = __syncbarrier_wait (barrier, waitfor); + } + pthread_mutex_unlock (&barrier->guard); + + return ret; +} + + +static int +__syncbarrier_wake (struct syncbarrier *barrier) +{ + struct synctask *task = NULL; + + if (!barrier) { + errno = EINVAL; + return -1; + } + + barrier->count++; + + 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); + } + + return 0; +} + + +int +syncbarrier_wake (struct syncbarrier *barrier) +{ + int ret = 0; + + pthread_mutex_lock (&barrier->guard); + { + ret = __syncbarrier_wake (barrier); + } + pthread_mutex_unlock (&barrier->guard); + + 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 *xattr, struct iatt *parent) + struct iatt *iatt, dict_t *xdata, struct iatt *parent) { struct syncargs *args = NULL; @@ -440,8 +801,8 @@ syncop_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, if (op_ret == 0) { args->iatt1 = *iatt; args->iatt2 = *parent; - if (xattr) - args->xattr = dict_ref (xattr); + if (xdata) + args->xdata = dict_ref (xdata); } __wake (args); @@ -451,22 +812,22 @@ syncop_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int -syncop_lookup (xlator_t *subvol, loc_t *loc, dict_t *xattr_req, - struct iatt *iatt, dict_t **xattr_rsp, struct iatt *parent) +syncop_lookup (xlator_t *subvol, loc_t *loc, dict_t *xdata_req, + struct iatt *iatt, dict_t **xdata_rsp, struct iatt *parent) { struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_lookup_cbk, subvol->fops->lookup, - loc, xattr_req); + loc, xdata_req); if (iatt) *iatt = args.iatt1; if (parent) *parent = args.iatt2; - if (xattr_rsp) - *xattr_rsp = args.xattr; - else if (args.xattr) - dict_unref (args.xattr); + if (xdata_rsp) + *xdata_rsp = args.xdata; + else if (args.xdata) + dict_unref (args.xdata); errno = args.op_errno; return args.op_ret; @@ -484,6 +845,8 @@ entry_copy (gf_dirent_t *source) sink->d_type = source->d_type; sink->d_stat = source->d_stat; + if (source->inode) + sink->inode = inode_ref (source->inode); return sink; } @@ -493,7 +856,7 @@ syncop_readdirp_cbk (call_frame_t *frame, xlator_t *this, int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries) + gf_dirent_t *entries, dict_t *xdata) { struct syncargs *args = NULL; gf_dirent_t *entry = NULL; @@ -553,7 +916,7 @@ syncop_readdir_cbk (call_frame_t *frame, xlator_t *this, int32_t op_ret, int32_t op_errno, - gf_dirent_t *entries) + gf_dirent_t *entries, dict_t *xdata) { struct syncargs *args = NULL; gf_dirent_t *entry = NULL; @@ -595,7 +958,7 @@ syncop_readdir (xlator_t *subvol, struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_readdir_cbk, subvol->fops->readdir, - fd, size, off); + fd, size, off, NULL); if (entries) list_splice_init (&args.entries.list, &entries->list); @@ -612,7 +975,7 @@ syncop_opendir_cbk (call_frame_t *frame, xlator_t *this, int32_t op_ret, int32_t op_errno, - fd_t *fd) + fd_t *fd, dict_t *xdata) { struct syncargs *args = NULL; @@ -634,7 +997,7 @@ syncop_opendir (xlator_t *subvol, struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_opendir_cbk, subvol->fops->opendir, - loc, fd); + loc, fd, NULL); errno = args.op_errno; return args.op_ret; @@ -642,8 +1005,36 @@ syncop_opendir (xlator_t *subvol, } int +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; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; +} + +int +syncop_fsyncdir (xlator_t *subvol, fd_t *fd, int datasync) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_fsyncdir_cbk, subvol->fops->fsyncdir, + fd, datasync, NULL); + + errno = 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) + int op_ret, int op_errno, dict_t *xdata) { struct syncargs *args = NULL; @@ -663,7 +1054,7 @@ syncop_removexattr (xlator_t *subvol, loc_t *loc, const char *name) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_removexattr_cbk, subvol->fops->removexattr, - loc, name); + loc, name, NULL); errno = args.op_errno; return args.op_ret; @@ -671,7 +1062,7 @@ syncop_removexattr (xlator_t *subvol, loc_t *loc, const char *name) int syncop_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno) + int op_ret, int op_errno, dict_t *xdata) { struct syncargs *args = NULL; @@ -691,7 +1082,7 @@ syncop_fremovexattr (xlator_t *subvol, fd_t *fd, const char *name) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_fremovexattr_cbk, - subvol->fops->fremovexattr, fd, name); + subvol->fops->fremovexattr, fd, name, NULL); errno = args.op_errno; return args.op_ret; @@ -699,7 +1090,7 @@ syncop_fremovexattr (xlator_t *subvol, fd_t *fd, const char *name) int syncop_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno) + int op_ret, int op_errno, dict_t *xdata) { struct syncargs *args = NULL; @@ -720,7 +1111,7 @@ syncop_setxattr (xlator_t *subvol, loc_t *loc, dict_t *dict, int32_t flags) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_setxattr_cbk, subvol->fops->setxattr, - loc, dict, flags); + loc, dict, flags, NULL); errno = args.op_errno; return args.op_ret; @@ -728,7 +1119,7 @@ syncop_setxattr (xlator_t *subvol, loc_t *loc, dict_t *dict, int32_t flags) int syncop_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno) + int op_ret, int op_errno, dict_t *xdata) { struct syncargs *args = NULL; @@ -749,7 +1140,7 @@ syncop_fsetxattr (xlator_t *subvol, fd_t *fd, dict_t *dict, int32_t flags) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_fsetxattr_cbk, subvol->fops->fsetxattr, - fd, dict, flags); + fd, dict, flags, NULL); errno = args.op_errno; return args.op_ret; @@ -757,7 +1148,7 @@ syncop_fsetxattr (xlator_t *subvol, fd_t *fd, dict_t *dict, int32_t flags) int syncop_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, dict_t *dict) + int op_ret, int op_errno, dict_t *dict, dict_t *xdata) { struct syncargs *args = NULL; @@ -779,7 +1170,7 @@ syncop_listxattr (xlator_t *subvol, loc_t *loc, dict_t **dict) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_getxattr_cbk, subvol->fops->getxattr, - loc, NULL); + loc, NULL, NULL); if (dict) *dict = args.xattr; @@ -796,7 +1187,7 @@ syncop_getxattr (xlator_t *subvol, loc_t *loc, dict_t **dict, const char *key) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_getxattr_cbk, subvol->fops->getxattr, - loc, key); + loc, key, NULL); if (dict) *dict = args.xattr; @@ -813,7 +1204,7 @@ syncop_fgetxattr (xlator_t *subvol, fd_t *fd, dict_t **dict, const char *key) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_getxattr_cbk, subvol->fops->fgetxattr, - fd, key); + fd, key, NULL); if (dict) *dict = args.xattr; @@ -827,7 +1218,7 @@ syncop_fgetxattr (xlator_t *subvol, fd_t *fd, dict_t **dict, const char *key) int syncop_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, - struct statvfs *buf) + struct statvfs *buf, dict_t *xdata) { struct syncargs *args = NULL; @@ -854,7 +1245,7 @@ syncop_statfs (xlator_t *subvol, loc_t *loc, struct statvfs *buf) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_statfs_cbk, subvol->fops->statfs, - loc); + loc, NULL); if (buf) *buf = args.statvfs_buf; @@ -866,7 +1257,7 @@ syncop_statfs (xlator_t *subvol, loc_t *loc, struct statvfs *buf) 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) + struct iatt *preop, struct iatt *postop, dict_t *xdata) { struct syncargs *args = NULL; @@ -893,7 +1284,7 @@ syncop_setattr (xlator_t *subvol, loc_t *loc, struct iatt *iatt, int valid, struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_setattr_cbk, subvol->fops->setattr, - loc, iatt, valid); + loc, iatt, valid, NULL); if (preop) *preop = args.iatt1; @@ -912,7 +1303,7 @@ syncop_fsetattr (xlator_t *subvol, fd_t *fd, struct iatt *iatt, int valid, struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_setattr_cbk, subvol->fops->fsetattr, - fd, iatt, valid); + fd, iatt, valid, NULL); if (preop) *preop = args.iatt1; @@ -926,7 +1317,7 @@ syncop_fsetattr (xlator_t *subvol, fd_t *fd, struct iatt *iatt, int valid, 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) + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) { struct syncargs *args = NULL; @@ -935,9 +1326,6 @@ syncop_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, args->op_ret = op_ret; args->op_errno = op_errno; - if (op_ret != -1) - fd_ref (fd); - __wake (args); return 0; @@ -949,7 +1337,7 @@ syncop_open (xlator_t *subvol, loc_t *loc, int32_t flags, fd_t *fd) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_open_cbk, subvol->fops->open, - loc, flags, fd, 0); + loc, flags, fd, NULL); errno = args.op_errno; return args.op_ret; @@ -960,7 +1348,8 @@ syncop_open (xlator_t *subvol, loc_t *loc, int32_t flags, fd_t *fd) 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) + int32_t count, struct iatt *stbuf, struct iobref *iobref, + dict_t *xdata) { struct syncargs *args = NULL; @@ -992,11 +1381,14 @@ syncop_readv (xlator_t *subvol, fd_t *fd, size_t size, off_t off, struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_readv_cbk, subvol->fops->readv, - fd, size, off, flags); + fd, size, off, flags, NULL); + + if (args.op_ret < 0) + goto out; if (vector) *vector = args.vector; - else if (args.vector) + else GF_FREE (args.vector); if (count) @@ -1008,6 +1400,7 @@ syncop_readv (xlator_t *subvol, fd_t *fd, size_t size, off_t off, else if (args.iobref) iobref_unref (args.iobref); +out: errno = args.op_errno; return args.op_ret; @@ -1016,7 +1409,7 @@ syncop_readv (xlator_t *subvol, fd_t *fd, size_t size, off_t off, 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) + struct iatt *postbuf, dict_t *xdata) { struct syncargs *args = NULL; @@ -1031,14 +1424,15 @@ syncop_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } int -syncop_writev (xlator_t *subvol, fd_t *fd, struct iovec *vector, +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 syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_writev_cbk, subvol->fops->writev, - fd, vector, count, offset, flags, iobref); + fd, (struct iovec *) vector, count, offset, flags, iobref, + NULL); errno = args.op_errno; return args.op_ret; @@ -1054,7 +1448,7 @@ int syncop_write (xlator_t *subvol, fd_t *fd, const char *buf, int size, vec.iov_base = (void *)buf; SYNCOP (subvol, (&args), syncop_writev_cbk, subvol->fops->writev, - fd, &vec, 1, offset, flags, iobref); + fd, &vec, 1, offset, flags, iobref, NULL); errno = args.op_errno; return args.op_ret; @@ -1073,7 +1467,7 @@ 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) + struct iatt *postparent, dict_t *xdata) { struct syncargs *args = NULL; @@ -1082,8 +1476,8 @@ syncop_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, args->op_ret = op_ret; args->op_errno = op_errno; - if (op_ret != -1) - fd_ref (fd); + if (buf) + args->iatt1 = *buf; __wake (args); @@ -1092,14 +1486,17 @@ syncop_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int syncop_create (xlator_t *subvol, loc_t *loc, int32_t flags, mode_t mode, - fd_t *fd, dict_t *dict) + fd_t *fd, dict_t *xdata, struct iatt *iatt) { struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_create_cbk, subvol->fops->create, - loc, flags, mode, fd, dict); + loc, flags, mode, 0, fd, xdata); errno = args.op_errno; + if (iatt) + *iatt = args.iatt1; + return args.op_ret; } @@ -1107,7 +1504,7 @@ syncop_create (xlator_t *subvol, loc_t *loc, int32_t flags, mode_t mode, 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) + struct iatt *postparent, dict_t *xdata) { struct syncargs *args = NULL; @@ -1126,17 +1523,48 @@ syncop_unlink (xlator_t *subvol, loc_t *loc) { struct syncargs args = {0, }; - SYNCOP (subvol, (&args), syncop_unlink_cbk, subvol->fops->unlink, loc); + SYNCOP (subvol, (&args), syncop_unlink_cbk, subvol->fops->unlink, loc, + 0, NULL); + + errno = 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; +} + +int +syncop_rmdir (xlator_t *subvol, loc_t *loc) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_rmdir_cbk, subvol->fops->rmdir, loc, + 0, NULL); errno = 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) + 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; @@ -1157,17 +1585,52 @@ syncop_link (xlator_t *subvol, loc_t *oldloc, loc_t *newloc) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_link_cbk, subvol->fops->link, - oldloc, newloc); + oldloc, newloc, NULL); + + errno = args.op_errno; + + 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; +} + + +int +syncop_rename (xlator_t *subvol, loc_t *oldloc, loc_t *newloc) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_rename_cbk, subvol->fops->rename, + oldloc, newloc, NULL); errno = args.op_errno; 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) + struct iatt *postbuf, dict_t *xdata) { struct syncargs *args = NULL; @@ -1187,7 +1650,7 @@ syncop_ftruncate (xlator_t *subvol, fd_t *fd, off_t offset) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->ftruncate, - fd, offset); + fd, offset, NULL); errno = args.op_errno; return args.op_ret; @@ -1199,7 +1662,7 @@ syncop_truncate (xlator_t *subvol, loc_t *loc, off_t offset) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_ftruncate_cbk, subvol->fops->truncate, - loc, offset); + loc, offset, NULL); errno = args.op_errno; return args.op_ret; @@ -1208,7 +1671,7 @@ syncop_truncate (xlator_t *subvol, loc_t *loc, off_t offset) 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) + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) { struct syncargs *args = NULL; @@ -1224,12 +1687,43 @@ syncop_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } int -syncop_fsync (xlator_t *subvol, fd_t *fd) +syncop_fsync (xlator_t *subvol, fd_t *fd, int dataonly) { struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_fsync_cbk, subvol->fops->fsync, - fd, 0); + fd, dataonly, NULL); + + errno = 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; + +} + +int +syncop_flush (xlator_t *subvol, fd_t *fd) +{ + struct syncargs args = {0}; + + SYNCOP (subvol, (&args), syncop_flush_cbk, subvol->fops->flush, + fd, NULL); errno = args.op_errno; return args.op_ret; @@ -1238,7 +1732,7 @@ syncop_fsync (xlator_t *subvol, fd_t *fd) int syncop_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, struct iatt *stbuf) + int32_t op_ret, int32_t op_errno, struct iatt *stbuf, dict_t *xdata) { struct syncargs *args = NULL; @@ -1261,7 +1755,7 @@ syncop_fstat (xlator_t *subvol, fd_t *fd, struct iatt *stbuf) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_fstat_cbk, subvol->fops->fstat, - fd); + fd, NULL); if (stbuf) *stbuf = args.iatt1; @@ -1277,7 +1771,7 @@ syncop_stat (xlator_t *subvol, loc_t *loc, struct iatt *stbuf) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_fstat_cbk, subvol->fops->stat, - loc); + loc, NULL); if (stbuf) *stbuf = args.iatt1; @@ -1291,7 +1785,7 @@ 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) + struct iatt *postparent, dict_t *xdata) { struct syncargs *args = NULL; @@ -1299,6 +1793,8 @@ syncop_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, args->op_ret = op_ret; args->op_errno = op_errno; + if (buf) + args->iatt1 = *buf; __wake (args); @@ -1306,14 +1802,18 @@ syncop_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } int -syncop_symlink (xlator_t *subvol, loc_t *loc, char *newpath, dict_t *dict) +syncop_symlink (xlator_t *subvol, loc_t *loc, const char *newpath, dict_t *dict, + struct iatt *iatt) { struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_symlink_cbk, subvol->fops->symlink, - newpath, loc, dict); + newpath, loc, 0, dict); errno = args.op_errno; + if (iatt) + *iatt = args.iatt1; + return args.op_ret; } @@ -1321,7 +1821,7 @@ syncop_symlink (xlator_t *subvol, loc_t *loc, char *newpath, dict_t *dict) 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) + struct iatt *stbuf, dict_t *xdata) { struct syncargs *args = NULL; @@ -1344,12 +1844,11 @@ syncop_readlink (xlator_t *subvol, loc_t *loc, char **buffer, size_t size) struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_readlink_cbk, subvol->fops->readlink, - loc, size); + loc, size, NULL); if (buffer) *buffer = args.buffer; - else if (args.buffer) - GF_FREE (args.buffer); + else GF_FREE (args.buffer); errno = args.op_errno; return args.op_ret; @@ -1359,7 +1858,7 @@ 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) + struct iatt *postparent, dict_t *xdata) { struct syncargs *args = NULL; @@ -1368,6 +1867,9 @@ syncop_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, args->op_ret = op_ret; args->op_errno = op_errno; + if (buf) + args->iatt1 = *buf; + __wake (args); return 0; @@ -1375,14 +1877,178 @@ syncop_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int syncop_mknod (xlator_t *subvol, loc_t *loc, mode_t mode, dev_t rdev, - dict_t *dict) + dict_t *dict, struct iatt *iatt) { struct syncargs args = {0, }; SYNCOP (subvol, (&args), syncop_mknod_cbk, subvol->fops->mknod, - loc, mode, rdev, dict); + loc, mode, rdev, 0, dict); + + errno = args.op_errno; + if (iatt) + *iatt = args.iatt1; + + 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + if (buf) + args->iatt1 = *buf; + + __wake (args); + + return 0; +} + + +int +syncop_mkdir (xlator_t *subvol, loc_t *loc, mode_t mode, dict_t *dict, + struct iatt *iatt) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_mkdir_cbk, subvol->fops->mkdir, + loc, mode, 0, dict); + + errno = args.op_errno; + if (iatt) + *iatt = args.iatt1; + + 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + __wake (args); + + return 0; +} + +int +syncop_access (xlator_t *subvol, loc_t *loc, int32_t mask) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_access_cbk, subvol->fops->access, + loc, mask, NULL); + + errno = args.op_errno; + return args.op_ret; +} + + +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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; +} + +int +syncop_fallocate(xlator_t *subvol, fd_t *fd, int32_t keep_size, off_t offset, + size_t len) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_fallocate_cbk, subvol->fops->fallocate, + fd, keep_size, offset, len, NULL); + + errno = 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + + __wake (args); + + return 0; +} + +int +syncop_discard(xlator_t *subvol, fd_t *fd, off_t offset, size_t len) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_discard_cbk, subvol->fops->discard, + fd, offset, len, NULL); errno = 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) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + if (flock) + args->flock = *flock; + __wake (args); + + return 0; +} + + +int +syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_lk_cbk, subvol->fops->lk, + fd, cmd, flock, NULL); + + errno = args.op_errno; + *flock = args.flock; + + return args.op_ret; } |
