glusterfs
1260 строк · 46.7 Кб
1/*
2Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com>
3This file is part of GlusterFS.
4
5This file is licensed to you under your choice of the GNU Lesser
6General Public License, version 3 or any later version (LGPLv3 or
7later), or the GNU General Public License, version 2 (GPLv2), in all
8cases as published by the Free Software Foundation.
9*/
10
11/* Perform fop on all subvolumes represented by list[] array and wait
12for all callbacks to return */
13
14/* NOTE: Cluster-syncop, like syncop blocks the executing thread until the
15* responses are gathered if it is not executed as part of synctask. So it
16* shouldn't be invoked in epoll worker thread */
17#include "glusterfs/cluster-syncop.h"18
19#define FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fop, \20args...) \21do { \22int __i = 0; \23int __count = 0; \24cluster_local_t __local = { \250, \26}; \27void *__old_local = frame->local; \28\29__local.replies = replies; \30memset(output, 0, numsubvols); \31cluster_replies_wipe(replies, numsubvols); \32for (__i = 0; __i < numsubvols; __i++) \33INIT_LIST_HEAD(&replies[__i].entries.list); \34if (syncbarrier_init(&__local.barrier)) \35break; \36frame->local = &__local; \37for (__i = 0; __i < numsubvols; __i++) { \38if (on[__i]) { \39__count++; \40} \41} \42__local.barrier.waitfor = __count; \43for (__i = 0; __i < numsubvols; __i++) { \44if (!on[__i]) \45continue; \46STACK_WIND_COOKIE(frame, cluster_##fop##_cbk, (void *)(long)__i, \47subvols[__i], subvols[__i]->fops->fop, args); \48} \49syncbarrier_wait(&__local.barrier, __count); \50syncbarrier_destroy(&__local.barrier); \51frame->local = __old_local; \52STACK_RESET(frame->root); \53} while (0)54
55#define FOP_SEQ(subvols, on, numsubvols, replies, output, frame, fop, args...) \56do { \57int __i = 0; \58\59cluster_local_t __local = { \600, \61}; \62void *__old_local = frame->local; \63__local.replies = replies; \64memset(output, 0, numsubvols); \65cluster_replies_wipe(replies, numsubvols); \66for (__i = 0; __i < numsubvols; __i++) \67INIT_LIST_HEAD(&replies[__i].entries.list); \68if (syncbarrier_init(&__local.barrier)) \69break; \70frame->local = &__local; \71for (__i = 0; __i < numsubvols; __i++) { \72if (!on[__i]) \73continue; \74STACK_WIND_COOKIE(frame, cluster_##fop##_cbk, (void *)(long)__i, \75subvols[__i], subvols[__i]->fops->fop, args); \76syncbarrier_wait(&__local.barrier, 1); \77} \78syncbarrier_destroy(&__local.barrier); \79frame->local = __old_local; \80STACK_RESET(frame->root); \81} while (0)82
83#define FOP_CBK(fop, frame, cookie, args...) \84do { \85cluster_local_t *__local = frame->local; \86int __i = (long)cookie; \87args_##fop##_cbk_store(&__local->replies[__i], args); \88__local->replies[__i].valid = 1; \89syncbarrier_wake(&__local->barrier); \90} while (0)91
92int32_t
93cluster_fop_success_fill(default_args_cbk_t *replies, int numsubvols,94unsigned char *success)95{
96int i = 0;97int count = 0;98
99for (i = 0; i < numsubvols; i++) {100if (replies[i].valid && replies[i].op_ret >= 0) {101success[i] = 1;102count++;103} else {104success[i] = 0;105}106}107
108return count;109}
110
111void
112cluster_replies_wipe(default_args_cbk_t *replies, int numsubvols)113{
114int i = 0;115
116if (!replies)117return;118
119for (i = 0; i < numsubvols; i++)120args_cbk_wipe(&replies[i]);121memset(replies, 0, numsubvols * sizeof(*replies));122}
123
124int32_t
125cluster_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,126int32_t op_ret, int32_t op_errno, inode_t *inode,127struct iatt *buf, dict_t *xdata, struct iatt *postparent)128{
129FOP_CBK(lookup, frame, cookie, op_ret, op_errno, inode, buf, xdata,130postparent);131return 0;132}
133
134int32_t
135cluster_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,136int32_t op_ret, int32_t op_errno, struct iatt *buf,137dict_t *xdata)138{
139FOP_CBK(stat, frame, cookie, op_ret, op_errno, buf, xdata);140return 0;141}
142
143int32_t
144cluster_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,145int32_t op_ret, int32_t op_errno, struct iatt *prebuf,146struct iatt *postbuf, dict_t *xdata)147{
148FOP_CBK(truncate, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata);149return 0;150}
151
152int32_t
153cluster_ftruncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,154int32_t op_ret, int32_t op_errno, struct iatt *prebuf,155struct iatt *postbuf, dict_t *xdata)156{
157FOP_CBK(ftruncate, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata);158return 0;159}
160
161int32_t
162cluster_access_cbk(call_frame_t *frame, void *cookie, xlator_t *this,163int32_t op_ret, int32_t op_errno, dict_t *xdata)164{
165FOP_CBK(access, frame, cookie, op_ret, op_errno, xdata);166return 0;167}
168
169int32_t
170cluster_readlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,171int32_t op_ret, int32_t op_errno, const char *path,172struct iatt *buf, dict_t *xdata)173{
174FOP_CBK(readlink, frame, cookie, op_ret, op_errno, path, buf, xdata);175return 0;176}
177
178int32_t
179cluster_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this,180int32_t op_ret, int32_t op_errno, inode_t *inode,181struct iatt *buf, struct iatt *preparent,182struct iatt *postparent, dict_t *xdata)183{
184FOP_CBK(mknod, frame, cookie, op_ret, op_errno, inode, buf, preparent,185postparent, xdata);186return 0;187}
188
189int32_t
190cluster_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,191int32_t op_ret, int32_t op_errno, inode_t *inode,192struct iatt *buf, struct iatt *preparent,193struct iatt *postparent, dict_t *xdata)194{
195FOP_CBK(mkdir, frame, cookie, op_ret, op_errno, inode, buf, preparent,196postparent, xdata);197return 0;198}
199
200int32_t
201cluster_unlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,202int32_t op_ret, int32_t op_errno, struct iatt *preparent,203struct iatt *postparent, dict_t *xdata)204{
205FOP_CBK(unlink, frame, cookie, op_ret, op_errno, preparent, postparent,206xdata);207return 0;208}
209
210int32_t
211cluster_rmdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,212int32_t op_ret, int32_t op_errno, struct iatt *preparent,213struct iatt *postparent, dict_t *xdata)214{
215FOP_CBK(rmdir, frame, cookie, op_ret, op_errno, preparent, postparent,216xdata);217return 0;218}
219
220int32_t
221cluster_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,222int32_t op_ret, int32_t op_errno, inode_t *inode,223struct iatt *buf, struct iatt *preparent,224struct iatt *postparent, dict_t *xdata)225{
226FOP_CBK(symlink, frame, cookie, op_ret, op_errno, inode, buf, preparent,227postparent, xdata);228return 0;229}
230
231int32_t
232cluster_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,233int32_t op_ret, int32_t op_errno, struct iatt *buf,234struct iatt *preoldparent, struct iatt *postoldparent,235struct iatt *prenewparent, struct iatt *postnewparent,236dict_t *xdata)237{
238FOP_CBK(rename, frame, cookie, op_ret, op_errno, buf, preoldparent,239postoldparent, prenewparent, postnewparent, xdata);240return 0;241}
242
243int32_t
244cluster_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this,245int32_t op_ret, int32_t op_errno, inode_t *inode,246struct iatt *buf, struct iatt *preparent,247struct iatt *postparent, dict_t *xdata)248{
249FOP_CBK(link, frame, cookie, op_ret, op_errno, inode, buf, preparent,250postparent, xdata);251return 0;252}
253
254int32_t
255cluster_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,256int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode,257struct iatt *buf, struct iatt *preparent,258struct iatt *postparent, dict_t *xdata)259{
260FOP_CBK(create, frame, cookie, op_ret, op_errno, fd, inode, buf, preparent,261postparent, xdata);262return 0;263}
264
265int32_t
266cluster_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this,267int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)268{
269FOP_CBK(open, frame, cookie, op_ret, op_errno, fd, xdata);270return 0;271}
272
273int32_t
274cluster_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this,275int32_t op_ret, int32_t op_errno, struct iovec *vector,276int32_t count, struct iatt *stbuf, struct iobref *iobref,277dict_t *xdata)278{
279FOP_CBK(readv, frame, cookie, op_ret, op_errno, vector, count, stbuf,280iobref, xdata);281return 0;282}
283
284int32_t
285cluster_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,286int32_t op_ret, int32_t op_errno, struct iatt *prebuf,287struct iatt *postbuf, dict_t *xdata)288{
289FOP_CBK(writev, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata);290return 0;291}
292
293int32_t
294cluster_put_cbk(call_frame_t *frame, void *cookie, xlator_t *this,295int32_t op_ret, int32_t op_errno, inode_t *inode,296struct iatt *buf, struct iatt *preparent,297struct iatt *postparent, dict_t *xdata)298{
299FOP_CBK(put, frame, cookie, op_ret, op_errno, inode, buf, preparent,300postparent, xdata);301return 0;302}
303
304int32_t
305cluster_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this,306int32_t op_ret, int32_t op_errno, dict_t *xdata)307{
308FOP_CBK(flush, frame, cookie, op_ret, op_errno, xdata);309return 0;310}
311
312int32_t
313cluster_fsync_cbk(call_frame_t *frame, void *cookie, xlator_t *this,314int32_t op_ret, int32_t op_errno, struct iatt *prebuf,315struct iatt *postbuf, dict_t *xdata)316{
317FOP_CBK(fsync, frame, cookie, op_ret, op_errno, prebuf, postbuf, xdata);318return 0;319}
320
321int32_t
322cluster_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,323int32_t op_ret, int32_t op_errno, struct iatt *buf,324dict_t *xdata)325{
326FOP_CBK(fstat, frame, cookie, op_ret, op_errno, buf, xdata);327return 0;328}
329
330int32_t
331cluster_opendir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,332int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)333{
334FOP_CBK(opendir, frame, cookie, op_ret, op_errno, fd, xdata);335return 0;336}
337
338int32_t
339cluster_fsyncdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,340int32_t op_ret, int32_t op_errno, dict_t *xdata)341{
342FOP_CBK(fsyncdir, frame, cookie, op_ret, op_errno, xdata);343return 0;344}
345
346int32_t
347cluster_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this,348int32_t op_ret, int32_t op_errno, struct statvfs *buf,349dict_t *xdata)350{
351FOP_CBK(statfs, frame, cookie, op_ret, op_errno, buf, xdata);352return 0;353}
354
355int32_t
356cluster_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,357int32_t op_ret, int32_t op_errno, dict_t *xdata)358{
359FOP_CBK(setxattr, frame, cookie, op_ret, op_errno, xdata);360return 0;361}
362
363int32_t
364cluster_fsetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,365int32_t op_ret, int32_t op_errno, dict_t *xdata)366{
367FOP_CBK(fsetxattr, frame, cookie, op_ret, op_errno, xdata);368return 0;369}
370
371int32_t
372cluster_fgetxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,373int32_t op_ret, int32_t op_errno, dict_t *dict,374dict_t *xdata)375{
376FOP_CBK(fgetxattr, frame, cookie, op_ret, op_errno, dict, xdata);377return 0;378}
379
380int32_t
381cluster_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,382int32_t op_ret, int32_t op_errno, dict_t *dict,383dict_t *xdata)384{
385FOP_CBK(getxattr, frame, cookie, op_ret, op_errno, dict, xdata);386return 0;387}
388
389int32_t
390cluster_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,391int32_t op_ret, int32_t op_errno, dict_t *dict,392dict_t *xdata)393{
394FOP_CBK(xattrop, frame, cookie, op_ret, op_errno, dict, xdata);395return 0;396}
397
398int32_t
399cluster_fxattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,400int32_t op_ret, int32_t op_errno, dict_t *dict,401dict_t *xdata)402{
403FOP_CBK(fxattrop, frame, cookie, op_ret, op_errno, dict, xdata);404return 0;405}
406
407int32_t
408cluster_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,409int32_t op_ret, int32_t op_errno, dict_t *xdata)410{
411FOP_CBK(removexattr, frame, cookie, op_ret, op_errno, xdata);412return 0;413}
414
415int32_t
416cluster_fremovexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,417int32_t op_ret, int32_t op_errno, dict_t *xdata)418{
419FOP_CBK(fremovexattr, frame, cookie, op_ret, op_errno, xdata);420return 0;421}
422
423int32_t
424cluster_lk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,425int32_t op_ret, int32_t op_errno, struct gf_flock *lock,426dict_t *xdata)427{
428FOP_CBK(lk, frame, cookie, op_ret, op_errno, lock, xdata);429return 0;430}
431
432int32_t
433cluster_inodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,434int32_t op_ret, int32_t op_errno, dict_t *xdata)435{
436FOP_CBK(inodelk, frame, cookie, op_ret, op_errno, xdata);437return 0;438}
439
440int32_t
441cluster_finodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,442int32_t op_ret, int32_t op_errno, dict_t *xdata)443{
444FOP_CBK(finodelk, frame, cookie, op_ret, op_errno, xdata);445return 0;446}
447
448int32_t
449cluster_entrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,450int32_t op_ret, int32_t op_errno, dict_t *xdata)451{
452FOP_CBK(entrylk, frame, cookie, op_ret, op_errno, xdata);453return 0;454}
455
456int32_t
457cluster_fentrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,458int32_t op_ret, int32_t op_errno, dict_t *xdata)459{
460FOP_CBK(fentrylk, frame, cookie, op_ret, op_errno, xdata);461return 0;462}
463
464int32_t
465cluster_rchecksum_cbk(call_frame_t *frame, void *cookie, xlator_t *this,466int32_t op_ret, int32_t op_errno, uint32_t weak_checksum,467uint8_t *strong_checksum, dict_t *xdata)468{
469FOP_CBK(rchecksum, frame, cookie, op_ret, op_errno, weak_checksum,470strong_checksum, xdata);471return 0;472}
473
474int32_t
475cluster_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,476int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,477dict_t *xdata)478{
479FOP_CBK(readdir, frame, cookie, op_ret, op_errno, entries, xdata);480return 0;481}
482
483int32_t
484cluster_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this,485int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,486dict_t *xdata)487{
488FOP_CBK(readdirp, frame, cookie, op_ret, op_errno, entries, xdata);489return 0;490}
491
492int32_t
493cluster_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,494int32_t op_ret, int32_t op_errno, struct iatt *statpre,495struct iatt *statpost, dict_t *xdata)496{
497FOP_CBK(setattr, frame, cookie, op_ret, op_errno, statpre, statpost, xdata);498return 0;499}
500
501int32_t
502cluster_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,503int32_t op_ret, int32_t op_errno, struct iatt *statpre,504struct iatt *statpost, dict_t *xdata)505{
506FOP_CBK(fsetattr, frame, cookie, op_ret, op_errno, statpre, statpost,507xdata);508return 0;509}
510
511int32_t
512cluster_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,513int32_t op_ret, int32_t op_errno, struct iatt *pre,514struct iatt *post, dict_t *xdata)515{
516FOP_CBK(fallocate, frame, cookie, op_ret, op_errno, pre, post, xdata);517return 0;518}
519
520int32_t
521cluster_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this,522int32_t op_ret, int32_t op_errno, struct iatt *pre,523struct iatt *post, dict_t *xdata)524{
525FOP_CBK(discard, frame, cookie, op_ret, op_errno, pre, post, xdata);526return 0;527}
528
529int32_t
530cluster_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this,531int32_t op_ret, int32_t op_errno, struct iatt *pre,532struct iatt *post, dict_t *xdata)533{
534FOP_CBK(zerofill, frame, cookie, op_ret, op_errno, pre, post, xdata);535return 0;536}
537
538int32_t
539cluster_ipc_cbk(call_frame_t *frame, void *cookie, xlator_t *this,540int32_t op_ret, int32_t op_errno, dict_t *xdata)541{
542FOP_CBK(ipc, frame, cookie, op_ret, op_errno, xdata);543return 0;544}
545
546int32_t
547cluster_fgetxattr(xlator_t **subvols, unsigned char *on, int numsubvols,548default_args_cbk_t *replies, unsigned char *output,549call_frame_t *frame, xlator_t *this, fd_t *fd,550const char *name, dict_t *xdata)551{
552FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fgetxattr, fd,553name, xdata);554return cluster_fop_success_fill(replies, numsubvols, output);555}
556
557int32_t
558cluster_fsetxattr(xlator_t **subvols, unsigned char *on, int numsubvols,559default_args_cbk_t *replies, unsigned char *output,560call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,561int32_t flags, dict_t *xdata)562{
563FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsetxattr, fd,564dict, flags, xdata);565return cluster_fop_success_fill(replies, numsubvols, output);566}
567
568int32_t
569cluster_setxattr(xlator_t **subvols, unsigned char *on, int numsubvols,570default_args_cbk_t *replies, unsigned char *output,571call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,572int32_t flags, dict_t *xdata)573{
574FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, setxattr, loc,575dict, flags, xdata);576return cluster_fop_success_fill(replies, numsubvols, output);577}
578
579int32_t
580cluster_statfs(xlator_t **subvols, unsigned char *on, int numsubvols,581default_args_cbk_t *replies, unsigned char *output,582call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)583{
584FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, statfs, loc,585xdata);586return cluster_fop_success_fill(replies, numsubvols, output);587}
588
589int32_t
590cluster_fsyncdir(xlator_t **subvols, unsigned char *on, int numsubvols,591default_args_cbk_t *replies, unsigned char *output,592call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,593dict_t *xdata)594{
595FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsyncdir, fd,596flags, xdata);597return cluster_fop_success_fill(replies, numsubvols, output);598}
599
600int32_t
601cluster_opendir(xlator_t **subvols, unsigned char *on, int numsubvols,602default_args_cbk_t *replies, unsigned char *output,603call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,604dict_t *xdata)605{
606FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, opendir, loc,607fd, xdata);608return cluster_fop_success_fill(replies, numsubvols, output);609}
610
611int32_t
612cluster_fstat(xlator_t **subvols, unsigned char *on, int numsubvols,613default_args_cbk_t *replies, unsigned char *output,614call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)615{
616FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fstat, fd,617xdata);618return cluster_fop_success_fill(replies, numsubvols, output);619}
620
621int32_t
622cluster_fsync(xlator_t **subvols, unsigned char *on, int numsubvols,623default_args_cbk_t *replies, unsigned char *output,624call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags,625dict_t *xdata)626{
627FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsync, fd,628flags, xdata);629return cluster_fop_success_fill(replies, numsubvols, output);630}
631
632int32_t
633cluster_flush(xlator_t **subvols, unsigned char *on, int numsubvols,634default_args_cbk_t *replies, unsigned char *output,635call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)636{
637FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, flush, fd,638xdata);639return cluster_fop_success_fill(replies, numsubvols, output);640}
641
642int32_t
643cluster_writev(xlator_t **subvols, unsigned char *on, int numsubvols,644default_args_cbk_t *replies, unsigned char *output,645call_frame_t *frame, xlator_t *this, fd_t *fd,646struct iovec *vector, int32_t count, off_t off, uint32_t flags,647struct iobref *iobref, dict_t *xdata)648{
649FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, writev, fd,650vector, count, off, flags, iobref, xdata);651return cluster_fop_success_fill(replies, numsubvols, output);652}
653
654int32_t
655cluster_put(xlator_t **subvols, unsigned char *on, int numsubvols,656default_args_cbk_t *replies, unsigned char *output,657call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,658mode_t umask, uint32_t flags, struct iovec *vector, int32_t count,659off_t offset, struct iobref *iobref, dict_t *xattr, dict_t *xdata)660{
661FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, put, loc, mode,662umask, flags, vector, count, offset, iobref, xattr, xdata);663return cluster_fop_success_fill(replies, numsubvols, output);664}
665
666int32_t
667cluster_readv(xlator_t **subvols, unsigned char *on, int numsubvols,668default_args_cbk_t *replies, unsigned char *output,669call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,670off_t offset, uint32_t flags, dict_t *xdata)671{
672FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readv, fd, size,673offset, flags, xdata);674return cluster_fop_success_fill(replies, numsubvols, output);675}
676
677int32_t
678cluster_open(xlator_t **subvols, unsigned char *on, int numsubvols,679default_args_cbk_t *replies, unsigned char *output,680call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,681fd_t *fd, dict_t *xdata)682{
683FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, open, loc,684flags, fd, xdata);685return cluster_fop_success_fill(replies, numsubvols, output);686}
687
688int32_t
689cluster_create(xlator_t **subvols, unsigned char *on, int numsubvols,690default_args_cbk_t *replies, unsigned char *output,691call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,692mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)693{
694FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, create, loc,695flags, mode, umask, fd, xdata);696return cluster_fop_success_fill(replies, numsubvols, output);697}
698
699int32_t
700cluster_link(xlator_t **subvols, unsigned char *on, int numsubvols,701default_args_cbk_t *replies, unsigned char *output,702call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc,703dict_t *xdata)704{
705FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, link, oldloc,706newloc, xdata);707return cluster_fop_success_fill(replies, numsubvols, output);708}
709
710int32_t
711cluster_rename(xlator_t **subvols, unsigned char *on, int numsubvols,712default_args_cbk_t *replies, unsigned char *output,713call_frame_t *frame, xlator_t *this, loc_t *oldloc,714loc_t *newloc, dict_t *xdata)715{
716FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, rename, oldloc,717newloc, xdata);718return cluster_fop_success_fill(replies, numsubvols, output);719}
720
721int
722cluster_symlink(xlator_t **subvols, unsigned char *on, int numsubvols,723default_args_cbk_t *replies, unsigned char *output,724call_frame_t *frame, xlator_t *this, const char *linkpath,725loc_t *loc, mode_t umask, dict_t *xdata)726{
727FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, symlink,728linkpath, loc, umask, xdata);729return cluster_fop_success_fill(replies, numsubvols, output);730}
731
732int32_t
733cluster_rmdir(xlator_t **subvols, unsigned char *on, int numsubvols,734default_args_cbk_t *replies, unsigned char *output,735call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,736dict_t *xdata)737{
738FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, rmdir, loc,739flags, xdata);740return cluster_fop_success_fill(replies, numsubvols, output);741}
742
743int32_t
744cluster_unlink(xlator_t **subvols, unsigned char *on, int numsubvols,745default_args_cbk_t *replies, unsigned char *output,746call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,747dict_t *xdata)748{
749FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, unlink, loc,750xflag, xdata);751return cluster_fop_success_fill(replies, numsubvols, output);752}
753
754int
755cluster_mkdir(xlator_t **subvols, unsigned char *on, int numsubvols,756default_args_cbk_t *replies, unsigned char *output,757call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,758mode_t umask, dict_t *xdata)759{
760FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, mkdir, loc,761mode, umask, xdata);762return cluster_fop_success_fill(replies, numsubvols, output);763}
764
765int
766cluster_mknod(xlator_t **subvols, unsigned char *on, int numsubvols,767default_args_cbk_t *replies, unsigned char *output,768call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,769dev_t rdev, mode_t umask, dict_t *xdata)770{
771FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, mknod, loc,772mode, rdev, umask, xdata);773return cluster_fop_success_fill(replies, numsubvols, output);774}
775
776int32_t
777cluster_readlink(xlator_t **subvols, unsigned char *on, int numsubvols,778default_args_cbk_t *replies, unsigned char *output,779call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size,780dict_t *xdata)781{
782FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readlink, loc,783size, xdata);784return cluster_fop_success_fill(replies, numsubvols, output);785}
786
787int32_t
788cluster_access(xlator_t **subvols, unsigned char *on, int numsubvols,789default_args_cbk_t *replies, unsigned char *output,790call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask,791dict_t *xdata)792{
793FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, access, loc,794mask, xdata);795return cluster_fop_success_fill(replies, numsubvols, output);796}
797
798int32_t
799cluster_ftruncate(xlator_t **subvols, unsigned char *on, int numsubvols,800default_args_cbk_t *replies, unsigned char *output,801call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,802dict_t *xdata)803{
804FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, ftruncate, fd,805offset, xdata);806return cluster_fop_success_fill(replies, numsubvols, output);807}
808
809int32_t
810cluster_getxattr(xlator_t **subvols, unsigned char *on, int numsubvols,811default_args_cbk_t *replies, unsigned char *output,812call_frame_t *frame, xlator_t *this, loc_t *loc,813const char *name, dict_t *xdata)814{
815FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, getxattr, loc,816name, xdata);817return cluster_fop_success_fill(replies, numsubvols, output);818}
819
820int32_t
821cluster_xattrop(xlator_t **subvols, unsigned char *on, int numsubvols,822default_args_cbk_t *replies, unsigned char *output,823call_frame_t *frame, xlator_t *this, loc_t *loc,824gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)825{
826FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, xattrop, loc,827flags, dict, xdata);828return cluster_fop_success_fill(replies, numsubvols, output);829}
830
831int32_t
832cluster_fxattrop(xlator_t **subvols, unsigned char *on, int numsubvols,833default_args_cbk_t *replies, unsigned char *output,834call_frame_t *frame, xlator_t *this, fd_t *fd,835gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata)836{
837FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fxattrop, fd,838flags, dict, xdata);839return cluster_fop_success_fill(replies, numsubvols, output);840}
841
842int32_t
843cluster_removexattr(xlator_t **subvols, unsigned char *on, int numsubvols,844default_args_cbk_t *replies, unsigned char *output,845call_frame_t *frame, xlator_t *this, loc_t *loc,846const char *name, dict_t *xdata)847{
848FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, removexattr,849loc, name, xdata);850return cluster_fop_success_fill(replies, numsubvols, output);851}
852
853int32_t
854cluster_fremovexattr(xlator_t **subvols, unsigned char *on, int numsubvols,855default_args_cbk_t *replies, unsigned char *output,856call_frame_t *frame, xlator_t *this, fd_t *fd,857const char *name, dict_t *xdata)858{
859FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fremovexattr,860fd, name, xdata);861return cluster_fop_success_fill(replies, numsubvols, output);862}
863
864int32_t
865cluster_lk(xlator_t **subvols, unsigned char *on, int numsubvols,866default_args_cbk_t *replies, unsigned char *output,867call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,868struct gf_flock *lock, dict_t *xdata)869{
870FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, lk, fd, cmd,871lock, xdata);872return cluster_fop_success_fill(replies, numsubvols, output);873}
874
875int32_t
876cluster_rchecksum(xlator_t **subvols, unsigned char *on, int numsubvols,877default_args_cbk_t *replies, unsigned char *output,878call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,879int32_t len, dict_t *xdata)880{
881FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, rchecksum, fd,882offset, len, xdata);883return cluster_fop_success_fill(replies, numsubvols, output);884}
885
886int32_t
887cluster_readdir(xlator_t **subvols, unsigned char *on, int numsubvols,888default_args_cbk_t *replies, unsigned char *output,889call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,890off_t off, dict_t *xdata)891{
892FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readdir, fd,893size, off, xdata);894return cluster_fop_success_fill(replies, numsubvols, output);895}
896
897int32_t
898cluster_readdirp(xlator_t **subvols, unsigned char *on, int numsubvols,899default_args_cbk_t *replies, unsigned char *output,900call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,901off_t off, dict_t *xdata)902{
903FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, readdirp, fd,904size, off, xdata);905return cluster_fop_success_fill(replies, numsubvols, output);906}
907
908int32_t
909cluster_setattr(xlator_t **subvols, unsigned char *on, int numsubvols,910default_args_cbk_t *replies, unsigned char *output,911call_frame_t *frame, xlator_t *this, loc_t *loc,912struct iatt *stbuf, int32_t valid, dict_t *xdata)913{
914FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, setattr, loc,915stbuf, valid, xdata);916return cluster_fop_success_fill(replies, numsubvols, output);917}
918
919int32_t
920cluster_truncate(xlator_t **subvols, unsigned char *on, int numsubvols,921default_args_cbk_t *replies, unsigned char *output,922call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,923dict_t *xdata)924{
925FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, truncate, loc,926offset, xdata);927return cluster_fop_success_fill(replies, numsubvols, output);928}
929
930int32_t
931cluster_stat(xlator_t **subvols, unsigned char *on, int numsubvols,932default_args_cbk_t *replies, unsigned char *output,933call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)934{
935FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, stat, loc,936xdata);937return cluster_fop_success_fill(replies, numsubvols, output);938}
939
940int32_t
941cluster_lookup(xlator_t **subvols, unsigned char *on, int numsubvols,942default_args_cbk_t *replies, unsigned char *output,943call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)944{
945FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, lookup, loc,946xdata);947return cluster_fop_success_fill(replies, numsubvols, output);948}
949
950int32_t
951cluster_fsetattr(xlator_t **subvols, unsigned char *on, int numsubvols,952default_args_cbk_t *replies, unsigned char *output,953call_frame_t *frame, xlator_t *this, fd_t *fd,954struct iatt *stbuf, int32_t valid, dict_t *xdata)955{
956FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fsetattr, fd,957stbuf, valid, xdata);958return cluster_fop_success_fill(replies, numsubvols, output);959}
960
961int32_t
962cluster_fallocate(xlator_t **subvols, unsigned char *on, int numsubvols,963default_args_cbk_t *replies, unsigned char *output,964call_frame_t *frame, xlator_t *this, fd_t *fd,965int32_t keep_size, off_t offset, size_t len, dict_t *xdata)966{
967FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, fallocate, fd,968keep_size, offset, len, xdata);969return cluster_fop_success_fill(replies, numsubvols, output);970}
971
972int32_t
973cluster_discard(xlator_t **subvols, unsigned char *on, int numsubvols,974default_args_cbk_t *replies, unsigned char *output,975call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,976size_t len, dict_t *xdata)977{
978FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, discard, fd,979offset, len, xdata);980return cluster_fop_success_fill(replies, numsubvols, output);981}
982
983int32_t
984cluster_zerofill(xlator_t **subvols, unsigned char *on, int numsubvols,985default_args_cbk_t *replies, unsigned char *output,986call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,987off_t len, dict_t *xdata)988{
989FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, zerofill, fd,990offset, len, xdata);991return cluster_fop_success_fill(replies, numsubvols, output);992}
993
994int32_t
995cluster_ipc(xlator_t **subvols, unsigned char *on, int numsubvols,996default_args_cbk_t *replies, unsigned char *output,997call_frame_t *frame, xlator_t *this, int32_t op, dict_t *xdata)998{
999FOP_ONLIST(subvols, on, numsubvols, replies, output, frame, ipc, op, xdata);1000return cluster_fop_success_fill(replies, numsubvols, output);1001}
1002
1003int
1004cluster_uninodelk(xlator_t **subvols, unsigned char *locked_on, int numsubvols,1005default_args_cbk_t *replies, unsigned char *output,1006call_frame_t *frame, xlator_t *this, char *dom,1007inode_t *inode, off_t off, size_t size)1008{
1009loc_t loc = {10100,1011};1012struct gf_flock flock = {10130,1014};1015
1016loc.inode = inode_ref(inode);1017gf_uuid_copy(loc.gfid, inode->gfid);1018
1019flock.l_type = F_UNLCK;1020flock.l_start = off;1021flock.l_len = size;1022
1023FOP_ONLIST(subvols, locked_on, numsubvols, replies, output, frame, inodelk,1024dom, &loc, F_SETLK, &flock, NULL);1025
1026loc_wipe(&loc);1027
1028return cluster_fop_success_fill(replies, numsubvols, output);1029}
1030
1031int
1032cluster_tryinodelk(xlator_t **subvols, unsigned char *on, int numsubvols,1033default_args_cbk_t *replies, unsigned char *locked_on,1034call_frame_t *frame, xlator_t *this, char *dom,1035inode_t *inode, off_t off, size_t size)1036{
1037struct gf_flock flock = {10380,1039};1040loc_t loc = {0};1041
1042flock.l_type = F_WRLCK;1043flock.l_start = off;1044flock.l_len = size;1045
1046loc.inode = inode_ref(inode);1047gf_uuid_copy(loc.gfid, inode->gfid);1048FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom,1049&loc, F_SETLK, &flock, NULL);1050
1051loc_wipe(&loc);1052return cluster_fop_success_fill(replies, numsubvols, locked_on);1053}
1054
1055int
1056cluster_inodelk(xlator_t **subvols, unsigned char *on, int numsubvols,1057default_args_cbk_t *replies, unsigned char *locked_on,1058call_frame_t *frame, xlator_t *this, char *dom, inode_t *inode,1059off_t off, size_t size)1060{
1061struct gf_flock flock = {10620,1063};1064int i = 0;1065loc_t loc = {0};1066unsigned char *output = NULL;1067
1068flock.l_type = F_WRLCK;1069flock.l_start = off;1070flock.l_len = size;1071
1072output = alloca(numsubvols);1073loc.inode = inode_ref(inode);1074gf_uuid_copy(loc.gfid, inode->gfid);1075FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom,1076&loc, F_SETLK, &flock, NULL);1077
1078for (i = 0; i < numsubvols; i++) {1079if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) {1080cluster_fop_success_fill(replies, numsubvols, locked_on);1081cluster_uninodelk(subvols, locked_on, numsubvols, replies, output,1082frame, this, dom, inode, off, size);1083
1084FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame, inodelk,1085dom, &loc, F_SETLKW, &flock, NULL);1086break;1087}1088}1089
1090loc_wipe(&loc);1091return cluster_fop_success_fill(replies, numsubvols, locked_on);1092}
1093
1094int
1095cluster_unentrylk(xlator_t **subvols, unsigned char *locked_on, int numsubvols,1096default_args_cbk_t *replies, unsigned char *output,1097call_frame_t *frame, xlator_t *this, char *dom,1098inode_t *inode, const char *name)1099{
1100loc_t loc = {11010,1102};1103
1104loc.inode = inode_ref(inode);1105gf_uuid_copy(loc.gfid, inode->gfid);1106
1107FOP_ONLIST(subvols, locked_on, numsubvols, replies, output, frame, entrylk,1108dom, &loc, name, ENTRYLK_UNLOCK, ENTRYLK_WRLCK, NULL);1109
1110loc_wipe(&loc);1111
1112return cluster_fop_success_fill(replies, numsubvols, output);1113}
1114
1115int
1116cluster_tryentrylk(xlator_t **subvols, unsigned char *on, int numsubvols,1117default_args_cbk_t *replies, unsigned char *locked_on,1118call_frame_t *frame, xlator_t *this, char *dom,1119inode_t *inode, const char *name)1120{
1121loc_t loc = {0};1122
1123loc.inode = inode_ref(inode);1124gf_uuid_copy(loc.gfid, inode->gfid);1125FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, entrylk, dom,1126&loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, NULL);1127
1128loc_wipe(&loc);1129return cluster_fop_success_fill(replies, numsubvols, locked_on);1130}
1131
1132int
1133cluster_entrylk(xlator_t **subvols, unsigned char *on, int numsubvols,1134default_args_cbk_t *replies, unsigned char *locked_on,1135call_frame_t *frame, xlator_t *this, char *dom, inode_t *inode,1136const char *name)1137{
1138int i = 0;1139loc_t loc = {0};1140unsigned char *output = NULL;1141
1142output = alloca(numsubvols);1143loc.inode = inode_ref(inode);1144gf_uuid_copy(loc.gfid, inode->gfid);1145FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, entrylk, dom,1146&loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, NULL);1147
1148for (i = 0; i < numsubvols; i++) {1149if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) {1150cluster_fop_success_fill(replies, numsubvols, locked_on);1151cluster_unentrylk(subvols, locked_on, numsubvols, replies, output,1152frame, this, dom, inode, name);1153FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame, entrylk,1154dom, &loc, name, ENTRYLK_LOCK, ENTRYLK_WRLCK, NULL);1155break;1156}1157}1158
1159loc_wipe(&loc);1160return cluster_fop_success_fill(replies, numsubvols, locked_on);1161}
1162
1163int
1164cluster_tiebreaker_inodelk(xlator_t **subvols, unsigned char *on,1165int numsubvols, default_args_cbk_t *replies,1166unsigned char *locked_on, call_frame_t *frame,1167xlator_t *this, char *dom, inode_t *inode, off_t off,1168size_t size)1169{
1170struct gf_flock flock = {11710,1172};1173int i = 0;1174int num_success = 0;1175loc_t loc = {0};1176unsigned char *output = NULL;1177
1178flock.l_type = F_WRLCK;1179flock.l_start = off;1180flock.l_len = size;1181
1182output = alloca(numsubvols);1183loc.inode = inode_ref(inode);1184gf_uuid_copy(loc.gfid, inode->gfid);1185FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, inodelk, dom,1186&loc, F_SETLK, &flock, NULL);1187
1188for (i = 0; i < numsubvols; i++) {1189if (replies[i].valid && replies[i].op_ret == 0) {1190num_success++;1191continue;1192}1193
1194/* TODO: If earlier subvols fail with an error other1195* than EAGAIN, we could still have 2 clients competing
1196* for the lock*/
1197if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) {1198cluster_fop_success_fill(replies, numsubvols, locked_on);1199cluster_uninodelk(subvols, locked_on, numsubvols, replies, output,1200frame, this, dom, inode, off, size);1201
1202if (num_success) {1203FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame,1204inodelk, dom, &loc, F_SETLKW, &flock, NULL);1205} else {1206loc_wipe(&loc);1207memset(locked_on, 0, numsubvols);1208return 0;1209}1210break;1211}1212}1213
1214loc_wipe(&loc);1215return cluster_fop_success_fill(replies, numsubvols, locked_on);1216}
1217
1218int
1219cluster_tiebreaker_entrylk(xlator_t **subvols, unsigned char *on,1220int numsubvols, default_args_cbk_t *replies,1221unsigned char *locked_on, call_frame_t *frame,1222xlator_t *this, char *dom, inode_t *inode,1223const char *name)1224{
1225int i = 0;1226loc_t loc = {0};1227unsigned char *output = NULL;1228int num_success = 0;1229
1230output = alloca(numsubvols);1231loc.inode = inode_ref(inode);1232gf_uuid_copy(loc.gfid, inode->gfid);1233FOP_ONLIST(subvols, on, numsubvols, replies, locked_on, frame, entrylk, dom,1234&loc, name, ENTRYLK_LOCK_NB, ENTRYLK_WRLCK, NULL);1235
1236for (i = 0; i < numsubvols; i++) {1237if (replies[i].valid && replies[i].op_ret == 0) {1238num_success++;1239continue;1240}1241if (replies[i].op_ret == -1 && replies[i].op_errno == EAGAIN) {1242cluster_fop_success_fill(replies, numsubvols, locked_on);1243cluster_unentrylk(subvols, locked_on, numsubvols, replies, output,1244frame, this, dom, inode, name);1245if (num_success) {1246FOP_SEQ(subvols, on, numsubvols, replies, locked_on, frame,1247entrylk, dom, &loc, name, ENTRYLK_LOCK, ENTRYLK_WRLCK,1248NULL);1249} else {1250loc_wipe(&loc);1251memset(locked_on, 0, numsubvols);1252return 0;1253}1254break;1255}1256}1257
1258loc_wipe(&loc);1259return cluster_fop_success_fill(replies, numsubvols, locked_on);1260}
1261