From e16868dede6455cab644805af6fe1ac312775e13 Mon Sep 17 00:00:00 2001 From: Gluster Ant Date: Wed, 12 Sep 2018 17:52:45 +0530 Subject: Land part 2 of clang-format changes Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu --- api/examples/glfsxmp.c | 2960 +-- api/src/glfs-fops.c | 8474 +++---- api/src/glfs-handleops.c | 3859 +-- api/src/glfs-master.c | 225 +- api/src/glfs-mgmt.c | 1818 +- api/src/glfs-resolve.c | 1877 +- api/src/glfs.c | 2370 +- cli/src/cli-cmd-global.c | 176 +- cli/src/cli-cmd-misc.c | 149 +- cli/src/cli-cmd-parser.c | 9441 +++---- cli/src/cli-cmd-peer.c | 432 +- cli/src/cli-cmd-snapshot.c | 206 +- cli/src/cli-cmd-system.c | 953 +- cli/src/cli-cmd-volume.c | 5579 +++-- cli/src/cli-cmd.c | 541 +- cli/src/cli-quotad-client.c | 199 +- cli/src/cli-rl.c | 502 +- cli/src/cli-rpc-ops.c | 20932 ++++++++-------- cli/src/cli-xml-output.c | 9928 ++++---- cli/src/cli.c | 1115 +- cli/src/input.c | 102 +- cli/src/registry.c | 495 +- extras/benchmarking/glfs-bm.c | 509 +- extras/benchmarking/rdd.c | 1001 +- extras/create_new_xlator/new-xlator-tmpl.c | 141 +- extras/geo-rep/gsync-sync-gfid.c | 165 +- extras/stripe-merge.c | 687 +- extras/test/ld-preload-test/ld-preload-lib.c | 598 +- extras/test/ld-preload-test/ld-preload-test.c | 503 +- extras/test/open-fd-tests.c | 83 +- extras/test/test-ffop.c | 1638 +- geo-replication/src/gsyncd.c | 585 +- geo-replication/src/procdiggy.c | 196 +- glusterfsd/src/gf_attach.c | 293 +- glusterfsd/src/glusterfsd-mgmt.c | 4965 ++-- glusterfsd/src/glusterfsd.c | 4226 ++-- heal/src/glfs-heal.c | 2855 ++- libglusterfs/src/atomic.h | 12 +- libglusterfs/src/call-stub.c | 3231 ++- libglusterfs/src/checksum.c | 15 +- libglusterfs/src/circ-buff.c | 294 +- libglusterfs/src/client_t.c | 1390 +- libglusterfs/src/cluster-syncop.c | 1670 +- libglusterfs/src/common-utils.c | 7053 +++--- libglusterfs/src/compat-errno.c | 1726 +- libglusterfs/src/compat.c | 906 +- libglusterfs/src/compound-fop-utils.c | 164 +- libglusterfs/src/ctx.c | 108 +- libglusterfs/src/daemon.c | 66 +- libglusterfs/src/default-args.c | 2147 +- libglusterfs/src/defaults-tmpl.c | 313 +- libglusterfs/src/dict.c | 4481 ++-- libglusterfs/src/event-epoll.c | 1518 +- libglusterfs/src/event-history.c | 81 +- libglusterfs/src/event-poll.c | 760 +- libglusterfs/src/event.c | 367 +- libglusterfs/src/events.c | 197 +- libglusterfs/src/fd-lk.c | 617 +- libglusterfs/src/fd.c | 1693 +- libglusterfs/src/gf-dirent.c | 413 +- libglusterfs/src/gfdb/gfdb_data_store.c | 1005 +- libglusterfs/src/gfdb/gfdb_data_store_helper.c | 773 +- libglusterfs/src/gfdb/gfdb_sqlite3.c | 2355 +- libglusterfs/src/gfdb/gfdb_sqlite3_helper.c | 2361 +- libglusterfs/src/gidcache.c | 306 +- libglusterfs/src/globals.c | 669 +- libglusterfs/src/graph-print.c | 241 +- libglusterfs/src/graph.c | 1748 +- libglusterfs/src/hashfn.c | 262 +- libglusterfs/src/inode.c | 3562 ++- libglusterfs/src/iobuf.c | 1701 +- libglusterfs/src/latency.c | 106 +- libglusterfs/src/locking.c | 5 +- libglusterfs/src/logging.c | 4038 +-- libglusterfs/src/mem-pool.c | 1354 +- libglusterfs/src/monitoring.c | 420 +- libglusterfs/src/options.c | 1947 +- libglusterfs/src/options.h | 4 +- libglusterfs/src/parse-utils.c | 135 +- libglusterfs/src/quota-common-utils.c | 332 +- libglusterfs/src/rbthash.c | 663 +- libglusterfs/src/refcount.c | 129 +- libglusterfs/src/rot-buffs.c | 616 +- libglusterfs/src/run.c | 766 +- libglusterfs/src/stack.c | 720 +- libglusterfs/src/statedump.c | 1496 +- libglusterfs/src/store.c | 1167 +- libglusterfs/src/strfd.c | 101 +- libglusterfs/src/syncop-utils.c | 1025 +- libglusterfs/src/syncop.c | 4679 ++-- libglusterfs/src/syscall.c | 743 +- libglusterfs/src/throttle-tbf.c | 375 +- libglusterfs/src/timer.c | 440 +- libglusterfs/src/timespec.c | 94 +- libglusterfs/src/trie.c | 483 +- libglusterfs/src/unittest/global_mock.c | 3 +- libglusterfs/src/unittest/log_mock.c | 30 +- libglusterfs/src/unittest/mem_pool_unittest.c | 58 +- libglusterfs/src/xlator.c | 2270 +- rpc/rpc-lib/src/auth-glusterfs.c | 615 +- rpc/rpc-lib/src/auth-null.c | 36 +- rpc/rpc-lib/src/auth-unix.c | 75 +- rpc/rpc-lib/src/autoscale-threads.c | 12 +- rpc/rpc-lib/src/mgmt-pmap.c | 212 +- rpc/rpc-lib/src/rpc-clnt-ping.c | 569 +- rpc/rpc-lib/src/rpc-clnt.c | 3376 ++- rpc/rpc-lib/src/rpc-drc.c | 1100 +- rpc/rpc-lib/src/rpc-transport.c | 1000 +- rpc/rpc-lib/src/rpcsvc-auth.c | 790 +- rpc/rpc-lib/src/rpcsvc.c | 4525 ++-- rpc/rpc-lib/src/xdr-rpc.c | 259 +- rpc/rpc-lib/src/xdr-rpcclnt.c | 108 +- rpc/rpc-transport/rdma/src/name.c | 1002 +- rpc/rpc-transport/rdma/src/rdma.c | 8125 +++--- rpc/rpc-transport/socket/src/name.c | 1151 +- rpc/rpc-transport/socket/src/socket.c | 7446 +++--- rpc/xdr/src/msg-nfs3.c | 442 +- rpc/xdr/src/xdr-generic.c | 129 +- rpc/xdr/src/xdr-nfs3.c | 2572 +- tests/basic/ctime/ctime-glfs-init.c | 85 +- tests/basic/ec/ec-fast-fgetxattr.c | 191 +- tests/basic/ec/seek.c | 235 +- tests/basic/fops-sanity.c | 1811 +- tests/basic/fuse/seek.c | 102 +- tests/basic/gfapi/anonymous_fd_read_write.c | 177 +- tests/basic/gfapi/bug-1241104.c | 141 +- tests/basic/gfapi/bug1283983.c | 205 +- tests/basic/gfapi/bug1291259.c | 300 +- tests/basic/gfapi/bug1613098.c | 157 +- tests/basic/gfapi/gfapi-async-calls-test.c | 272 +- tests/basic/gfapi/gfapi-dup.c | 144 +- tests/basic/gfapi/gfapi-load-volfile.c | 64 +- tests/basic/gfapi/gfapi-ssl-test.c | 194 +- tests/basic/gfapi/gfapi-trunc.c | 151 +- tests/basic/gfapi/glfd-lkowner.c | 350 +- tests/basic/gfapi/glfs_sysrq.c | 93 +- tests/basic/gfapi/glfs_xreaddirplus_r.c | 346 +- tests/basic/gfapi/libgfapi-fini-hang.c | 97 +- tests/basic/gfapi/mandatory-lock-optimal.c | 765 +- tests/basic/gfapi/seek.c | 138 +- tests/basic/gfapi/upcall-cache-invalidate.c | 359 +- tests/basic/gfapi/upcall-register-api.c | 477 +- tests/basic/logchecks.c | 350 +- tests/basic/posix/zero-fill-enospace.c | 100 +- tests/basic/quota.c | 107 +- tests/basic/tier/file_lock.c | 127 +- tests/bitrot/br-stub.c | 304 +- tests/bugs/access-control/bug-1051896.c | 147 +- tests/bugs/access-control/bug-1387241.c | 17 +- tests/bugs/cli/bug-1169302.c | 127 +- tests/bugs/core/bug-834465.c | 85 +- tests/bugs/distribute/bug-1193636.c | 100 +- tests/bugs/distribute/bug-860663.c | 48 +- tests/bugs/ec/bug-1161886.c | 84 +- tests/bugs/fuse/bug-1126048.c | 48 +- tests/bugs/gfapi/bug-1093594.c | 508 +- tests/bugs/gfapi/bug-1319374.c | 220 +- tests/bugs/gfapi/bug-1447266/1460514.c | 259 +- tests/bugs/gfapi/bug-1447266/bug-1447266.c | 194 +- tests/bugs/gfapi/glfs_vol_set_IO_ERR.c | 260 +- tests/bugs/glusterd/bug-824753-file-locker.c | 14 +- tests/bugs/glusterfs-server/bug-905864.c | 99 +- tests/bugs/glusterfs/getlk_owner.c | 96 +- tests/bugs/io-cache/bug-858242.c | 113 +- tests/bugs/io-cache/bug-read-hang.c | 200 +- tests/bugs/nfs/bug-1210338.c | 27 +- tests/bugs/posix/bug-1175711.c | 40 +- .../posix/disallow-gfid-volumeid-fremovexattr.c | 160 +- tests/bugs/protocol/bug-808400-fcntl.c | 191 +- tests/bugs/protocol/bug-808400-flock.c | 124 +- tests/bugs/quick-read/bz1523599/test_bz1523599.c | 322 +- tests/bugs/readdir-ahead/bug-1390050.c | 98 +- tests/bugs/replicate/bug-1250170-fsync.c | 78 +- tests/bugs/shard/bug-shard-discard.c | 97 +- tests/bugs/shard/bug-shard-zerofill.c | 101 +- tests/bugs/shard/shard-append-test.c | 276 +- tests/bugs/shard/shard-fallocate.c | 151 +- tests/bugs/write-behind/bug-1058663.c | 158 +- tests/bugs/write-behind/bug-1279730.c | 232 +- tests/encryption/frag.c | 478 +- tests/features/glfs-lease.c | 970 +- tests/features/mandatory-lock-forced.c | 249 +- tests/utils/arequal-checksum.c | 876 +- tests/utils/changelog/get-history.c | 70 +- tools/gfind_missing_files/gcrawler.c | 780 +- tools/setgfid2path/src/main.c | 202 +- xlators/cluster/afr/src/afr-common.c | 10695 ++++---- xlators/cluster/afr/src/afr-dir-read.c | 493 +- xlators/cluster/afr/src/afr-dir-write.c | 2270 +- xlators/cluster/afr/src/afr-inode-read.c | 2873 ++- xlators/cluster/afr/src/afr-inode-write.c | 3534 ++- xlators/cluster/afr/src/afr-lk-common.c | 1683 +- xlators/cluster/afr/src/afr-open.c | 526 +- xlators/cluster/afr/src/afr-read-txn.c | 752 +- xlators/cluster/afr/src/afr-self-heal-common.c | 4108 ++-- xlators/cluster/afr/src/afr-self-heal-data.c | 1469 +- xlators/cluster/afr/src/afr-self-heal-entry.c | 1902 +- xlators/cluster/afr/src/afr-self-heal-metadata.c | 820 +- xlators/cluster/afr/src/afr-self-heal-name.c | 1091 +- xlators/cluster/afr/src/afr-self-heald.c | 2151 +- xlators/cluster/afr/src/afr-transaction.c | 3887 ++- xlators/cluster/afr/src/afr.c | 2045 +- xlators/cluster/dht/src/dht-common.c | 18427 +++++++------- xlators/cluster/dht/src/dht-diskusage.c | 853 +- xlators/cluster/dht/src/dht-hashfn.c | 142 +- xlators/cluster/dht/src/dht-helper.c | 3382 ++- xlators/cluster/dht/src/dht-inode-read.c | 2453 +- xlators/cluster/dht/src/dht-inode-write.c | 2316 +- xlators/cluster/dht/src/dht-layout.c | 1275 +- xlators/cluster/dht/src/dht-linkfile.c | 515 +- xlators/cluster/dht/src/dht-lock.c | 2141 +- xlators/cluster/dht/src/dht-rebalance.c | 9142 ++++--- xlators/cluster/dht/src/dht-rename.c | 3322 ++- xlators/cluster/dht/src/dht-selfheal.c | 4568 ++-- xlators/cluster/dht/src/dht-shared.c | 1999 +- xlators/cluster/dht/src/dht.c | 118 +- xlators/cluster/dht/src/nufa.c | 1091 +- xlators/cluster/dht/src/switch.c | 1477 +- xlators/cluster/dht/src/tier-common.c | 1988 +- xlators/cluster/dht/src/tier.c | 5232 ++-- xlators/cluster/dht/src/unittest/dht_layout_mock.c | 33 +- .../cluster/dht/src/unittest/dht_layout_unittest.c | 22 +- xlators/cluster/ec/src/ec-code-avx.c | 43 +- xlators/cluster/ec/src/ec-code-c.c | 902 +- xlators/cluster/ec/src/ec-code-intel.c | 64 +- xlators/cluster/ec/src/ec-code-sse.c | 43 +- xlators/cluster/ec/src/ec-code-x64.c | 47 +- xlators/cluster/ec/src/ec-code.c | 391 +- xlators/cluster/ec/src/ec-combine.c | 495 +- xlators/cluster/ec/src/ec-common.c | 1785 +- xlators/cluster/ec/src/ec-data.c | 186 +- xlators/cluster/ec/src/ec-dir-read.c | 339 +- xlators/cluster/ec/src/ec-dir-write.c | 607 +- xlators/cluster/ec/src/ec-generic.c | 805 +- xlators/cluster/ec/src/ec-gf8.c | 10679 ++++---- xlators/cluster/ec/src/ec-heal.c | 4917 ++-- xlators/cluster/ec/src/ec-heald.c | 814 +- xlators/cluster/ec/src/ec-helpers.c | 333 +- xlators/cluster/ec/src/ec-inode-read.c | 1068 +- xlators/cluster/ec/src/ec-inode-write.c | 1740 +- xlators/cluster/ec/src/ec-locks.c | 612 +- xlators/cluster/ec/src/ec-method.c | 40 +- xlators/cluster/ec/src/ec.c | 1880 +- xlators/cluster/stripe/src/stripe-helpers.c | 1043 +- xlators/cluster/stripe/src/stripe.c | 9394 ++++--- xlators/debug/delay-gen/src/delay-gen.c | 858 +- xlators/debug/error-gen/src/error-gen.c | 2534 +- xlators/debug/io-stats/src/io-stats.c | 6842 +++--- xlators/debug/sink/src/sink.c | 57 +- xlators/debug/trace/src/trace.c | 5447 +++-- xlators/encryption/crypt/src/atom.c | 1210 +- xlators/encryption/crypt/src/crypt.c | 7571 +++--- xlators/encryption/crypt/src/data.c | 1131 +- xlators/encryption/crypt/src/keys.c | 368 +- xlators/encryption/crypt/src/metadata.c | 875 +- xlators/encryption/rot-13/src/rot-13.c | 230 +- .../dht2/dht2-client/src/dht2-client-main.c | 35 +- .../dht2/dht2-server/src/dht2-server-main.c | 35 +- xlators/experimental/fdl/src/dump-tmpl.c | 223 +- xlators/experimental/fdl/src/fdl-tmpl.c | 788 +- xlators/experimental/fdl/src/logdump.c | 77 +- xlators/experimental/fdl/src/recon-tmpl.c | 423 +- xlators/experimental/fdl/src/recon.c | 120 +- xlators/experimental/jbr-client/src/fop-template.c | 171 +- xlators/experimental/jbr-client/src/jbrc.c | 373 +- .../experimental/jbr-server/src/all-templates.c | 824 +- xlators/experimental/jbr-server/src/jbr.c | 2739 +-- .../experimental/posix2/ds/src/posix2-ds-main.c | 33 +- .../experimental/posix2/mds/src/posix2-mds-main.c | 33 +- xlators/features/arbiter/src/arbiter.c | 514 +- xlators/features/barrier/src/barrier.c | 1069 +- .../bit-rot/src/bitd/bit-rot-scrub-status.c | 82 +- xlators/features/bit-rot/src/bitd/bit-rot-scrub.c | 3171 +-- xlators/features/bit-rot/src/bitd/bit-rot-ssm.c | 129 +- xlators/features/bit-rot/src/bitd/bit-rot.c | 3282 +-- .../bit-rot/src/stub/bit-rot-stub-helpers.c | 1202 +- xlators/features/bit-rot/src/stub/bit-rot-stub.c | 5023 ++-- .../changelog/lib/examples/c/get-changes-multi.c | 80 +- .../changelog/lib/examples/c/get-changes.c | 102 +- .../changelog/lib/examples/c/get-history.c | 148 +- .../features/changelog/lib/src/gf-changelog-api.c | 305 +- .../changelog/lib/src/gf-changelog-helpers.c | 256 +- .../lib/src/gf-changelog-journal-handler.c | 1635 +- .../changelog/lib/src/gf-changelog-reborp.c | 581 +- .../features/changelog/lib/src/gf-changelog-rpc.c | 90 +- xlators/features/changelog/lib/src/gf-changelog.c | 859 +- .../changelog/lib/src/gf-history-changelog.c | 1551 +- xlators/features/changelog/src/changelog-barrier.c | 140 +- .../features/changelog/src/changelog-encoders.c | 298 +- .../features/changelog/src/changelog-ev-handle.c | 570 +- xlators/features/changelog/src/changelog-helpers.c | 2987 ++- .../features/changelog/src/changelog-rpc-common.c | 525 +- xlators/features/changelog/src/changelog-rpc.c | 548 +- xlators/features/changelog/src/changelog-rt.c | 57 +- xlators/features/changelog/src/changelog.c | 4631 ++-- .../changetimerecorder/src/changetimerecorder.c | 3705 ++- .../features/changetimerecorder/src/ctr-helper.c | 450 +- .../changetimerecorder/src/ctr-xlator-ctx.c | 557 +- xlators/features/cloudsync/src/cloudsync-common.c | 42 +- .../src/cloudsyncs3/src/libcloudsyncs3.c | 896 +- xlators/features/cloudsync/src/cloudsync.c | 2460 +- xlators/features/compress/src/cdc-helper.c | 756 +- xlators/features/compress/src/cdc.c | 557 +- xlators/features/gfid-access/src/gfid-access.c | 2135 +- xlators/features/glupy/src/glupy.c | 2987 ++- xlators/features/index/src/index.c | 4050 ++- xlators/features/leases/src/leases-internal.c | 2013 +- xlators/features/leases/src/leases.c | 1526 +- xlators/features/locks/src/clear.c | 701 +- xlators/features/locks/src/common.c | 1437 +- xlators/features/locks/src/entrylk.c | 1627 +- xlators/features/locks/src/inodelk.c | 1669 +- xlators/features/locks/src/posix.c | 6661 +++-- xlators/features/locks/src/reservelk.c | 555 +- xlators/features/locks/tests/unit-test.c | 88 +- xlators/features/marker/src/marker-common.c | 69 +- xlators/features/marker/src/marker-quota-helper.c | 651 +- xlators/features/marker/src/marker-quota.c | 3491 +-- xlators/features/marker/src/marker.c | 4781 ++-- xlators/features/namespace/src/namespace.c | 1784 +- xlators/features/quiesce/src/quiesce.c | 3516 ++- xlators/features/quota/src/quota-enforcer-client.c | 702 +- xlators/features/quota/src/quota.c | 8293 +++---- xlators/features/quota/src/quotad-aggregator.c | 696 +- xlators/features/quota/src/quotad-helpers.c | 114 +- xlators/features/quota/src/quotad.c | 316 +- xlators/features/read-only/src/read-only-common.c | 555 +- xlators/features/read-only/src/read-only.c | 167 +- xlators/features/read-only/src/worm-helper.c | 604 +- xlators/features/read-only/src/worm.c | 1069 +- xlators/features/sdfs/src/sdfs.c | 2188 +- xlators/features/selinux/src/selinux.c | 407 +- xlators/features/shard/src/shard.c | 10988 +++++---- .../features/snapview-client/src/snapview-client.c | 3918 +-- .../snapview-server/src/snapview-server-helpers.c | 869 +- .../snapview-server/src/snapview-server-mgmt.c | 817 +- .../features/snapview-server/src/snapview-server.c | 4270 ++-- xlators/features/thin-arbiter/src/thin-arbiter.c | 433 +- xlators/features/trash/src/trash.c | 4338 ++-- xlators/features/upcall/src/upcall-internal.c | 987 +- xlators/features/upcall/src/upcall.c | 3205 ++- xlators/features/utime/src/utime-helpers.c | 85 +- xlators/features/utime/src/utime.c | 198 +- xlators/lib/src/libxlator.c | 791 +- xlators/meta/src/active-link.c | 21 +- xlators/meta/src/cmdline-file.c | 23 +- xlators/meta/src/frames-file.c | 154 +- xlators/meta/src/graph-dir.c | 125 +- xlators/meta/src/graphs-dir.c | 83 +- xlators/meta/src/history-file.c | 25 +- xlators/meta/src/logfile-link.c | 21 +- xlators/meta/src/logging-dir.c | 38 +- xlators/meta/src/loglevel-file.c | 34 +- xlators/meta/src/mallinfo-file.c | 19 +- xlators/meta/src/measure-file.c | 31 +- xlators/meta/src/meminfo-file.c | 25 +- xlators/meta/src/meta-defaults.c | 771 +- xlators/meta/src/meta-helpers.c | 425 +- xlators/meta/src/meta.c | 279 +- xlators/meta/src/name-file.c | 25 +- xlators/meta/src/option-file.c | 32 +- xlators/meta/src/options-dir.c | 58 +- xlators/meta/src/private-file.c | 25 +- xlators/meta/src/process_uuid-file.c | 19 +- xlators/meta/src/profile-file.c | 25 +- xlators/meta/src/root-dir.c | 101 +- xlators/meta/src/subvolume-link.c | 63 +- xlators/meta/src/subvolumes-dir.c | 61 +- xlators/meta/src/top-link.c | 27 +- xlators/meta/src/type-file.c | 25 +- xlators/meta/src/version-file.c | 20 +- xlators/meta/src/view-dir.c | 23 +- xlators/meta/src/volfile-file.c | 65 +- xlators/meta/src/xlator-dir.c | 126 +- xlators/mgmt/glusterd/src/glusterd-bitd-svc.c | 283 +- xlators/mgmt/glusterd/src/glusterd-bitrot.c | 1209 +- xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 6213 +++-- xlators/mgmt/glusterd/src/glusterd-conn-helper.c | 4 +- xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c | 169 +- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 11598 +++++---- .../glusterd/src/glusterd-gfproxyd-svc-helper.c | 288 +- xlators/mgmt/glusterd/src/glusterd-gfproxyd-svc.c | 770 +- xlators/mgmt/glusterd/src/glusterd-handler.c | 11402 ++++----- xlators/mgmt/glusterd/src/glusterd-handshake.c | 3973 ++- xlators/mgmt/glusterd/src/glusterd-hooks.c | 904 +- xlators/mgmt/glusterd/src/glusterd-locks.c | 1389 +- xlators/mgmt/glusterd/src/glusterd-log-ops.c | 450 +- xlators/mgmt/glusterd/src/glusterd-mgmt-handler.c | 1647 +- xlators/mgmt/glusterd/src/glusterd-mgmt.c | 4550 ++-- xlators/mgmt/glusterd/src/glusterd-mountbroker.c | 1224 +- xlators/mgmt/glusterd/src/glusterd-nfs-svc.c | 317 +- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 14309 ++++++----- xlators/mgmt/glusterd/src/glusterd-peer-utils.c | 1488 +- xlators/mgmt/glusterd/src/glusterd-pmap.c | 953 +- xlators/mgmt/glusterd/src/glusterd-proc-mgmt.c | 180 +- xlators/mgmt/glusterd/src/glusterd-quota.c | 3671 +-- xlators/mgmt/glusterd/src/glusterd-quotad-svc.c | 311 +- xlators/mgmt/glusterd/src/glusterd-rebalance.c | 1862 +- xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 1195 +- xlators/mgmt/glusterd/src/glusterd-reset-brick.c | 653 +- xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 4101 ++-- xlators/mgmt/glusterd/src/glusterd-scrub-svc.c | 280 +- xlators/mgmt/glusterd/src/glusterd-server-quorum.c | 732 +- xlators/mgmt/glusterd/src/glusterd-shd-svc.c | 379 +- xlators/mgmt/glusterd/src/glusterd-sm.c | 2515 +- .../mgmt/glusterd/src/glusterd-snapd-svc-helper.c | 69 +- xlators/mgmt/glusterd/src/glusterd-snapd-svc.c | 749 +- .../mgmt/glusterd/src/glusterd-snapshot-utils.c | 7011 +++--- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 18529 +++++++------- xlators/mgmt/glusterd/src/glusterd-statedump.c | 388 +- xlators/mgmt/glusterd/src/glusterd-store.c | 8473 ++++--- xlators/mgmt/glusterd/src/glusterd-svc-helper.c | 408 +- xlators/mgmt/glusterd/src/glusterd-svc-mgmt.c | 523 +- xlators/mgmt/glusterd/src/glusterd-syncop.c | 3299 ++- xlators/mgmt/glusterd/src/glusterd-tier.c | 2377 +- .../mgmt/glusterd/src/glusterd-tierd-svc-helper.c | 284 +- xlators/mgmt/glusterd/src/glusterd-tierd-svc.c | 815 +- xlators/mgmt/glusterd/src/glusterd-utils.c | 24499 +++++++++---------- xlators/mgmt/glusterd/src/glusterd-volgen.c | 10906 ++++----- xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 5710 ++--- xlators/mgmt/glusterd/src/glusterd-volume-set.c | 6986 +++--- xlators/mgmt/glusterd/src/glusterd.c | 3714 ++- xlators/mount/fuse/src/fuse-bridge.c | 9377 ++++--- xlators/mount/fuse/src/fuse-helpers.c | 1065 +- xlators/mount/fuse/src/fuse-resolve.c | 1036 +- xlators/nfs/server/src/acl3.c | 1560 +- xlators/nfs/server/src/auth-cache.c | 543 +- xlators/nfs/server/src/exports.c | 1609 +- xlators/nfs/server/src/mount3-auth.c | 680 +- xlators/nfs/server/src/mount3.c | 6430 +++-- xlators/nfs/server/src/mount3udp_svc.c | 344 +- xlators/nfs/server/src/netgroups.c | 1018 +- xlators/nfs/server/src/nfs-common.c | 643 +- xlators/nfs/server/src/nfs-fops.c | 2349 +- xlators/nfs/server/src/nfs-generics.c | 333 +- xlators/nfs/server/src/nfs-inodes.c | 764 +- xlators/nfs/server/src/nfs.c | 3417 ++- xlators/nfs/server/src/nfs3-fh.c | 206 +- xlators/nfs/server/src/nfs3-helpers.c | 5055 ++-- xlators/nfs/server/src/nfs3.c | 9220 ++++--- xlators/nfs/server/src/nlm4.c | 4315 ++-- xlators/nfs/server/src/nlmcbk_svc.c | 157 +- .../performance/decompounder/src/decompounder.c | 1182 +- xlators/performance/io-cache/src/io-cache.c | 3023 ++- xlators/performance/io-cache/src/ioc-inode.c | 300 +- xlators/performance/io-cache/src/page.c | 1436 +- xlators/performance/io-threads/src/io-threads.c | 1968 +- xlators/performance/md-cache/src/md-cache.c | 5261 ++-- xlators/performance/nl-cache/src/nl-cache-helper.c | 1725 +- xlators/performance/nl-cache/src/nl-cache.c | 1263 +- xlators/performance/open-behind/src/open-behind.c | 1788 +- xlators/performance/quick-read/src/quick-read.c | 2372 +- xlators/performance/read-ahead/src/page.c | 857 +- xlators/performance/read-ahead/src/read-ahead.c | 1840 +- .../performance/readdir-ahead/src/readdir-ahead.c | 1793 +- .../performance/symlink-cache/src/symlink-cache.c | 508 +- .../performance/write-behind/src/write-behind.c | 4742 ++-- xlators/playground/template/src/template.c | 227 +- xlators/protocol/auth/addr/src/addr.c | 520 +- xlators/protocol/auth/login/src/login.c | 351 +- xlators/protocol/client/src/client-callback.c | 447 +- xlators/protocol/client/src/client-common.c | 4530 ++-- xlators/protocol/client/src/client-handshake.c | 2809 +-- xlators/protocol/client/src/client-helpers.c | 5465 ++--- xlators/protocol/client/src/client-lk.c | 701 +- xlators/protocol/client/src/client-rpc-fops.c | 10907 +++++---- xlators/protocol/client/src/client-rpc-fops_v2.c | 10841 ++++---- xlators/protocol/client/src/client.c | 4377 ++-- xlators/protocol/server/src/authenticate.c | 327 +- xlators/protocol/server/src/server-common.c | 1166 +- xlators/protocol/server/src/server-handshake.c | 1730 +- xlators/protocol/server/src/server-helpers.c | 9813 ++++---- xlators/protocol/server/src/server-resolve.c | 955 +- xlators/protocol/server/src/server-rpc-fops.c | 8892 +++---- xlators/protocol/server/src/server-rpc-fops_v2.c | 8452 +++---- xlators/protocol/server/src/server.c | 3086 ++- xlators/storage/bd/src/bd-aio.c | 835 +- xlators/storage/bd/src/bd-helper.c | 1685 +- xlators/storage/bd/src/bd.c | 3593 ++- xlators/storage/posix/src/posix-aio.c | 970 +- xlators/storage/posix/src/posix-common.c | 2208 +- xlators/storage/posix/src/posix-entry-ops.c | 3943 ++- xlators/storage/posix/src/posix-gfid-path.c | 501 +- xlators/storage/posix/src/posix-handle.c | 1607 +- xlators/storage/posix/src/posix-helpers.c | 5182 ++-- xlators/storage/posix/src/posix-inode-fd-ops.c | 8597 +++---- xlators/storage/posix/src/posix-metadata.c | 1063 +- xlators/storage/posix/src/posix.c | 118 +- xlators/system/posix-acl/src/posix-acl-xattr.c | 229 +- xlators/system/posix-acl/src/posix-acl.c | 3373 ++- 490 files changed, 429552 insertions(+), 442550 deletions(-) diff --git a/api/examples/glfsxmp.c b/api/examples/glfsxmp.c index 9bfb1d2a81f..9d96eea1d87 100644 --- a/api/examples/glfsxmp.c +++ b/api/examples/glfsxmp.c @@ -6,1593 +6,1633 @@ #include #include - int -test_dirops (glfs_t *fs) +test_dirops(glfs_t *fs) { - glfs_fd_t *fd = NULL; - char buf[512]; - struct dirent *entry = NULL; - - fd = glfs_opendir (fs, "/"); - if (!fd) { - fprintf (stderr, "/: %s\n", strerror (errno)); - return -1; - } - - fprintf (stderr, "Entries:\n"); - while (glfs_readdir_r (fd, (struct dirent *)buf, &entry), entry) { - fprintf (stderr, "%s: %lu\n", entry->d_name, glfs_telldir (fd)); - } - - glfs_closedir (fd); - return 0; + glfs_fd_t *fd = NULL; + char buf[512]; + struct dirent *entry = NULL; + + fd = glfs_opendir(fs, "/"); + if (!fd) { + fprintf(stderr, "/: %s\n", strerror(errno)); + return -1; + } + + fprintf(stderr, "Entries:\n"); + while (glfs_readdir_r(fd, (struct dirent *)buf, &entry), entry) { + fprintf(stderr, "%s: %lu\n", entry->d_name, glfs_telldir(fd)); + } + + glfs_closedir(fd); + return 0; } - int -test_xattr (glfs_t *fs) +test_xattr(glfs_t *fs) { - char *filename = "/filename2"; - char buf[512]; - char *ptr; - int ret; - - ret = glfs_setxattr (fs, filename, "user.testkey", "testval", 8, 0); - fprintf (stderr, "setxattr(%s): %d (%s)\n", filename, ret, - strerror (errno)); - - ret = glfs_setxattr (fs, filename, "user.testkey2", "testval", 8, 0); - fprintf (stderr, "setxattr(%s): %d (%s)\n", filename, ret, - strerror (errno)); - - ret = glfs_listxattr (fs, filename, buf, 512); - fprintf (stderr, "listxattr(%s): %d (%s)\n", filename, ret, - strerror (errno)); - if (ret < 0) - return -1; - - for (ptr = buf; ptr < buf + ret; ptr++) { - printf ("key=%s\n", ptr); - ptr += strlen (ptr); - } - - return 0; -} - - -int -test_chdir (glfs_t *fs) -{ - int ret = -1; - char *topdir = "/topdir"; - char *linkdir = "/linkdir"; - char *subdir = "./subdir"; - char *respath = NULL; - char pathbuf[4096]; - - ret = glfs_mkdir (fs, topdir, 0755); - if (ret) { - fprintf (stderr, "mkdir(%s): %s\n", topdir, strerror (errno)); - return -1; - } - - respath = glfs_getcwd (fs, pathbuf, 4096); - fprintf (stdout, "getcwd() = %s\n", respath); - - ret = glfs_symlink (fs, topdir, linkdir); - if (ret) { - fprintf (stderr, "symlink(%s, %s): %s\n", topdir, linkdir, strerror (errno)); - return -1; - } + char *filename = "/filename2"; + char buf[512]; + char *ptr; + int ret; - ret = glfs_chdir (fs, linkdir); - if (ret) { - fprintf (stderr, "chdir(%s): %s\n", linkdir, strerror (errno)); - return -1; - } + ret = glfs_setxattr(fs, filename, "user.testkey", "testval", 8, 0); + fprintf(stderr, "setxattr(%s): %d (%s)\n", filename, ret, strerror(errno)); - respath = glfs_getcwd (fs, pathbuf, 4096); - fprintf (stdout, "getcwd() = %s\n", respath); + ret = glfs_setxattr(fs, filename, "user.testkey2", "testval", 8, 0); + fprintf(stderr, "setxattr(%s): %d (%s)\n", filename, ret, strerror(errno)); - respath = glfs_realpath (fs, subdir, pathbuf); - if (respath) { - fprintf (stderr, "realpath(%s) worked unexpectedly: %s\n", subdir, respath); - return -1; - } + ret = glfs_listxattr(fs, filename, buf, 512); + fprintf(stderr, "listxattr(%s): %d (%s)\n", filename, ret, strerror(errno)); + if (ret < 0) + return -1; - ret = glfs_mkdir (fs, subdir, 0755); - if (ret) { - fprintf (stderr, "mkdir(%s): %s\n", subdir, strerror (errno)); - return -1; - } - - respath = glfs_realpath (fs, subdir, pathbuf); - if (!respath) { - fprintf (stderr, "realpath(%s): %s\n", subdir, strerror (errno)); - } else { - fprintf (stdout, "realpath(%s) = %s\n", subdir, respath); - } + for (ptr = buf; ptr < buf + ret; ptr++) { + printf("key=%s\n", ptr); + ptr += strlen(ptr); + } - ret = glfs_chdir (fs, subdir); - if (ret) { - fprintf (stderr, "chdir(%s): %s\n", subdir, strerror (errno)); - return -1; - } - - respath = glfs_getcwd (fs, pathbuf, 4096); - fprintf (stdout, "getcwd() = %s\n", respath); - - respath = glfs_realpath (fs, "/linkdir/subdir", pathbuf); - if (!respath) { - fprintf (stderr, "realpath(/linkdir/subdir): %s\n", strerror (errno)); - } else { - fprintf (stdout, "realpath(/linkdir/subdir) = %s\n", respath); - } + return 0; +} - return 0; +int +test_chdir(glfs_t *fs) +{ + int ret = -1; + char *topdir = "/topdir"; + char *linkdir = "/linkdir"; + char *subdir = "./subdir"; + char *respath = NULL; + char pathbuf[4096]; + + ret = glfs_mkdir(fs, topdir, 0755); + if (ret) { + fprintf(stderr, "mkdir(%s): %s\n", topdir, strerror(errno)); + return -1; + } + + respath = glfs_getcwd(fs, pathbuf, 4096); + fprintf(stdout, "getcwd() = %s\n", respath); + + ret = glfs_symlink(fs, topdir, linkdir); + if (ret) { + fprintf(stderr, "symlink(%s, %s): %s\n", topdir, linkdir, + strerror(errno)); + return -1; + } + + ret = glfs_chdir(fs, linkdir); + if (ret) { + fprintf(stderr, "chdir(%s): %s\n", linkdir, strerror(errno)); + return -1; + } + + respath = glfs_getcwd(fs, pathbuf, 4096); + fprintf(stdout, "getcwd() = %s\n", respath); + + respath = glfs_realpath(fs, subdir, pathbuf); + if (respath) { + fprintf(stderr, "realpath(%s) worked unexpectedly: %s\n", subdir, + respath); + return -1; + } + + ret = glfs_mkdir(fs, subdir, 0755); + if (ret) { + fprintf(stderr, "mkdir(%s): %s\n", subdir, strerror(errno)); + return -1; + } + + respath = glfs_realpath(fs, subdir, pathbuf); + if (!respath) { + fprintf(stderr, "realpath(%s): %s\n", subdir, strerror(errno)); + } else { + fprintf(stdout, "realpath(%s) = %s\n", subdir, respath); + } + + ret = glfs_chdir(fs, subdir); + if (ret) { + fprintf(stderr, "chdir(%s): %s\n", subdir, strerror(errno)); + return -1; + } + + respath = glfs_getcwd(fs, pathbuf, 4096); + fprintf(stdout, "getcwd() = %s\n", respath); + + respath = glfs_realpath(fs, "/linkdir/subdir", pathbuf); + if (!respath) { + fprintf(stderr, "realpath(/linkdir/subdir): %s\n", strerror(errno)); + } else { + fprintf(stdout, "realpath(/linkdir/subdir) = %s\n", respath); + } + + return 0; } #ifdef DEBUG static void -peek_stat (struct stat *sb) +peek_stat(struct stat *sb) { - printf ("Dumping stat information:\n"); - printf ("File type: "); - - switch (sb->st_mode & S_IFMT) { - case S_IFBLK: printf ("block device\n"); break; - case S_IFCHR: printf ("character device\n"); break; - case S_IFDIR: printf ("directory\n"); break; - case S_IFIFO: printf ("FIFO/pipe\n"); break; - case S_IFLNK: printf ("symlink\n"); break; - case S_IFREG: printf ("regular file\n"); break; - case S_IFSOCK: printf ("socket\n"); break; - default: printf ("unknown?\n"); break; - } - - printf ("I-node number: %ld\n", (long) sb->st_ino); - - printf ("Mode: %lo (octal)\n", - (unsigned long) sb->st_mode); - - printf ("Link count: %ld\n", (long) sb->st_nlink); - printf ("Ownership: UID=%ld GID=%ld\n", - (long) sb->st_uid, (long) sb->st_gid); - - printf ("Preferred I/O block size: %ld bytes\n", - (long) sb->st_blksize); - printf ("File size: %lld bytes\n", - (long long) sb->st_size); - printf ("Blocks allocated: %lld\n", - (long long) sb->st_blocks); - - printf ("Last status change: %s", ctime(&sb->st_ctime)); - printf ("Last file access: %s", ctime(&sb->st_atime)); - printf ("Last file modification: %s", ctime(&sb->st_mtime)); - - return; + printf("Dumping stat information:\n"); + printf("File type: "); + + switch (sb->st_mode & S_IFMT) { + case S_IFBLK: + printf("block device\n"); + break; + case S_IFCHR: + printf("character device\n"); + break; + case S_IFDIR: + printf("directory\n"); + break; + case S_IFIFO: + printf("FIFO/pipe\n"); + break; + case S_IFLNK: + printf("symlink\n"); + break; + case S_IFREG: + printf("regular file\n"); + break; + case S_IFSOCK: + printf("socket\n"); + break; + default: + printf("unknown?\n"); + break; + } + + printf("I-node number: %ld\n", (long)sb->st_ino); + + printf("Mode: %lo (octal)\n", + (unsigned long)sb->st_mode); + + printf("Link count: %ld\n", (long)sb->st_nlink); + printf("Ownership: UID=%ld GID=%ld\n", (long)sb->st_uid, + (long)sb->st_gid); + + printf("Preferred I/O block size: %ld bytes\n", (long)sb->st_blksize); + printf("File size: %lld bytes\n", (long long)sb->st_size); + printf("Blocks allocated: %lld\n", (long long)sb->st_blocks); + + printf("Last status change: %s", ctime(&sb->st_ctime)); + printf("Last file access: %s", ctime(&sb->st_atime)); + printf("Last file modification: %s", ctime(&sb->st_mtime)); + + return; } static void -peek_handle (unsigned char *glid) +peek_handle(unsigned char *glid) { - int i; + int i; - for (i = 0; i < GFAPI_HANDLE_LENGTH; i++) - { - printf (":%02x:", glid[i]); - } - printf ("\n"); + for (i = 0; i < GFAPI_HANDLE_LENGTH; i++) { + printf(":%02x:", glid[i]); + } + printf("\n"); } -#else /* DEBUG */ +#else /* DEBUG */ static void -peek_stat (struct stat *sb) +peek_stat(struct stat *sb) { - return; + return; } static void -peek_handle (unsigned char *id) +peek_handle(unsigned char *id) { - return; + return; } #endif /* DEBUG */ -glfs_t *fs = NULL; -char *full_parent_name = "/testdir", *parent_name = "testdir"; +glfs_t *fs = NULL; +char *full_parent_name = "/testdir", *parent_name = "testdir"; void -test_h_unlink (void) +test_h_unlink(void) { - char *my_dir = "unlinkdir"; - char *my_file = "file.txt"; - char *my_subdir = "dir1"; - struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL, - *subdir = NULL, *subleaf = NULL; - struct stat sb; - int ret; - - printf ("glfs_h_unlink tests: In Progress\n"); - - /* Prepare tests */ - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dir = glfs_h_mkdir (fs, parent, my_dir, 0644, &sb); - if (dir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - leaf = glfs_h_creat (fs, dir, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - subdir = glfs_h_mkdir (fs, dir, my_subdir, 0644, &sb); - if (subdir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_subdir, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - subleaf = glfs_h_creat (fs, subdir, my_file, O_CREAT, 0644, &sb); - if (subleaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, subdir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink non empty directory */ - ret = glfs_h_unlink (fs, dir, my_subdir); - if ((ret && errno != ENOTEMPTY) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: it is non empty: %s\n", - my_subdir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink regular file */ - ret = glfs_h_unlink (fs, subdir, my_file); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_file, subdir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink directory */ - ret = glfs_h_unlink (fs, dir, my_subdir); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_subdir, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink regular file */ - ret = glfs_h_unlink (fs, dir, my_file); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink non-existent regular file */ - ret = glfs_h_unlink (fs, dir, my_file); - if ((ret && errno != ENOENT) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking non-existent %s: invalid errno ,%d, %s\n", - my_file, ret, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink non-existent directory */ - ret = glfs_h_unlink (fs, dir, my_subdir); - if ((ret && errno != ENOENT) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking non-existent %s: invalid errno ,%d, %s\n", - my_subdir, ret, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink directory */ - ret = glfs_h_unlink (fs, parent, my_dir); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - printf ("glfs_h_unlink tests: PASSED\n"); + char *my_dir = "unlinkdir"; + char *my_file = "file.txt"; + char *my_subdir = "dir1"; + struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL, + *subdir = NULL, *subleaf = NULL; + struct stat sb; + int ret; + + printf("glfs_h_unlink tests: In Progress\n"); + + /* Prepare tests */ + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dir = glfs_h_mkdir(fs, parent, my_dir, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, parent, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + leaf = glfs_h_creat(fs, dir, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + subdir = glfs_h_mkdir(fs, dir, my_subdir, 0644, &sb); + if (subdir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_subdir, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + subleaf = glfs_h_creat(fs, subdir, my_file, O_CREAT, 0644, &sb); + if (subleaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, subdir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink non empty directory */ + ret = glfs_h_unlink(fs, dir, my_subdir); + if ((ret && errno != ENOTEMPTY) || (ret == 0)) { + fprintf(stderr, + "glfs_h_unlink: error unlinking %s: it is non empty: %s\n", + my_subdir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink regular file */ + ret = glfs_h_unlink(fs, subdir, my_file); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_file, subdir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink directory */ + ret = glfs_h_unlink(fs, dir, my_subdir); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_subdir, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink regular file */ + ret = glfs_h_unlink(fs, dir, my_file); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink non-existent regular file */ + ret = glfs_h_unlink(fs, dir, my_file); + if ((ret && errno != ENOENT) || (ret == 0)) { + fprintf(stderr, + "glfs_h_unlink: error unlinking non-existent %s: invalid errno " + ",%d, %s\n", + my_file, ret, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink non-existent directory */ + ret = glfs_h_unlink(fs, dir, my_subdir); + if ((ret && errno != ENOENT) || (ret == 0)) { + fprintf(stderr, + "glfs_h_unlink: error unlinking non-existent %s: invalid " + "errno ,%d, %s\n", + my_subdir, ret, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink directory */ + ret = glfs_h_unlink(fs, parent, my_dir); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_dir, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + printf("glfs_h_unlink tests: PASSED\n"); out: - if (dir) - glfs_h_close (dir); - if (leaf) - glfs_h_close (leaf); - if (subdir) - glfs_h_close (subdir); - if (subleaf) - glfs_h_close (subleaf); - if (parent) - glfs_h_close (parent); - - return; + if (dir) + glfs_h_close(dir); + if (leaf) + glfs_h_close(leaf); + if (subdir) + glfs_h_close(subdir); + if (subleaf) + glfs_h_close(subleaf); + if (parent) + glfs_h_close(parent); + + return; } void -test_h_getsetattrs (void) +test_h_getsetattrs(void) { - char *my_dir = "attrdir"; - char *my_file = "attrfile.txt"; - struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; - struct stat sb, retsb; - int ret, valid; - struct timespec timestamp; - - printf("glfs_h_getattrs and setattrs tests: In Progress\n"); - - /* Prepare tests */ - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dir = glfs_h_mkdir (fs, parent, my_dir, 0644, &sb); - if (dir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, dir, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - ret = glfs_h_getattrs (fs, dir, &retsb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - peek_stat (&retsb); - /* TODO: Compare stat information */ - - retsb.st_mode = 00666; - retsb.st_uid = 1000; - retsb.st_gid = 1001; - ret = clock_gettime (CLOCK_REALTIME, ×tamp); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - retsb.st_atim = timestamp; - retsb.st_mtim = timestamp; - valid = GFAPI_SET_ATTR_MODE | GFAPI_SET_ATTR_UID | GFAPI_SET_ATTR_GID | - GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME; - peek_stat (&retsb); - - ret = glfs_h_setattrs (fs, dir, &retsb, valid); - if (ret != 0) { - fprintf (stderr, "glfs_h_setattrs: error %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - memset(&retsb, 0, sizeof (struct stat)); - ret = glfs_h_stat (fs, dir, &retsb); - if (ret != 0) { - fprintf (stderr, "glfs_h_stat: error %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - peek_stat (&retsb); - - printf ("glfs_h_getattrs and setattrs tests: PASSED\n"); + char *my_dir = "attrdir"; + char *my_file = "attrfile.txt"; + struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; + struct stat sb, retsb; + int ret, valid; + struct timespec timestamp; + + printf("glfs_h_getattrs and setattrs tests: In Progress\n"); + + /* Prepare tests */ + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dir = glfs_h_mkdir(fs, parent, my_dir, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, parent, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, dir, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + ret = glfs_h_getattrs(fs, dir, &retsb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error %s: from (%p),%s\n", my_dir, + dir, strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + peek_stat(&retsb); + /* TODO: Compare stat information */ + + retsb.st_mode = 00666; + retsb.st_uid = 1000; + retsb.st_gid = 1001; + ret = clock_gettime(CLOCK_REALTIME, ×tamp); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + retsb.st_atim = timestamp; + retsb.st_mtim = timestamp; + valid = GFAPI_SET_ATTR_MODE | GFAPI_SET_ATTR_UID | GFAPI_SET_ATTR_GID | + GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME; + peek_stat(&retsb); + + ret = glfs_h_setattrs(fs, dir, &retsb, valid); + if (ret != 0) { + fprintf(stderr, "glfs_h_setattrs: error %s: from (%p),%s\n", my_dir, + dir, strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + memset(&retsb, 0, sizeof(struct stat)); + ret = glfs_h_stat(fs, dir, &retsb); + if (ret != 0) { + fprintf(stderr, "glfs_h_stat: error %s: from (%p),%s\n", my_dir, dir, + strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + peek_stat(&retsb); + + printf("glfs_h_getattrs and setattrs tests: PASSED\n"); out: - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - if (dir) - glfs_h_close (dir); - - return; + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + if (dir) + glfs_h_close(dir); + + return; } void -test_h_truncate (void) +test_h_truncate(void) { - char *my_dir = "truncatedir"; - char *my_file = "file.txt"; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL; - struct stat sb; - glfs_fd_t *fd = NULL; - char buf[32]; - off_t offset = 0; - int ret = 0; - - printf("glfs_h_truncate tests: In Progress\n"); - - /* Prepare tests */ - root = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_mkdir (fs, root, my_dir, 0644, &sb); - if (parent == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, root, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - fd = glfs_h_open (fs, leaf, O_RDWR); - if (fd == NULL) { - fprintf (stderr, "glfs_h_open: error on open of %s: %s\n", - my_file, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - memcpy (buf, "abcdefghijklmnopqrstuvwxyz012345", 32); - ret = glfs_write (fd, buf, 32, 0); - - /* run tests */ - /* truncate lower */ - offset = 30; - ret = glfs_h_truncate (fs, leaf, offset); - if (ret != 0) { - fprintf (stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - ret = glfs_h_getattrs (fs, leaf, &sb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error for %s (%p),%s\n", - my_file, leaf, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - if (sb.st_size != offset) { - fprintf (stderr, "glfs_h_truncate: post size mismatch\n"); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - /* truncate higher */ - offset = 32; - ret = glfs_h_truncate (fs, leaf, offset); - if (ret != 0) { - fprintf (stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - ret = glfs_h_getattrs (fs, leaf, &sb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error for %s (%p),%s\n", - my_file, leaf, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - if (sb.st_size != offset) { - fprintf (stderr, "glfs_h_truncate: post size mismatch\n"); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - /* truncate equal */ - offset = 30; - ret = glfs_h_truncate (fs, leaf, offset); - if (ret != 0) { - fprintf (stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - ret = glfs_h_getattrs (fs, leaf, &sb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error for %s (%p),%s\n", - my_file, leaf, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - if (sb.st_size != offset) { - fprintf (stderr, "glfs_h_truncate: post size mismatch\n"); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - printf ("glfs_h_truncate tests: PASSED\n"); + char *my_dir = "truncatedir"; + char *my_file = "file.txt"; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL; + struct stat sb; + glfs_fd_t *fd = NULL; + char buf[32]; + off_t offset = 0; + int ret = 0; + + printf("glfs_h_truncate tests: In Progress\n"); + + /* Prepare tests */ + root = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_mkdir(fs, root, my_dir, 0644, &sb); + if (parent == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, root, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + fd = glfs_h_open(fs, leaf, O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_h_open: error on open of %s: %s\n", my_file, + strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + memcpy(buf, "abcdefghijklmnopqrstuvwxyz012345", 32); + ret = glfs_write(fd, buf, 32, 0); + + /* run tests */ + /* truncate lower */ + offset = 30; + ret = glfs_h_truncate(fs, leaf, offset); + if (ret != 0) { + fprintf(stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + ret = glfs_h_getattrs(fs, leaf, &sb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error for %s (%p),%s\n", my_file, + leaf, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + if (sb.st_size != offset) { + fprintf(stderr, "glfs_h_truncate: post size mismatch\n"); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + /* truncate higher */ + offset = 32; + ret = glfs_h_truncate(fs, leaf, offset); + if (ret != 0) { + fprintf(stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + ret = glfs_h_getattrs(fs, leaf, &sb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error for %s (%p),%s\n", my_file, + leaf, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + if (sb.st_size != offset) { + fprintf(stderr, "glfs_h_truncate: post size mismatch\n"); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + /* truncate equal */ + offset = 30; + ret = glfs_h_truncate(fs, leaf, offset); + if (ret != 0) { + fprintf(stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + ret = glfs_h_getattrs(fs, leaf, &sb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error for %s (%p),%s\n", my_file, + leaf, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + if (sb.st_size != offset) { + fprintf(stderr, "glfs_h_truncate: post size mismatch\n"); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + printf("glfs_h_truncate tests: PASSED\n"); out: - if (fd) - glfs_close (fd); - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - - return; + if (fd) + glfs_close(fd); + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + + return; } void -test_h_links (void) +test_h_links(void) { - char *my_dir = "linkdir"; - char *my_file = "file.txt"; - char *my_symlnk = "slnk.txt"; - char *my_lnk = "lnk.txt"; - char *linksrc_dir = "dir1"; - char *linktgt_dir = "dir2"; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, - *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; - struct glfs_object *ln1 = NULL; - struct stat sb; - int ret; - char *buf = NULL; - - printf("glfs_h_link(s) tests: In Progress\n"); - - /* Prepare tests */ - root = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_mkdir (fs, root, my_dir, 0644, &sb); - if (parent == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, root, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirsrc = glfs_h_mkdir (fs, parent, linksrc_dir, 0644, &sb); - if (dirsrc == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - linksrc_dir, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirtgt = glfs_h_mkdir (fs, parent, linktgt_dir, 0644, &sb); - if (dirtgt == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - linktgt_dir, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dleaf = glfs_h_creat (fs, dirsrc, my_file, O_CREAT, 0644, &sb); - if (dleaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dirsrc, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* run tests */ - /* sym link: /testdir/linkdir/file.txt to ./slnk.txt */ - ln1 = glfs_h_symlink (fs, parent, my_symlnk, "./file.txt", &sb); - if (ln1 == NULL) { - fprintf (stderr, "glfs_h_symlink: error creating %s: from (%p),%s\n", - my_symlnk, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - buf = calloc (1024, sizeof(char)); - if (buf == NULL) { - fprintf (stderr, "Error allocating memory\n"); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - - ret = glfs_h_readlink (fs, ln1, buf, 1024); - if (ret <= 0) { - fprintf (stderr, "glfs_h_readlink: error reading %s: from (%p),%s\n", - my_symlnk, ln1, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - if (!(strncmp (buf, my_symlnk, strlen (my_symlnk)))) { - fprintf (stderr, "glfs_h_readlink: error mismatch in link name: actual %s: retrieved %s\n", - my_symlnk, buf); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - - /* link: /testdir/linkdir/file.txt to ./lnk.txt */ - ret = glfs_h_link (fs, leaf, parent, my_lnk); - if (ret != 0) { - fprintf (stderr, "glfs_h_link: error creating %s: from (%p),%s\n", - my_lnk, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - /* TODO: Should write content to a file and read from the link */ - - /* link: /testdir/linkdir/dir1/file.txt to ../dir2/slnk.txt */ - ret = glfs_h_link (fs, dleaf, dirtgt, my_lnk); - if (ret != 0) { - fprintf (stderr, "glfs_h_link: error creating %s: from (%p),%s\n", - my_lnk, dirtgt, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - /* TODO: Should write content to a file and read from the link */ - - printf ("glfs_h_link(s) tests: PASSED\n"); + char *my_dir = "linkdir"; + char *my_file = "file.txt"; + char *my_symlnk = "slnk.txt"; + char *my_lnk = "lnk.txt"; + char *linksrc_dir = "dir1"; + char *linktgt_dir = "dir2"; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, + *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; + struct glfs_object *ln1 = NULL; + struct stat sb; + int ret; + char *buf = NULL; + + printf("glfs_h_link(s) tests: In Progress\n"); + + /* Prepare tests */ + root = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_mkdir(fs, root, my_dir, 0644, &sb); + if (parent == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, root, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirsrc = glfs_h_mkdir(fs, parent, linksrc_dir, 0644, &sb); + if (dirsrc == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + linksrc_dir, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirtgt = glfs_h_mkdir(fs, parent, linktgt_dir, 0644, &sb); + if (dirtgt == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + linktgt_dir, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dleaf = glfs_h_creat(fs, dirsrc, my_file, O_CREAT, 0644, &sb); + if (dleaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dirsrc, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* run tests */ + /* sym link: /testdir/linkdir/file.txt to ./slnk.txt */ + ln1 = glfs_h_symlink(fs, parent, my_symlnk, "./file.txt", &sb); + if (ln1 == NULL) { + fprintf(stderr, "glfs_h_symlink: error creating %s: from (%p),%s\n", + my_symlnk, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + buf = calloc(1024, sizeof(char)); + if (buf == NULL) { + fprintf(stderr, "Error allocating memory\n"); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + + ret = glfs_h_readlink(fs, ln1, buf, 1024); + if (ret <= 0) { + fprintf(stderr, "glfs_h_readlink: error reading %s: from (%p),%s\n", + my_symlnk, ln1, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + if (!(strncmp(buf, my_symlnk, strlen(my_symlnk)))) { + fprintf(stderr, + "glfs_h_readlink: error mismatch in link name: actual %s: " + "retrieved %s\n", + my_symlnk, buf); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + + /* link: /testdir/linkdir/file.txt to ./lnk.txt */ + ret = glfs_h_link(fs, leaf, parent, my_lnk); + if (ret != 0) { + fprintf(stderr, "glfs_h_link: error creating %s: from (%p),%s\n", + my_lnk, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + /* TODO: Should write content to a file and read from the link */ + + /* link: /testdir/linkdir/dir1/file.txt to ../dir2/slnk.txt */ + ret = glfs_h_link(fs, dleaf, dirtgt, my_lnk); + if (ret != 0) { + fprintf(stderr, "glfs_h_link: error creating %s: from (%p),%s\n", + my_lnk, dirtgt, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + /* TODO: Should write content to a file and read from the link */ + + printf("glfs_h_link(s) tests: PASSED\n"); out: - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - if (dirsrc) - glfs_h_close (dirsrc); - if (dirtgt) - glfs_h_close (dirtgt); - if (dleaf) - glfs_h_close (dleaf); - if (ln1) - glfs_h_close (ln1); - if (buf) - free (buf); - - return; + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + if (dirsrc) + glfs_h_close(dirsrc); + if (dirtgt) + glfs_h_close(dirtgt); + if (dleaf) + glfs_h_close(dleaf); + if (ln1) + glfs_h_close(ln1); + if (buf) + free(buf); + + return; } void -test_h_rename (void) +test_h_rename(void) { - char *my_dir = "renamedir"; - char *my_file = "file.txt"; - char *src_dir = "dir1"; - char *tgt_dir = "dir2"; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, - *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; - struct stat sb; - int ret; - - printf("glfs_h_rename tests: In Progress\n"); - - /* Prepare tests */ - root = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_mkdir (fs, root, my_dir, 0644, &sb); - if (parent == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, root, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirsrc = glfs_h_mkdir (fs, parent, src_dir, 0644, &sb); - if (dirsrc == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - src_dir, parent, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirtgt = glfs_h_mkdir (fs, parent, tgt_dir, 0644, &sb); - if (dirtgt == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - tgt_dir, parent, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dleaf = glfs_h_creat (fs, dirsrc, my_file, O_CREAT, 0644, &sb); - if (dleaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dirsrc, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* run tests */ - /* Rename file.txt -> file1.txt */ - ret = glfs_h_rename (fs, parent, "file.txt", parent, "file1.txt"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "file.txt", "file1.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir1/file.txt -> file.txt */ - ret = glfs_h_rename (fs, dirsrc, "file.txt", parent, "file.txt"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s/%s to %s (%s)\n", - src_dir, "file.txt", "file.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename file1.txt -> file.txt (exists) */ - ret = glfs_h_rename (fs, parent, "file1.txt", parent, "file.txt"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "file.txt", "file.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir1 -> dir3 */ - ret = glfs_h_rename (fs, parent, "dir1", parent, "dir3"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "dir1", "dir3", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir2 ->dir3 (exists) */ - ret = glfs_h_rename (fs, parent, "dir2", parent, "dir3"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "dir2", "dir3", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename file.txt -> dir3 (fail) */ - ret = glfs_h_rename (fs, parent, "file.txt", parent, "dir3"); - if (ret == 0) { - fprintf (stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", - "file.txt", "dir3", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir3 -> file.txt (fail) */ - ret = glfs_h_rename (fs, parent, "dir3", parent, "file.txt"); - if (ret == 0) { - fprintf (stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", - "dir3", "file.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - printf ("glfs_h_rename tests: PASSED\n"); + char *my_dir = "renamedir"; + char *my_file = "file.txt"; + char *src_dir = "dir1"; + char *tgt_dir = "dir2"; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, + *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; + struct stat sb; + int ret; + + printf("glfs_h_rename tests: In Progress\n"); + + /* Prepare tests */ + root = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_mkdir(fs, root, my_dir, 0644, &sb); + if (parent == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, root, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirsrc = glfs_h_mkdir(fs, parent, src_dir, 0644, &sb); + if (dirsrc == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + src_dir, parent, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirtgt = glfs_h_mkdir(fs, parent, tgt_dir, 0644, &sb); + if (dirtgt == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + tgt_dir, parent, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dleaf = glfs_h_creat(fs, dirsrc, my_file, O_CREAT, 0644, &sb); + if (dleaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dirsrc, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* run tests */ + /* Rename file.txt -> file1.txt */ + ret = glfs_h_rename(fs, parent, "file.txt", parent, "file1.txt"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", + "file.txt", "file1.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir1/file.txt -> file.txt */ + ret = glfs_h_rename(fs, dirsrc, "file.txt", parent, "file.txt"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s/%s to %s (%s)\n", + src_dir, "file.txt", "file.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename file1.txt -> file.txt (exists) */ + ret = glfs_h_rename(fs, parent, "file1.txt", parent, "file.txt"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", + "file.txt", "file.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir1 -> dir3 */ + ret = glfs_h_rename(fs, parent, "dir1", parent, "dir3"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", "dir1", + "dir3", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir2 ->dir3 (exists) */ + ret = glfs_h_rename(fs, parent, "dir2", parent, "dir3"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", "dir2", + "dir3", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename file.txt -> dir3 (fail) */ + ret = glfs_h_rename(fs, parent, "file.txt", parent, "dir3"); + if (ret == 0) { + fprintf(stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", + "file.txt", "dir3", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir3 -> file.txt (fail) */ + ret = glfs_h_rename(fs, parent, "dir3", parent, "file.txt"); + if (ret == 0) { + fprintf(stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", + "dir3", "file.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + printf("glfs_h_rename tests: PASSED\n"); out: - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - if (dirsrc) - glfs_h_close (dirsrc); - if (dirtgt) - glfs_h_close (dirtgt); - if (dleaf) - glfs_h_close (dleaf); - - return; + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + if (dirsrc) + glfs_h_close(dirsrc); + if (dirtgt) + glfs_h_close(dirtgt); + if (dleaf) + glfs_h_close(dleaf); + + return; } void -assimilatetime (struct timespec *ts, struct timespec ts_st, - struct timespec ts_ed) +assimilatetime(struct timespec *ts, struct timespec ts_st, + struct timespec ts_ed) { - if ((ts_ed.tv_nsec - ts_st.tv_nsec) < 0) { - ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec - 1; - ts->tv_nsec += 1000000000 + ts_ed.tv_nsec - ts_st.tv_nsec; - } else { - ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec; - ts->tv_nsec += ts_ed.tv_nsec - ts_st.tv_nsec; - } - - if (ts->tv_nsec > 1000000000) { - ts->tv_nsec = ts->tv_nsec - 1000000000; - ts->tv_sec += 1; - } - - return; + if ((ts_ed.tv_nsec - ts_st.tv_nsec) < 0) { + ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec - 1; + ts->tv_nsec += 1000000000 + ts_ed.tv_nsec - ts_st.tv_nsec; + } else { + ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec; + ts->tv_nsec += ts_ed.tv_nsec - ts_st.tv_nsec; + } + + if (ts->tv_nsec > 1000000000) { + ts->tv_nsec = ts->tv_nsec - 1000000000; + ts->tv_sec += 1; + } + + return; } #define MAX_FILES_CREATE 10 -#define MAXPATHNAME 512 +#define MAXPATHNAME 512 void -test_h_performance (void) +test_h_performance(void) { - char *my_dir = "perftest", - *full_dir_path="/testdir/perftest"; - char *my_file = "file_", my_file_name[MAXPATHNAME]; - struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; - struct stat sb; - int ret, i; - struct glfs_fd *fd; - struct timespec c_ts = {0, 0}, c_ts_st, c_ts_ed; - struct timespec o_ts = {0, 0}, o_ts_st, o_ts_ed; - - printf("glfs_h_performance tests: In Progress\n"); - - /* Prepare tests */ - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - dir = glfs_h_mkdir (fs, parent, my_dir, 0644, &sb); - if (dir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* create performance */ - ret = clock_gettime (CLOCK_REALTIME, &o_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + char *my_dir = "perftest", *full_dir_path = "/testdir/perftest"; + char *my_file = "file_", my_file_name[MAXPATHNAME]; + struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; + struct stat sb; + int ret, i; + struct glfs_fd *fd; + struct timespec c_ts = {0, 0}, c_ts_st, c_ts_ed; + struct timespec o_ts = {0, 0}, o_ts_st, o_ts_ed; + + printf("glfs_h_performance tests: In Progress\n"); + + /* Prepare tests */ + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; + } + + dir = glfs_h_mkdir(fs, parent, my_dir, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, parent, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* create performance */ + ret = clock_gettime(CLOCK_REALTIME, &o_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + for (i = 0; i < MAX_FILES_CREATE; i++) { + sprintf(my_file_name, "%s%d", my_file, i); + + ret = clock_gettime(CLOCK_REALTIME, &c_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; } - for (i = 0; i < MAX_FILES_CREATE; i++) { - sprintf (my_file_name, "%s%d", my_file, i); - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - leaf = glfs_h_lookupat (fs, dir, my_file_name, &sb, 0); - if (leaf != NULL) { - fprintf (stderr, "glfs_h_lookup: exists %s\n", - my_file_name); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - leaf = glfs_h_creat (fs, dir, my_file_name, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - assimilatetime (&c_ts, c_ts_st, c_ts_ed); - glfs_h_close (leaf); leaf = NULL; + leaf = glfs_h_lookupat(fs, dir, my_file_name, &sb, 0); + if (leaf != NULL) { + fprintf(stderr, "glfs_h_lookup: exists %s\n", my_file_name); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - ret = clock_gettime (CLOCK_REALTIME, &o_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + leaf = glfs_h_creat(fs, dir, my_file_name, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - assimilatetime (&o_ts, o_ts_st, o_ts_ed); - - printf ("Creation performance (handle based):\n\t# empty files:%d\n", - MAX_FILES_CREATE); - printf ("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - o_ts.tv_sec, o_ts.tv_nsec); - printf ("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - c_ts.tv_sec, c_ts.tv_nsec); - - /* create using path */ - c_ts.tv_sec = o_ts.tv_sec = 0; - c_ts.tv_nsec = o_ts.tv_nsec = 0; - - sprintf (my_file_name, "%s1", full_dir_path); - ret = glfs_mkdir (fs, my_file_name, 0644); + ret = clock_gettime(CLOCK_REALTIME, &c_ts_ed); if (ret != 0) { - fprintf (stderr, "glfs_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - ret = clock_gettime (CLOCK_REALTIME, &o_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&c_ts, c_ts_st, c_ts_ed); + glfs_h_close(leaf); + leaf = NULL; + } + + ret = clock_gettime(CLOCK_REALTIME, &o_ts_ed); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&o_ts, o_ts_st, o_ts_ed); + + printf("Creation performance (handle based):\n\t# empty files:%d\n", + MAX_FILES_CREATE); + printf("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", o_ts.tv_sec, + o_ts.tv_nsec); + printf("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", + c_ts.tv_sec, c_ts.tv_nsec); + + /* create using path */ + c_ts.tv_sec = o_ts.tv_sec = 0; + c_ts.tv_nsec = o_ts.tv_nsec = 0; + + sprintf(my_file_name, "%s1", full_dir_path); + ret = glfs_mkdir(fs, my_file_name, 0644); + if (ret != 0) { + fprintf(stderr, "glfs_mkdir: error creating %s: from (%p),%s\n", my_dir, + parent, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + ret = clock_gettime(CLOCK_REALTIME, &o_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + for (i = 0; i < MAX_FILES_CREATE; i++) { + sprintf(my_file_name, "%s1/%sn%d", full_dir_path, my_file, i); + + ret = clock_gettime(CLOCK_REALTIME, &c_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; } - for (i = 0; i < MAX_FILES_CREATE; i++) { - sprintf (my_file_name, "%s1/%sn%d", full_dir_path, my_file, i); - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - ret = glfs_stat (fs, my_file_name, &sb); - if (ret == 0) { - fprintf (stderr, "glfs_stat: exists %s\n", - my_file_name); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - fd = glfs_creat (fs, my_file_name, O_CREAT, 0644); - if (fd == NULL) { - fprintf (stderr, "glfs_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - assimilatetime (&c_ts, c_ts_st, c_ts_ed); - glfs_close (fd); + ret = glfs_stat(fs, my_file_name, &sb); + if (ret == 0) { + fprintf(stderr, "glfs_stat: exists %s\n", my_file_name); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - ret = clock_gettime (CLOCK_REALTIME, &o_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + fd = glfs_creat(fs, my_file_name, O_CREAT, 0644); + if (fd == NULL) { + fprintf(stderr, "glfs_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - assimilatetime (&o_ts, o_ts_st, o_ts_ed); - - printf ("Creation performance (path based):\n\t# empty files:%d\n", - MAX_FILES_CREATE); - printf ("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - o_ts.tv_sec, o_ts.tv_nsec); - printf ("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - c_ts.tv_sec, c_ts.tv_nsec); + ret = clock_gettime(CLOCK_REALTIME, &c_ts_ed); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&c_ts, c_ts_st, c_ts_ed); + glfs_close(fd); + } + + ret = clock_gettime(CLOCK_REALTIME, &o_ts_ed); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&o_ts, o_ts_st, o_ts_ed); + + printf("Creation performance (path based):\n\t# empty files:%d\n", + MAX_FILES_CREATE); + printf("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", o_ts.tv_sec, + o_ts.tv_nsec); + printf("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", + c_ts.tv_sec, c_ts.tv_nsec); out: - return; + return; } int -test_handleops (int argc, char *argv[]) +test_handleops(int argc, char *argv[]) { - int ret = 0; - glfs_fd_t *fd = NULL; - struct stat sb = {0, }; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, - *tmp = NULL; - char readbuf[32], writebuf[32]; - unsigned char leaf_handle[GFAPI_HANDLE_LENGTH]; - - char *full_leaf_name = "/testdir/testfile.txt", - *leaf_name = "testfile.txt", - *relative_leaf_name = "testdir/testfile.txt"; - char *leaf_name1 = "testfile1.txt"; - char *full_newparent_name = "/testdir/dir1", - *newparent_name = "dir1"; - char *full_newnod_name = "/testdir/nod1", - *newnod_name = "nod1"; - - /* Initialize test area */ - ret = glfs_mkdir (fs, full_parent_name, 0644); - if (ret != 0 && errno != EEXIST) { - fprintf (stderr, "%s: (%p) %s\n", full_parent_name, fd, - strerror (errno)); - printf ("Test initialization failed on volume %s\n", argv[1]); - goto out; - } - else if (ret != 0) { - printf ("Found test directory %s to be existing\n", - full_parent_name); - printf ("Cleanup test directory and restart tests\n"); - goto out; - } - - fd = glfs_creat (fs, full_leaf_name, O_CREAT, 0644); - if (fd == NULL) { - fprintf (stderr, "%s: (%p) %s\n", full_leaf_name, fd, - strerror (errno)); - printf ("Test initialization failed on volume %s\n", argv[1]); - goto out; - } - glfs_close (fd); - - printf ("Initialized the test area, within volume %s\n", argv[1]); - - /* Handle based APIs test area */ - - /* glfs_lookupat test */ - printf ("glfs_h_lookupat tests: In Progress\n"); - /* start at root of the volume */ - root = glfs_h_lookupat (fs, NULL, "/", &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - "/", NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* lookup a parent within root */ - parent = glfs_h_lookupat (fs, root, parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - parent_name, root, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* lookup a leaf/child within the parent */ - leaf = glfs_h_lookupat (fs, parent, leaf_name, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - leaf_name, parent, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* reset */ - glfs_h_close (root); root = NULL; - glfs_h_close (leaf); leaf = NULL; - glfs_h_close (parent); parent = NULL; - - /* check absolute paths */ - root = glfs_h_lookupat (fs, NULL, "/", &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - "/", NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_lookupat (fs, NULL, full_leaf_name, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_leaf_name, parent, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* reset */ - glfs_h_close (leaf); leaf = NULL; - - /* check multiple component paths */ - leaf = glfs_h_lookupat (fs, root, relative_leaf_name, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - relative_leaf_name, parent, strerror (errno)); - goto out; - } - peek_stat (&sb); - - /* reset */ - glfs_h_close (root); root = NULL; - glfs_h_close (parent); parent = NULL; - - /* check symlinks in path */ - - /* TODO: -ve test cases */ - /* parent invalid - * path invalid - * path does not exist after some components - * no parent, but relative path - * parent and full path? -ve? - */ - - printf ("glfs_h_lookupat tests: PASSED\n"); - - /* glfs_openat test */ - printf ("glfs_h_open tests: In Progress\n"); - fd = glfs_h_open (fs, leaf, O_RDWR); - if (fd == NULL) { - fprintf (stderr, "glfs_h_open: error on open of %s: %s\n", - full_leaf_name, strerror (errno)); - printf ("glfs_h_open tests: FAILED\n"); - goto out; - } - - /* test read/write based on fd */ - memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); - ret = glfs_write (fd, writebuf, 32, 0); - - glfs_lseek (fd, 0, SEEK_SET); - - ret = glfs_read (fd, readbuf, 32, 0); - if (memcmp (readbuf, writebuf, 32)) { - printf ("Failed to read what I wrote: %s %s\n", readbuf, - writebuf); - glfs_close (fd); - printf ("glfs_h_open tests: FAILED\n"); - goto out; - } - - glfs_h_close (leaf); leaf = NULL; - glfs_close (fd); - - printf ("glfs_h_open tests: PASSED\n"); - - /* Create tests */ - printf ("glfs_h_creat tests: In Progress\n"); - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, leaf_name1, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n", - leaf_name1, parent, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_creat (fs, parent, leaf_name1, O_CREAT | O_EXCL, 0644, - &sb); - if (leaf != NULL || errno != EEXIST) { - fprintf (stderr, "glfs_h_creat: existing file, leaf = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - if (leaf != NULL) { - glfs_h_close (leaf); leaf = NULL; - } - } - - tmp = glfs_h_creat (fs, root, parent_name, O_CREAT, 0644, &sb); - if (tmp != NULL || !(errno == EISDIR || errno == EINVAL)) { - fprintf (stderr, "glfs_h_creat: dir create, tmp = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - if (tmp != NULL) { - glfs_h_close (tmp); tmp = NULL; - } - } - - /* TODO: Other combinations and -ve cases as applicable */ - printf ("glfs_h_creat tests: PASSED\n"); - - /* extract handle and create from handle test */ - printf ("glfs_h_extract_handle and glfs_h_create_from_handle tests: In Progress\n"); - /* TODO: Change the lookup to create below for a GIFD recovery failure, - * that needs to be fixed */ - leaf = glfs_h_lookupat (fs, parent, leaf_name1, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - leaf_name1, parent, strerror (errno)); - printf ("glfs_h_extract_handle tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - ret = glfs_h_extract_handle (leaf, leaf_handle, - GFAPI_HANDLE_LENGTH); - if (ret < 0) { - fprintf (stderr, "glfs_h_extract_handle: error extracting handle of %s: %s\n", - full_leaf_name, strerror (errno)); - printf ("glfs_h_extract_handle tests: FAILED\n"); - goto out; - } - peek_handle (leaf_handle); - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_create_from_handle (fs, leaf_handle, GFAPI_HANDLE_LENGTH, - &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n", - leaf_name1, leaf_handle, strerror (errno)); - printf ("glfs_h_create_from_handle tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - fd = glfs_h_open (fs, leaf, O_RDWR); - if (fd == NULL) { - fprintf (stderr, "glfs_h_open: error on open of %s: %s\n", - full_leaf_name, strerror (errno)); - printf ("glfs_h_create_from_handle tests: FAILED\n"); - goto out; - } - - /* test read/write based on fd */ - memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); - ret = glfs_write (fd, writebuf, 32, 0); - - glfs_lseek (fd, 0, SEEK_SET); - - ret = glfs_read (fd, readbuf, 32, 0); - if (memcmp (readbuf, writebuf, 32)) { - printf ("Failed to read what I wrote: %s %s\n", writebuf, - writebuf); - printf ("glfs_h_create_from_handle tests: FAILED\n"); - glfs_close (fd); - goto out; - } - - glfs_close (fd); - glfs_h_close (leaf); leaf = NULL; - glfs_h_close (parent); parent = NULL; - - printf ("glfs_h_extract_handle and glfs_h_create_from_handle tests: PASSED\n"); - - /* Mkdir tests */ - printf ("glfs_h_mkdir tests: In Progress\n"); - - ret = glfs_rmdir (fs, full_newparent_name); - if (ret && errno != ENOENT) { - fprintf (stderr, "glfs_rmdir: Failed for %s: %s\n", - full_newparent_name, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - goto out; - } - - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_mkdir (fs, parent, newparent_name, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", - newparent_name, parent, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_mkdir (fs, parent, newparent_name, 0644, &sb); - if (leaf != NULL || errno != EEXIST) { - fprintf (stderr, "glfs_h_mkdir: existing directory, leaf = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - if (leaf != NULL) { - glfs_h_close (leaf); leaf = NULL; - } - } - - glfs_h_close (parent); parent = NULL; - - printf ("glfs_h_mkdir tests: PASSED\n"); - - /* Mknod tests */ - printf ("glfs_h_mknod tests: In Progress\n"); - ret = glfs_unlink (fs, full_newnod_name); - if (ret && errno != ENOENT) { - fprintf (stderr, "glfs_unlink: Failed for %s: %s\n", - full_newnod_name, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - goto out; - } - - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_mknod (fs, parent, newnod_name, S_IFIFO, 0, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", - newnod_name, parent, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* TODO: create op on a FIFO node hangs, need to check and fix - tmp = glfs_h_creat (fs, parent, newnod_name, O_CREAT, 0644, &sb); - if (tmp != NULL || errno != EINVAL) { - fprintf (stderr, "glfs_h_creat: node create, tmp = (%p), errno = %s\n", - tmp, strerror (errno)); - printf ("glfs_h_creat/mknod tests: FAILED\n"); - if (tmp != NULL) { - glfs_h_close(tmp); tmp = NULL; - } - } */ - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_mknod (fs, parent, newnod_name, 0644, 0, &sb); - if (leaf != NULL || errno != EEXIST) { - fprintf (stderr, "glfs_h_mknod: existing node, leaf = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - if (leaf != NULL) { - glfs_h_close (leaf); leaf = NULL; - } - } - - glfs_h_close (parent); parent = NULL; - - printf ("glfs_h_mknod tests: PASSED\n"); - - /* unlink tests */ - test_h_unlink (); - - /* TODO: opendir tests */ - - /* getattr tests */ - test_h_getsetattrs (); - - /* TODO: setattr tests */ - - /* truncate tests */ - test_h_truncate(); - - /* link tests */ - test_h_links (); - - /* rename tests */ - test_h_rename (); - - /* performance tests */ - test_h_performance (); - - /* END: New APIs test area */ + int ret = 0; + glfs_fd_t *fd = NULL; + struct stat sb = { + 0, + }; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, *tmp = NULL; + char readbuf[32], writebuf[32]; + unsigned char leaf_handle[GFAPI_HANDLE_LENGTH]; + + char *full_leaf_name = "/testdir/testfile.txt", *leaf_name = "testfile.txt", + *relative_leaf_name = "testdir/testfile.txt"; + char *leaf_name1 = "testfile1.txt"; + char *full_newparent_name = "/testdir/dir1", *newparent_name = "dir1"; + char *full_newnod_name = "/testdir/nod1", *newnod_name = "nod1"; + + /* Initialize test area */ + ret = glfs_mkdir(fs, full_parent_name, 0644); + if (ret != 0 && errno != EEXIST) { + fprintf(stderr, "%s: (%p) %s\n", full_parent_name, fd, strerror(errno)); + printf("Test initialization failed on volume %s\n", argv[1]); + goto out; + } else if (ret != 0) { + printf("Found test directory %s to be existing\n", full_parent_name); + printf("Cleanup test directory and restart tests\n"); + goto out; + } + + fd = glfs_creat(fs, full_leaf_name, O_CREAT, 0644); + if (fd == NULL) { + fprintf(stderr, "%s: (%p) %s\n", full_leaf_name, fd, strerror(errno)); + printf("Test initialization failed on volume %s\n", argv[1]); + goto out; + } + glfs_close(fd); + + printf("Initialized the test area, within volume %s\n", argv[1]); + + /* Handle based APIs test area */ + + /* glfs_lookupat test */ + printf("glfs_h_lookupat tests: In Progress\n"); + /* start at root of the volume */ + root = glfs_h_lookupat(fs, NULL, "/", &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", "/", + NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* lookup a parent within root */ + parent = glfs_h_lookupat(fs, root, parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + parent_name, root, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* lookup a leaf/child within the parent */ + leaf = glfs_h_lookupat(fs, parent, leaf_name, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + leaf_name, parent, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* reset */ + glfs_h_close(root); + root = NULL; + glfs_h_close(leaf); + leaf = NULL; + glfs_h_close(parent); + parent = NULL; + + /* check absolute paths */ + root = glfs_h_lookupat(fs, NULL, "/", &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", "/", + NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_lookupat(fs, NULL, full_leaf_name, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_leaf_name, parent, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* reset */ + glfs_h_close(leaf); + leaf = NULL; + + /* check multiple component paths */ + leaf = glfs_h_lookupat(fs, root, relative_leaf_name, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + relative_leaf_name, parent, strerror(errno)); + goto out; + } + peek_stat(&sb); + + /* reset */ + glfs_h_close(root); + root = NULL; + glfs_h_close(parent); + parent = NULL; + + /* check symlinks in path */ + + /* TODO: -ve test cases */ + /* parent invalid + * path invalid + * path does not exist after some components + * no parent, but relative path + * parent and full path? -ve? + */ + + printf("glfs_h_lookupat tests: PASSED\n"); + + /* glfs_openat test */ + printf("glfs_h_open tests: In Progress\n"); + fd = glfs_h_open(fs, leaf, O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_h_open: error on open of %s: %s\n", + full_leaf_name, strerror(errno)); + printf("glfs_h_open tests: FAILED\n"); + goto out; + } + + /* test read/write based on fd */ + memcpy(writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); + ret = glfs_write(fd, writebuf, 32, 0); + + glfs_lseek(fd, 0, SEEK_SET); + + ret = glfs_read(fd, readbuf, 32, 0); + if (memcmp(readbuf, writebuf, 32)) { + printf("Failed to read what I wrote: %s %s\n", readbuf, writebuf); + glfs_close(fd); + printf("glfs_h_open tests: FAILED\n"); + goto out; + } + + glfs_h_close(leaf); + leaf = NULL; + glfs_close(fd); + + printf("glfs_h_open tests: PASSED\n"); + + /* Create tests */ + printf("glfs_h_creat tests: In Progress\n"); + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, leaf_name1, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n", + leaf_name1, parent, strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_creat(fs, parent, leaf_name1, O_CREAT | O_EXCL, 0644, &sb); + if (leaf != NULL || errno != EEXIST) { + fprintf(stderr, + "glfs_h_creat: existing file, leaf = (%p), errno = %s\n", leaf, + strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + if (leaf != NULL) { + glfs_h_close(leaf); + leaf = NULL; + } + } + + tmp = glfs_h_creat(fs, root, parent_name, O_CREAT, 0644, &sb); + if (tmp != NULL || !(errno == EISDIR || errno == EINVAL)) { + fprintf(stderr, "glfs_h_creat: dir create, tmp = (%p), errno = %s\n", + leaf, strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + if (tmp != NULL) { + glfs_h_close(tmp); + tmp = NULL; + } + } + + /* TODO: Other combinations and -ve cases as applicable */ + printf("glfs_h_creat tests: PASSED\n"); + + /* extract handle and create from handle test */ + printf( + "glfs_h_extract_handle and glfs_h_create_from_handle tests: In " + "Progress\n"); + /* TODO: Change the lookup to create below for a GIFD recovery failure, + * that needs to be fixed */ + leaf = glfs_h_lookupat(fs, parent, leaf_name1, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + leaf_name1, parent, strerror(errno)); + printf("glfs_h_extract_handle tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + ret = glfs_h_extract_handle(leaf, leaf_handle, GFAPI_HANDLE_LENGTH); + if (ret < 0) { + fprintf(stderr, + "glfs_h_extract_handle: error extracting handle of %s: %s\n", + full_leaf_name, strerror(errno)); + printf("glfs_h_extract_handle tests: FAILED\n"); + goto out; + } + peek_handle(leaf_handle); + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_create_from_handle(fs, leaf_handle, GFAPI_HANDLE_LENGTH, &sb); + if (leaf == NULL) { + fprintf( + stderr, + "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n", + leaf_name1, leaf_handle, strerror(errno)); + printf("glfs_h_create_from_handle tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + fd = glfs_h_open(fs, leaf, O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_h_open: error on open of %s: %s\n", + full_leaf_name, strerror(errno)); + printf("glfs_h_create_from_handle tests: FAILED\n"); + goto out; + } + + /* test read/write based on fd */ + memcpy(writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); + ret = glfs_write(fd, writebuf, 32, 0); + + glfs_lseek(fd, 0, SEEK_SET); + + ret = glfs_read(fd, readbuf, 32, 0); + if (memcmp(readbuf, writebuf, 32)) { + printf("Failed to read what I wrote: %s %s\n", writebuf, writebuf); + printf("glfs_h_create_from_handle tests: FAILED\n"); + glfs_close(fd); + goto out; + } + + glfs_close(fd); + glfs_h_close(leaf); + leaf = NULL; + glfs_h_close(parent); + parent = NULL; + + printf( + "glfs_h_extract_handle and glfs_h_create_from_handle tests: PASSED\n"); + + /* Mkdir tests */ + printf("glfs_h_mkdir tests: In Progress\n"); + + ret = glfs_rmdir(fs, full_newparent_name); + if (ret && errno != ENOENT) { + fprintf(stderr, "glfs_rmdir: Failed for %s: %s\n", full_newparent_name, + strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + goto out; + } + + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_mkdir(fs, parent, newparent_name, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", + newparent_name, parent, strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_mkdir(fs, parent, newparent_name, 0644, &sb); + if (leaf != NULL || errno != EEXIST) { + fprintf(stderr, + "glfs_h_mkdir: existing directory, leaf = (%p), errno = %s\n", + leaf, strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + if (leaf != NULL) { + glfs_h_close(leaf); + leaf = NULL; + } + } + + glfs_h_close(parent); + parent = NULL; + + printf("glfs_h_mkdir tests: PASSED\n"); + + /* Mknod tests */ + printf("glfs_h_mknod tests: In Progress\n"); + ret = glfs_unlink(fs, full_newnod_name); + if (ret && errno != ENOENT) { + fprintf(stderr, "glfs_unlink: Failed for %s: %s\n", full_newnod_name, + strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + goto out; + } + + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_mknod(fs, parent, newnod_name, S_IFIFO, 0, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", + newnod_name, parent, strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* TODO: create op on a FIFO node hangs, need to check and fix + tmp = glfs_h_creat (fs, parent, newnod_name, O_CREAT, 0644, &sb); + if (tmp != NULL || errno != EINVAL) { + fprintf (stderr, "glfs_h_creat: node create, tmp = (%p), errno = + %s\n", tmp, strerror (errno)); printf ("glfs_h_creat/mknod tests: + FAILED\n"); if (tmp != NULL) { glfs_h_close(tmp); tmp = NULL; + } + } */ + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_mknod(fs, parent, newnod_name, 0644, 0, &sb); + if (leaf != NULL || errno != EEXIST) { + fprintf(stderr, + "glfs_h_mknod: existing node, leaf = (%p), errno = %s\n", leaf, + strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + if (leaf != NULL) { + glfs_h_close(leaf); + leaf = NULL; + } + } + + glfs_h_close(parent); + parent = NULL; + + printf("glfs_h_mknod tests: PASSED\n"); + + /* unlink tests */ + test_h_unlink(); + + /* TODO: opendir tests */ + + /* getattr tests */ + test_h_getsetattrs(); + + /* TODO: setattr tests */ + + /* truncate tests */ + test_h_truncate(); + + /* link tests */ + test_h_links(); + + /* rename tests */ + test_h_rename(); + + /* performance tests */ + test_h_performance(); + + /* END: New APIs test area */ out: - /* Cleanup glfs handles */ - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - - return ret; + /* Cleanup glfs handles */ + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + + return ret; } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - glfs_t *fs2 = NULL; - int ret = 0; - glfs_fd_t *fd = NULL; - glfs_fd_t *fd2 = NULL; - struct stat sb = {0, }; - char readbuf[32]; - char writebuf[32]; - - char *filename = "/filename2"; - - if (argc != 3) { - printf ("Expect following args\n\t%s \n", argv[0]); - return -1; - } + glfs_t *fs2 = NULL; + int ret = 0; + glfs_fd_t *fd = NULL; + glfs_fd_t *fd2 = NULL; + struct stat sb = { + 0, + }; + char readbuf[32]; + char writebuf[32]; - fs = glfs_new (argv[1]); - if (!fs) { - fprintf (stderr, "glfs_new: returned NULL\n"); - return 1; - } + char *filename = "/filename2"; -// ret = glfs_set_volfile (fs, "/tmp/posix.vol"); + if (argc != 3) { + printf("Expect following args\n\t%s \n", argv[0]); + return -1; + } - ret = glfs_set_volfile_server (fs, "tcp", argv[2], 24007); + fs = glfs_new(argv[1]); + if (!fs) { + fprintf(stderr, "glfs_new: returned NULL\n"); + return 1; + } -// ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); + // ret = glfs_set_volfile (fs, "/tmp/posix.vol"); - ret = glfs_set_logging (fs, "/dev/stderr", 7); + ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007); - ret = glfs_init (fs); + // ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); - fprintf (stderr, "glfs_init: returned %d\n", ret); + ret = glfs_set_logging(fs, "/dev/stderr", 7); - sleep (2); + ret = glfs_init(fs); - fs2 = glfs_new (argv[1]); - if (!fs2) { - fprintf (stderr, "glfs_new: returned NULL\n"); - return 1; - } + fprintf(stderr, "glfs_init: returned %d\n", ret); + sleep(2); -// ret = glfs_set_volfile (fs2, "/tmp/posix.vol"); + fs2 = glfs_new(argv[1]); + if (!fs2) { + fprintf(stderr, "glfs_new: returned NULL\n"); + return 1; + } - ret = glfs_set_volfile_server (fs2, "tcp", argv[2], 24007); + // ret = glfs_set_volfile (fs2, "/tmp/posix.vol"); - ret = glfs_set_logging (fs2, "/dev/stderr", 7); + ret = glfs_set_volfile_server(fs2, "tcp", argv[2], 24007); - ret = glfs_init (fs2); + ret = glfs_set_logging(fs2, "/dev/stderr", 7); - fprintf (stderr, "glfs_init: returned %d\n", ret); + ret = glfs_init(fs2); - ret = glfs_lstat (fs, filename, &sb); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + fprintf(stderr, "glfs_init: returned %d\n", ret); - fd = glfs_creat (fs, filename, O_RDWR, 0644); - fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); + ret = glfs_lstat(fs, filename, &sb); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); - fd2 = glfs_open (fs2, filename, O_RDWR); - fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); + fd = glfs_creat(fs, filename, O_RDWR, 0644); + fprintf(stderr, "%s: (%p) %s\n", filename, fd, strerror(errno)); - sprintf (writebuf, "hi there\n"); - ret = glfs_write (fd, writebuf, 32, 0); + fd2 = glfs_open(fs2, filename, O_RDWR); + fprintf(stderr, "%s: (%p) %s\n", filename, fd, strerror(errno)); - glfs_lseek (fd2, 0, SEEK_SET); + sprintf(writebuf, "hi there\n"); + ret = glfs_write(fd, writebuf, 32, 0); - ret = glfs_read (fd2, readbuf, 32, 0); + glfs_lseek(fd2, 0, SEEK_SET); - printf ("read %d, %s", ret, readbuf); + ret = glfs_read(fd2, readbuf, 32, 0); - glfs_close (fd); - glfs_close (fd2); + printf("read %d, %s", ret, readbuf); - filename = "/filename3"; - ret = glfs_mknod (fs, filename, S_IFIFO, 0); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + glfs_close(fd); + glfs_close(fd2); - ret = glfs_lstat (fs, filename, &sb); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + filename = "/filename3"; + ret = glfs_mknod(fs, filename, S_IFIFO, 0); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); + ret = glfs_lstat(fs, filename, &sb); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_rename (fs, filename, "/filename4"); - fprintf (stderr, "rename(%s): (%d) %s\n", filename, ret, - strerror (errno)); + ret = glfs_rename(fs, filename, "/filename4"); + fprintf(stderr, "rename(%s): (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_unlink (fs, "/filename4"); - fprintf (stderr, "unlink(%s): (%d) %s\n", "/filename4", ret, - strerror (errno)); + ret = glfs_unlink(fs, "/filename4"); + fprintf(stderr, "unlink(%s): (%d) %s\n", "/filename4", ret, + strerror(errno)); - filename = "/dirname2"; - ret = glfs_mkdir (fs, filename, 0); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + filename = "/dirname2"; + ret = glfs_mkdir(fs, filename, 0); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_lstat (fs, filename, &sb); - fprintf (stderr, "lstat(%s): (%d) %s\n", filename, ret, strerror (errno)); + ret = glfs_lstat(fs, filename, &sb); + fprintf(stderr, "lstat(%s): (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_rmdir (fs, filename); - fprintf (stderr, "rmdir(%s): (%d) %s\n", filename, ret, strerror (errno)); + ret = glfs_rmdir(fs, filename); + fprintf(stderr, "rmdir(%s): (%d) %s\n", filename, ret, strerror(errno)); - test_dirops (fs); + test_dirops(fs); - test_xattr (fs); + test_xattr(fs); - test_chdir (fs); + test_chdir(fs); - test_handleops (argc, argv); - // done + test_handleops(argc, argv); + // done - glfs_fini (fs); - glfs_fini (fs2); + glfs_fini(fs); + glfs_fini(fs2); - return ret; + return ret; } diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 611cb14d9eb..f6786845a4f 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -33,23 +33,23 @@ #define READDIRBUF_SIZE (sizeof(struct dirent) + GF_NAME_MAX + 1) -typedef void (*glfs_io_cbk34) (glfs_fd_t *fd, ssize_t ret, void *data); +typedef void (*glfs_io_cbk34)(glfs_fd_t *fd, ssize_t ret, void *data); /* * This function will mark glfd for deletion and decrement its refcount. */ int -glfs_mark_glfd_for_deletion (struct glfs_fd *glfd) +glfs_mark_glfd_for_deletion(struct glfs_fd *glfd) { - LOCK (&glfd->lock); - { - glfd->state = GLFD_CLOSE; - } - UNLOCK (&glfd->lock); + LOCK(&glfd->lock); + { + glfd->state = GLFD_CLOSE; + } + UNLOCK(&glfd->lock); - GF_REF_PUT (glfd); + GF_REF_PUT(glfd); - return 0; + return 0; } /* This function is useful for all async fops. There is chance that glfd is @@ -60,33 +60,33 @@ glfs_mark_glfd_for_deletion (struct glfs_fd *glfd) * _gf_false. */ gf_boolean_t -glfs_is_glfd_still_valid (struct glfs_fd *glfd) +glfs_is_glfd_still_valid(struct glfs_fd *glfd) { - gf_boolean_t ret = _gf_false; + gf_boolean_t ret = _gf_false; - LOCK (&glfd->lock); - { - if (glfd->state != GLFD_CLOSE) - ret = _gf_true; - } - UNLOCK (&glfd->lock); + LOCK(&glfd->lock); + { + if (glfd->state != GLFD_CLOSE) + ret = _gf_true; + } + UNLOCK(&glfd->lock); - return ret; + return ret; } void -glfd_set_state_bind (struct glfs_fd *glfd) +glfd_set_state_bind(struct glfs_fd *glfd) { - LOCK (&glfd->lock); - { - glfd->state = GLFD_OPEN; - } - UNLOCK (&glfd->lock); + LOCK(&glfd->lock); + { + glfd->state = GLFD_OPEN; + } + UNLOCK(&glfd->lock); - fd_bind (glfd->fd); - glfs_fd_bind (glfd); + fd_bind(glfd->fd); + glfs_fd_bind(glfd); - return; + return; } /* @@ -97,4528 +97,4581 @@ glfd_set_state_bind (struct glfs_fd *glfd) * maintained by gfapi. */ int -glfs_get_upcall_cache_invalidation (struct gf_upcall *to_up_data, - struct gf_upcall *from_up_data) +glfs_get_upcall_cache_invalidation(struct gf_upcall *to_up_data, + struct gf_upcall *from_up_data) { + struct gf_upcall_cache_invalidation *ca_data = NULL; + struct gf_upcall_cache_invalidation *f_ca_data = NULL; + int ret = -1; - struct gf_upcall_cache_invalidation *ca_data = NULL; - struct gf_upcall_cache_invalidation *f_ca_data = NULL; - int ret = -1; - - GF_VALIDATE_OR_GOTO (THIS->name, to_up_data, out); - GF_VALIDATE_OR_GOTO (THIS->name, from_up_data, out); + GF_VALIDATE_OR_GOTO(THIS->name, to_up_data, out); + GF_VALIDATE_OR_GOTO(THIS->name, from_up_data, out); - f_ca_data = from_up_data->data; - GF_VALIDATE_OR_GOTO (THIS->name, f_ca_data, out); + f_ca_data = from_up_data->data; + GF_VALIDATE_OR_GOTO(THIS->name, f_ca_data, out); - ca_data = GF_CALLOC (1, sizeof(*ca_data), - glfs_mt_upcall_entry_t); + ca_data = GF_CALLOC(1, sizeof(*ca_data), glfs_mt_upcall_entry_t); - if (!ca_data) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + if (!ca_data) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - to_up_data->data = ca_data; + to_up_data->data = ca_data; - ca_data->flags = f_ca_data->flags; - ca_data->expire_time_attr = f_ca_data->expire_time_attr; - ca_data->stat = f_ca_data->stat; - ca_data->p_stat = f_ca_data->p_stat; - ca_data->oldp_stat = f_ca_data->oldp_stat; + ca_data->flags = f_ca_data->flags; + ca_data->expire_time_attr = f_ca_data->expire_time_attr; + ca_data->stat = f_ca_data->stat; + ca_data->p_stat = f_ca_data->p_stat; + ca_data->oldp_stat = f_ca_data->oldp_stat; - ret = 0; + ret = 0; out: - return ret; + return ret; } int -glfs_get_upcall_lease (struct gf_upcall *to_up_data, - struct gf_upcall *from_up_data) +glfs_get_upcall_lease(struct gf_upcall *to_up_data, + struct gf_upcall *from_up_data) { + struct gf_upcall_recall_lease *ca_data = NULL; + struct gf_upcall_recall_lease *f_ca_data = NULL; + int ret = -1; - struct gf_upcall_recall_lease *ca_data = NULL; - struct gf_upcall_recall_lease *f_ca_data = NULL; - int ret = -1; - - GF_VALIDATE_OR_GOTO (THIS->name, to_up_data, out); - GF_VALIDATE_OR_GOTO (THIS->name, from_up_data, out); + GF_VALIDATE_OR_GOTO(THIS->name, to_up_data, out); + GF_VALIDATE_OR_GOTO(THIS->name, from_up_data, out); - f_ca_data = from_up_data->data; - GF_VALIDATE_OR_GOTO (THIS->name, f_ca_data, out); + f_ca_data = from_up_data->data; + GF_VALIDATE_OR_GOTO(THIS->name, f_ca_data, out); - ca_data = GF_CALLOC (1, sizeof(*ca_data), - glfs_mt_upcall_entry_t); + ca_data = GF_CALLOC(1, sizeof(*ca_data), glfs_mt_upcall_entry_t); - if (!ca_data) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + if (!ca_data) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - to_up_data->data = ca_data; + to_up_data->data = ca_data; - ca_data->lease_type = f_ca_data->lease_type; - gf_uuid_copy (ca_data->tid, f_ca_data->tid); - ca_data->dict = f_ca_data->dict; + ca_data->lease_type = f_ca_data->lease_type; + gf_uuid_copy(ca_data->tid, f_ca_data->tid); + ca_data->dict = f_ca_data->dict; - ret = 0; + ret = 0; out: - return ret; + return ret; } int -glfs_loc_link (loc_t *loc, struct iatt *iatt) +glfs_loc_link(loc_t *loc, struct iatt *iatt) { - int ret = -1; - inode_t *old_inode = NULL; - uint64_t ctx_value = LOOKUP_NOT_NEEDED; - - if (!loc->inode) { - errno = EINVAL; - return -1; - } + int ret = -1; + inode_t *old_inode = NULL; + uint64_t ctx_value = LOOKUP_NOT_NEEDED; - old_inode = loc->inode; - - /* If the inode already exists in the cache, the inode - * returned here points to the existing one. We need - * to update loc.inode accordingly. - */ - loc->inode = inode_link (loc->inode, loc->parent, loc->name, iatt); - if (loc->inode) { - inode_ctx_set (loc->inode, THIS, &ctx_value); - inode_lookup (loc->inode); - inode_unref (old_inode); - ret = 0; - } else { - ret = -1; - } + if (!loc->inode) { + errno = EINVAL; + return -1; + } + + old_inode = loc->inode; + + /* If the inode already exists in the cache, the inode + * returned here points to the existing one. We need + * to update loc.inode accordingly. + */ + loc->inode = inode_link(loc->inode, loc->parent, loc->name, iatt); + if (loc->inode) { + inode_ctx_set(loc->inode, THIS, &ctx_value); + inode_lookup(loc->inode); + inode_unref(old_inode); + ret = 0; + } else { + ret = -1; + } - return ret; + return ret; } - void -glfs_iatt_to_stat (struct glfs *fs, struct iatt *iatt, struct stat *stat) +glfs_iatt_to_stat(struct glfs *fs, struct iatt *iatt, struct stat *stat) { - iatt_to_stat (iatt, stat); - stat->st_dev = fs->dev_id; + iatt_to_stat(iatt, stat); + stat->st_dev = fs->dev_id; } - int -glfs_loc_unlink (loc_t *loc) +glfs_loc_unlink(loc_t *loc) { - inode_unlink (loc->inode, loc->parent, loc->name); + inode_unlink(loc->inode, loc->parent, loc->name); - /* since glfs_h_* objects hold a reference to inode - * it is safe to keep lookup count to '0' */ - if (!inode_has_dentry (loc->inode)) - inode_forget (loc->inode, 0); + /* since glfs_h_* objects hold a reference to inode + * it is safe to keep lookup count to '0' */ + if (!inode_has_dentry(loc->inode)) + inode_forget(loc->inode, 0); - return 0; + return 0; } - struct glfs_fd * -pub_glfs_open (struct glfs *fs, const char *path, int flags) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; +pub_glfs_open(struct glfs *fs, const char *path, int flags) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret) - goto out; - - if (IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = EISDIR; - goto out; - } - - if (!IA_ISREG (iatt.ia_type)) { - ret = -1; - errno = EINVAL; - goto out; - } - - if (glfd->fd) { - /* Retry. Safe to touch glfd->fd as we - still have not glfs_fd_bind() yet. - */ - fd_unref (glfd->fd); - glfd->fd = NULL; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - glfd->fd->flags = flags; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ret = syncop_open (subvol, &loc, flags, glfd->fd, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + if (ret) + goto out; + + if (IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = EISDIR; + goto out; + } + + if (!IA_ISREG(iatt.ia_type)) { + ret = -1; + errno = EINVAL; + goto out; + } + + if (glfd->fd) { + /* Retry. Safe to touch glfd->fd as we + still have not glfs_fd_bind() yet. + */ + fd_unref(glfd->fd); + glfd->fd = NULL; + } + + glfd->fd = fd_create(loc.inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + glfd->fd->flags = flags; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_open(subvol, &loc, flags, glfd->fd, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (fop_attr) - dict_unref (fop_attr); + if (fop_attr) + dict_unref(fop_attr); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_open, 3.4.0); int -pub_glfs_close (struct glfs_fd *glfd) -{ - xlator_t *subvol = NULL; - int ret = -1; - fd_t *fd = NULL; - struct glfs *fs = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - if (glfd->lk_owner.len != 0) { - ret = syncopctx_setfslkowner (&glfd->lk_owner); - if (ret) - goto out; - } - ret = get_fop_attr_thrd_key (&fop_attr); +pub_glfs_close(struct glfs_fd *glfd) +{ + xlator_t *subvol = NULL; + int ret = -1; + fd_t *fd = NULL; + struct glfs *fs = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + if (glfd->lk_owner.len != 0) { + ret = syncopctx_setfslkowner(&glfd->lk_owner); if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_flush (subvol, fd, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + goto out; + } + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_flush(subvol, fd, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - fs = glfd->fs; - - if (fd) - fd_unref (fd); - if (fop_attr) - dict_unref (fop_attr); + fs = glfd->fs; + if (fd) + fd_unref(fd); + if (fop_attr) + dict_unref(fop_attr); - glfs_mark_glfd_for_deletion (glfd); - glfs_subvol_done (fs, subvol); + glfs_mark_glfd_for_deletion(glfd); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_close, 3.4.0); - int -pub_glfs_lstat (struct glfs *fs, const char *path, struct stat *stat) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_lstat(struct glfs *fs, const char *path, struct stat *stat) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0 && stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (ret == 0 && stat) + glfs_iatt_to_stat(fs, &iatt, stat); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lstat, 3.4.0); - int -pub_glfs_stat (struct glfs *fs, const char *path, struct stat *stat) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_stat(struct glfs *fs, const char *path, struct stat *stat) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0 && stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (ret == 0 && stat) + glfs_iatt_to_stat(fs, &iatt, stat); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_stat, 3.4.0); - int -pub_glfs_fstat (struct glfs_fd *glfd, struct stat *stat) -{ - int ret = -1; - xlator_t *subvol = NULL; - struct iatt iatt = {0, }; - fd_t *fd = NULL; +pub_glfs_fstat(struct glfs_fd *glfd, struct stat *stat) +{ + int ret = -1; + xlator_t *subvol = NULL; + struct iatt iatt = { + 0, + }; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = syncop_fstat(subvol, fd, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == 0 && stat) + glfs_iatt_to_stat(glfd->fs, &iatt, stat); +out: + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + glfs_subvol_done(glfd->fs, subvol); - GF_REF_GET (glfd); + __GLFS_EXIT_FS; - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +invalid_fs: + return ret; +} - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fstat, 3.4.0); - ret = syncop_fstat (subvol, fd, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +struct glfs_fd * +pub_glfs_creat(struct glfs *fs, const char *path, int flags, mode_t mode) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; + + /* This must be glfs_resolve() and NOT glfs_lresolve(). + That is because open("name", O_CREAT) where "name" + is a danging symlink must create the dangling + destination. + */ +retry: + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - if (ret == 0 && stat) - glfs_iatt_to_stat (glfd->fs, &iatt, stat); -out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - glfs_subvol_done (glfd->fs, subvol); + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - __GLFS_EXIT_FS; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; -invalid_fs: - return ret; -} + if (loc.inode) { + if (flags & O_EXCL) { + ret = -1; + errno = EEXIST; + goto out; + } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fstat, 3.4.0); + if (IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = EISDIR; + goto out; + } + if (!IA_ISREG(iatt.ia_type)) { + ret = -1; + errno = EINVAL; + goto out; + } + } + + if (ret == -1 && errno == ENOENT) { + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } + } -struct glfs_fd * -pub_glfs_creat (struct glfs *fs, const char *path, int flags, mode_t mode) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; - - /* This must be glfs_resolve() and NOT glfs_lresolve(). - That is because open("name", O_CREAT) where "name" - is a danging symlink must create the dangling - destination. - */ -retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; - - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; - - if (loc.inode) { - if (flags & O_EXCL) { - ret = -1; - errno = EEXIST; - goto out; - } - - if (IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = EISDIR; - goto out; - } - - if (!IA_ISREG (iatt.ia_type)) { - ret = -1; - errno = EINVAL; - goto out; - } - } - - if (ret == -1 && errno == ENOENT) { - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } - } - - if (glfd->fd) { - /* Retry. Safe to touch glfd->fd as we - still have not glfs_fd_bind() yet. - */ - fd_unref (glfd->fd); - glfd->fd = NULL; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - glfd->fd->flags = flags; - - if (get_fop_attr_thrd_key (&xattr_req)) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - if (ret == 0) { - ret = syncop_open (subvol, &loc, flags, glfd->fd, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - } else { - ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, - &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - } - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (glfd->fd) { + /* Retry. Safe to touch glfd->fd as we + still have not glfs_fd_bind() yet. + */ + fd_unref(glfd->fd); + glfd->fd = NULL; + } + + glfd->fd = fd_create(loc.inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + glfd->fd->flags = flags; + + if (get_fop_attr_thrd_key(&xattr_req)) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + if (ret == 0) { + ret = syncop_open(subvol, &loc, flags, glfd->fd, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + } else { + ret = syncop_create(subvol, &loc, flags, mode, glfd->fd, &iatt, + xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + } + + ESTALE_RETRY(ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_creat, 3.4.0); #ifdef HAVE_SEEK_HOLE static int -glfs_seek (struct glfs_fd *glfd, off_t offset, int whence) +glfs_seek(struct glfs_fd *glfd, off_t offset, int whence) { - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - gf_seek_what_t what = 0; - off_t off = -1; + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + gf_seek_what_t what = 0; + off_t off = -1; - switch (whence) { + switch (whence) { case SEEK_DATA: - what = GF_SEEK_DATA; - break; + what = GF_SEEK_DATA; + break; case SEEK_HOLE: - what = GF_SEEK_HOLE; - break; + what = GF_SEEK_HOLE; + break; default: - /* other SEEK_* do not make sense, all operations get an offset - * and the position in the fd is not tracked */ - errno = EINVAL; - goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto done; - } - - ret = syncop_seek (subvol, fd, offset, what, NULL, &off); - DECODE_SYNCOP_ERR (ret); - - if (ret != -1) - glfd->offset = off; + /* other SEEK_* do not make sense, all operations get an offset + * and the position in the fd is not tracked */ + errno = EINVAL; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto done; + } + + ret = syncop_seek(subvol, fd, offset, what, NULL, &off); + DECODE_SYNCOP_ERR(ret); + + if (ret != -1) + glfd->offset = off; done: - if (fd) - fd_unref (fd); + if (fd) + fd_unref(fd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); out: - return ret; + return ret; } #endif off_t -pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) -{ - struct stat sb = {0, }; - int ret = -1; - off_t off = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - switch (whence) { - case SEEK_SET: - glfd->offset = offset; - ret = 0; - break; - case SEEK_CUR: - glfd->offset += offset; - ret = 0; - break; - case SEEK_END: - ret = pub_glfs_fstat (glfd, &sb); - if (ret) { - /* seek cannot fail :O */ - break; - } - glfd->offset = sb.st_size + offset; - break; +pub_glfs_lseek(struct glfs_fd *glfd, off_t offset, int whence) +{ + struct stat sb = { + 0, + }; + int ret = -1; + off_t off = -1; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + switch (whence) { + case SEEK_SET: + glfd->offset = offset; + ret = 0; + break; + case SEEK_CUR: + glfd->offset += offset; + ret = 0; + break; + case SEEK_END: + ret = pub_glfs_fstat(glfd, &sb); + if (ret) { + /* seek cannot fail :O */ + break; + } + glfd->offset = sb.st_size + offset; + break; #ifdef HAVE_SEEK_HOLE case SEEK_DATA: case SEEK_HOLE: - ret = glfs_seek (glfd, offset, whence); - break; + ret = glfs_seek(glfd, offset, whence); + break; #endif default: - errno = EINVAL; - } + errno = EINVAL; + } - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - if (ret != -1) - off = glfd->offset; + if (ret != -1) + off = glfd->offset; - return off; + return off; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0); - static ssize_t -glfs_preadv_common (struct glfs_fd *glfd, const struct iovec *iovec, - int iovcnt, off_t offset, int flags, struct stat *poststat) -{ - xlator_t *subvol = NULL; - ssize_t ret = -1; - ssize_t size = -1; - struct iovec *iov = NULL; - int cnt = 0; - struct iobref *iobref = NULL; - fd_t *fd = NULL; - struct iatt iatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - size = iov_length (iovec, iovcnt); - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); +glfs_preadv_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags, struct stat *poststat) +{ + xlator_t *subvol = NULL; + ssize_t ret = -1; + ssize_t size = -1; + struct iovec *iov = NULL; + int cnt = 0; + struct iobref *iobref = NULL; + fd_t *fd = NULL; + struct iatt iatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + size = iov_length(iovec, iovcnt); - ret = syncop_readv (subvol, fd, size, offset, 0, &iov, &cnt, &iobref, - &iatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); - if (ret >= 0 && poststat) - glfs_iatt_to_stat (glfd->fs, &iatt, poststat); + ret = syncop_readv(subvol, fd, size, offset, 0, &iov, &cnt, &iobref, &iatt, + fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); - if (ret <= 0) - goto out; + if (ret >= 0 && poststat) + glfs_iatt_to_stat(glfd->fs, &iatt, poststat); - size = iov_copy (iovec, iovcnt, iov, cnt); /* FIXME!!! */ + if (ret <= 0) + goto out; - glfd->offset = (offset + size); + size = iov_copy(iovec, iovcnt, iov, cnt); /* FIXME!!! */ - ret = size; + glfd->offset = (offset + size); + + ret = size; out: - if (iov) - GF_FREE (iov); - if (iobref) - iobref_unref (iobref); + if (iov) + GF_FREE(iov); + if (iobref) + iobref_unref(iobref); - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } ssize_t -pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags) +pub_glfs_preadv(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags) { - return glfs_preadv_common (glfd, iovec, iovcnt, offset, flags, NULL); + return glfs_preadv_common(glfd, iovec, iovcnt, offset, flags, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv, 3.4.0); - ssize_t -pub_glfs_read (struct glfs_fd *glfd, void *buf, size_t count, int flags) +pub_glfs_read(struct glfs_fd *glfd, void *buf, size_t count, int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = pub_glfs_preadv (glfd, &iov, 1, glfd->offset, flags); + ret = pub_glfs_preadv(glfd, &iov, 1, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read, 3.4.0); - ssize_t -pub_glfs_pread34 (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, - int flags) +pub_glfs_pread34(struct glfs_fd *glfd, void *buf, size_t count, off_t offset, + int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = pub_glfs_preadv (glfd, &iov, 1, offset, flags); + ret = pub_glfs_preadv(glfd, &iov, 1, offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pread34, glfs_pread, 3.4.0); - ssize_t -pub_glfs_pread (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, - int flags, struct stat *poststat) +pub_glfs_pread(struct glfs_fd *glfd, void *buf, size_t count, off_t offset, + int flags, struct stat *poststat) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_common (glfd, &iov, 1, offset, flags, poststat); + ret = glfs_preadv_common(glfd, &iov, 1, offset, flags, poststat); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread, future); - ssize_t -pub_glfs_readv (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags) +pub_glfs_readv(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = pub_glfs_preadv (glfd, iov, count, glfd->offset, flags); + ret = pub_glfs_preadv(glfd, iov, count, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv, 3.4.0); - struct glfs_io { - struct glfs_fd *glfd; - int op; - off_t offset; - struct iovec *iov; - int count; - int flags; - gf_boolean_t oldcb; - union { - glfs_io_cbk34 fn34; - glfs_io_cbk fn; - }; - void *data; + struct glfs_fd *glfd; + int op; + off_t offset; + struct iovec *iov; + int count; + int flags; + gf_boolean_t oldcb; + union { + glfs_io_cbk34 fn34; + glfs_io_cbk fn; + }; + void *data; }; - static int -glfs_io_async_cbk (int op_ret, int op_errno, call_frame_t *frame, - void *cookie, struct iovec *iovec, int count, - struct iatt *prebuf, struct iatt *postbuf) -{ - struct glfs_io *gio = NULL; - xlator_t *subvol = NULL; - struct glfs *fs = NULL; - struct glfs_fd *glfd = NULL; - int ret = -1; - struct stat prestat = {}, *prestatp = NULL; - struct stat poststat = {}, *poststatp = NULL; - - GF_VALIDATE_OR_GOTO ("gfapi", frame, inval); - GF_VALIDATE_OR_GOTO ("gfapi", cookie, inval); - - gio = frame->local; - frame->local = NULL; - subvol = cookie; - glfd = gio->glfd; - fs = glfd->fs; - - if (!glfs_is_glfd_still_valid (glfd)) - goto err; - - if (op_ret <= 0) { - goto out; - } else if (gio->op == GF_FOP_READ) { - if (!iovec) { - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_ret = iov_copy (gio->iov, gio->count, iovec, count); - glfd->offset = gio->offset + op_ret; - } else if (gio->op == GF_FOP_WRITE) { - glfd->offset = gio->offset + gio->iov->iov_len; +glfs_io_async_cbk(int op_ret, int op_errno, call_frame_t *frame, void *cookie, + struct iovec *iovec, int count, struct iatt *prebuf, + struct iatt *postbuf) +{ + struct glfs_io *gio = NULL; + xlator_t *subvol = NULL; + struct glfs *fs = NULL; + struct glfs_fd *glfd = NULL; + int ret = -1; + struct stat prestat = {}, *prestatp = NULL; + struct stat poststat = {}, *poststatp = NULL; + + GF_VALIDATE_OR_GOTO("gfapi", frame, inval); + GF_VALIDATE_OR_GOTO("gfapi", cookie, inval); + + gio = frame->local; + frame->local = NULL; + subvol = cookie; + glfd = gio->glfd; + fs = glfd->fs; + + if (!glfs_is_glfd_still_valid(glfd)) + goto err; + + if (op_ret <= 0) { + goto out; + } else if (gio->op == GF_FOP_READ) { + if (!iovec) { + op_ret = -1; + op_errno = EINVAL; + goto out; } -out: - errno = op_errno; - if (gio->oldcb) { - gio->fn34 (gio->glfd, op_ret, gio->data); - } else { - if (prebuf) { - prestatp = &prestat; - glfs_iatt_to_stat (fs, prebuf, prestatp); - } - - if (postbuf) { - poststatp = &poststat; - glfs_iatt_to_stat (fs, postbuf, poststatp); - } + op_ret = iov_copy(gio->iov, gio->count, iovec, count); + glfd->offset = gio->offset + op_ret; + } else if (gio->op == GF_FOP_WRITE) { + glfd->offset = gio->offset + gio->iov->iov_len; + } - gio->fn (gio->glfd, op_ret, prestatp, poststatp, gio->data); +out: + errno = op_errno; + if (gio->oldcb) { + gio->fn34(gio->glfd, op_ret, gio->data); + } else { + if (prebuf) { + prestatp = &prestat; + glfs_iatt_to_stat(fs, prebuf, prestatp); } -err: - fd_unref (glfd->fd); - /* Since the async operation is complete - * release the ref taken during the start - * of async operation - */ - GF_REF_PUT (glfd); - GF_FREE (gio->iov); - GF_FREE (gio); - STACK_DESTROY (frame->root); - glfs_subvol_done (fs, subvol); + if (postbuf) { + poststatp = &poststat; + glfs_iatt_to_stat(fs, postbuf, poststatp); + } - ret = 0; + gio->fn(gio->glfd, op_ret, prestatp, poststatp, gio->data); + } +err: + fd_unref(glfd->fd); + /* Since the async operation is complete + * release the ref taken during the start + * of async operation + */ + GF_REF_PUT(glfd); + + GF_FREE(gio->iov); + GF_FREE(gio); + STACK_DESTROY(frame->root); + glfs_subvol_done(fs, subvol); + + ret = 0; inval: - return ret; + return ret; } static int -glfs_preadv_async_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iovec *iovec, - int count, struct iatt *stbuf, struct iobref *iobref, - dict_t *xdata) +glfs_preadv_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iovec *iovec, int count, + struct iatt *stbuf, struct iobref *iobref, dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, iovec, count, - NULL, stbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, iovec, count, NULL, + stbuf); - return 0; + return 0; } - static int -glfs_preadv_async_common (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_preadv_async_common(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, gf_boolean_t oldcb, + glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = 0; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - struct glfs *fs = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - fs = glfd->fs; - - frame = syncop_create_frame (THIS); - if (!frame) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio->iov = iov_dup (iovec, count); - if (!gio->iov) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_READ; - gio->glfd = glfd; - gio->count = count; - gio->offset = offset; - gio->flags = flags; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_preadv_async_cbk, subvol, subvol, - subvol->fops->readv, fd, iov_length (iovec, count), - offset, flags, fop_attr); + struct glfs_io *gio = NULL; + int ret = 0; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + struct glfs *fs = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + fs = glfd->fs; + + frame = syncop_create_frame(THIS); + if (!frame) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio->iov = iov_dup(iovec, count); + if (!gio->iov) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_READ; + gio->glfd = glfd; + gio->count = count; + gio->offset = offset; + gio->flags = flags; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_preadv_async_cbk, subvol, subvol, + subvol->fops->readv, fd, iov_length(iovec, count), offset, + flags, fop_attr); out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (gio) { - GF_FREE (gio->iov); - GF_FREE (gio); - } - if (frame) { - STACK_DESTROY (frame->root); - } - glfs_subvol_done (fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (gio) { + GF_FREE(gio->iov); + GF_FREE(gio); + } + if (frame) { + STACK_DESTROY(frame->root); + } + glfs_subvol_done(fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return ret; + return ret; invalid_fs: - return -1; + return -1; } int -pub_glfs_preadv_async34 (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk34 fn, - void *data) +pub_glfs_preadv_async34(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk34 fn, + void *data) { - return glfs_preadv_async_common (glfd, iovec, count, offset, flags, - _gf_true, (void *)fn, data); + return glfs_preadv_async_common(glfd, iovec, count, offset, flags, _gf_true, + (void *)fn, data); } GFAPI_SYMVER_PUBLIC(glfs_preadv_async34, glfs_preadv_async, 3.4.0); - int -pub_glfs_preadv_async (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk fn, - void *data) +pub_glfs_preadv_async(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk fn, + void *data) { - return glfs_preadv_async_common (glfd, iovec, count, offset, flags, - _gf_false, fn, data); + return glfs_preadv_async_common(glfd, iovec, count, offset, flags, + _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv_async, future); - int -pub_glfs_read_async34 (struct glfs_fd *glfd, void *buf, size_t count, int flags, - glfs_io_cbk34 fn, void *data) +pub_glfs_read_async34(struct glfs_fd *glfd, void *buf, size_t count, int flags, + glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, glfd->offset, flags, _gf_true, + (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_read_async34, glfs_read_async, 3.4.0); - int -pub_glfs_read_async (struct glfs_fd *glfd, void *buf, size_t count, int flags, - glfs_io_cbk fn, void *data) +pub_glfs_read_async(struct glfs_fd *glfd, void *buf, size_t count, int flags, + glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_false, fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, glfd->offset, flags, + _gf_false, fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read_async, future); - int -pub_glfs_pread_async34 (struct glfs_fd *glfd, void *buf, size_t count, - off_t offset, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_pread_async34(struct glfs_fd *glfd, void *buf, size_t count, + off_t offset, int flags, glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, offset, flags, _gf_true, + (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pread_async34, glfs_pread_async, 3.4.0); - int -pub_glfs_pread_async (struct glfs_fd *glfd, void *buf, size_t count, - off_t offset, int flags, glfs_io_cbk fn, void *data) +pub_glfs_pread_async(struct glfs_fd *glfd, void *buf, size_t count, + off_t offset, int flags, glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, offset, flags, - _gf_false, fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, offset, flags, _gf_false, fn, + data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread_async, future); - int -pub_glfs_readv_async34 (struct glfs_fd *glfd, const struct iovec *iov, - int count, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_readv_async34(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags, glfs_io_cbk34 fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_preadv_async_common (glfd, iov, count, glfd->offset, flags, - _gf_true, (void *)fn, data); - return ret; + ret = glfs_preadv_async_common(glfd, iov, count, glfd->offset, flags, + _gf_true, (void *)fn, data); + return ret; } GFAPI_SYMVER_PUBLIC(glfs_readv_async34, glfs_readv_async, 3.4.0); - int -pub_glfs_readv_async (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags, glfs_io_cbk fn, void *data) +pub_glfs_readv_async(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags, glfs_io_cbk fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_preadv_async_common (glfd, iov, count, glfd->offset, flags, - _gf_false, fn, data); - return ret; + ret = glfs_preadv_async_common(glfd, iov, count, glfd->offset, flags, + _gf_false, fn, data); + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv_async, future); static ssize_t -glfs_pwritev_common (struct glfs_fd *glfd, const struct iovec *iovec, - int iovcnt, off_t offset, int flags, - struct stat *prestat, struct stat *poststat) -{ - xlator_t *subvol = NULL; - int ret = -1; - struct iobref *iobref = NULL; - struct iobuf *iobuf = NULL; - struct iovec iov = {0, }; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = iobuf_copy (subvol->ctx->iobuf_pool, iovec, iovcnt, &iobref, - &iobuf, &iov); - if (ret) - goto out; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, - &preiatt, &postiatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } - - if (ret <= 0) - goto out; - - glfd->offset = (offset + iov.iov_len); +glfs_pwritev_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags, struct stat *prestat, + struct stat *poststat) +{ + xlator_t *subvol = NULL; + int ret = -1; + struct iobref *iobref = NULL; + struct iobuf *iobuf = NULL; + struct iovec iov = { + 0, + }; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = iobuf_copy(subvol->ctx->iobuf_pool, iovec, iovcnt, &iobref, &iobuf, + &iov); + if (ret) + goto out; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_writev(subvol, fd, &iov, 1, offset, iobref, flags, &preiatt, + &postiatt, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } + + if (ret <= 0) + goto out; + + glfd->offset = (offset + iov.iov_len); out: - if (iobuf) - iobuf_unref (iobuf); - if (iobref) - iobref_unref (iobref); - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (iobuf) + iobuf_unref(iobuf); + if (iobref) + iobref_unref(iobref); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } ssize_t -pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags) +pub_glfs_pwritev(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags) { - return glfs_pwritev_common (glfd, iovec, iovcnt, offset, flags, - NULL, NULL); + return glfs_pwritev_common(glfd, iovec, iovcnt, offset, flags, NULL, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev, 3.4.0); - ssize_t -pub_glfs_write (struct glfs_fd *glfd, const void *buf, size_t count, int flags) +pub_glfs_write(struct glfs_fd *glfd, const void *buf, size_t count, int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = pub_glfs_pwritev (glfd, &iov, 1, glfd->offset, flags); + ret = pub_glfs_pwritev(glfd, &iov, 1, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_write, 3.4.0); - ssize_t -pub_glfs_writev (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags) +pub_glfs_writev(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = pub_glfs_pwritev (glfd, iov, count, glfd->offset, flags); + ret = pub_glfs_pwritev(glfd, iov, count, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev, 3.4.0); - ssize_t -pub_glfs_pwrite34 (struct glfs_fd *glfd, const void *buf, size_t count, - off_t offset, int flags) +pub_glfs_pwrite34(struct glfs_fd *glfd, const void *buf, size_t count, + off_t offset, int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = pub_glfs_pwritev (glfd, &iov, 1, offset, flags); + ret = pub_glfs_pwritev(glfd, &iov, 1, offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pwrite34, glfs_pwrite, 3.4.0); ssize_t -pub_glfs_pwrite (struct glfs_fd *glfd, const void *buf, size_t count, - off_t offset, int flags, struct stat *prestat, - struct stat *poststat) +pub_glfs_pwrite(struct glfs_fd *glfd, const void *buf, size_t count, + off_t offset, int flags, struct stat *prestat, + struct stat *poststat) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_common (glfd, &iov, 1, offset, flags, - prestat, poststat); + ret = glfs_pwritev_common(glfd, &iov, 1, offset, flags, prestat, poststat); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite, future); -extern glfs_t *pub_glfs_from_glfd (glfs_fd_t *); - +extern glfs_t * +pub_glfs_from_glfd(glfs_fd_t *); static int -glfs_pwritev_async_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) +glfs_pwritev_async_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) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - prebuf, postbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf, + postbuf); - return 0; + return 0; } static int -glfs_pwritev_async_common (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_pwritev_async_common(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iobref *iobref = NULL; - struct iobuf *iobuf = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_WRITE; - gio->glfd = glfd; - gio->offset = offset; - gio->flags = flags; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - gio->count = 1; - gio->iov = GF_CALLOC (gio->count, sizeof (*(gio->iov)), - gf_common_mt_iovec); - if (!gio->iov) { - errno = ENOMEM; - goto out; - } - - ret = iobuf_copy (subvol->ctx->iobuf_pool, iovec, count, &iobref, - &iobuf, gio->iov); - if (ret) - goto out; - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - ret = -1; - goto out; - } - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_pwritev_async_cbk, subvol, subvol, - subvol->fops->writev, fd, gio->iov, - gio->count, offset, flags, iobref, fop_attr); - - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iobref *iobref = NULL; + struct iobuf *iobuf = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_WRITE; + gio->glfd = glfd; + gio->offset = offset; + gio->flags = flags; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + gio->count = 1; + gio->iov = GF_CALLOC(gio->count, sizeof(*(gio->iov)), gf_common_mt_iovec); + if (!gio->iov) { + errno = ENOMEM; + goto out; + } + + ret = iobuf_copy(subvol->ctx->iobuf_pool, iovec, count, &iobref, &iobuf, + gio->iov); + if (ret) + goto out; + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + ret = -1; + goto out; + } + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_pwritev_async_cbk, subvol, subvol, + subvol->fops->writev, fd, gio->iov, gio->count, offset, + flags, iobref, fop_attr); + + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - /* - * If there is any error condition check after the frame - * creation, we have to destroy the frame root. - */ - glfs_subvol_done (glfd->fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + /* + * If there is any error condition check after the frame + * creation, we have to destroy the frame root. + */ + glfs_subvol_done(glfd->fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - if (iobuf) - iobuf_unref (iobuf); - if (iobref) - iobref_unref (iobref); + if (iobuf) + iobuf_unref(iobuf); + if (iobref) + iobref_unref(iobref); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_pwritev_async34 (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk34 fn, - void *data) +pub_glfs_pwritev_async34(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk34 fn, + void *data) { - return glfs_pwritev_async_common (glfd, iovec, count, offset, flags, - _gf_true, (void *)fn, data); + return glfs_pwritev_async_common(glfd, iovec, count, offset, flags, + _gf_true, (void *)fn, data); } GFAPI_SYMVER_PUBLIC(glfs_pwritev_async34, glfs_pwritev_async, 3.4.0); - int -pub_glfs_pwritev_async (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk fn, - void *data) +pub_glfs_pwritev_async(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk fn, + void *data) { - return glfs_pwritev_async_common (glfd, iovec, count, offset, flags, - _gf_false, fn, data); + return glfs_pwritev_async_common(glfd, iovec, count, offset, flags, + _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev_async, future); - int -pub_glfs_write_async34 (struct glfs_fd *glfd, const void *buf, size_t count, - int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_write_async34(struct glfs_fd *glfd, const void *buf, size_t count, + int flags, glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, glfd->offset, flags, + _gf_true, (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_write_async34, glfs_write_async, 3.4.0); - int -pub_glfs_write_async (struct glfs_fd *glfd, const void *buf, size_t count, - int flags, glfs_io_cbk fn, void *data) +pub_glfs_write_async(struct glfs_fd *glfd, const void *buf, size_t count, + int flags, glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_false, fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, glfd->offset, flags, + _gf_false, fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_write_async, future); - int -pub_glfs_pwrite_async34 (struct glfs_fd *glfd, const void *buf, int count, - off_t offset, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_pwrite_async34(struct glfs_fd *glfd, const void *buf, int count, + off_t offset, int flags, glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, offset, flags, _gf_true, + (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pwrite_async34, glfs_pwrite_async, 3.4.0); - int -pub_glfs_pwrite_async (struct glfs_fd *glfd, const void *buf, int count, - off_t offset, int flags, glfs_io_cbk fn, void *data) +pub_glfs_pwrite_async(struct glfs_fd *glfd, const void *buf, int count, + off_t offset, int flags, glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, offset, flags, - _gf_false, fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, offset, flags, _gf_false, fn, + data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite_async, future); - int -pub_glfs_writev_async34 (struct glfs_fd *glfd, const struct iovec *iov, - int count, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_writev_async34(struct glfs_fd *glfd, const struct iovec *iov, + int count, int flags, glfs_io_cbk34 fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_pwritev_async_common (glfd, iov, count, glfd->offset, flags, - _gf_true, (void *)fn, data); - return ret; + ret = glfs_pwritev_async_common(glfd, iov, count, glfd->offset, flags, + _gf_true, (void *)fn, data); + return ret; } GFAPI_SYMVER_PUBLIC(glfs_writev_async34, glfs_writev_async, 3.4.0); - int -pub_glfs_writev_async (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags, glfs_io_cbk fn, void *data) +pub_glfs_writev_async(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags, glfs_io_cbk fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_pwritev_async_common (glfd, iov, count, glfd->offset, flags, - _gf_false, fn, data); - return ret; + ret = glfs_pwritev_async_common(glfd, iov, count, glfd->offset, flags, + _gf_false, fn, data); + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev_async, future); - static int -glfs_fsync_common (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_fsync (subvol, fd, 0, &preiatt, &postiatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } +glfs_fsync_common(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_fsync(subvol, fd, 0, &preiatt, &postiatt, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_fsync34 (struct glfs_fd *glfd) +pub_glfs_fsync34(struct glfs_fd *glfd) { - return glfs_fsync_common (glfd, NULL, NULL); + return glfs_fsync_common(glfd, NULL, NULL); } GFAPI_SYMVER_PUBLIC(glfs_fsync34, glfs_fsync, 3.4.0); - int -pub_glfs_fsync (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +pub_glfs_fsync(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) { - return glfs_fsync_common (glfd, prestat, poststat); + return glfs_fsync_common(glfd, prestat, poststat); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync, future); - static int -glfs_fsync_async_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) +glfs_fsync_async_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) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - prebuf, postbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf, + postbuf); - return 0; + return 0; } static int -glfs_fsync_async_common (struct glfs_fd *glfd, gf_boolean_t oldcb, - glfs_io_cbk fn, void *data, int dataonly) -{ - struct glfs_io *gio = NULL; - int ret = 0; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; +glfs_fsync_async_common(struct glfs_fd *glfd, gf_boolean_t oldcb, + glfs_io_cbk fn, void *data, int dataonly) +{ + struct glfs_io *gio = NULL; + int ret = 0; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + ret = -1; + goto out; + } + + gio->op = GF_FOP_FSYNC; + gio->glfd = glfd; + gio->flags = dataonly; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + STACK_WIND_COOKIE(frame, glfs_fsync_async_cbk, subvol, subvol, + subvol->fops->fsync, fd, dataonly, NULL); - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); +out: + if (ret) { + if (fd) + fd_unref(fd); + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + return ret; +} - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } +int +pub_glfs_fsync_async34(struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) +{ + int ret = -1; - frame = syncop_create_frame (THIS); - if (!frame) { - ret = -1; - errno = ENOMEM; - goto out; - } + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - ret = -1; - goto out; - } + ret = glfs_fsync_async_common(glfd, _gf_true, (void *)fn, data, 0); - gio->op = GF_FOP_FSYNC; - gio->glfd = glfd; - gio->flags = dataonly; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; + __GLFS_EXIT_FS; - frame->local = gio; - - STACK_WIND_COOKIE (frame, glfs_fsync_async_cbk, subvol, subvol, - subvol->fops->fsync, fd, dataonly, NULL); - -out: - if (ret) { - if (fd) - fd_unref (fd); - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } - - return ret; -} - - -int -pub_glfs_fsync_async34 (struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) -{ - int ret = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - ret = glfs_fsync_async_common (glfd, _gf_true, (void *)fn, data, 0); - - __GLFS_EXIT_FS; - -invalid_fs: - return ret; -} - -GFAPI_SYMVER_PUBLIC(glfs_fsync_async34, glfs_fsync_async, 3.4.0); +invalid_fs: + return ret; +} +GFAPI_SYMVER_PUBLIC(glfs_fsync_async34, glfs_fsync_async, 3.4.0); int -pub_glfs_fsync_async (struct glfs_fd *glfd, glfs_io_cbk fn, void *data) +pub_glfs_fsync_async(struct glfs_fd *glfd, glfs_io_cbk fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_false, fn, data, 0); + ret = glfs_fsync_async_common(glfd, _gf_false, fn, data, 0); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync_async, future); - static int -glfs_fdatasync_common (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_fsync (subvol, fd, 1, &preiatt, &postiatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } +glfs_fdatasync_common(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_fsync(subvol, fd, 1, &preiatt, &postiatt, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_fdatasync34 (struct glfs_fd *glfd) +pub_glfs_fdatasync34(struct glfs_fd *glfd) { - return glfs_fdatasync_common (glfd, NULL, NULL); + return glfs_fdatasync_common(glfd, NULL, NULL); } GFAPI_SYMVER_PUBLIC(glfs_fdatasync34, glfs_fdatasync, 3.4.0); - int -pub_glfs_fdatasync (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +pub_glfs_fdatasync(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) { - return glfs_fdatasync_common (glfd, prestat, poststat); + return glfs_fdatasync_common(glfd, prestat, poststat); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync, future); - int -pub_glfs_fdatasync_async34 (struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) +pub_glfs_fdatasync_async34(struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_true, (void *)fn, data, 1); + ret = glfs_fsync_async_common(glfd, _gf_true, (void *)fn, data, 1); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_fdatasync_async34, glfs_fdatasync_async, 3.4.0); - int -pub_glfs_fdatasync_async (struct glfs_fd *glfd, glfs_io_cbk fn, void *data) +pub_glfs_fdatasync_async(struct glfs_fd *glfd, glfs_io_cbk fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_false, fn, data, 1); + ret = glfs_fsync_async_common(glfd, _gf_false, fn, data, 1); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync_async, future); - static int -glfs_ftruncate_common (struct glfs_fd *glfd, off_t offset, - struct stat *prestat, struct stat *poststat) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_ftruncate (subvol, fd, offset, &preiatt, &postiatt, - fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } +glfs_ftruncate_common(struct glfs_fd *glfd, off_t offset, struct stat *prestat, + struct stat *poststat) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_ftruncate(subvol, fd, offset, &preiatt, &postiatt, fop_attr, + NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_ftruncate34 (struct glfs_fd *glfd, off_t offset) +pub_glfs_ftruncate34(struct glfs_fd *glfd, off_t offset) { - return glfs_ftruncate_common (glfd, offset, NULL, NULL); + return glfs_ftruncate_common(glfd, offset, NULL, NULL); } GFAPI_SYMVER_PUBLIC(glfs_ftruncate34, glfs_ftruncate, 3.4.0); - int -pub_glfs_ftruncate (struct glfs_fd *glfd, off_t offset, struct stat *prestat, - struct stat *poststat) +pub_glfs_ftruncate(struct glfs_fd *glfd, off_t offset, struct stat *prestat, + struct stat *poststat) { - return glfs_ftruncate_common (glfd, offset, prestat, poststat); + return glfs_ftruncate_common(glfd, offset, prestat, poststat); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate, future); - int -pub_glfs_truncate (struct glfs *fs, const char *path, off_t length) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_truncate(struct glfs *fs, const char *path, off_t length) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_truncate (subvol, &loc, length, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_truncate(subvol, &loc, length, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_truncate, 3.7.15); - static int -glfs_ftruncate_async_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) +glfs_ftruncate_async_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) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - prebuf, postbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf, + postbuf); - return 0; + return 0; } static int -glfs_ftruncate_async_common (struct glfs_fd *glfd, off_t offset, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_ftruncate_async_common(struct glfs_fd *glfd, off_t offset, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_FTRUNCATE; - gio->glfd = glfd; - gio->offset = offset; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_ftruncate_async_cbk, subvol, subvol, - subvol->fops->ftruncate, fd, offset, fop_attr); - - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_FTRUNCATE; + gio->glfd = glfd; + gio->offset = offset; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_ftruncate_async_cbk, subvol, subvol, + subvol->fops->ftruncate, fd, offset, fop_attr); + + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_ftruncate_async34 (struct glfs_fd *glfd, off_t offset, - glfs_io_cbk34 fn, void *data) +pub_glfs_ftruncate_async34(struct glfs_fd *glfd, off_t offset, glfs_io_cbk34 fn, + void *data) { - return glfs_ftruncate_async_common (glfd, offset, _gf_true, - (void *)fn, data); + return glfs_ftruncate_async_common(glfd, offset, _gf_true, (void *)fn, + data); } GFAPI_SYMVER_PUBLIC(glfs_ftruncate_async34, glfs_ftruncate_async, 3.4.0); - int -pub_glfs_ftruncate_async (struct glfs_fd *glfd, off_t offset, - glfs_io_cbk fn, void *data) +pub_glfs_ftruncate_async(struct glfs_fd *glfd, off_t offset, glfs_io_cbk fn, + void *data) { - return glfs_ftruncate_async_common (glfd, offset, _gf_false, fn, data); + return glfs_ftruncate_async_common(glfd, offset, _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate_async, future); - int -pub_glfs_access (struct glfs *fs, const char *path, int mode) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_access(struct glfs *fs, const char *path, int mode) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_access (subvol, &loc, mode, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_access(subvol, &loc, mode, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_access, 3.4.0); - int -pub_glfs_symlink (struct glfs *fs, const char *data, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_symlink(struct glfs *fs, const char *data, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (loc.inode) { - errno = EEXIST; - ret = -1; - goto out; - } + if (loc.inode) { + errno = EEXIST; + ret = -1; + goto out; + } - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; - /* ret == -1 && errno == ENOENT */ - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } + /* ret == -1 && errno == ENOENT */ + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_symlink (subvol, &loc, data, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_symlink(subvol, &loc, data, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_symlink, 3.4.0); - int -pub_glfs_readlink (struct glfs *fs, const char *path, char *buf, size_t bufsiz) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - char *linkval = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_readlink(struct glfs *fs, const char *path, char *buf, size_t bufsiz) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + char *linkval = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (iatt.ia_type != IA_IFLNK) { - ret = -1; - errno = EINVAL; - goto out; - } + if (iatt.ia_type != IA_IFLNK) { + ret = -1; + errno = EINVAL; + goto out; + } - ret = syncop_readlink (subvol, &loc, &linkval, bufsiz, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret > 0) { - memcpy (buf, linkval, ret); - GF_FREE (linkval); - } + ret = syncop_readlink(subvol, &loc, &linkval, bufsiz, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret > 0) { + memcpy(buf, linkval, ret); + GF_FREE(linkval); + } - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readlink, 3.4.0); - int -pub_glfs_mknod (struct glfs *fs, const char *path, mode_t mode, dev_t dev) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_mknod(struct glfs *fs, const char *path, mode_t mode, dev_t dev) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (loc.inode) { - errno = EEXIST; - ret = -1; - goto out; - } + if (loc.inode) { + errno = EEXIST; + ret = -1; + goto out; + } - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; - /* ret == -1 && errno == ENOENT */ - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } + /* ret == -1 && errno == ENOENT */ + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_mknod (subvol, &loc, mode, dev, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_mknod(subvol, &loc, mode, dev, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_mknod, 3.4.0); - int -pub_glfs_mkdir (struct glfs *fs, const char *path, mode_t mode) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_mkdir(struct glfs *fs, const char *path, mode_t mode) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (loc.inode) { - errno = EEXIST; - ret = -1; - goto out; - } + if (loc.inode) { + errno = EEXIST; + ret = -1; + goto out; + } - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; - /* ret == -1 && errno == ENOENT */ - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } + /* ret == -1 && errno == ENOENT */ + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_mkdir (subvol, &loc, mode, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_mkdir(subvol, &loc, mode, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_mkdir, 3.4.0); - int -pub_glfs_unlink (struct glfs *fs, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_unlink(struct glfs *fs, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (iatt.ia_type == IA_IFDIR) { - ret = -1; - errno = EISDIR; - goto out; - } + if (iatt.ia_type == IA_IFDIR) { + ret = -1; + errno = EISDIR; + goto out; + } - /* TODO: Add leaseid */ - ret = syncop_unlink (subvol, &loc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* TODO: Add leaseid */ + ret = syncop_unlink(subvol, &loc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_unlink (&loc); + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_unlink, 3.4.0); - int -pub_glfs_rmdir (struct glfs *fs, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_rmdir(struct glfs *fs, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (iatt.ia_type != IA_IFDIR) { - ret = -1; - errno = ENOTDIR; - goto out; - } + if (iatt.ia_type != IA_IFDIR) { + ret = -1; + errno = ENOTDIR; + goto out; + } - ret = syncop_rmdir (subvol, &loc, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_rmdir(subvol, &loc, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_unlink (&loc); + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_rmdir, 3.4.0); - int -pub_glfs_rename (struct glfs *fs, const char *oldpath, const char *newpath) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt oldiatt = {0, }; - struct iatt newiatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_rename(struct glfs *fs, const char *oldpath, const char *newpath) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt oldiatt = { + 0, + }; + struct iatt newiatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, oldpath, &oldloc, &oldiatt, reval); + ret = glfs_lresolve(fs, subvol, oldpath, &oldloc, &oldiatt, reval); - ESTALE_RETRY (ret, errno, reval, &oldloc, retry); + ESTALE_RETRY(ret, errno, reval, &oldloc, retry); - if (ret) - goto out; + if (ret) + goto out; retrynew: - ret = glfs_lresolve (fs, subvol, newpath, &newloc, &newiatt, reval); - - ESTALE_RETRY (ret, errno, reval, &newloc, retrynew); - - if (ret && errno != ENOENT && newloc.parent) - goto out; - - if (newiatt.ia_type != IA_INVAL) { - if ((oldiatt.ia_type == IA_IFDIR) != - (newiatt.ia_type == IA_IFDIR)) { - /* Either both old and new must be dirs, - * or both must be non-dirs. Else, fail. - */ - ret = -1; - errno = EISDIR; - goto out; - } + ret = glfs_lresolve(fs, subvol, newpath, &newloc, &newiatt, reval); + + ESTALE_RETRY(ret, errno, reval, &newloc, retrynew); + + if (ret && errno != ENOENT && newloc.parent) + goto out; + + if (newiatt.ia_type != IA_INVAL) { + if ((oldiatt.ia_type == IA_IFDIR) != (newiatt.ia_type == IA_IFDIR)) { + /* Either both old and new must be dirs, + * or both must be non-dirs. Else, fail. + */ + ret = -1; + errno = EISDIR; + goto out; + } + } + + /* TODO: - check if new or old is a prefix of the other, and fail EINVAL + * - Add leaseid */ + + ret = syncop_rename(subvol, &oldloc, &newloc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == -1 && errno == ESTALE) { + if (reval < DEFAULT_REVAL_COUNT) { + reval++; + loc_wipe(&oldloc); + loc_wipe(&newloc); + goto retry; } + } + + if (ret == 0) { + inode_rename(oldloc.parent->table, oldloc.parent, oldloc.name, + newloc.parent, newloc.name, oldloc.inode, &oldiatt); - /* TODO: - check if new or old is a prefix of the other, and fail EINVAL - * - Add leaseid */ - - ret = syncop_rename (subvol, &oldloc, &newloc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == -1 && errno == ESTALE) { - if (reval < DEFAULT_REVAL_COUNT) { - reval++; - loc_wipe (&oldloc); - loc_wipe (&newloc); - goto retry; - } - } - - if (ret == 0) { - inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name, - newloc.parent, newloc.name, oldloc.inode, - &oldiatt); - - if (newloc.inode && !inode_has_dentry (newloc.inode)) - inode_forget (newloc.inode, 0); - } + if (newloc.inode && !inode_has_dentry(newloc.inode)) + inode_forget(newloc.inode, 0); + } out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_rename, 3.4.0); - int -pub_glfs_link (struct glfs *fs, const char *oldpath, const char *newpath) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt oldiatt = {0, }; - struct iatt newiatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_link(struct glfs *fs, const char *oldpath, const char *newpath) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt oldiatt = { + 0, + }; + struct iatt newiatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, oldpath, &oldloc, &oldiatt, reval); + ret = glfs_lresolve(fs, subvol, oldpath, &oldloc, &oldiatt, reval); - ESTALE_RETRY (ret, errno, reval, &oldloc, retry); + ESTALE_RETRY(ret, errno, reval, &oldloc, retry); - if (ret) - goto out; + if (ret) + goto out; retrynew: - ret = glfs_lresolve (fs, subvol, newpath, &newloc, &newiatt, reval); - - ESTALE_RETRY (ret, errno, reval, &newloc, retrynew); - - if (ret == 0) { - ret = -1; - errno = EEXIST; - goto out; - } - - if (oldiatt.ia_type == IA_IFDIR) { - ret = -1; - errno = EISDIR; - goto out; - } - - /* Filling the inode of the hard link to be same as that of the - original file - */ - if (newloc.inode) { - inode_unref (newloc.inode); - newloc.inode = NULL; - } - newloc.inode = inode_ref (oldloc.inode); - - ret = syncop_link (subvol, &oldloc, &newloc, &newiatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == -1 && errno == ESTALE) { - loc_wipe (&oldloc); - loc_wipe (&newloc); - if (reval--) - goto retry; - } - - if (ret == 0) - ret = glfs_loc_link (&newloc, &newiatt); + ret = glfs_lresolve(fs, subvol, newpath, &newloc, &newiatt, reval); + + ESTALE_RETRY(ret, errno, reval, &newloc, retrynew); + + if (ret == 0) { + ret = -1; + errno = EEXIST; + goto out; + } + + if (oldiatt.ia_type == IA_IFDIR) { + ret = -1; + errno = EISDIR; + goto out; + } + + /* Filling the inode of the hard link to be same as that of the + original file + */ + if (newloc.inode) { + inode_unref(newloc.inode); + newloc.inode = NULL; + } + newloc.inode = inode_ref(oldloc.inode); + + ret = syncop_link(subvol, &oldloc, &newloc, &newiatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == -1 && errno == ESTALE) { + loc_wipe(&oldloc); + loc_wipe(&newloc); + if (reval--) + goto retry; + } + + if (ret == 0) + ret = glfs_loc_link(&newloc, &newiatt); out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_link, 3.4.0); - struct glfs_fd * -pub_glfs_opendir (struct glfs *fs, const char *path) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; - - INIT_LIST_HEAD (&glfd->entries); +pub_glfs_opendir(struct glfs *fs, const char *path) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; + + INIT_LIST_HEAD(&glfd->entries); retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret) - goto out; - - if (!IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } - - if (glfd->fd) { - /* Retry. Safe to touch glfd->fd as we - still have not glfs_fd_bind() yet. - */ - fd_unref (glfd->fd); - glfd->fd = NULL; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - - ret = syncop_opendir (subvol, &loc, glfd->fd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); + + if (ret) + goto out; + + if (!IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } + + if (glfd->fd) { + /* Retry. Safe to touch glfd->fd as we + still have not glfs_fd_bind() yet. + */ + fd_unref(glfd->fd); + glfd->fd = NULL; + } + + glfd->fd = fd_create(loc.inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + + ret = syncop_opendir(subvol, &loc, glfd->fd, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_opendir, 3.4.0); - int -pub_glfs_closedir (struct glfs_fd *glfd) +pub_glfs_closedir(struct glfs_fd *glfd) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - gf_dirent_free (list_entry (&glfd->entries, gf_dirent_t, list)); + gf_dirent_free(list_entry(&glfd->entries, gf_dirent_t, list)); - glfs_mark_glfd_for_deletion (glfd); + glfs_mark_glfd_for_deletion(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - ret = 0; + ret = 0; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_closedir, 3.4.0); - long -pub_glfs_telldir (struct glfs_fd *fd) +pub_glfs_telldir(struct glfs_fd *fd) { - return fd->offset; + return fd->offset; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_telldir, 3.4.0); - void -pub_glfs_seekdir (struct glfs_fd *fd, long offset) +pub_glfs_seekdir(struct glfs_fd *fd, long offset) { - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; + gf_dirent_t *entry = NULL; + gf_dirent_t *tmp = NULL; - if (fd->offset == offset) - return; + if (fd->offset == offset) + return; - fd->offset = offset; - fd->next = NULL; + fd->offset = offset; + fd->next = NULL; - list_for_each_entry_safe (entry, tmp, &fd->entries, list) { - if (entry->d_off != offset) - continue; + list_for_each_entry_safe(entry, tmp, &fd->entries, list) + { + if (entry->d_off != offset) + continue; - if (&tmp->list != &fd->entries) { - /* found! */ - fd->next = tmp; - return; - } - } - /* could not find entry at requested offset in the cache. - next readdir_r() will result in glfd_entry_refresh() - */ + if (&tmp->list != &fd->entries) { + /* found! */ + fd->next = tmp; + return; + } + } + /* could not find entry at requested offset in the cache. + next readdir_r() will result in glfd_entry_refresh() + */ } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_seekdir, 3.4.0); static int -glfs_discard_async_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *preop_stbuf, - struct iatt *postop_stbuf, dict_t *xdata) +glfs_discard_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preop_stbuf, struct iatt *postop_stbuf, + dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - preop_stbuf, postop_stbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, preop_stbuf, + postop_stbuf); - return 0; + return 0; } static int -glfs_discard_async_common (struct glfs_fd *glfd, off_t offset, size_t len, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_discard_async_common(struct glfs_fd *glfd, off_t offset, size_t len, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_DISCARD; - gio->glfd = glfd; - gio->offset = offset; - gio->count = len; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_discard_async_cbk, subvol, subvol, - subvol->fops->discard, fd, offset, len, fop_attr); - - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_DISCARD; + gio->glfd = glfd; + gio->offset = offset; + gio->count = len; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_discard_async_cbk, subvol, subvol, + subvol->fops->discard, fd, offset, len, fop_attr); + + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_discard_async35 (struct glfs_fd *glfd, off_t offset, size_t len, - glfs_io_cbk34 fn, void *data) +pub_glfs_discard_async35(struct glfs_fd *glfd, off_t offset, size_t len, + glfs_io_cbk34 fn, void *data) { - return glfs_discard_async_common (glfd, offset, len, _gf_true, - (void *)fn, data); + return glfs_discard_async_common(glfd, offset, len, _gf_true, (void *)fn, + data); } GFAPI_SYMVER_PUBLIC(glfs_discard_async35, glfs_discard_async, 3.5.0); - int -pub_glfs_discard_async (struct glfs_fd *glfd, off_t offset, size_t len, - glfs_io_cbk fn, void *data) +pub_glfs_discard_async(struct glfs_fd *glfd, off_t offset, size_t len, + glfs_io_cbk fn, void *data) { - return glfs_discard_async_common (glfd, offset, len, _gf_false, fn, - data); + return glfs_discard_async_common(glfd, offset, len, _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_discard_async, future); - static int -glfs_zerofill_async_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *preop_stbuf, - struct iatt *postop_stbuf, dict_t *xdata) +glfs_zerofill_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preop_stbuf, struct iatt *postop_stbuf, + dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - preop_stbuf, postop_stbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, preop_stbuf, + postop_stbuf); - return 0; + return 0; } - static int -glfs_zerofill_async_common (struct glfs_fd *glfd, off_t offset, off_t len, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_zerofill_async_common(struct glfs_fd *glfd, off_t offset, off_t len, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_ZEROFILL; - gio->glfd = glfd; - gio->offset = offset; - gio->count = len; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_zerofill_async_cbk, subvol, subvol, - subvol->fops->zerofill, fd, offset, len, fop_attr); - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_ZEROFILL; + gio->glfd = glfd; + gio->offset = offset; + gio->count = len; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_zerofill_async_cbk, subvol, subvol, + subvol->fops->zerofill, fd, offset, len, fop_attr); + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_zerofill_async35 (struct glfs_fd *glfd, off_t offset, off_t len, - glfs_io_cbk34 fn, void *data) +pub_glfs_zerofill_async35(struct glfs_fd *glfd, off_t offset, off_t len, + glfs_io_cbk34 fn, void *data) { - return glfs_zerofill_async_common (glfd, offset, len, _gf_true, - (void *)fn, data); + return glfs_zerofill_async_common(glfd, offset, len, _gf_true, (void *)fn, + data); } GFAPI_SYMVER_PUBLIC(glfs_zerofill_async35, glfs_zerofill_async, 3.5.0); - int -pub_glfs_zerofill_async (struct glfs_fd *glfd, off_t offset, off_t len, - glfs_io_cbk fn, void *data) +pub_glfs_zerofill_async(struct glfs_fd *glfd, off_t offset, off_t len, + glfs_io_cbk fn, void *data) { - return glfs_zerofill_async_common (glfd, offset, len, _gf_false, - fn, data); + return glfs_zerofill_async_common(glfd, offset, len, _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_zerofill_async, future); - void -gf_dirent_to_dirent (gf_dirent_t *gf_dirent, struct dirent *dirent) +gf_dirent_to_dirent(gf_dirent_t *gf_dirent, struct dirent *dirent) { - dirent->d_ino = gf_dirent->d_ino; + dirent->d_ino = gf_dirent->d_ino; #ifdef _DIRENT_HAVE_D_OFF - dirent->d_off = gf_dirent->d_off; + dirent->d_off = gf_dirent->d_off; #endif #ifdef _DIRENT_HAVE_D_TYPE - dirent->d_type = gf_dirent->d_type; + dirent->d_type = gf_dirent->d_type; #endif #ifdef _DIRENT_HAVE_D_NAMLEN - dirent->d_namlen = strlen (gf_dirent->d_name); + dirent->d_namlen = strlen(gf_dirent->d_name); #endif - snprintf (dirent->d_name, NAME_MAX, "%s", gf_dirent->d_name); + snprintf(dirent->d_name, NAME_MAX, "%s", gf_dirent->d_name); } - int -glfd_entry_refresh (struct glfs_fd *glfd, int plus) -{ - xlator_t *subvol = NULL; - gf_dirent_t entries; - gf_dirent_t old; - gf_dirent_t *entry = NULL; - int ret = -1; - fd_t *fd = NULL; - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - if (fd->inode->ia_type != IA_IFDIR) { - ret = -1; - errno = EBADF; - goto out; - } - - INIT_LIST_HEAD (&entries.list); - INIT_LIST_HEAD (&old.list); - - if (plus) - ret = syncop_readdirp (subvol, fd, 131072, glfd->offset, - &entries, NULL, NULL); - else - ret = syncop_readdir (subvol, fd, 131072, glfd->offset, - &entries, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret >= 0) { - if (plus) { - list_for_each_entry (entry, &entries.list, list) { - if (!entry->inode && - !IA_ISDIR (entry->d_stat.ia_type)) { - /* entry->inode for directories will be - * always set to null to force a lookup - * on the dentry. Also we will have - * proper stat if directory present on - * hashed subvolume. - */ - gf_fill_iatt_for_dirent (entry, - fd->inode, - subvol); - } - } - - gf_link_inodes_from_dirent (THIS, fd->inode, &entries); +glfd_entry_refresh(struct glfs_fd *glfd, int plus) +{ + xlator_t *subvol = NULL; + gf_dirent_t entries; + gf_dirent_t old; + gf_dirent_t *entry = NULL; + int ret = -1; + fd_t *fd = NULL; + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + if (fd->inode->ia_type != IA_IFDIR) { + ret = -1; + errno = EBADF; + goto out; + } + + INIT_LIST_HEAD(&entries.list); + INIT_LIST_HEAD(&old.list); + + if (plus) + ret = syncop_readdirp(subvol, fd, 131072, glfd->offset, &entries, NULL, + NULL); + else + ret = syncop_readdir(subvol, fd, 131072, glfd->offset, &entries, NULL, + NULL); + DECODE_SYNCOP_ERR(ret); + if (ret >= 0) { + if (plus) { + list_for_each_entry(entry, &entries.list, list) + { + if (!entry->inode && !IA_ISDIR(entry->d_stat.ia_type)) { + /* entry->inode for directories will be + * always set to null to force a lookup + * on the dentry. Also we will have + * proper stat if directory present on + * hashed subvolume. + */ + gf_fill_iatt_for_dirent(entry, fd->inode, subvol); } + } - list_splice_init (&glfd->entries, &old.list); - list_splice_init (&entries.list, &glfd->entries); + gf_link_inodes_from_dirent(THIS, fd->inode, &entries); + } - /* spurious errno is dangerous for glfd_entry_next() */ - errno = 0; - } + list_splice_init(&glfd->entries, &old.list); + list_splice_init(&entries.list, &glfd->entries); + /* spurious errno is dangerous for glfd_entry_next() */ + errno = 0; + } - if (ret > 0) - glfd->next = list_entry (glfd->entries.next, gf_dirent_t, list); + if (ret > 0) + glfd->next = list_entry(glfd->entries.next, gf_dirent_t, list); - gf_dirent_free (&old); + gf_dirent_free(&old); out: - if (fd) - fd_unref (fd); + if (fd) + fd_unref(fd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - return ret; + return ret; } - gf_dirent_t * -glfd_entry_next (struct glfs_fd *glfd, int plus) +glfd_entry_next(struct glfs_fd *glfd, int plus) { - gf_dirent_t *entry = NULL; - int ret = -1; + gf_dirent_t *entry = NULL; + int ret = -1; - if (!glfd->offset || !glfd->next) { - ret = glfd_entry_refresh (glfd, plus); - if (ret < 0) - return NULL; - } + if (!glfd->offset || !glfd->next) { + ret = glfd_entry_refresh(glfd, plus); + if (ret < 0) + return NULL; + } - entry = glfd->next; - if (!entry) - return NULL; + entry = glfd->next; + if (!entry) + return NULL; - if (&entry->next->list == &glfd->entries) - glfd->next = NULL; - else - glfd->next = entry->next; + if (&entry->next->list == &glfd->entries) + glfd->next = NULL; + else + glfd->next = entry->next; - glfd->offset = entry->d_off; + glfd->offset = entry->d_off; - return entry; + return entry; } - struct dirent * -glfs_readdirbuf_get (struct glfs_fd *glfd) +glfs_readdirbuf_get(struct glfs_fd *glfd) { - struct dirent *buf = NULL; + struct dirent *buf = NULL; - LOCK (&glfd->fd->lock); - { - buf = glfd->readdirbuf; - if (buf) { - memset (buf, 0, READDIRBUF_SIZE); - goto unlock; - } - - buf = GF_CALLOC (1, READDIRBUF_SIZE, glfs_mt_readdirbuf_t); - if (!buf) { - errno = ENOMEM; - goto unlock; - } + LOCK(&glfd->fd->lock); + { + buf = glfd->readdirbuf; + if (buf) { + memset(buf, 0, READDIRBUF_SIZE); + goto unlock; + } - glfd->readdirbuf = buf; + buf = GF_CALLOC(1, READDIRBUF_SIZE, glfs_mt_readdirbuf_t); + if (!buf) { + errno = ENOMEM; + goto unlock; } + + glfd->readdirbuf = buf; + } unlock: - UNLOCK (&glfd->fd->lock); + UNLOCK(&glfd->fd->lock); - return buf; + return buf; } - int -pub_glfs_readdirplus_r (struct glfs_fd *glfd, struct stat *stat, - struct dirent *ext, struct dirent **res) +pub_glfs_readdirplus_r(struct glfs_fd *glfd, struct stat *stat, + struct dirent *ext, struct dirent **res) { - int ret = 0; - gf_dirent_t *entry = NULL; - struct dirent *buf = NULL; + int ret = 0; + gf_dirent_t *entry = NULL; + struct dirent *buf = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - errno = 0; + errno = 0; - if (ext) - buf = ext; - else - buf = glfs_readdirbuf_get (glfd); + if (ext) + buf = ext; + else + buf = glfs_readdirbuf_get(glfd); - if (!buf) { - errno = ENOMEM; - ret = -1; - goto out; - } + if (!buf) { + errno = ENOMEM; + ret = -1; + goto out; + } - entry = glfd_entry_next (glfd, !!stat); - if (errno) - ret = -1; + entry = glfd_entry_next(glfd, !!stat); + if (errno) + ret = -1; - if (res) { - if (entry) - *res = buf; - else - *res = NULL; - } + if (res) { + if (entry) + *res = buf; + else + *res = NULL; + } - if (entry) { - gf_dirent_to_dirent (entry, buf); - if (stat) - glfs_iatt_to_stat (glfd->fs, &entry->d_stat, stat); - } + if (entry) { + gf_dirent_to_dirent(entry, buf); + if (stat) + glfs_iatt_to_stat(glfd->fs, &entry->d_stat, stat); + } out: - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return ret; + return ret; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus_r, 3.4.0); - int -pub_glfs_readdir_r (struct glfs_fd *glfd, struct dirent *buf, - struct dirent **res) +pub_glfs_readdir_r(struct glfs_fd *glfd, struct dirent *buf, + struct dirent **res) { - return pub_glfs_readdirplus_r (glfd, 0, buf, res); + return pub_glfs_readdirplus_r(glfd, 0, buf, res); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdir_r, 3.4.0); - struct dirent * -pub_glfs_readdirplus (struct glfs_fd *glfd, struct stat *stat) +pub_glfs_readdirplus(struct glfs_fd *glfd, struct stat *stat) { - struct dirent *res = NULL; - int ret = -1; + struct dirent *res = NULL; + int ret = -1; - ret = pub_glfs_readdirplus_r (glfd, stat, NULL, &res); - if (ret) - return NULL; + ret = pub_glfs_readdirplus_r(glfd, stat, NULL, &res); + if (ret) + return NULL; - return res; + return res; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus, 3.5.0); - struct dirent * -pub_glfs_readdir (struct glfs_fd *glfd) +pub_glfs_readdir(struct glfs_fd *glfd) { - return pub_glfs_readdirplus (glfd, NULL); + return pub_glfs_readdirplus(glfd, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdir, 3.5.0); - int -pub_glfs_statvfs (struct glfs *fs, const char *path, struct statvfs *buf) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_statvfs(struct glfs *fs, const char *path, struct statvfs *buf) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_statfs (subvol, &loc, buf, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_statfs(subvol, &loc, buf, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_statvfs, 3.4.0); - int -glfs_setattr (struct glfs *fs, const char *path, struct iatt *iatt, - int valid, int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt riatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_setattr(struct glfs *fs, const char *path, struct iatt *iatt, int valid, + int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt riatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &riatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &riatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &riatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &riatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - /* TODO : Add leaseid */ - ret = syncop_setattr (subvol, &loc, iatt, valid, 0, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* TODO : Add leaseid */ + ret = syncop_setattr(subvol, &loc, iatt, valid, 0, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -glfs_fsetattr (struct glfs_fd *glfd, struct iatt *iatt, int valid) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - /* TODO : Add leaseid */ - ret = syncop_fsetattr (subvol, fd, iatt, valid, 0, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +glfs_fsetattr(struct glfs_fd *glfd, struct iatt *iatt, int valid) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + /* TODO : Add leaseid */ + ret = syncop_fsetattr(subvol, fd, iatt, valid, 0, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -pub_glfs_chmod (struct glfs *fs, const char *path, mode_t mode) +pub_glfs_chmod(struct glfs *fs, const char *path, mode_t mode) { - int ret = -1; - struct iatt iatt = {0, }; - int valid = 0; + int ret = -1; + struct iatt iatt = { + 0, + }; + int valid = 0; - iatt.ia_prot = ia_prot_from_st_mode (mode); - valid = GF_SET_ATTR_MODE; + iatt.ia_prot = ia_prot_from_st_mode(mode); + valid = GF_SET_ATTR_MODE; - ret = glfs_setattr (fs, path, &iatt, valid, 1); + ret = glfs_setattr(fs, path, &iatt, valid, 1); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chmod, 3.4.0); - int -pub_glfs_fchmod (struct glfs_fd *glfd, mode_t mode) +pub_glfs_fchmod(struct glfs_fd *glfd, mode_t mode) { - int ret = -1; - struct iatt iatt = {0, }; - int valid = 0; + int ret = -1; + struct iatt iatt = { + 0, + }; + int valid = 0; - iatt.ia_prot = ia_prot_from_st_mode (mode); - valid = GF_SET_ATTR_MODE; + iatt.ia_prot = ia_prot_from_st_mode(mode); + valid = GF_SET_ATTR_MODE; - ret = glfs_fsetattr (glfd, &iatt, valid); + ret = glfs_fsetattr(glfd, &iatt, valid); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchmod, 3.4.0); - int -pub_glfs_chown (struct glfs *fs, const char *path, uid_t uid, gid_t gid) +pub_glfs_chown(struct glfs *fs, const char *path, uid_t uid, gid_t gid) { - int ret = 0; - int valid = 0; - struct iatt iatt = {0, }; + int ret = 0; + int valid = 0; + struct iatt iatt = { + 0, + }; - if (uid != (uid_t) -1) { - iatt.ia_uid = uid; - valid = GF_SET_ATTR_UID; - } + if (uid != (uid_t)-1) { + iatt.ia_uid = uid; + valid = GF_SET_ATTR_UID; + } - if (gid != (uid_t) -1) { - iatt.ia_gid = gid; - valid = valid | GF_SET_ATTR_GID; - } + if (gid != (uid_t)-1) { + iatt.ia_gid = gid; + valid = valid | GF_SET_ATTR_GID; + } - if (valid) - ret = glfs_setattr (fs, path, &iatt, valid, 1); + if (valid) + ret = glfs_setattr(fs, path, &iatt, valid, 1); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chown, 3.4.0); - int -pub_glfs_lchown (struct glfs *fs, const char *path, uid_t uid, gid_t gid) +pub_glfs_lchown(struct glfs *fs, const char *path, uid_t uid, gid_t gid) { - int ret = 0; - int valid = 0; - struct iatt iatt = {0, }; + int ret = 0; + int valid = 0; + struct iatt iatt = { + 0, + }; - if (uid != (uid_t) -1) { - iatt.ia_uid = uid; - valid = GF_SET_ATTR_UID; - } + if (uid != (uid_t)-1) { + iatt.ia_uid = uid; + valid = GF_SET_ATTR_UID; + } - if (gid != (uid_t) -1) { - iatt.ia_gid = gid; - valid = valid | GF_SET_ATTR_GID; - } + if (gid != (uid_t)-1) { + iatt.ia_gid = gid; + valid = valid | GF_SET_ATTR_GID; + } - if (valid) - ret = glfs_setattr (fs, path, &iatt, valid, 0); + if (valid) + ret = glfs_setattr(fs, path, &iatt, valid, 0); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lchown, 3.4.0); - int -pub_glfs_fchown (struct glfs_fd *glfd, uid_t uid, gid_t gid) +pub_glfs_fchown(struct glfs_fd *glfd, uid_t uid, gid_t gid) { - int ret = 0; - int valid = 0; - struct iatt iatt = {0, }; + int ret = 0; + int valid = 0; + struct iatt iatt = { + 0, + }; - if (uid != (uid_t) -1) { - iatt.ia_uid = uid; - valid = GF_SET_ATTR_UID; - } + if (uid != (uid_t)-1) { + iatt.ia_uid = uid; + valid = GF_SET_ATTR_UID; + } - if (gid != (uid_t) -1) { - iatt.ia_gid = gid; - valid = valid | GF_SET_ATTR_GID; - } + if (gid != (uid_t)-1) { + iatt.ia_gid = gid; + valid = valid | GF_SET_ATTR_GID; + } - if (valid) - ret = glfs_fsetattr (glfd, &iatt, valid); + if (valid) + ret = glfs_fsetattr(glfd, &iatt, valid); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchown, 3.4.0); - int -pub_glfs_utimens (struct glfs *fs, const char *path, - const struct timespec times[2]) +pub_glfs_utimens(struct glfs *fs, const char *path, + const struct timespec times[2]) { - int ret = -1; - int valid = 0; - struct iatt iatt = {0, }; + int ret = -1; + int valid = 0; + struct iatt iatt = { + 0, + }; - iatt.ia_atime = times[0].tv_sec; - iatt.ia_atime_nsec = times[0].tv_nsec; - iatt.ia_mtime = times[1].tv_sec; - iatt.ia_mtime_nsec = times[1].tv_nsec; + iatt.ia_atime = times[0].tv_sec; + iatt.ia_atime_nsec = times[0].tv_nsec; + iatt.ia_mtime = times[1].tv_sec; + iatt.ia_mtime_nsec = times[1].tv_nsec; - valid = GF_SET_ATTR_ATIME|GF_SET_ATTR_MTIME; + valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - ret = glfs_setattr (fs, path, &iatt, valid, 1); + ret = glfs_setattr(fs, path, &iatt, valid, 1); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_utimens, 3.4.0); - int -pub_glfs_lutimens (struct glfs *fs, const char *path, - const struct timespec times[2]) +pub_glfs_lutimens(struct glfs *fs, const char *path, + const struct timespec times[2]) { - int ret = -1; - int valid = 0; - struct iatt iatt = {0, }; + int ret = -1; + int valid = 0; + struct iatt iatt = { + 0, + }; - iatt.ia_atime = times[0].tv_sec; - iatt.ia_atime_nsec = times[0].tv_nsec; - iatt.ia_mtime = times[1].tv_sec; - iatt.ia_mtime_nsec = times[1].tv_nsec; + iatt.ia_atime = times[0].tv_sec; + iatt.ia_atime_nsec = times[0].tv_nsec; + iatt.ia_mtime = times[1].tv_sec; + iatt.ia_mtime_nsec = times[1].tv_nsec; - valid = GF_SET_ATTR_ATIME|GF_SET_ATTR_MTIME; + valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - ret = glfs_setattr (fs, path, &iatt, valid, 0); + ret = glfs_setattr(fs, path, &iatt, valid, 0); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lutimens, 3.4.0); - int -pub_glfs_futimens (struct glfs_fd *glfd, const struct timespec times[2]) +pub_glfs_futimens(struct glfs_fd *glfd, const struct timespec times[2]) { - int ret = -1; - int valid = 0; - struct iatt iatt = {0, }; + int ret = -1; + int valid = 0; + struct iatt iatt = { + 0, + }; - iatt.ia_atime = times[0].tv_sec; - iatt.ia_atime_nsec = times[0].tv_nsec; - iatt.ia_mtime = times[1].tv_sec; - iatt.ia_mtime_nsec = times[1].tv_nsec; + iatt.ia_atime = times[0].tv_sec; + iatt.ia_atime_nsec = times[0].tv_nsec; + iatt.ia_mtime = times[1].tv_sec; + iatt.ia_mtime_nsec = times[1].tv_nsec; - valid = GF_SET_ATTR_ATIME|GF_SET_ATTR_MTIME; + valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - ret = glfs_fsetattr (glfd, &iatt, valid); + ret = glfs_fsetattr(glfd, &iatt, valid); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_futimens, 3.4.0); - int -glfs_getxattr_process (void *value, size_t size, dict_t *xattr, - const char *name) -{ - data_t *data = NULL; - int ret = -1; - - data = dict_get (xattr, (char *)name); - if (!data) { - errno = ENODATA; - ret = -1; - goto out; - } - - ret = data->len; - if (!value || !size) - goto out; - - if (size < ret) { - ret = -1; - errno = ERANGE; - goto out; - } - - memcpy (value, data->data, ret); -out: - return ret; -} - - -ssize_t -glfs_getxattr_common (struct glfs *fs, const char *path, const char *name, - void *value, size_t size, int follow) +glfs_getxattr_process(void *value, size_t size, dict_t *xattr, const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - dict_t *xattr = NULL; - int reval = 0; + data_t *data = NULL; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + data = dict_get(xattr, (char *)name); + if (!data) { + errno = ENODATA; + ret = -1; + goto out; + } - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } + ret = data->len; + if (!value || !size) + goto out; - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } + if (size < ret) { + ret = -1; + errno = ERANGE; + goto out; + } + + memcpy(value, data->data, ret); +out: + return ret; +} - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +ssize_t +glfs_getxattr_common(struct glfs *fs, const char *path, const char *name, + void *value, size_t size, int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *xattr = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_getxattr (subvol, &loc, &xattr, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_getxattr(subvol, &loc, &xattr, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = glfs_getxattr_process (value, size, xattr, name); + ret = glfs_getxattr_process(value, size, xattr, name); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - ssize_t -pub_glfs_getxattr (struct glfs *fs, const char *path, const char *name, - void *value, size_t size) +pub_glfs_getxattr(struct glfs *fs, const char *path, const char *name, + void *value, size_t size) { - return glfs_getxattr_common (fs, path, name, value, size, 1); + return glfs_getxattr_common(fs, path, name, value, size, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_getxattr, 3.4.0); - ssize_t -pub_glfs_lgetxattr (struct glfs *fs, const char *path, const char *name, - void *value, size_t size) +pub_glfs_lgetxattr(struct glfs *fs, const char *path, const char *name, + void *value, size_t size) { - return glfs_getxattr_common (fs, path, name, value, size, 0); + return glfs_getxattr_common(fs, path, name, value, size, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lgetxattr, 3.4.0); - ssize_t -pub_glfs_fgetxattr (struct glfs_fd *glfd, const char *name, void *value, - size_t size) -{ - int ret = -1; - xlator_t *subvol = NULL; - dict_t *xattr = NULL; - fd_t *fd = NULL; +pub_glfs_fgetxattr(struct glfs_fd *glfd, const char *name, void *value, + size_t size) +{ + int ret = -1; + xlator_t *subvol = NULL; + dict_t *xattr = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = syncop_fgetxattr(subvol, fd, &xattr, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret) + goto out; + + ret = glfs_getxattr_process(value, size, xattr, name); +out: + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (xattr) + dict_unref(xattr); - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + glfs_subvol_done(glfd->fs, subvol); - GF_REF_GET (glfd); + __GLFS_EXIT_FS; - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = syncop_fgetxattr (subvol, fd, &xattr, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret) - goto out; - - ret = glfs_getxattr_process (value, size, xattr, name); -out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (xattr) - dict_unref (xattr); - - glfs_subvol_done (glfd->fs, subvol); - - __GLFS_EXIT_FS; - -invalid_fs: - return ret; -} - -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fgetxattr, 3.4.0); +invalid_fs: + return ret; +} +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fgetxattr, 3.4.0); int -glfs_listxattr_process (void *value, size_t size, dict_t *xattr) +glfs_listxattr_process(void *value, size_t size, dict_t *xattr) { - int ret = -1; + int ret = -1; - if (!xattr) - goto out; + if (!xattr) + goto out; - ret = dict_keys_join (NULL, 0, xattr, NULL); + ret = dict_keys_join(NULL, 0, xattr, NULL); - if (!value || !size) - goto out; + if (!value || !size) + goto out; - if (size < ret) { - ret = -1; - errno = ERANGE; - } else { - dict_keys_join (value, size, xattr, NULL); - } + if (size < ret) { + ret = -1; + errno = ERANGE; + } else { + dict_keys_join(value, size, xattr, NULL); + } out: - return ret; + return ret; } - ssize_t -glfs_listxattr_common (struct glfs *fs, const char *path, void *value, - size_t size, int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - dict_t *xattr = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_listxattr_common(struct glfs *fs, const char *path, void *value, + size_t size, int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *xattr = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_getxattr (subvol, &loc, &xattr, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_getxattr(subvol, &loc, &xattr, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = glfs_listxattr_process (value, size, xattr); + ret = glfs_listxattr_process(value, size, xattr); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - ssize_t -pub_glfs_listxattr (struct glfs *fs, const char *path, void *value, size_t size) +pub_glfs_listxattr(struct glfs *fs, const char *path, void *value, size_t size) { - return glfs_listxattr_common (fs, path, value, size, 1); + return glfs_listxattr_common(fs, path, value, size, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_listxattr, 3.4.0); - ssize_t -pub_glfs_llistxattr (struct glfs *fs, const char *path, void *value, size_t size) +pub_glfs_llistxattr(struct glfs *fs, const char *path, void *value, size_t size) { - return glfs_listxattr_common (fs, path, value, size, 0); + return glfs_listxattr_common(fs, path, value, size, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_llistxattr, 3.4.0); - ssize_t -pub_glfs_flistxattr (struct glfs_fd *glfd, void *value, size_t size) -{ - int ret = -1; - xlator_t *subvol = NULL; - dict_t *xattr = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = syncop_fgetxattr (subvol, fd, &xattr, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret) - goto out; - - ret = glfs_listxattr_process (value, size, xattr); +pub_glfs_flistxattr(struct glfs_fd *glfd, void *value, size_t size) +{ + int ret = -1; + xlator_t *subvol = NULL; + dict_t *xattr = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = syncop_fgetxattr(subvol, fd, &xattr, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret) + goto out; + + ret = glfs_listxattr_process(value, size, xattr); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (xattr) - dict_unref (xattr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_flistxattr, 3.4.0); int -glfs_setxattr_common (struct glfs *fs, const char *path, const char *name, - const void *value, size_t size, int flags, int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - dict_t *xattr = NULL; - int reval = 0; - void *value_cp = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_setxattr_common(struct glfs *fs, const char *path, const char *name, + const void *value, size_t size, int flags, int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *xattr = NULL; + int reval = 0; + void *value_cp = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - value_cp = gf_memdup (value, size); - GF_CHECK_ALLOC_AND_LOG (subvol->name, value_cp, ret, "Failed to" - " duplicate setxattr value", out); + value_cp = gf_memdup(value, size); + GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret, + "Failed to" + " duplicate setxattr value", + out); - xattr = dict_for_key_value (name, value_cp, size, _gf_false); - if (!xattr) { - GF_FREE (value_cp); - ret = -1; - errno = ENOMEM; - goto out; - } + xattr = dict_for_key_value(name, value_cp, size, _gf_false); + if (!xattr) { + GF_FREE(value_cp); + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_setxattr (subvol, &loc, xattr, flags, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_setxattr(subvol, &loc, xattr, flags, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); - if (xattr) - dict_unref (xattr); + loc_wipe(&loc); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -pub_glfs_setxattr (struct glfs *fs, const char *path, const char *name, - const void *value, size_t size, int flags) +pub_glfs_setxattr(struct glfs *fs, const char *path, const char *name, + const void *value, size_t size, int flags) { - return glfs_setxattr_common (fs, path, name, value, size, flags, 1); + return glfs_setxattr_common(fs, path, name, value, size, flags, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setxattr, 3.4.0); - int -pub_glfs_lsetxattr (struct glfs *fs, const char *path, const char *name, - const void *value, size_t size, int flags) +pub_glfs_lsetxattr(struct glfs *fs, const char *path, const char *name, + const void *value, size_t size, int flags) { - return glfs_setxattr_common (fs, path, name, value, size, flags, 0); + return glfs_setxattr_common(fs, path, name, value, size, flags, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lsetxattr, 3.4.0); - int -pub_glfs_fsetxattr (struct glfs_fd *glfd, const char *name, const void *value, - size_t size, int flags) -{ - int ret = -1; - xlator_t *subvol = NULL; - dict_t *xattr = NULL; - fd_t *fd = NULL; - void *value_cp = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - value_cp = gf_memdup (value, size); - GF_CHECK_ALLOC_AND_LOG (subvol->name, value_cp, ret, "Failed to" - " duplicate setxattr value", out); - - xattr = dict_for_key_value (name, value_cp, size, _gf_false); - if (!xattr) { - GF_FREE (value_cp); - ret = -1; - errno = ENOMEM; - goto out; - } - - ret = syncop_fsetxattr (subvol, fd, xattr, flags, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +pub_glfs_fsetxattr(struct glfs_fd *glfd, const char *name, const void *value, + size_t size, int flags) +{ + int ret = -1; + xlator_t *subvol = NULL; + dict_t *xattr = NULL; + fd_t *fd = NULL; + void *value_cp = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + value_cp = gf_memdup(value, size); + GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret, + "Failed to" + " duplicate setxattr value", + out); + + xattr = dict_for_key_value(name, value_cp, size, _gf_false); + if (!xattr) { + GF_FREE(value_cp); + ret = -1; + errno = ENOMEM; + goto out; + } + + ret = syncop_fsetxattr(subvol, fd, xattr, flags, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsetxattr, 3.4.0); - int -glfs_removexattr_common (struct glfs *fs, const char *path, const char *name, - int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_removexattr_common(struct glfs *fs, const char *path, const char *name, + int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_removexattr (subvol, &loc, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_removexattr(subvol, &loc, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -pub_glfs_removexattr (struct glfs *fs, const char *path, const char *name) +pub_glfs_removexattr(struct glfs *fs, const char *path, const char *name) { - return glfs_removexattr_common (fs, path, name, 1); + return glfs_removexattr_common(fs, path, name, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_removexattr, 3.4.0); - int -pub_glfs_lremovexattr (struct glfs *fs, const char *path, const char *name) +pub_glfs_lremovexattr(struct glfs *fs, const char *path, const char *name) { - return glfs_removexattr_common (fs, path, name, 0); + return glfs_removexattr_common(fs, path, name, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lremovexattr, 3.4.0); - int -pub_glfs_fremovexattr (struct glfs_fd *glfd, const char *name) +pub_glfs_fremovexattr(struct glfs_fd *glfd, const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } - ret = syncop_fremovexattr (subvol, fd, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_fremovexattr(subvol, fd, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fremovexattr, 3.4.0); - int -pub_glfs_fallocate (struct glfs_fd *glfd, int keep_size, off_t offset, size_t len) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_fallocate (subvol, fd, keep_size, offset, len, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); +pub_glfs_fallocate(struct glfs_fd *glfd, int keep_size, off_t offset, + size_t len) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_fallocate(subvol, fd, keep_size, offset, len, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref(fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fallocate, 3.5.0); - int -pub_glfs_discard (struct glfs_fd *glfd, off_t offset, size_t len) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_discard (subvol, fd, offset, len, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); +pub_glfs_discard(struct glfs_fd *glfd, off_t offset, size_t len) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_discard(subvol, fd, offset, len, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref(fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_discard, 3.5.0); - int -pub_glfs_zerofill (struct glfs_fd *glfd, off_t offset, off_t len) +pub_glfs_zerofill(struct glfs_fd *glfd, off_t offset, off_t len) { - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); - ret = syncop_zerofill (subvol, fd, offset, len, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_zerofill(subvol, fd, offset, len, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref(fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_zerofill, 3.5.0); - int -pub_glfs_chdir (struct glfs *fs, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_chdir(struct glfs *fs, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (!IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } + if (!IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } - glfs_cwd_set (fs, loc.inode); + glfs_cwd_set(fs, loc.inode); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chdir, 3.4.0); - int -pub_glfs_fchdir (struct glfs_fd *glfd) -{ - int ret = -1; - inode_t *inode = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - inode = fd->inode; - - if (!IA_ISDIR (inode->ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } - - glfs_cwd_set (glfd->fs, inode); - ret = 0; +pub_glfs_fchdir(struct glfs_fd *glfd) +{ + int ret = -1; + inode_t *inode = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + inode = fd->inode; + + if (!IA_ISDIR(inode->ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } + + glfs_cwd_set(glfd->fs, inode); + ret = 0; out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchdir, 3.4.0); @@ -4626,680 +4679,673 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchdir, 3.4.0); static gf_boolean_t warn_realpath = _gf_true; /* log once */ static char * -glfs_realpath_common (struct glfs *fs, const char *path, char *resolved_path, - gf_boolean_t warn_deprecated) -{ - int ret = -1; - char *retpath = NULL; - char *allocpath = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - if (resolved_path) - retpath = resolved_path; - else if (warn_deprecated) { - retpath = allocpath = malloc (PATH_MAX + 1); - if (warn_realpath) { - warn_realpath = _gf_false; - gf_log (THIS->name, GF_LOG_WARNING, "this application " - "is compiled against an old version of " - "libgfapi, it should use glfs_free() to " - "release the path returned by " - "glfs_realpath()"); - } - } else { - retpath = allocpath = GLFS_CALLOC (1, PATH_MAX + 1, NULL, - glfs_mt_realpath_t); +glfs_realpath_common(struct glfs *fs, const char *path, char *resolved_path, + gf_boolean_t warn_deprecated) +{ + int ret = -1; + char *retpath = NULL; + char *allocpath = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (resolved_path) + retpath = resolved_path; + else if (warn_deprecated) { + retpath = allocpath = malloc(PATH_MAX + 1); + if (warn_realpath) { + warn_realpath = _gf_false; + gf_log(THIS->name, GF_LOG_WARNING, + "this application " + "is compiled against an old version of " + "libgfapi, it should use glfs_free() to " + "release the path returned by " + "glfs_realpath()"); } - - if (!retpath) { - ret = -1; - errno = ENOMEM; - goto out; - } - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + } else { + retpath = allocpath = GLFS_CALLOC(1, PATH_MAX + 1, NULL, + glfs_mt_realpath_t); + } + + if (!retpath) { + ret = -1; + errno = ENOMEM; + goto out; + } + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (loc.path) { - snprintf (retpath, PATH_MAX, "%s", loc.path); - } + if (loc.path) { + snprintf(retpath, PATH_MAX, "%s", loc.path); + } out: - loc_wipe (&loc); + loc_wipe(&loc); - if (ret == -1) { - if (warn_deprecated && allocpath) - free (allocpath); - else if (allocpath) - GLFS_FREE (allocpath); - retpath = NULL; - } + if (ret == -1) { + if (warn_deprecated && allocpath) + free(allocpath); + else if (allocpath) + GLFS_FREE(allocpath); + retpath = NULL; + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return retpath; + return retpath; } - char * -pub_glfs_realpath34 (struct glfs *fs, const char *path, char *resolved_path) +pub_glfs_realpath34(struct glfs *fs, const char *path, char *resolved_path) { - return glfs_realpath_common (fs, path, resolved_path, _gf_true); + return glfs_realpath_common(fs, path, resolved_path, _gf_true); } GFAPI_SYMVER_PUBLIC(glfs_realpath34, glfs_realpath, 3.4.0); char * -pub_glfs_realpath (struct glfs *fs, const char *path, char *resolved_path) +pub_glfs_realpath(struct glfs *fs, const char *path, char *resolved_path) { - return glfs_realpath_common (fs, path, resolved_path, _gf_false); + return glfs_realpath_common(fs, path, resolved_path, _gf_false); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_realpath, 3.7.17); - char * -pub_glfs_getcwd (struct glfs *fs, char *buf, size_t n) -{ - int ret = -1; - inode_t *inode = NULL; - char *path = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - if (!buf || n < 2) { - ret = -1; - errno = EINVAL; - goto out; - } - - inode = glfs_cwd_get (fs); - - if (!inode) { - strncpy (buf, "/", n); - ret = 0; - goto out; - } - - ret = inode_path (inode, 0, &path); - if (n <= ret) { - ret = -1; - errno = ERANGE; - goto out; - } - - strncpy (buf, path, n); - ret = 0; +pub_glfs_getcwd(struct glfs *fs, char *buf, size_t n) +{ + int ret = -1; + inode_t *inode = NULL; + char *path = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (!buf || n < 2) { + ret = -1; + errno = EINVAL; + goto out; + } + + inode = glfs_cwd_get(fs); + + if (!inode) { + strncpy(buf, "/", n); + ret = 0; + goto out; + } + + ret = inode_path(inode, 0, &path); + if (n <= ret) { + ret = -1; + errno = ERANGE; + goto out; + } + + strncpy(buf, path, n); + ret = 0; out: - GF_FREE (path); + GF_FREE(path); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - if (ret < 0) - return NULL; + if (ret < 0) + return NULL; - return buf; + return buf; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_getcwd, 3.4.0); - static void -gf_flock_to_flock (struct gf_flock *gf_flock, struct flock *flock) +gf_flock_to_flock(struct gf_flock *gf_flock, struct flock *flock) { - flock->l_type = gf_flock->l_type; - flock->l_whence = gf_flock->l_whence; - flock->l_start = gf_flock->l_start; - flock->l_len = gf_flock->l_len; - flock->l_pid = gf_flock->l_pid; + flock->l_type = gf_flock->l_type; + flock->l_whence = gf_flock->l_whence; + flock->l_start = gf_flock->l_start; + flock->l_len = gf_flock->l_len; + flock->l_pid = gf_flock->l_pid; } - static void -gf_flock_from_flock (struct gf_flock *gf_flock, struct flock *flock) +gf_flock_from_flock(struct gf_flock *gf_flock, struct flock *flock) { - gf_flock->l_type = flock->l_type; - gf_flock->l_whence = flock->l_whence; - gf_flock->l_start = flock->l_start; - gf_flock->l_len = flock->l_len; - gf_flock->l_pid = flock->l_pid; + gf_flock->l_type = flock->l_type; + gf_flock->l_whence = flock->l_whence; + gf_flock->l_start = flock->l_start; + gf_flock->l_len = flock->l_len; + gf_flock->l_pid = flock->l_pid; } static int -glfs_lock_common (struct glfs_fd *glfd, int cmd, struct flock *flock, - dict_t *xdata) -{ - int ret = -1; - xlator_t *subvol = NULL; - struct gf_flock gf_flock = {0, }; - struct gf_flock saved_flock = {0, }; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); +glfs_lock_common(struct glfs_fd *glfd, int cmd, struct flock *flock, + dict_t *xdata) +{ + int ret = -1; + xlator_t *subvol = NULL; + struct gf_flock gf_flock = { + 0, + }; + struct gf_flock saved_flock = { + 0, + }; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + if (!flock) { + errno = EINVAL; + goto out; + } + + GF_REF_GET(glfd); + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + /* Generate glusterfs flock structure from client flock + * structure to be processed by server */ + gf_flock_from_flock(&gf_flock, flock); + + /* Keep another copy of flock for split/merge of locks + * at client side */ + gf_flock_from_flock(&saved_flock, flock); + + if (glfd->lk_owner.len != 0) { + ret = syncopctx_setfslkowner(&glfd->lk_owner); - if (!flock) { - errno = EINVAL; - goto out; - } - - GF_REF_GET (glfd); - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - /* Generate glusterfs flock structure from client flock - * structure to be processed by server */ - gf_flock_from_flock (&gf_flock, flock); + if (ret) + goto out; + } - /* Keep another copy of flock for split/merge of locks - * at client side */ - gf_flock_from_flock (&saved_flock, flock); + ret = get_fop_attr_thrd_key(&xdata); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); - if (glfd->lk_owner.len != 0) { - ret = syncopctx_setfslkowner (&glfd->lk_owner); + ret = syncop_lk(subvol, fd, cmd, &gf_flock, xdata, NULL); + DECODE_SYNCOP_ERR(ret); - if (ret) - goto out; - } + /* Convert back from gf_flock to flock as expected by application */ + gf_flock_to_flock(&gf_flock, flock); - ret = get_fop_attr_thrd_key (&xdata); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_lk (subvol, fd, cmd, &gf_flock, xdata, NULL); - DECODE_SYNCOP_ERR (ret); - - /* Convert back from gf_flock to flock as expected by application */ - gf_flock_to_flock (&gf_flock, flock); - - if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) { - ret = fd_lk_insert_and_merge (fd, cmd, &saved_flock); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, - API_MSG_LOCK_INSERT_MERGE_FAILED, - "Lock insertion and splitting/merging failed " - "on gfid %s", uuid_utoa (fd->inode->gfid)); - ret = 0; - } + if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) { + ret = fd_lk_insert_and_merge(fd, cmd, &saved_flock); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, + API_MSG_LOCK_INSERT_MERGE_FAILED, + "Lock insertion and splitting/merging failed " + "on gfid %s", + uuid_utoa(fd->inode->gfid)); + ret = 0; } + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_file_lock (struct glfs_fd *glfd, int cmd, struct flock *flock, - glfs_lock_mode_t lk_mode) -{ - int ret = -1; - dict_t *xdata_in = NULL; - - if (lk_mode == GLFS_LK_MANDATORY) { - /* Create a new dictionary */ - xdata_in = dict_new (); - if (xdata_in == NULL) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_file_lock(struct glfs_fd *glfd, int cmd, struct flock *flock, + glfs_lock_mode_t lk_mode) +{ + int ret = -1; + dict_t *xdata_in = NULL; + + if (lk_mode == GLFS_LK_MANDATORY) { + /* Create a new dictionary */ + xdata_in = dict_new(); + if (xdata_in == NULL) { + ret = -1; + errno = ENOMEM; + goto out; + } - /* Set GF_LK_MANDATORY internally within dictionary to map - * GLFS_LK_MANDATORY */ - ret = dict_set_uint32 (xdata_in, GF_LOCK_MODE, GF_LK_MANDATORY); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, - API_MSG_SETTING_LOCK_TYPE_FAILED, - "Setting lock type failed"); - ret = -1; - errno = ENOMEM; - goto out; - } + /* Set GF_LK_MANDATORY internally within dictionary to map + * GLFS_LK_MANDATORY */ + ret = dict_set_uint32(xdata_in, GF_LOCK_MODE, GF_LK_MANDATORY); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, + API_MSG_SETTING_LOCK_TYPE_FAILED, + "Setting lock type failed"); + ret = -1; + errno = ENOMEM; + goto out; } + } - ret = glfs_lock_common (glfd, cmd, flock, xdata_in); + ret = glfs_lock_common(glfd, cmd, flock, xdata_in); out: - if (xdata_in) - dict_unref (xdata_in); + if (xdata_in) + dict_unref(xdata_in); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_file_lock, 4.0.0); int -pub_glfs_posix_lock (struct glfs_fd *glfd, int cmd, struct flock *flock) +pub_glfs_posix_lock(struct glfs_fd *glfd, int cmd, struct flock *flock) { - return glfs_lock_common (glfd, cmd, flock, NULL); + return glfs_lock_common(glfd, cmd, flock, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_posix_lock, 3.4.0); int -pub_glfs_fd_set_lkowner (struct glfs_fd *glfd, void *data, int len) +pub_glfs_fd_set_lkowner(struct glfs_fd *glfd, void *data, int len) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - if (!GF_REF_GET (glfd)) { - goto invalid_fs; - } + if (!GF_REF_GET(glfd)) { + goto invalid_fs; + } - GF_VALIDATE_OR_GOTO (THIS->name, data, out); + GF_VALIDATE_OR_GOTO(THIS->name, data, out); - if ((len <= 0) || (len > GFAPI_MAX_LOCK_OWNER_LEN)) { - errno = EINVAL; - gf_msg (THIS->name, GF_LOG_ERROR, errno, - LG_MSG_INVALID_ARG, - "Invalid lk_owner len (%d)", len); - goto out; - } + if ((len <= 0) || (len > GFAPI_MAX_LOCK_OWNER_LEN)) { + errno = EINVAL; + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "Invalid lk_owner len (%d)", len); + goto out; + } - glfd->lk_owner.len = len; + glfd->lk_owner.len = len; - memcpy (glfd->lk_owner.data, data, len); + memcpy(glfd->lk_owner.data, data, len); - ret = 0; + ret = 0; out: - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fd_set_lkowner, 3.10.7); struct glfs_fd * -pub_glfs_dup (struct glfs_fd *glfd) -{ - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct glfs_fd *dupfd = NULL; - struct glfs *fs = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - fs = glfd->fs; - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - dupfd = glfs_fd_new (fs); - if (!dupfd) { - errno = ENOMEM; - goto out; - } - - dupfd->fd = fd_ref (fd); - dupfd->state = glfd->state; +pub_glfs_dup(struct glfs_fd *glfd) +{ + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct glfs_fd *dupfd = NULL; + struct glfs *fs = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + fs = glfd->fs; + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + dupfd = glfs_fd_new(fs); + if (!dupfd) { + errno = ENOMEM; + goto out; + } + + dupfd->fd = fd_ref(fd); + dupfd->state = glfd->state; out: - if (fd) - fd_unref (fd); - if (dupfd) - glfs_fd_bind (dupfd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (dupfd) + glfs_fd_bind(dupfd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return dupfd; + return dupfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_dup, 3.4.0); static void -glfs_enqueue_upcall_data (struct glfs *fs, struct gf_upcall *upcall_data) +glfs_enqueue_upcall_data(struct glfs *fs, struct gf_upcall *upcall_data) { - int ret = -1; - upcall_entry *u_list = NULL; + int ret = -1; + upcall_entry *u_list = NULL; - if (!fs || !upcall_data) - goto out; + if (!fs || !upcall_data) + goto out; - u_list = GF_CALLOC (1, sizeof(*u_list), - glfs_mt_upcall_entry_t); + u_list = GF_CALLOC(1, sizeof(*u_list), glfs_mt_upcall_entry_t); - if (!u_list) { - gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + if (!u_list) { + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - INIT_LIST_HEAD (&u_list->upcall_list); + INIT_LIST_HEAD(&u_list->upcall_list); - gf_uuid_copy (u_list->upcall_data.gfid, upcall_data->gfid); - u_list->upcall_data.event_type = upcall_data->event_type; + gf_uuid_copy(u_list->upcall_data.gfid, upcall_data->gfid); + u_list->upcall_data.event_type = upcall_data->event_type; - switch (upcall_data->event_type) { + switch (upcall_data->event_type) { case GF_UPCALL_CACHE_INVALIDATION: - ret = glfs_get_upcall_cache_invalidation (&u_list->upcall_data, - upcall_data); - break; + ret = glfs_get_upcall_cache_invalidation(&u_list->upcall_data, + upcall_data); + break; case GF_UPCALL_RECALL_LEASE: - ret = glfs_get_upcall_lease (&u_list->upcall_data, - upcall_data); - break; + ret = glfs_get_upcall_lease(&u_list->upcall_data, upcall_data); + break; default: - break; - } + break; + } - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_INVALID_ENTRY, - "Upcall entry validation failed."); - goto out; - } + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY, + "Upcall entry validation failed."); + goto out; + } - pthread_mutex_lock (&fs->upcall_list_mutex); - { - list_add_tail (&u_list->upcall_list, - &fs->upcall_list); - } - pthread_mutex_unlock (&fs->upcall_list_mutex); + pthread_mutex_lock(&fs->upcall_list_mutex); + { + list_add_tail(&u_list->upcall_list, &fs->upcall_list); + } + pthread_mutex_unlock(&fs->upcall_list_mutex); - ret = 0; + ret = 0; out: - if (ret && u_list) { - GF_FREE (u_list->upcall_data.data); - GF_FREE(u_list); - } + if (ret && u_list) { + GF_FREE(u_list->upcall_data.data); + GF_FREE(u_list); + } } static void -glfs_free_upcall_lease (void *to_free) +glfs_free_upcall_lease(void *to_free) { - struct glfs_upcall_lease *arg = to_free; + struct glfs_upcall_lease *arg = to_free; - if (!arg) - return; + if (!arg) + return; - if (arg->object) - glfs_h_close (arg->object); + if (arg->object) + glfs_h_close(arg->object); - GF_FREE (arg); + GF_FREE(arg); } int -glfs_recall_lease_fd (struct glfs *fs, - struct gf_upcall *up_data) -{ - struct gf_upcall_recall_lease *recall_lease = NULL; - xlator_t *subvol = NULL; - int ret = 0; - inode_t *inode = NULL; - struct glfs_fd *glfd = NULL; - struct glfs_fd *tmp = NULL; - struct list_head glfd_list = { 0, }; - fd_t *fd = NULL; - uint64_t value = 0; - struct glfs_lease lease = {0, }; - - GF_VALIDATE_OR_GOTO ("gfapi", up_data, out); - GF_VALIDATE_OR_GOTO ("gfapi", fs, out); - - recall_lease = up_data->data; - GF_VALIDATE_OR_GOTO ("gfapi", recall_lease, out); - - INIT_LIST_HEAD(&glfd_list); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - gf_msg_debug (THIS->name, 0, - "Recall lease received for gfid:%s", - uuid_utoa(up_data->gfid)); - - - inode = inode_find (subvol->itable, up_data->gfid); - if (!inode) { - ret = -1; - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_INODE_FIND_FAILED, - "Unable to find inode entry for gfid:%s graph id:%d", - uuid_utoa(up_data->gfid), subvol->graph->id); - goto out; +glfs_recall_lease_fd(struct glfs *fs, struct gf_upcall *up_data) +{ + struct gf_upcall_recall_lease *recall_lease = NULL; + xlator_t *subvol = NULL; + int ret = 0; + inode_t *inode = NULL; + struct glfs_fd *glfd = NULL; + struct glfs_fd *tmp = NULL; + struct list_head glfd_list = { + 0, + }; + fd_t *fd = NULL; + uint64_t value = 0; + struct glfs_lease lease = { + 0, + }; + + GF_VALIDATE_OR_GOTO("gfapi", up_data, out); + GF_VALIDATE_OR_GOTO("gfapi", fs, out); + + recall_lease = up_data->data; + GF_VALIDATE_OR_GOTO("gfapi", recall_lease, out); + + INIT_LIST_HEAD(&glfd_list); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + gf_msg_debug(THIS->name, 0, "Recall lease received for gfid:%s", + uuid_utoa(up_data->gfid)); + + inode = inode_find(subvol->itable, up_data->gfid); + if (!inode) { + ret = -1; + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INODE_FIND_FAILED, + "Unable to find inode entry for gfid:%s graph id:%d", + uuid_utoa(up_data->gfid), subvol->graph->id); + goto out; + } + + LOCK(&inode->lock); + { + list_for_each_entry(fd, &inode->fd_list, inode_list) + { + ret = fd_ctx_get(fd, subvol, &value); + glfd = (struct glfs_fd *)value; + if (glfd) { + gf_msg_trace(THIS->name, 0, "glfd (%p) has held lease", glfd); + GF_REF_GET(glfd); + list_add_tail(&glfd->list, &glfd_list); + } } + } + UNLOCK(&inode->lock); - LOCK (&inode->lock); + list_for_each_entry_safe(glfd, tmp, &glfd_list, list) + { + LOCK(&glfd->lock); { - list_for_each_entry (fd, &inode->fd_list, inode_list) { - ret = fd_ctx_get (fd, subvol, &value); - glfd = (struct glfs_fd *) value; - if (glfd) { - gf_msg_trace (THIS->name, 0, - "glfd (%p) has held lease", glfd); - GF_REF_GET (glfd); - list_add_tail (&glfd->list, &glfd_list); - } - } + if (glfd->state != GLFD_CLOSE) { + gf_msg_trace(THIS->name, 0, + "glfd (%p) has held lease, " + "calling recall cbk", + glfd); + glfd->cbk(lease, glfd->cookie); + } } - UNLOCK (&inode->lock); - - list_for_each_entry_safe (glfd, tmp, &glfd_list, list) { - LOCK (&glfd->lock); - { - if (glfd->state != GLFD_CLOSE) { - gf_msg_trace (THIS->name, 0, - "glfd (%p) has held lease, " - "calling recall cbk", glfd); - glfd->cbk (lease, glfd->cookie); - } - } - UNLOCK (&glfd->lock); + UNLOCK(&glfd->lock); - list_del_init (&glfd->list); - GF_REF_PUT (glfd); - } + list_del_init(&glfd->list); + GF_REF_PUT(glfd); + } out: - return ret; + return ret; } int -glfs_recall_lease_upcall (struct glfs *fs, - struct glfs_upcall *up_arg, - struct gf_upcall *up_data) -{ - struct gf_upcall_recall_lease *recall_lease = NULL; - struct glfs_object *object = NULL; - xlator_t *subvol = NULL; - int ret = -1; - struct glfs_upcall_lease *up_lease_arg = NULL; - - GF_VALIDATE_OR_GOTO ("gfapi", up_data, out); - GF_VALIDATE_OR_GOTO ("gfapi", fs, out); - - recall_lease = up_data->data; - GF_VALIDATE_OR_GOTO ("gfapi", recall_lease, out); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } - - gf_msg_debug (THIS->name, 0, - "Recall lease received for gfid:%s", - uuid_utoa(up_data->gfid)); - - object = glfs_h_find_handle (fs, up_data->gfid, - GFAPI_HANDLE_LENGTH); - if (!object) { - /* The reason handle creation will fail is because we - * couldn't find the inode in the gfapi inode table. - * - * But since application would have taken inode_ref, the - * only case when this can happen is when it has closed - * the handle and hence will no more be interested in - * the upcall for this particular gfid. - */ - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_CREATE_HANDLE_FAILED, - "handle creation of %s failed", - uuid_utoa (up_data->gfid)); - errno = ESTALE; - goto out; - } - - up_lease_arg = GF_CALLOC (1, sizeof (struct glfs_upcall_lease), - glfs_mt_upcall_inode_t); - up_lease_arg->object = object; +glfs_recall_lease_upcall(struct glfs *fs, struct glfs_upcall *up_arg, + struct gf_upcall *up_data) +{ + struct gf_upcall_recall_lease *recall_lease = NULL; + struct glfs_object *object = NULL; + xlator_t *subvol = NULL; + int ret = -1; + struct glfs_upcall_lease *up_lease_arg = NULL; + + GF_VALIDATE_OR_GOTO("gfapi", up_data, out); + GF_VALIDATE_OR_GOTO("gfapi", fs, out); + + recall_lease = up_data->data; + GF_VALIDATE_OR_GOTO("gfapi", recall_lease, out); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } + + gf_msg_debug(THIS->name, 0, "Recall lease received for gfid:%s", + uuid_utoa(up_data->gfid)); + + object = glfs_h_find_handle(fs, up_data->gfid, GFAPI_HANDLE_LENGTH); + if (!object) { + /* The reason handle creation will fail is because we + * couldn't find the inode in the gfapi inode table. + * + * But since application would have taken inode_ref, the + * only case when this can happen is when it has closed + * the handle and hence will no more be interested in + * the upcall for this particular gfid. + */ + gf_msg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_CREATE_HANDLE_FAILED, + "handle creation of %s failed", uuid_utoa(up_data->gfid)); + errno = ESTALE; + goto out; + } - GF_VALIDATE_OR_GOTO ("glfs_recall_lease", - up_lease_arg, out); + up_lease_arg = GF_CALLOC(1, sizeof(struct glfs_upcall_lease), + glfs_mt_upcall_inode_t); + up_lease_arg->object = object; + GF_VALIDATE_OR_GOTO("glfs_recall_lease", up_lease_arg, out); - up_lease_arg->lease_type = recall_lease->lease_type; + up_lease_arg->lease_type = recall_lease->lease_type; - up_arg->reason = GF_UPCALL_RECALL_LEASE; - up_arg->event = up_lease_arg; - up_arg->free_event = glfs_free_upcall_lease; + up_arg->reason = GF_UPCALL_RECALL_LEASE; + up_arg->event = up_lease_arg; + up_arg->free_event = glfs_free_upcall_lease; - ret = 0; + ret = 0; out: - if (ret) { - /* Close p_object and oldp_object as well if being referenced.*/ - if (object) - glfs_h_close (object); + if (ret) { + /* Close p_object and oldp_object as well if being referenced.*/ + if (object) + glfs_h_close(object); - /* Set reason to prevent applications from using ->event */ - up_arg->reason = GF_UPCALL_EVENT_NULL; - } - return ret; + /* Set reason to prevent applications from using ->event */ + up_arg->reason = GF_UPCALL_EVENT_NULL; + } + return ret; } static void -glfs_cbk_upcall_data (struct glfs *fs, struct gf_upcall *upcall_data) +glfs_cbk_upcall_data(struct glfs *fs, struct gf_upcall *upcall_data) { - int ret = -1; - struct glfs_upcall *up_arg = NULL; + int ret = -1; + struct glfs_upcall *up_arg = NULL; - if (!fs || !upcall_data) - goto out; + if (!fs || !upcall_data) + goto out; - if (!(fs->upcall_events & upcall_data->event_type)) { - /* ignore events which application hasn't registered*/ - goto out; - } + if (!(fs->upcall_events & upcall_data->event_type)) { + /* ignore events which application hasn't registered*/ + goto out; + } - up_arg = GLFS_CALLOC (1, sizeof (struct gf_upcall), - glfs_release_upcall, - glfs_mt_upcall_entry_t); - if (!up_arg) { - gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + up_arg = GLFS_CALLOC(1, sizeof(struct gf_upcall), glfs_release_upcall, + glfs_mt_upcall_entry_t); + if (!up_arg) { + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - switch (upcall_data->event_type) { + switch (upcall_data->event_type) { case GF_UPCALL_CACHE_INVALIDATION: - ret = glfs_h_poll_cache_invalidation (fs, up_arg, upcall_data); - break; + ret = glfs_h_poll_cache_invalidation(fs, up_arg, upcall_data); + break; case GF_UPCALL_RECALL_LEASE: - ret = glfs_recall_lease_upcall (fs, up_arg, upcall_data); - break; + ret = glfs_recall_lease_upcall(fs, up_arg, upcall_data); + break; default: - errno = EINVAL; - } - - if (!ret && (up_arg->reason != GLFS_UPCALL_EVENT_NULL)) { - /* It could so happen that the file which got - * upcall notification may have got deleted by - * the same client. In such cases up_arg->reason - * is set to GLFS_UPCALL_EVENT_NULL. No need to - * send upcall then */ - (fs->up_cbk) (up_arg, fs->up_data); - } else if (up_arg->reason == GLFS_UPCALL_EVENT_NULL) { - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_INVALID_ENTRY, - "Upcall_EVENT_NULL received. Skipping it."); - goto out; - } else { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_INVALID_ENTRY, - "Upcall entry validation failed."); - goto out; - } - - /* application takes care of calling glfs_free on up_arg post - * their processing */ - ret = 0; + errno = EINVAL; + } + + if (!ret && (up_arg->reason != GLFS_UPCALL_EVENT_NULL)) { + /* It could so happen that the file which got + * upcall notification may have got deleted by + * the same client. In such cases up_arg->reason + * is set to GLFS_UPCALL_EVENT_NULL. No need to + * send upcall then */ + (fs->up_cbk)(up_arg, fs->up_data); + } else if (up_arg->reason == GLFS_UPCALL_EVENT_NULL) { + gf_msg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_INVALID_ENTRY, + "Upcall_EVENT_NULL received. Skipping it."); + goto out; + } else { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY, + "Upcall entry validation failed."); + goto out; + } + + /* application takes care of calling glfs_free on up_arg post + * their processing */ + ret = 0; out: - if (ret && up_arg) { - GLFS_FREE (up_arg); - } + if (ret && up_arg) { + GLFS_FREE(up_arg); + } - return; + return; } /* @@ -5317,251 +5363,254 @@ out: * to be read/polled by the applications. */ void -priv_glfs_process_upcall_event (struct glfs *fs, void *data) +priv_glfs_process_upcall_event(struct glfs *fs, void *data) { - glusterfs_ctx_t *ctx = NULL; - struct gf_upcall *upcall_data = NULL; + glusterfs_ctx_t *ctx = NULL; + struct gf_upcall *upcall_data = NULL; - DECLARE_OLD_THIS; + DECLARE_OLD_THIS; - gf_msg_debug (THIS->name, 0, - "Upcall gfapi callback is called"); + gf_msg_debug(THIS->name, 0, "Upcall gfapi callback is called"); - __GLFS_ENTRY_VALIDATE_FS (fs, err); + __GLFS_ENTRY_VALIDATE_FS(fs, err); - if (!data) - goto out; + if (!data) + goto out; - /* Unlike in I/O path, "glfs_fini" would not have freed - * 'fs' by the time we take lock as it waits for all epoll - * threads to exit including this - */ - pthread_mutex_lock (&fs->mutex); - { - ctx = fs->ctx; - - /* if we're not interested in upcalls (anymore), skip them */ - if (ctx->cleanup_started || !fs->cache_upcalls) { - pthread_mutex_unlock (&fs->mutex); - goto out; - } + /* Unlike in I/O path, "glfs_fini" would not have freed + * 'fs' by the time we take lock as it waits for all epoll + * threads to exit including this + */ + pthread_mutex_lock(&fs->mutex); + { + ctx = fs->ctx; - fs->pin_refcnt++; + /* if we're not interested in upcalls (anymore), skip them */ + if (ctx->cleanup_started || !fs->cache_upcalls) { + pthread_mutex_unlock(&fs->mutex); + goto out; } - pthread_mutex_unlock (&fs->mutex); - upcall_data = (struct gf_upcall *)data; - - gf_msg_trace (THIS->name, 0, "Upcall gfapi gfid = %s" , - (char *)(upcall_data->gfid)); - - /* * - * TODO: RECALL LEASE for each glfd - * - * In case of RECALL_LEASE, we could associate separate - * cbk function for each glfd either by - * - extending pub_glfs_lease to accept new args (recall_cbk_fn, cookie) - * - or by defining new API "glfs_register_recall_cbk_fn (glfd, recall_cbk_fn, cookie) - * . In such cases, flag it and instead of calling below upcall functions, define - * a new one to go through the glfd list and invoke each of theirs recall_cbk_fn. - * */ - - if (fs->up_cbk) { /* upcall cbk registered */ - (void) glfs_cbk_upcall_data (fs, upcall_data); - } else { - (void) glfs_enqueue_upcall_data (fs, upcall_data); - } - - pthread_mutex_lock (&fs->mutex); - { - fs->pin_refcnt--; - } - pthread_mutex_unlock (&fs->mutex); + fs->pin_refcnt++; + } + pthread_mutex_unlock(&fs->mutex); + + upcall_data = (struct gf_upcall *)data; + + gf_msg_trace(THIS->name, 0, "Upcall gfapi gfid = %s", + (char *)(upcall_data->gfid)); + + /* * + * TODO: RECALL LEASE for each glfd + * + * In case of RECALL_LEASE, we could associate separate + * cbk function for each glfd either by + * - extending pub_glfs_lease to accept new args (recall_cbk_fn, cookie) + * - or by defining new API "glfs_register_recall_cbk_fn (glfd, + * recall_cbk_fn, cookie) . In such cases, flag it and instead of calling + * below upcall functions, define a new one to go through the glfd list and + * invoke each of theirs recall_cbk_fn. + * */ + + if (fs->up_cbk) { /* upcall cbk registered */ + (void)glfs_cbk_upcall_data(fs, upcall_data); + } else { + (void)glfs_enqueue_upcall_data(fs, upcall_data); + } + + pthread_mutex_lock(&fs->mutex); + { + fs->pin_refcnt--; + } + pthread_mutex_unlock(&fs->mutex); out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; err: - return; + return; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_process_upcall_event, 3.7.0); ssize_t -glfs_anonymous_pwritev (struct glfs *fs, struct glfs_object *object, - const struct iovec *iovec, int iovcnt, - off_t offset, int flags) -{ - xlator_t *subvol = NULL; - struct iobref *iobref = NULL; - struct iobuf *iobuf = NULL; - struct iovec iov = {0, }; - inode_t *inode = NULL; - fd_t *fd = NULL; - int ret = -1; - size_t size = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - ret = -1; - errno = ESTALE; - goto out; - } - - fd = fd_anonymous (inode); - if (!fd) { - ret = -1; - gf_msg ("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, - "Allocating anonymous fd failed"); - errno = ENOMEM; - goto out; - } - - size = iov_length (iovec, iovcnt); - - iobuf = iobuf_get2 (subvol->ctx->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, iovcnt); - - iov.iov_base = iobuf_ptr (iobuf); - iov.iov_len = size; - - /* TODO : set leaseid */ - ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, - NULL, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - iobuf_unref (iobuf); - iobref_unref (iobref); - - if (ret <= 0) - goto out; +glfs_anonymous_pwritev(struct glfs *fs, struct glfs_object *object, + const struct iovec *iovec, int iovcnt, off_t offset, + int flags) +{ + xlator_t *subvol = NULL; + struct iobref *iobref = NULL; + struct iobuf *iobuf = NULL; + struct iovec iov = { + 0, + }; + inode_t *inode = NULL; + fd_t *fd = NULL; + int ret = -1; + size_t size = -1; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + ret = -1; + errno = ESTALE; + goto out; + } + + fd = fd_anonymous(inode); + if (!fd) { + ret = -1; + gf_msg("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, + "Allocating anonymous fd failed"); + errno = ENOMEM; + goto out; + } + + size = iov_length(iovec, iovcnt); + + iobuf = iobuf_get2(subvol->ctx->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, iovcnt); + + iov.iov_base = iobuf_ptr(iobuf); + iov.iov_len = size; + + /* TODO : set leaseid */ + ret = syncop_writev(subvol, fd, &iov, 1, offset, iobref, flags, NULL, NULL, + NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + iobuf_unref(iobuf); + iobref_unref(iobref); + + if (ret <= 0) + goto out; out: - if (fd) - fd_unref(fd); + if (fd) + fd_unref(fd); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } ssize_t -glfs_anonymous_preadv (struct glfs *fs, struct glfs_object *object, - const struct iovec *iovec, int iovcnt, - off_t offset, int flags) -{ - xlator_t *subvol = NULL; - struct iovec *iov = NULL; - struct iobref *iobref = NULL; - inode_t *inode = NULL; - fd_t *fd = NULL; - int cnt = 0; - ssize_t ret = -1; - ssize_t size = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - ret = -1; - errno = ESTALE; - goto out; - } - - fd = fd_anonymous (inode); - if (!fd) { - ret = -1; - gf_msg ("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, - "Allocating anonymous fd failed"); - errno = ENOMEM; - goto out; - } - - size = iov_length (iovec, iovcnt); - - /* TODO : set leaseid */ - ret = syncop_readv (subvol, fd, size, offset, flags, &iov, &cnt, - &iobref, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret <= 0) - goto out; - - size = iov_copy (iovec, iovcnt, iov, cnt); - - ret = size; +glfs_anonymous_preadv(struct glfs *fs, struct glfs_object *object, + const struct iovec *iovec, int iovcnt, off_t offset, + int flags) +{ + xlator_t *subvol = NULL; + struct iovec *iov = NULL; + struct iobref *iobref = NULL; + inode_t *inode = NULL; + fd_t *fd = NULL; + int cnt = 0; + ssize_t ret = -1; + ssize_t size = -1; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + ret = -1; + errno = ESTALE; + goto out; + } + + fd = fd_anonymous(inode); + if (!fd) { + ret = -1; + gf_msg("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, + "Allocating anonymous fd failed"); + errno = ENOMEM; + goto out; + } + + size = iov_length(iovec, iovcnt); + + /* TODO : set leaseid */ + ret = syncop_readv(subvol, fd, size, offset, flags, &iov, &cnt, &iobref, + NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret <= 0) + goto out; + + size = iov_copy(iovec, iovcnt, iov, cnt); + + ret = size; out: - if (iov) - GF_FREE (iov); - if (iobref) - iobref_unref (iobref); - if (fd) - fd_unref(fd); + if (iov) + GF_FREE(iov); + if (iobref) + iobref_unref(iobref); + if (fd) + fd_unref(fd); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } -static void glfs_release_xreaddirp_stat (void *ptr) +static void +glfs_release_xreaddirp_stat(void *ptr) { - struct glfs_xreaddirp_stat *to_free = ptr; + struct glfs_xreaddirp_stat *to_free = ptr; - if (to_free->object) - glfs_h_close (to_free->object); + if (to_free->object) + glfs_h_close(to_free->object); } /* @@ -5569,253 +5618,248 @@ static void glfs_release_xreaddirp_stat (void *ptr) * xstat along with dirents. */ int -pub_glfs_xreaddirplus_r (struct glfs_fd *glfd, uint32_t flags, - struct glfs_xreaddirp_stat **xstat_p, - struct dirent *ext, - struct dirent **res) +pub_glfs_xreaddirplus_r(struct glfs_fd *glfd, uint32_t flags, + struct glfs_xreaddirp_stat **xstat_p, + struct dirent *ext, struct dirent **res) { - int ret = -1; - gf_dirent_t *entry = NULL; - struct dirent *buf = NULL; - struct glfs_xreaddirp_stat *xstat = NULL; + int ret = -1; + gf_dirent_t *entry = NULL; + struct dirent *buf = NULL; + struct glfs_xreaddirp_stat *xstat = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - GF_VALIDATE_OR_GOTO (THIS->name, xstat_p, out); - GF_VALIDATE_OR_GOTO (THIS->name, res, out); + GF_VALIDATE_OR_GOTO(THIS->name, xstat_p, out); + GF_VALIDATE_OR_GOTO(THIS->name, res, out); - errno = 0; + errno = 0; - if (ext) - buf = ext; - else - buf = glfs_readdirbuf_get (glfd); + if (ext) + buf = ext; + else + buf = glfs_readdirbuf_get(glfd); - if (!buf) - goto out; + if (!buf) + goto out; - xstat = GLFS_CALLOC(1, sizeof(struct glfs_xreaddirp_stat), - glfs_release_xreaddirp_stat, - glfs_mt_xreaddirp_stat_t); + xstat = GLFS_CALLOC(1, sizeof(struct glfs_xreaddirp_stat), + glfs_release_xreaddirp_stat, glfs_mt_xreaddirp_stat_t); - if (!xstat) - goto out; + if (!xstat) + goto out; - /* this is readdirplus operation */ - entry = glfd_entry_next (glfd, 1); + /* this is readdirplus operation */ + entry = glfd_entry_next(glfd, 1); - /* XXX: Ideally when we reach EOD, errno should have been - * set to ENOENT. But that doesn't seem to be the case. - * - * The only way to confirm if its EOD at this point is that - * errno == 0 and entry == NULL - */ - if (errno) - goto out; + /* XXX: Ideally when we reach EOD, errno should have been + * set to ENOENT. But that doesn't seem to be the case. + * + * The only way to confirm if its EOD at this point is that + * errno == 0 and entry == NULL + */ + if (errno) + goto out; - if (!entry) { - /* reached EOD, ret = 0 */ - ret = 0; - *res = NULL; - *xstat_p = NULL; - - /* free xstat as applications shall not be using it */ - GLFS_FREE (xstat); - - goto out; - } - - *res = buf; - gf_dirent_to_dirent (entry, buf); - - if (flags & GFAPI_XREADDIRP_STAT) { - glfs_iatt_to_stat (glfd->fs, &entry->d_stat, &xstat->st); - xstat->flags_handled |= GFAPI_XREADDIRP_STAT; - } - - if ((flags & GFAPI_XREADDIRP_HANDLE) && - /* skip . and .. */ - strcmp(buf->d_name, ".") - && strcmp(buf->d_name, "..")) { - - /* Now create object. - * We can use "glfs_h_find_handle" as well as inodes would have - * already got linked as part of 'gf_link_inodes_from_dirent' */ - xstat->object = glfs_h_create_from_handle (glfd->fs, - entry->d_stat.ia_gfid, - GFAPI_HANDLE_LENGTH, - NULL); - - if (xstat->object) { /* success */ - /* note: xstat->object->inode->ref is taken - * This shall be unref'ed when application does - * glfs_free(xstat) */ - xstat->flags_handled |= GFAPI_XREADDIRP_HANDLE; - } + if (!entry) { + /* reached EOD, ret = 0 */ + ret = 0; + *res = NULL; + *xstat_p = NULL; + + /* free xstat as applications shall not be using it */ + GLFS_FREE(xstat); + + goto out; + } + + *res = buf; + gf_dirent_to_dirent(entry, buf); + + if (flags & GFAPI_XREADDIRP_STAT) { + glfs_iatt_to_stat(glfd->fs, &entry->d_stat, &xstat->st); + xstat->flags_handled |= GFAPI_XREADDIRP_STAT; + } + + if ((flags & GFAPI_XREADDIRP_HANDLE) && + /* skip . and .. */ + strcmp(buf->d_name, ".") && strcmp(buf->d_name, "..")) { + /* Now create object. + * We can use "glfs_h_find_handle" as well as inodes would have + * already got linked as part of 'gf_link_inodes_from_dirent' */ + xstat->object = glfs_h_create_from_handle( + glfd->fs, entry->d_stat.ia_gfid, GFAPI_HANDLE_LENGTH, NULL); + + if (xstat->object) { /* success */ + /* note: xstat->object->inode->ref is taken + * This shall be unref'ed when application does + * glfs_free(xstat) */ + xstat->flags_handled |= GFAPI_XREADDIRP_HANDLE; } + } - ret = xstat->flags_handled; - *xstat_p = xstat; + ret = xstat->flags_handled; + *xstat_p = xstat; - gf_msg_debug (THIS->name, 0, - "xreaddirp- requested_flags (%x) , processed_flags (%x)", - flags, xstat->flags_handled); + gf_msg_debug(THIS->name, 0, + "xreaddirp- requested_flags (%x) , processed_flags (%x)", + flags, xstat->flags_handled); out: - GF_REF_PUT (glfd); + GF_REF_PUT(glfd); - if (ret < 0) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, - API_MSG_XREADDIRP_R_FAILED, - "glfs_x_readdirp_r failed - reason (%s)", - strerror(errno)); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, API_MSG_XREADDIRP_R_FAILED, + "glfs_x_readdirp_r failed - reason (%s)", strerror(errno)); - if (xstat) - GLFS_FREE (xstat); - } + if (xstat) + GLFS_FREE(xstat); + } - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return ret; + return ret; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_r, 3.11.0); -struct stat* -pub_glfs_xreaddirplus_get_stat (struct glfs_xreaddirp_stat *xstat) +struct stat * +pub_glfs_xreaddirplus_get_stat(struct glfs_xreaddirp_stat *xstat) { - GF_VALIDATE_OR_GOTO ("glfs_xreaddirplus_get_stat", xstat, out); + GF_VALIDATE_OR_GOTO("glfs_xreaddirplus_get_stat", xstat, out); - if (!xstat->flags_handled & GFAPI_XREADDIRP_STAT) - gf_msg (THIS->name, GF_LOG_ERROR, errno, - LG_MSG_INVALID_ARG, - "GFAPI_XREADDIRP_STAT is not set. Flags" - "handled for xstat(%p) are (%x)", - xstat, xstat->flags_handled); - return &xstat->st; + if (!xstat->flags_handled & GFAPI_XREADDIRP_STAT) + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "GFAPI_XREADDIRP_STAT is not set. Flags" + "handled for xstat(%p) are (%x)", + xstat, xstat->flags_handled); + return &xstat->st; out: - return NULL; + return NULL; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_get_stat, 3.11.0); void -gf_lease_to_glfs_lease (struct gf_lease *gf_lease, struct glfs_lease *lease) +gf_lease_to_glfs_lease(struct gf_lease *gf_lease, struct glfs_lease *lease) { - lease->cmd = gf_lease->cmd; - lease->lease_type = gf_lease->lease_type; - memcpy (lease->lease_id, gf_lease->lease_id, LEASE_ID_SIZE); + lease->cmd = gf_lease->cmd; + lease->lease_type = gf_lease->lease_type; + memcpy(lease->lease_id, gf_lease->lease_id, LEASE_ID_SIZE); } void -glfs_lease_to_gf_lease (struct glfs_lease *lease, struct gf_lease *gf_lease) +glfs_lease_to_gf_lease(struct glfs_lease *lease, struct gf_lease *gf_lease) { - gf_lease->cmd = lease->cmd; - gf_lease->lease_type = lease->lease_type; - memcpy (gf_lease->lease_id, lease->lease_id, LEASE_ID_SIZE); + gf_lease->cmd = lease->cmd; + gf_lease->lease_type = lease->lease_type; + memcpy(gf_lease->lease_id, lease->lease_id, LEASE_ID_SIZE); } int -pub_glfs_lease (struct glfs_fd *glfd, struct glfs_lease *lease, - glfs_recall_cbk fn, void *data) -{ - int ret = -1; - loc_t loc = {0, }; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct gf_lease gf_lease = {0, }; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - if (!is_valid_lease_id (lease->lease_id)) { +pub_glfs_lease(struct glfs_fd *glfd, struct glfs_lease *lease, + glfs_recall_cbk fn, void *data) +{ + int ret = -1; + loc_t loc = { + 0, + }; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct gf_lease gf_lease = { + 0, + }; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + if (!is_valid_lease_id(lease->lease_id)) { + ret = -1; + errno = EINVAL; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + switch (lease->lease_type) { + case GLFS_RD_LEASE: + if ((fd->flags != O_RDONLY) && !(fd->flags & O_RDWR)) { ret = -1; errno = EINVAL; goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { + } + break; + case GLFS_RW_LEASE: + if (!((fd->flags & O_WRONLY) || (fd->flags & O_RDWR))) { ret = -1; - errno = EIO; + errno = EINVAL; goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { + } + break; + default: + if (lease->cmd != GLFS_GET_LEASE) { ret = -1; - errno = EBADFD; + errno = EINVAL; goto out; - } - - switch (lease->lease_type) { - case GLFS_RD_LEASE: - if ((fd->flags != O_RDONLY) && !(fd->flags & O_RDWR)) { - ret = -1; - errno = EINVAL; - goto out; - } - break; - case GLFS_RW_LEASE: - if (!((fd->flags & O_WRONLY) || (fd->flags & O_RDWR))) { - ret = -1; - errno = EINVAL; - goto out; - } - break; - default: - if (lease->cmd != GLFS_GET_LEASE) { - ret = -1; - errno = EINVAL; - goto out; - } - break; - } + } + break; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (fd->inode, loc, out); + /* populate loc */ + GLFS_LOC_FILL_INODE(fd->inode, loc, out); - glfs_lease_to_gf_lease (lease, &gf_lease); + glfs_lease_to_gf_lease(lease, &gf_lease); - ret = syncop_lease (subvol, &loc, &gf_lease, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_lease(subvol, &loc, &gf_lease, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - gf_lease_to_glfs_lease (&gf_lease, lease); + gf_lease_to_glfs_lease(&gf_lease, lease); - /* TODO: Add leases for client replay - if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) - fd_lk_insert_and_merge (fd, cmd, &saved_flock); - */ - if (ret == 0) { - ret = fd_ctx_set (glfd->fd, subvol, (uint64_t)(long)glfd); - if (ret) { - gf_msg (subvol->name, GF_LOG_ERROR, ENOMEM, API_MSG_FDCTX_SET_FAILED, - "Setting fd ctx failed for fd(%p)", glfd->fd); - goto out; - } - glfd->cbk = fn; - glfd->cookie = data; + /* TODO: Add leases for client replay + if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) + fd_lk_insert_and_merge (fd, cmd, &saved_flock); + */ + if (ret == 0) { + ret = fd_ctx_set(glfd->fd, subvol, (uint64_t)(long)glfd); + if (ret) { + gf_msg(subvol->name, GF_LOG_ERROR, ENOMEM, API_MSG_FDCTX_SET_FAILED, + "Setting fd ctx failed for fd(%p)", glfd->fd); + goto out; } + glfd->cbk = fn; + glfd->cookie = data; + } out: - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - if (subvol) - glfs_subvol_done (glfd->fs, subvol); + if (subvol) + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lease, 4.0.0); diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 343fc384ddf..7e9f4c5c915 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -8,7 +8,6 @@ * cases as published by the Free Software Foundation. */ - #include "glfs-internal.h" #include "glfs-mem-types.h" #include "syncop.h" @@ -17,1809 +16,1844 @@ #include "gfapi-messages.h" int -glfs_listxattr_process (void *value, size_t size, dict_t *xattr); +glfs_listxattr_process(void *value, size_t size, dict_t *xattr); static void -glfs_iatt_from_stat (struct stat *stat, int valid, struct iatt *iatt, - int *glvalid) +glfs_iatt_from_stat(struct stat *stat, int valid, struct iatt *iatt, + int *glvalid) { - /* validate in args */ - if ((stat == NULL) || (iatt == NULL) || (glvalid == NULL)) { - errno = EINVAL; - return; - } - - *glvalid = 0; - - if (valid & GFAPI_SET_ATTR_MODE) { - iatt->ia_prot = ia_prot_from_st_mode (stat->st_mode); - *glvalid |= GF_SET_ATTR_MODE; - } - - if (valid & GFAPI_SET_ATTR_UID) { - iatt->ia_uid = stat->st_uid; - *glvalid |= GF_SET_ATTR_UID; - } - - if (valid & GFAPI_SET_ATTR_GID) { - iatt->ia_gid = stat->st_gid; - *glvalid |= GF_SET_ATTR_GID; - } - - if (valid & GFAPI_SET_ATTR_ATIME) { - iatt->ia_atime = stat->st_atime; - iatt->ia_atime_nsec = ST_ATIM_NSEC (stat); - *glvalid |= GF_SET_ATTR_ATIME; - } - - if (valid & GFAPI_SET_ATTR_MTIME) { - iatt->ia_mtime = stat->st_mtime; - iatt->ia_mtime_nsec = ST_MTIM_NSEC (stat); - *glvalid |= GF_SET_ATTR_MTIME; - } - + /* validate in args */ + if ((stat == NULL) || (iatt == NULL) || (glvalid == NULL)) { + errno = EINVAL; return; + } + + *glvalid = 0; + + if (valid & GFAPI_SET_ATTR_MODE) { + iatt->ia_prot = ia_prot_from_st_mode(stat->st_mode); + *glvalid |= GF_SET_ATTR_MODE; + } + + if (valid & GFAPI_SET_ATTR_UID) { + iatt->ia_uid = stat->st_uid; + *glvalid |= GF_SET_ATTR_UID; + } + + if (valid & GFAPI_SET_ATTR_GID) { + iatt->ia_gid = stat->st_gid; + *glvalid |= GF_SET_ATTR_GID; + } + + if (valid & GFAPI_SET_ATTR_ATIME) { + iatt->ia_atime = stat->st_atime; + iatt->ia_atime_nsec = ST_ATIM_NSEC(stat); + *glvalid |= GF_SET_ATTR_ATIME; + } + + if (valid & GFAPI_SET_ATTR_MTIME) { + iatt->ia_mtime = stat->st_mtime; + iatt->ia_mtime_nsec = ST_MTIM_NSEC(stat); + *glvalid |= GF_SET_ATTR_MTIME; + } + + return; } struct glfs_object * -pub_glfs_h_lookupat (struct glfs *fs, struct glfs_object *parent, - const char *path, struct stat *stat, int follow) +pub_glfs_h_lookupat(struct glfs *fs, struct glfs_object *parent, + const char *path, struct stat *stat, int follow) { - int ret = 0; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - struct iatt iatt = {0, }; - struct glfs_object *object = NULL; - loc_t loc = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if (path == NULL) { - errno = EINVAL; - return NULL; - } + int ret = 0; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + struct iatt iatt = { + 0, + }; + struct glfs_object *object = NULL; + loc_t loc = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if (path == NULL) { + errno = EINVAL; + return NULL; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - if (parent) { - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + if (parent) { + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; } + } - /* fop/op */ - ret = glfs_resolve_at (fs, subvol, inode, path, &loc, &iatt, - follow, 0); + /* fop/op */ + ret = glfs_resolve_at(fs, subvol, inode, path, &loc, &iatt, follow, 0); - /* populate out args */ - if (!ret) { - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + /* populate out args */ + if (!ret) { + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_lookupat, 3.7.4); struct glfs_object * -pub_glfs_h_lookupat34 (struct glfs *fs, struct glfs_object *parent, - const char *path, struct stat *stat) +pub_glfs_h_lookupat34(struct glfs *fs, struct glfs_object *parent, + const char *path, struct stat *stat) { - return pub_glfs_h_lookupat (fs, parent, path, stat, 0); + return pub_glfs_h_lookupat(fs, parent, path, stat, 0); } GFAPI_SYMVER_PUBLIC(glfs_h_lookupat34, glfs_h_lookupat, 3.4.2); int -pub_glfs_h_statfs (struct glfs *fs, struct glfs_object *object, - struct statvfs *statvfs) +pub_glfs_h_statfs(struct glfs *fs, struct glfs_object *object, + struct statvfs *statvfs) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((fs == NULL) || (object == NULL || statvfs == NULL)) { - errno = EINVAL; - return -1; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((fs == NULL) || (object == NULL || statvfs == NULL)) { + errno = EINVAL; + return -1; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_statfs (subvol, &loc, statvfs, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_statfs(subvol, &loc, statvfs, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - loc_wipe (&loc); + loc_wipe(&loc); out: - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_statfs, 3.7.0); int -pub_glfs_h_stat (struct glfs *fs, struct glfs_object *object, struct stat *stat) +pub_glfs_h_stat(struct glfs *fs, struct glfs_object *object, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = syncop_stat (subvol, &loc, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (!ret && stat) { - glfs_iatt_to_stat (fs, &iatt, stat); - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_stat(subvol, &loc, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (!ret && stat) { + glfs_iatt_to_stat(fs, &iatt, stat); + } out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_stat, 3.4.2); - int -pub_glfs_h_getattrs (struct glfs *fs, struct glfs_object *object, - struct stat *stat) +pub_glfs_h_getattrs(struct glfs *fs, struct glfs_object *object, + struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - struct iatt iatt = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - ret = 0; - errno = ESTALE; - goto out; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + struct iatt iatt = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + ret = 0; + errno = ESTALE; + goto out; + } - /* fop/op */ - ret = glfs_resolve_base (fs, subvol, inode, &iatt); + /* fop/op */ + ret = glfs_resolve_base(fs, subvol, inode, &iatt); - /* populate out args */ - if (!ret && stat) { - glfs_iatt_to_stat (fs, &iatt, stat); - } + /* populate out args */ + if (!ret && stat) { + glfs_iatt_to_stat(fs, &iatt, stat); + } out: - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_getattrs, 3.4.2); - int -glfs_h_getxattrs_common (struct glfs *fs, struct glfs_object *object, - dict_t **xattr, const char *name, - gf_boolean_t is_listxattr) +glfs_h_getxattrs_common(struct glfs *fs, struct glfs_object *object, + dict_t **xattr, const char *name, + gf_boolean_t is_listxattr) { - int ret = 0; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } - - if (!is_listxattr) { - if (!name || *name == '\0') { - errno = EINVAL; - return -1; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - errno = ENAMETOOLONG; - return -1; - } - } - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + int ret = 0; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; + if (!is_listxattr) { + if (!name || *name == '\0') { + errno = EINVAL; + return -1; } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - ret = syncop_getxattr (subvol, &loc, xattr, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + if (strlen(name) > GF_XATTR_NAME_MAX) { + errno = ENAMETOOLONG; + return -1; + } + } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + ret = syncop_getxattr(subvol, &loc, xattr, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - return ret; + return ret; } - int -pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object, - const char *name, void *value, size_t size) +pub_glfs_h_getxattrs(struct glfs *fs, struct glfs_object *object, + const char *name, void *value, size_t size) { - int ret = -1; - dict_t *xattr = NULL; + int ret = -1; + dict_t *xattr = NULL; - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - ret = glfs_h_getxattrs_common (fs, object, &xattr, name, - (name == NULL)); - if (ret) - goto out; + ret = glfs_h_getxattrs_common(fs, object, &xattr, name, (name == NULL)); + if (ret) + goto out; - /* If @name is NULL, means get all the xattrs (i.e listxattr). */ - if (name) - ret = glfs_getxattr_process (value, size, xattr, name); - else - ret = glfs_listxattr_process (value, size, xattr); + /* If @name is NULL, means get all the xattrs (i.e listxattr). */ + if (name) + ret = glfs_getxattr_process(value, size, xattr, name); + else + ret = glfs_listxattr_process(value, size, xattr); out: - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_getxattrs, 3.5.1); int -pub_glfs_h_setattrs (struct glfs *fs, struct glfs_object *object, - struct stat *stat, int valid) +pub_glfs_h_setattrs(struct glfs *fs, struct glfs_object *object, + struct stat *stat, int valid) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int glvalid = 0; - - /* validate in args */ - if ((fs == NULL) || (object == NULL) || (stat == NULL)) { - errno = EINVAL; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* map valid masks from in args */ - glfs_iatt_from_stat (stat, valid, &iatt, &glvalid); - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = syncop_setattr (subvol, &loc, &iatt, glvalid, 0, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int glvalid = 0; + + /* validate in args */ + if ((fs == NULL) || (object == NULL) || (stat == NULL)) { + errno = EINVAL; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* map valid masks from in args */ + glfs_iatt_from_stat(stat, valid, &iatt, &glvalid); + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_setattr(subvol, &loc, &iatt, glvalid, 0, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_setattrs, 3.4.2); - int -pub_glfs_h_setxattrs (struct glfs *fs, struct glfs_object *object, - const char *name, const void *value, size_t size, - int flags) +pub_glfs_h_setxattrs(struct glfs *fs, struct glfs_object *object, + const char *name, const void *value, size_t size, + int flags) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - dict_t *xattr = NULL; - void *value_cp = NULL; - - /* validate in args */ - if ((fs == NULL) || (object == NULL) || - (name == NULL) || (value == NULL)) { - errno = EINVAL; - return -1; - } - - if (!name || *name == '\0') { - errno = EINVAL; - return -1; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - errno = ENAMETOOLONG; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - value_cp = gf_memdup (value, size); - GF_CHECK_ALLOC_AND_LOG (subvol->name, value_cp, ret, "Failed to" - " duplicate setxattr value", out); - - xattr = dict_for_key_value (name, value_cp, size, _gf_false); - if (!xattr) { - GF_FREE (value_cp); - ret = -1; - errno = ENOMEM; - goto out; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + dict_t *xattr = NULL; + void *value_cp = NULL; + + /* validate in args */ + if ((fs == NULL) || (object == NULL) || (name == NULL) || (value == NULL)) { + errno = EINVAL; + return -1; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + if (!name || *name == '\0') { + errno = EINVAL; + return -1; + } - /* fop/op */ - ret = syncop_setxattr (subvol, &loc, xattr, flags, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + if (strlen(name) > GF_XATTR_NAME_MAX) { + errno = ENAMETOOLONG; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + value_cp = gf_memdup(value, size); + GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret, + "Failed to" + " duplicate setxattr value", + out); + + xattr = dict_for_key_value(name, value_cp, size, _gf_false); + if (!xattr) { + GF_FREE(value_cp); + ret = -1; + errno = ENOMEM; + goto out; + } + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_setxattr(subvol, &loc, xattr, flags, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_setxattrs, 3.5.0); - int -pub_glfs_h_removexattrs (struct glfs *fs, struct glfs_object *object, - const char *name) +pub_glfs_h_removexattrs(struct glfs *fs, struct glfs_object *object, + const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL) || (name == NULL)) { - errno = EINVAL; - return -1; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL) || (name == NULL)) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_removexattr (subvol, &loc, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_removexattr(subvol, &loc, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_removexattrs, 3.5.1); - struct glfs_fd * -pub_glfs_h_open (struct glfs *fs, struct glfs_object *object, int flags) +pub_glfs_h_open(struct glfs *fs, struct glfs_object *object, int flags) { - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - dict_t *fop_attr = NULL; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* check types to open */ - if (IA_ISDIR (inode->ia_type)) { - ret = -1; - errno = EISDIR; - goto out; - } - - if (!IA_ISREG (inode->ia_type)) { - ret = -1; - errno = EINVAL; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) { - ret = -1; - errno = ENOMEM; - goto out; - } - - glfd->fd = fd_create (inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - glfd->fd->flags = flags; - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + dict_t *fop_attr = NULL; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* check types to open */ + if (IA_ISDIR(inode->ia_type)) { + ret = -1; + errno = EISDIR; + goto out; + } + + if (!IA_ISREG(inode->ia_type)) { + ret = -1; + errno = EINVAL; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) { + ret = -1; + errno = ENOMEM; + goto out; + } + + glfd->fd = fd_create(inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + glfd->fd->flags = flags; + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_open(subvol, &loc, flags, glfd->fd, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + glfd->fd->flags = flags; - ret = syncop_open (subvol, &loc, flags, glfd->fd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +out: + loc_wipe(&loc); - glfd->fd->flags = flags; + if (inode) + inode_unref(inode); + if (fop_attr) + dict_unref(fop_attr); -out: - loc_wipe (&loc); - - if (inode) - inode_unref (inode); - if (fop_attr) - dict_unref (fop_attr); - - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_open, 3.4.2); - struct glfs_object * -pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, - int flags, mode_t mode, struct stat *stat) +pub_glfs_h_creat(struct glfs *fs, struct glfs_object *parent, const char *path, + int flags, mode_t mode, struct stat *stat) { - int ret = -1; - fd_t *fd = NULL; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - ret = -1; - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } - - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - - fd = fd_create (loc.inode, getpid()); - if (!fd) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + fd_t *fd = NULL; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + ret = -1; + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, path); + + fd = fd_create(loc.inode, getpid()); + if (!fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + fd->flags = flags; + + /* fop/op */ + ret = syncop_create(subvol, &loc, flags, mode, fd, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - fd->flags = flags; - - /* fop/op */ - ret = syncop_create (subvol, &loc, flags, mode, fd, &iatt, - xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (ret == 0) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - /* Release the held reference */ - glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + /* Release the held reference */ + glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - if (fd) - fd_unref(fd); + if (fd) + fd_unref(fd); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_creat, 3.4.2); - struct glfs_object * -pub_glfs_h_mkdir (struct glfs *fs, struct glfs_object *parent, const char *path, - mode_t mode, struct stat *stat) +pub_glfs_h_mkdir(struct glfs *fs, struct glfs_object *parent, const char *path, + mode_t mode, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, path); + + /* fop/op */ + ret = syncop_mkdir(subvol, &loc, mode, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - - /* fop/op */ - ret = syncop_mkdir (subvol, &loc, mode, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if ( ret == 0 ) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); - - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_mkdir, 3.4.2); - struct glfs_object * -pub_glfs_h_mknod (struct glfs *fs, struct glfs_object *parent, const char *path, - mode_t mode, dev_t dev, struct stat *stat) +pub_glfs_h_mknod(struct glfs *fs, struct glfs_object *parent, const char *path, + mode_t mode, dev_t dev, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, path); + + /* fop/op */ + ret = syncop_mknod(subvol, &loc, mode, dev, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - - /* fop/op */ - ret = syncop_mknod (subvol, &loc, mode, dev, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (ret == 0) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_mknod, 3.4.2); - int -pub_glfs_h_unlink (struct glfs *fs, struct glfs_object *parent, const char *path) +pub_glfs_h_unlink(struct glfs *fs, struct glfs_object *parent, const char *path) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if ( !subvol ) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - ret = glfs_resolve_at (fs, subvol, inode, path, &loc, NULL, 0 , 0); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + ret = glfs_resolve_at(fs, subvol, inode, path, &loc, NULL, 0, 0); + if (ret != 0) { + goto out; + } + + if (!IA_ISDIR(loc.inode->ia_type)) { + ret = syncop_unlink(subvol, &loc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); if (ret != 0) { - goto out; + goto out; } - - if (!IA_ISDIR(loc.inode->ia_type)) { - ret = syncop_unlink (subvol, &loc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret != 0) { - goto out; - } - } else { - ret = syncop_rmdir (subvol, &loc, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret != 0) { - goto out; - } + } else { + ret = syncop_rmdir(subvol, &loc, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret != 0) { + goto out; } + } - if (ret == 0) - ret = glfs_loc_unlink (&loc); + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); - - if (inode) - inode_unref (inode); - - glfs_subvol_done (fs, subvol); - - __GLFS_EXIT_FS; + loc_wipe(&loc); -invalid_fs: - return ret; -} - -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_unlink, 3.4.2); - - -struct glfs_fd * -pub_glfs_h_opendir (struct glfs *fs, struct glfs_object *object) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return NULL; - } + if (inode) + inode_unref(inode); - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + glfs_subvol_done(fs, subvol); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - if (!IA_ISDIR (inode->ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; - - INIT_LIST_HEAD (&glfd->entries); - - glfd->fd = fd_create (inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } + __GLFS_EXIT_FS; - GLFS_LOC_FILL_INODE (inode, loc, out); +invalid_fs: + return ret; +} + +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_unlink, 3.4.2); - /* fop/op */ - ret = syncop_opendir (subvol, &loc, glfd->fd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +struct glfs_fd * +pub_glfs_h_opendir(struct glfs *fs, struct glfs_object *object) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + if (!IA_ISDIR(inode->ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; + + INIT_LIST_HEAD(&glfd->entries); + + glfd->fd = fd_create(inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_opendir(subvol, &loc, glfd->fd, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_opendir, 3.4.2); - int -pub_glfs_h_access (struct glfs *fs, struct glfs_object *object, int mask) +pub_glfs_h_access(struct glfs *fs, struct glfs_object *object, int mask) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return ret; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return ret; + } - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - GLFS_LOC_FILL_INODE (inode, loc, out); + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ + /* fop/op */ - ret = syncop_access (subvol, &loc, mask, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_access(subvol, &loc, mask, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); - - if (inode) - inode_unref (inode); + loc_wipe(&loc); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_access, 3.6.0); - ssize_t -pub_glfs_h_extract_handle (struct glfs_object *object, unsigned char *handle, - int len) +pub_glfs_h_extract_handle(struct glfs_object *object, unsigned char *handle, + int len) { - ssize_t ret = -1; + ssize_t ret = -1; - /* validate in args */ - if (object == NULL) { - errno = EINVAL; - goto out; - } + /* validate in args */ + if (object == NULL) { + errno = EINVAL; + goto out; + } - if (!handle || !len) { - ret = GFAPI_HANDLE_LENGTH; - goto out; - } + if (!handle || !len) { + ret = GFAPI_HANDLE_LENGTH; + goto out; + } - if (len < GFAPI_HANDLE_LENGTH) - { - errno = ERANGE; - goto out; - } + if (len < GFAPI_HANDLE_LENGTH) { + errno = ERANGE; + goto out; + } - memcpy (handle, object->gfid, GFAPI_HANDLE_LENGTH); + memcpy(handle, object->gfid, GFAPI_HANDLE_LENGTH); - ret = GFAPI_HANDLE_LENGTH; + ret = GFAPI_HANDLE_LENGTH; out: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_extract_handle, 3.4.2); - struct glfs_object * -pub_glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len, - struct stat *stat) +pub_glfs_h_create_from_handle(struct glfs *fs, unsigned char *handle, int len, + struct stat *stat) { - loc_t loc = {0, }; - int ret = -1; - struct iatt iatt = {0, }; - inode_t *newinode = NULL; - xlator_t *subvol = NULL; - struct glfs_object *object = NULL; - uint64_t ctx_value = LOOKUP_NOT_NEEDED; - gf_boolean_t lookup_needed = _gf_false; - - /* validate in args */ - if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) { - errno = EINVAL; - return NULL; - } + loc_t loc = { + 0, + }; + int ret = -1; + struct iatt iatt = { + 0, + }; + inode_t *newinode = NULL; + xlator_t *subvol = NULL; + struct glfs_object *object = NULL; + uint64_t ctx_value = LOOKUP_NOT_NEEDED; + gf_boolean_t lookup_needed = _gf_false; + + /* validate in args */ + if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) { + errno = EINVAL; + return NULL; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } - memcpy (loc.gfid, handle, GFAPI_HANDLE_LENGTH); - - /* make sure the gfid received is valid */ - GF_VALIDATE_OR_GOTO ("glfs_h_create_from_handle", - !(gf_uuid_is_null (loc.gfid)), out); - - newinode = inode_find (subvol->itable, loc.gfid); - if (newinode) { - if (!stat) /* No need of lookup */ - goto found; - - lookup_needed = inode_needs_lookup (newinode, THIS); - if (lookup_needed) { - loc.inode = newinode; - } else { - /* populate loc */ - GLFS_LOC_FILL_INODE (newinode, loc, fill_out); - - /* fop/op */ - ret = syncop_stat (subvol, &loc, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret) { -fill_out: - /* Drop the reference hold in inode_find */ - inode_unref (newinode); - goto out; - } - - glfs_iatt_to_stat (fs, &iatt, stat); - goto found; - } - } else { - loc.inode = inode_new (subvol->itable); - if (!loc.inode) { - errno = ENOMEM; - goto out; - } - } + memcpy(loc.gfid, handle, GFAPI_HANDLE_LENGTH); - ret = syncop_lookup (subvol, &loc, &iatt, 0, 0, 0); - DECODE_SYNCOP_ERR (ret); - if (ret) { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_REFRESH_FAILED, - "inode refresh of %s failed: %s", - uuid_utoa (loc.gfid), strerror (errno)); - goto out; - } + /* make sure the gfid received is valid */ + GF_VALIDATE_OR_GOTO("glfs_h_create_from_handle", + !(gf_uuid_is_null(loc.gfid)), out); - newinode = inode_link (loc.inode, 0, 0, &iatt); - if (newinode) { - if (newinode == loc.inode) { - inode_ctx_set (newinode, THIS, &ctx_value); - } - inode_lookup (newinode); - } else { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_LINK_FAILED, - "inode linking of %s failed", uuid_utoa (loc.gfid)); - goto out; - } + newinode = inode_find(subvol->itable, loc.gfid); + if (newinode) { + if (!stat) /* No need of lookup */ + goto found; - /* populate stat */ - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + lookup_needed = inode_needs_lookup(newinode, THIS); + if (lookup_needed) { + loc.inode = newinode; + } else { + /* populate loc */ + GLFS_LOC_FILL_INODE(newinode, loc, fill_out); + + /* fop/op */ + ret = syncop_stat(subvol, &loc, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret) { + fill_out: + /* Drop the reference hold in inode_find */ + inode_unref(newinode); + goto out; + } + + glfs_iatt_to_stat(fs, &iatt, stat); + goto found; + } + } else { + loc.inode = inode_new(subvol->itable); + if (!loc.inode) { + errno = ENOMEM; + goto out; + } + } + + ret = syncop_lookup(subvol, &loc, &iatt, 0, 0, 0); + DECODE_SYNCOP_ERR(ret); + if (ret) { + gf_msg(subvol->name, GF_LOG_WARNING, errno, + API_MSG_INODE_REFRESH_FAILED, "inode refresh of %s failed: %s", + uuid_utoa(loc.gfid), strerror(errno)); + goto out; + } + + newinode = inode_link(loc.inode, 0, 0, &iatt); + if (newinode) { + if (newinode == loc.inode) { + inode_ctx_set(newinode, THIS, &ctx_value); + } + inode_lookup(newinode); + } else { + gf_msg(subvol->name, GF_LOG_WARNING, errno, API_MSG_INODE_LINK_FAILED, + "inode linking of %s failed", uuid_utoa(loc.gfid)); + goto out; + } + + /* populate stat */ + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); found: - object = GF_CALLOC (1, sizeof(struct glfs_object), - glfs_mt_glfs_object_t); - if (object == NULL) { - errno = ENOMEM; - ret = -1; - goto out; - } + object = GF_CALLOC(1, sizeof(struct glfs_object), glfs_mt_glfs_object_t); + if (object == NULL) { + errno = ENOMEM; + ret = -1; + goto out; + } - /* populate the return object */ - object->inode = newinode; - gf_uuid_copy (object->gfid, object->inode->gfid); + /* populate the return object */ + object->inode = newinode; + gf_uuid_copy(object->gfid, object->inode->gfid); out: - /* TODO: Check where the inode ref is being held? */ - loc_wipe (&loc); + /* TODO: Check where the inode ref is being held? */ + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_create_from_handle, 3.4.2); - int -pub_glfs_h_close (struct glfs_object *object) +pub_glfs_h_close(struct glfs_object *object) { - /* since glfs_h_* objects hold a reference to inode - * it is safe to keep lookup count to '0' */ - inode_forget (object->inode, 0); - inode_unref (object->inode); - GF_FREE (object); + /* since glfs_h_* objects hold a reference to inode + * it is safe to keep lookup count to '0' */ + inode_forget(object->inode, 0); + inode_unref(object->inode); + GF_FREE(object); - return 0; + return 0; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_close, 3.4.2); - int -pub_glfs_h_truncate (struct glfs *fs, struct glfs_object *object, off_t offset) +pub_glfs_h_truncate(struct glfs *fs, struct glfs_object *object, off_t offset) { - loc_t loc = {0, }; - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - - DECLARE_OLD_THIS; - - /* validate in args */ - if (object == NULL) { - errno = EINVAL; - return -1; - } + loc_t loc = { + 0, + }; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + + DECLARE_OLD_THIS; + + /* validate in args */ + if (object == NULL) { + errno = EINVAL; + return -1; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - GLFS_LOC_FILL_INODE (inode, loc, out); + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_truncate (subvol, &loc, (off_t)offset, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_truncate(subvol, &loc, (off_t)offset, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - /* populate out args */ - if (ret == 0) - ret = glfs_loc_unlink (&loc); + /* populate out args */ + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_truncate, 3.4.2); - struct glfs_object * -pub_glfs_h_symlink (struct glfs *fs, struct glfs_object *parent, - const char *name, const char *data, struct stat *stat) +pub_glfs_h_symlink(struct glfs *fs, struct glfs_object *parent, + const char *name, const char *data, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((parent == NULL) || (name == NULL) || - (data == NULL)) { - errno = EINVAL; - return NULL; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((parent == NULL) || (name == NULL) || (data == NULL)) { + errno = EINVAL; + return NULL; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, name); + + /* fop/op */ + ret = syncop_symlink(subvol, &loc, data, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, name); - - /* fop/op */ - ret = syncop_symlink (subvol, &loc, data, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (ret == 0) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - pub_glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + pub_glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_symlink, 3.4.2); - int -pub_glfs_h_readlink (struct glfs *fs, struct glfs_object *object, char *buf, - size_t bufsiz) +pub_glfs_h_readlink(struct glfs *fs, struct glfs_object *object, char *buf, + size_t bufsiz) { - loc_t loc = {0, }; - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - char *linkval = NULL; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((object == NULL) || (buf == NULL)) { - errno = EINVAL; - return -1; - } + loc_t loc = { + 0, + }; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + char *linkval = NULL; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((object == NULL) || (buf == NULL)) { + errno = EINVAL; + return -1; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - GLFS_LOC_FILL_INODE (inode, loc, out); + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_readlink (subvol, &loc, &linkval, bufsiz, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_readlink(subvol, &loc, &linkval, bufsiz, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - /* populate out args */ - if (ret > 0) - memcpy (buf, linkval, ret); + /* populate out args */ + if (ret > 0) + memcpy(buf, linkval, ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (linkval) - GF_FREE (linkval); + if (linkval) + GF_FREE(linkval); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_readlink, 3.4.2); - int -pub_glfs_h_link (struct glfs *fs, struct glfs_object *linksrc, - struct glfs_object *parent, const char *name) +pub_glfs_h_link(struct glfs *fs, struct glfs_object *linksrc, + struct glfs_object *parent, const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - inode_t *pinode = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt iatt = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((linksrc == NULL) || (parent == NULL) || - (name == NULL)) { - errno = EINVAL; - return -1; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, linksrc); - if (!inode) { - errno = ESTALE; - goto out; - } - - if (inode->ia_type == IA_IFDIR) { - ret = -1; - errno = EISDIR; - goto out; - } - - GLFS_LOC_FILL_INODE (inode, oldloc, out); - - /* get/refresh the in arg objects inode in correlation to the xlator */ - pinode = glfs_resolve_inode (fs, subvol, parent); - if (!pinode) { - errno = ESTALE; - goto out; - } - - /* setup newloc based on parent */ - newloc.parent = inode_ref (pinode); - newloc.name = name; - ret = glfs_loc_touchup (&newloc); - if (ret != 0) { - errno = EINVAL; - goto out; - } - - /* Filling the inode of the hard link to be same as that of the - * original file - */ - newloc.inode = inode_ref (inode); - - /* fop/op */ - ret = syncop_link (subvol, &oldloc, &newloc, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == 0) - ret = glfs_loc_link (&newloc, &iatt); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + inode_t *pinode = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt iatt = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((linksrc == NULL) || (parent == NULL) || (name == NULL)) { + errno = EINVAL; + return -1; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, linksrc); + if (!inode) { + errno = ESTALE; + goto out; + } + + if (inode->ia_type == IA_IFDIR) { + ret = -1; + errno = EISDIR; + goto out; + } + + GLFS_LOC_FILL_INODE(inode, oldloc, out); + + /* get/refresh the in arg objects inode in correlation to the xlator */ + pinode = glfs_resolve_inode(fs, subvol, parent); + if (!pinode) { + errno = ESTALE; + goto out; + } + + /* setup newloc based on parent */ + newloc.parent = inode_ref(pinode); + newloc.name = name; + ret = glfs_loc_touchup(&newloc); + if (ret != 0) { + errno = EINVAL; + goto out; + } + + /* Filling the inode of the hard link to be same as that of the + * original file + */ + newloc.inode = inode_ref(inode); + + /* fop/op */ + ret = syncop_link(subvol, &oldloc, &newloc, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == 0) + ret = glfs_loc_link(&newloc, &iatt); out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (pinode) - inode_unref (pinode); + if (pinode) + inode_unref(pinode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_link, 3.4.2); - int -pub_glfs_h_rename (struct glfs *fs, struct glfs_object *olddir, - const char *oldname, struct glfs_object *newdir, - const char *newname) +pub_glfs_h_rename(struct glfs *fs, struct glfs_object *olddir, + const char *oldname, struct glfs_object *newdir, + const char *newname) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *oldpinode = NULL; - inode_t *newpinode = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt oldiatt = {0, }; - struct iatt newiatt = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((olddir == NULL) || (oldname == NULL) || - (newdir == NULL) || (newname == NULL)) { - errno = EINVAL; - return -1; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if ( !subvol ) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - oldpinode = glfs_resolve_inode (fs, subvol, olddir); - if (!oldpinode) { - errno = ESTALE; - goto out; - } - - ret = glfs_resolve_at (fs, subvol, oldpinode, oldname, &oldloc, - &oldiatt, 0 , 0); - if (ret != 0) { - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - newpinode = glfs_resolve_inode (fs, subvol, newdir); - if (!newpinode) { - errno = ESTALE; - goto out; - } - - ret = glfs_resolve_at (fs, subvol, newpinode, newname, &newloc, - &newiatt, 0, 0); - - if (ret && errno != ENOENT && newloc.parent) - goto out; - - if (newiatt.ia_type != IA_INVAL) { - if ((oldiatt.ia_type == IA_IFDIR) != - (newiatt.ia_type == IA_IFDIR)) { - /* Either both old and new must be dirs, - * or both must be non-dirs. Else, fail. - */ - ret = -1; - errno = EEXIST; - goto out; - } - } - - /* TODO: check if new or old is a prefix of the other, and fail EINVAL */ - - ret = syncop_rename (subvol, &oldloc, &newloc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == 0) { - inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name, - newloc.parent, newloc.name, oldloc.inode, - &oldiatt); - - if (newloc.inode && !inode_has_dentry (newloc.inode)) - inode_forget (newloc.inode, 0); - - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *oldpinode = NULL; + inode_t *newpinode = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt oldiatt = { + 0, + }; + struct iatt newiatt = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((olddir == NULL) || (oldname == NULL) || (newdir == NULL) || + (newname == NULL)) { + errno = EINVAL; + return -1; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + oldpinode = glfs_resolve_inode(fs, subvol, olddir); + if (!oldpinode) { + errno = ESTALE; + goto out; + } + + ret = glfs_resolve_at(fs, subvol, oldpinode, oldname, &oldloc, &oldiatt, 0, + 0); + if (ret != 0) { + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + newpinode = glfs_resolve_inode(fs, subvol, newdir); + if (!newpinode) { + errno = ESTALE; + goto out; + } + + ret = glfs_resolve_at(fs, subvol, newpinode, newname, &newloc, &newiatt, 0, + 0); + + if (ret && errno != ENOENT && newloc.parent) + goto out; + + if (newiatt.ia_type != IA_INVAL) { + if ((oldiatt.ia_type == IA_IFDIR) != (newiatt.ia_type == IA_IFDIR)) { + /* Either both old and new must be dirs, + * or both must be non-dirs. Else, fail. + */ + ret = -1; + errno = EEXIST; + goto out; + } + } + + /* TODO: check if new or old is a prefix of the other, and fail EINVAL */ + + ret = syncop_rename(subvol, &oldloc, &newloc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == 0) { + inode_rename(oldloc.parent->table, oldloc.parent, oldloc.name, + newloc.parent, newloc.name, oldloc.inode, &oldiatt); + + if (newloc.inode && !inode_has_dentry(newloc.inode)) + inode_forget(newloc.inode, 0); + } out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - if (oldpinode) - inode_unref (oldpinode); + if (oldpinode) + inode_unref(oldpinode); - if (newpinode) - inode_unref (newpinode); + if (newpinode) + inode_unref(newpinode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_rename, 3.4.2); @@ -1829,199 +1863,186 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_rename, 3.4.2); * the inode table. If yes create and return the corresponding glfs_object. */ struct glfs_object * -glfs_h_find_handle (struct glfs *fs, unsigned char *handle, int len) +glfs_h_find_handle(struct glfs *fs, unsigned char *handle, int len) { - inode_t *newinode = NULL; - xlator_t *subvol = NULL; - struct glfs_object *object = NULL; - uuid_t gfid; - - /* validate in args */ - if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) { - errno = EINVAL; - return NULL; - } + inode_t *newinode = NULL; + xlator_t *subvol = NULL; + struct glfs_object *object = NULL; + uuid_t gfid; + + /* validate in args */ + if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) { + errno = EINVAL; + return NULL; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } - memcpy (gfid, handle, GFAPI_HANDLE_LENGTH); + memcpy(gfid, handle, GFAPI_HANDLE_LENGTH); - /* make sure the gfid received is valid */ - GF_VALIDATE_OR_GOTO ("glfs_h_find_handle", - !(gf_uuid_is_null (gfid)), out); + /* make sure the gfid received is valid */ + GF_VALIDATE_OR_GOTO("glfs_h_find_handle", !(gf_uuid_is_null(gfid)), out); - newinode = inode_find (subvol->itable, gfid); - if (!newinode) { - goto out; - } + newinode = inode_find(subvol->itable, gfid); + if (!newinode) { + goto out; + } - object = GF_CALLOC (1, sizeof(struct glfs_object), - glfs_mt_glfs_object_t); - if (object == NULL) { - errno = ENOMEM; - goto out; - } + object = GF_CALLOC(1, sizeof(struct glfs_object), glfs_mt_glfs_object_t); + if (object == NULL) { + errno = ENOMEM; + goto out; + } - /* populate the return object. The ref taken here - * is un'refed when the application does glfs_h_close() */ - object->inode = inode_ref(newinode); - gf_uuid_copy (object->gfid, object->inode->gfid); + /* populate the return object. The ref taken here + * is un'refed when the application does glfs_h_close() */ + object->inode = inode_ref(newinode); + gf_uuid_copy(object->gfid, object->inode->gfid); out: - /* inode_find takes a reference. Unref it. */ - if (newinode) - inode_unref (newinode); + /* inode_find takes a reference. Unref it. */ + if (newinode) + inode_unref(newinode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; - + return object; } static void -glfs_free_upcall_inode (void *to_free) +glfs_free_upcall_inode(void *to_free) { - struct glfs_upcall_inode *arg = to_free; + struct glfs_upcall_inode *arg = to_free; - if (!arg) - return; + if (!arg) + return; - if (arg->object) - glfs_h_close (arg->object); - if (arg->p_object) - glfs_h_close (arg->p_object); - if (arg->oldp_object) - glfs_h_close (arg->oldp_object); + if (arg->object) + glfs_h_close(arg->object); + if (arg->p_object) + glfs_h_close(arg->p_object); + if (arg->oldp_object) + glfs_h_close(arg->oldp_object); - GF_FREE (arg); + GF_FREE(arg); } int -glfs_h_poll_cache_invalidation (struct glfs *fs, - struct glfs_upcall *up_arg, - struct gf_upcall *upcall_data) +glfs_h_poll_cache_invalidation(struct glfs *fs, struct glfs_upcall *up_arg, + struct gf_upcall *upcall_data) { - int ret = -1; - struct glfs_object *p_object = NULL; - struct glfs_object *oldp_object = NULL; - struct glfs_object *object = NULL; - struct gf_upcall_cache_invalidation *ca_data = NULL; - struct glfs_upcall_inode *up_inode_arg = NULL; - - ca_data = upcall_data->data; - GF_VALIDATE_OR_GOTO ("glfs_h_poll_cache_invalidation", - ca_data, out); - - object = glfs_h_find_handle (fs, upcall_data->gfid, - GFAPI_HANDLE_LENGTH); - if (!object) { - /* The reason handle creation will fail is because we - * couldn't find the inode in the gfapi inode table. - * - * But since application would have taken inode_ref, the - * only case when this can happen is when it has closed - * the handle and hence will no more be interested in - * the upcall for this particular gfid. - */ - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_CREATE_HANDLE_FAILED, - "handle creation of %s failed", - uuid_utoa (upcall_data->gfid)); - errno = ESTALE; - goto out; - } - - up_inode_arg = GF_CALLOC (1, sizeof (struct glfs_upcall_inode), - glfs_mt_upcall_inode_t); - GF_VALIDATE_OR_GOTO ("glfs_h_poll_cache_invalidation", - up_inode_arg, out); - - up_inode_arg->object = object; - up_inode_arg->flags = ca_data->flags; - up_inode_arg->expire_time_attr = ca_data->expire_time_attr; - - /* XXX: Update stat as well in case of UP_*_TIMES. - * This will be addressed as part of INODE_UPDATE */ - if (ca_data->flags & GFAPI_INODE_UPDATE_FLAGS) { - glfs_iatt_to_stat (fs, &ca_data->stat, &up_inode_arg->buf); - } - - if (ca_data->flags & GFAPI_UP_PARENT_TIMES) { - p_object = glfs_h_find_handle (fs, - ca_data->p_stat.ia_gfid, - GFAPI_HANDLE_LENGTH); - if (!p_object) { - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_CREATE_HANDLE_FAILED, - "handle creation of %s failed", - uuid_utoa (ca_data->p_stat.ia_gfid)); - errno = ESTALE; - goto out; - } - - glfs_iatt_to_stat (fs, &ca_data->p_stat, &up_inode_arg->p_buf); - } - up_inode_arg->p_object = p_object; - - /* In case of RENAME, update old parent as well */ - if (ca_data->flags & GFAPI_UP_RENAME) { - oldp_object = glfs_h_find_handle (fs, - ca_data->oldp_stat.ia_gfid, - GFAPI_HANDLE_LENGTH); - if (!oldp_object) { - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_CREATE_HANDLE_FAILED, - "handle creation of %s failed", - uuid_utoa (ca_data->oldp_stat.ia_gfid)); - errno = ESTALE; - /* By the time we receive upcall old parent_dir may - * have got removed. We still need to send upcall - * for the file/dir and current parent handles. */ - up_inode_arg->oldp_object = NULL; - ret = 0; - } - - glfs_iatt_to_stat (fs, &ca_data->oldp_stat, - &up_inode_arg->oldp_buf); - } - up_inode_arg->oldp_object = oldp_object; - - up_arg->reason = GLFS_UPCALL_INODE_INVALIDATE; - up_arg->event = up_inode_arg; - up_arg->free_event = glfs_free_upcall_inode; - - ret = 0; + int ret = -1; + struct glfs_object *p_object = NULL; + struct glfs_object *oldp_object = NULL; + struct glfs_object *object = NULL; + struct gf_upcall_cache_invalidation *ca_data = NULL; + struct glfs_upcall_inode *up_inode_arg = NULL; + + ca_data = upcall_data->data; + GF_VALIDATE_OR_GOTO("glfs_h_poll_cache_invalidation", ca_data, out); + + object = glfs_h_find_handle(fs, upcall_data->gfid, GFAPI_HANDLE_LENGTH); + if (!object) { + /* The reason handle creation will fail is because we + * couldn't find the inode in the gfapi inode table. + * + * But since application would have taken inode_ref, the + * only case when this can happen is when it has closed + * the handle and hence will no more be interested in + * the upcall for this particular gfid. + */ + gf_msg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_CREATE_HANDLE_FAILED, + "handle creation of %s failed", uuid_utoa(upcall_data->gfid)); + errno = ESTALE; + goto out; + } + + up_inode_arg = GF_CALLOC(1, sizeof(struct glfs_upcall_inode), + glfs_mt_upcall_inode_t); + GF_VALIDATE_OR_GOTO("glfs_h_poll_cache_invalidation", up_inode_arg, out); + + up_inode_arg->object = object; + up_inode_arg->flags = ca_data->flags; + up_inode_arg->expire_time_attr = ca_data->expire_time_attr; + + /* XXX: Update stat as well in case of UP_*_TIMES. + * This will be addressed as part of INODE_UPDATE */ + if (ca_data->flags & GFAPI_INODE_UPDATE_FLAGS) { + glfs_iatt_to_stat(fs, &ca_data->stat, &up_inode_arg->buf); + } + + if (ca_data->flags & GFAPI_UP_PARENT_TIMES) { + p_object = glfs_h_find_handle(fs, ca_data->p_stat.ia_gfid, + GFAPI_HANDLE_LENGTH); + if (!p_object) { + gf_msg(THIS->name, GF_LOG_DEBUG, errno, + API_MSG_CREATE_HANDLE_FAILED, "handle creation of %s failed", + uuid_utoa(ca_data->p_stat.ia_gfid)); + errno = ESTALE; + goto out; + } + + glfs_iatt_to_stat(fs, &ca_data->p_stat, &up_inode_arg->p_buf); + } + up_inode_arg->p_object = p_object; + + /* In case of RENAME, update old parent as well */ + if (ca_data->flags & GFAPI_UP_RENAME) { + oldp_object = glfs_h_find_handle(fs, ca_data->oldp_stat.ia_gfid, + GFAPI_HANDLE_LENGTH); + if (!oldp_object) { + gf_msg(THIS->name, GF_LOG_DEBUG, errno, + API_MSG_CREATE_HANDLE_FAILED, "handle creation of %s failed", + uuid_utoa(ca_data->oldp_stat.ia_gfid)); + errno = ESTALE; + /* By the time we receive upcall old parent_dir may + * have got removed. We still need to send upcall + * for the file/dir and current parent handles. */ + up_inode_arg->oldp_object = NULL; + ret = 0; + } + + glfs_iatt_to_stat(fs, &ca_data->oldp_stat, &up_inode_arg->oldp_buf); + } + up_inode_arg->oldp_object = oldp_object; + + up_arg->reason = GLFS_UPCALL_INODE_INVALIDATE; + up_arg->event = up_inode_arg; + up_arg->free_event = glfs_free_upcall_inode; + + ret = 0; out: - if (ret) { - /* Close p_object and oldp_object as well if being referenced.*/ - if (object) - glfs_h_close (object); - - /* Set reason to prevent applications from using ->event */ - up_arg->reason = GLFS_UPCALL_EVENT_NULL; - GF_FREE (up_inode_arg); - } - return ret; + if (ret) { + /* Close p_object and oldp_object as well if being referenced.*/ + if (object) + glfs_h_close(object); + + /* Set reason to prevent applications from using ->event */ + up_arg->reason = GLFS_UPCALL_EVENT_NULL; + GF_FREE(up_inode_arg); + } + return ret; } -void glfs_release_upcall (void *ptr) +void +glfs_release_upcall(void *ptr) { - struct glfs_upcall *to_free = ptr; + struct glfs_upcall *to_free = ptr; - if (to_free->event) - to_free->free_event (to_free->event); + if (to_free->event) + to_free->free_event(to_free->event); } /* @@ -2045,123 +2066,120 @@ void glfs_release_upcall (void *ptr) * cannot be freed while in this routine. */ int -pub_glfs_h_poll_upcall (struct glfs *fs, struct glfs_upcall **up_arg) +pub_glfs_h_poll_upcall(struct glfs *fs, struct glfs_upcall **up_arg) { - upcall_entry *u_list = NULL; - upcall_entry *tmp = NULL; - xlator_t *subvol = NULL; - glusterfs_ctx_t *ctx = NULL; - int ret = -1; - struct gf_upcall *upcall_data = NULL; - - DECLARE_OLD_THIS; - - if (!up_arg) { - errno = EINVAL; - goto err; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, err); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto restore; - } - - /* Ideally applications should stop polling before calling - * 'glfs_fini'. Yet cross check if cleanup has started. */ - pthread_mutex_lock (&fs->mutex); + upcall_entry *u_list = NULL; + upcall_entry *tmp = NULL; + xlator_t *subvol = NULL; + glusterfs_ctx_t *ctx = NULL; + int ret = -1; + struct gf_upcall *upcall_data = NULL; + + DECLARE_OLD_THIS; + + if (!up_arg) { + errno = EINVAL; + goto err; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, err); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto restore; + } + + /* Ideally applications should stop polling before calling + * 'glfs_fini'. Yet cross check if cleanup has started. */ + pthread_mutex_lock(&fs->mutex); + { + ctx = fs->ctx; + + if (ctx->cleanup_started) { + pthread_mutex_unlock(&fs->mutex); + goto out; + } + + fs->pin_refcnt++; + + /* once we call this function, the applications seems to be + * interested in events, enable caching them */ + fs->cache_upcalls = _gf_true; + } + pthread_mutex_unlock(&fs->mutex); + + pthread_mutex_lock(&fs->upcall_list_mutex); + { + list_for_each_entry_safe(u_list, tmp, &fs->upcall_list, upcall_list) { - ctx = fs->ctx; - - if (ctx->cleanup_started) { - pthread_mutex_unlock (&fs->mutex); - goto out; + list_del_init(&u_list->upcall_list); + upcall_data = &u_list->upcall_data; + break; + } + } + /* No other thread can delete this entry. So unlock it */ + pthread_mutex_unlock(&fs->upcall_list_mutex); + + if (upcall_data) { + switch (upcall_data->event_type) { + case GF_UPCALL_CACHE_INVALIDATION: + *up_arg = GLFS_CALLOC(1, sizeof(struct gf_upcall), + glfs_release_upcall, + glfs_mt_upcall_entry_t); + if (!*up_arg) { + errno = ENOMEM; + break; /* goto free u_list */ } - fs->pin_refcnt++; - - /* once we call this function, the applications seems to be - * interested in events, enable caching them */ - fs->cache_upcalls = _gf_true; - } - pthread_mutex_unlock (&fs->mutex); + /* XXX: Need to revisit this to support + * GLFS_UPCALL_INODE_UPDATE if required. */ + ret = glfs_h_poll_cache_invalidation(fs, *up_arg, upcall_data); + if (ret || (*up_arg)->reason == GLFS_UPCALL_EVENT_NULL) { + /* It could so happen that the file which got + * upcall notification may have got deleted by + * the same client. Irrespective of the error, + * return with an error or success+ENOENT. */ + if ((*up_arg)->reason == GLFS_UPCALL_EVENT_NULL) + errno = ENOENT; - pthread_mutex_lock (&fs->upcall_list_mutex); - { - list_for_each_entry_safe (u_list, tmp, - &fs->upcall_list, - upcall_list) { - list_del_init (&u_list->upcall_list); - upcall_data = &u_list->upcall_data; - break; + GLFS_FREE(*up_arg); + *up_arg = NULL; } - } - /* No other thread can delete this entry. So unlock it */ - pthread_mutex_unlock (&fs->upcall_list_mutex); - - if (upcall_data) { - switch (upcall_data->event_type) { - case GF_UPCALL_CACHE_INVALIDATION: - *up_arg = GLFS_CALLOC (1, sizeof (struct gf_upcall), - glfs_release_upcall, - glfs_mt_upcall_entry_t); - if (!*up_arg) { - errno = ENOMEM; - break; /* goto free u_list */ - } - - /* XXX: Need to revisit this to support - * GLFS_UPCALL_INODE_UPDATE if required. */ - ret = glfs_h_poll_cache_invalidation (fs, *up_arg, - upcall_data); - if (ret - || (*up_arg)->reason == GLFS_UPCALL_EVENT_NULL) { - /* It could so happen that the file which got - * upcall notification may have got deleted by - * the same client. Irrespective of the error, - * return with an error or success+ENOENT. */ - if ((*up_arg)->reason == GLFS_UPCALL_EVENT_NULL) - errno = ENOENT; - - GLFS_FREE (*up_arg); - *up_arg = NULL; - } - break; - case GF_UPCALL_RECALL_LEASE: - gf_log ("glfs_h_poll_upcall", GF_LOG_DEBUG, - "UPCALL_RECALL_LEASE is not implemented yet"); - /* fallthrough till we support leases */ - case GF_UPCALL_EVENT_NULL: + break; + case GF_UPCALL_RECALL_LEASE: + gf_log("glfs_h_poll_upcall", GF_LOG_DEBUG, + "UPCALL_RECALL_LEASE is not implemented yet"); + /* fallthrough till we support leases */ + case GF_UPCALL_EVENT_NULL: /* no 'default:' label, to force handling all upcall events */ - errno = ENOENT; - break; - } - - GF_FREE (u_list->upcall_data.data); - GF_FREE (u_list); - } else { - /* fs->upcall_list was empty, no upcall events cached */ errno = ENOENT; + break; } - ret = 0; + GF_FREE(u_list->upcall_data.data); + GF_FREE(u_list); + } else { + /* fs->upcall_list was empty, no upcall events cached */ + errno = ENOENT; + } + + ret = 0; out: - pthread_mutex_lock (&fs->mutex); - { - fs->pin_refcnt--; - } - pthread_mutex_unlock (&fs->mutex); + pthread_mutex_lock(&fs->mutex); + { + fs->pin_refcnt--; + } + pthread_mutex_unlock(&fs->mutex); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); restore: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; err: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_poll_upcall, 3.7.16); @@ -2180,72 +2198,70 @@ static gf_boolean_t log_upcall370 = _gf_true; /* log once */ * WARNING: this function will be removed in the future. */ int -pub_glfs_h_poll_upcall370 (struct glfs *fs, struct glfs_callback_arg *up_arg) +pub_glfs_h_poll_upcall370(struct glfs *fs, struct glfs_callback_arg *up_arg) { - struct glfs_upcall *upcall = NULL; - int ret = -1; - - if (log_upcall370) { - log_upcall370 = _gf_false; - gf_log (THIS->name, GF_LOG_WARNING, "this application is " - "compiled against an old version of libgfapi, it " - "should use glfs_free() to release the structure " - "returned by glfs_h_poll_upcall() - for more details, " - "see http://review.gluster.org/14701"); - } + struct glfs_upcall *upcall = NULL; + int ret = -1; + + if (log_upcall370) { + log_upcall370 = _gf_false; + gf_log(THIS->name, GF_LOG_WARNING, + "this application is " + "compiled against an old version of libgfapi, it " + "should use glfs_free() to release the structure " + "returned by glfs_h_poll_upcall() - for more details, " + "see http://review.gluster.org/14701"); + } + + ret = pub_glfs_h_poll_upcall(fs, &upcall); + if (ret == 0) { + up_arg->fs = fs; + if (errno == ENOENT || upcall->event == NULL) { + up_arg->reason = GLFS_UPCALL_EVENT_NULL; + goto out; + } + + up_arg->reason = upcall->reason; + + if (upcall->reason == GLFS_UPCALL_INODE_INVALIDATE) { + struct glfs_callback_inode_arg *cb_inode = NULL; + struct glfs_upcall_inode *up_inode = NULL; + + cb_inode = GF_CALLOC(1, sizeof(struct glfs_callback_inode_arg), + glfs_mt_upcall_inode_t); + if (!cb_inode) { + errno = ENOMEM; + ret = -1; + goto out; + } - ret = pub_glfs_h_poll_upcall (fs, &upcall); - if (ret == 0) { - up_arg->fs = fs; - if (errno == ENOENT || upcall->event == NULL) { - up_arg->reason = GLFS_UPCALL_EVENT_NULL; - goto out; - } + up_inode = upcall->event; - up_arg->reason = upcall->reason; - - if (upcall->reason == GLFS_UPCALL_INODE_INVALIDATE) { - struct glfs_callback_inode_arg *cb_inode = NULL; - struct glfs_upcall_inode *up_inode = NULL; - - cb_inode = GF_CALLOC (1, - sizeof (struct glfs_callback_inode_arg), - glfs_mt_upcall_inode_t); - if (!cb_inode) { - errno = ENOMEM; - ret = -1; - goto out; - } - - up_inode = upcall->event; - - /* copy attributes one by one, the memory layout might - * be different between the old glfs_callback_inode_arg - * and new glfs_upcall_inode */ - cb_inode->object = up_inode->object; - cb_inode->flags = up_inode->flags; - memcpy (&cb_inode->buf, &up_inode->buf, - sizeof (struct stat)); - cb_inode->expire_time_attr = up_inode->expire_time_attr; - cb_inode->p_object = up_inode->p_object; - memcpy (&cb_inode->p_buf, &up_inode->p_buf, - sizeof (struct stat)); - cb_inode->oldp_object = up_inode->oldp_object; - memcpy (&cb_inode->oldp_buf, &up_inode->oldp_buf, - sizeof (struct stat)); - - up_arg->event_arg = cb_inode; - } + /* copy attributes one by one, the memory layout might + * be different between the old glfs_callback_inode_arg + * and new glfs_upcall_inode */ + cb_inode->object = up_inode->object; + cb_inode->flags = up_inode->flags; + memcpy(&cb_inode->buf, &up_inode->buf, sizeof(struct stat)); + cb_inode->expire_time_attr = up_inode->expire_time_attr; + cb_inode->p_object = up_inode->p_object; + memcpy(&cb_inode->p_buf, &up_inode->p_buf, sizeof(struct stat)); + cb_inode->oldp_object = up_inode->oldp_object; + memcpy(&cb_inode->oldp_buf, &up_inode->oldp_buf, + sizeof(struct stat)); + + up_arg->event_arg = cb_inode; } + } out: - if (upcall) { - /* we can not use glfs_free() here, objects need to stay */ - GF_FREE (upcall->event); - GF_FREE (upcall); - } + if (upcall) { + /* we can not use glfs_free() here, objects need to stay */ + GF_FREE(upcall->event); + GF_FREE(upcall); + } - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_h_poll_upcall370, glfs_h_poll_upcall, 3.7.0); @@ -2255,123 +2271,121 @@ GFAPI_SYMVER_PUBLIC(glfs_h_poll_upcall370, glfs_h_poll_upcall, 3.7.0); #include int -pub_glfs_h_acl_set (struct glfs *fs, struct glfs_object *object, - const acl_type_t type, const acl_t acl) +pub_glfs_h_acl_set(struct glfs *fs, struct glfs_object *object, + const acl_type_t type, const acl_t acl) { - int ret = -1; - char *acl_s = NULL; - const char *acl_key = NULL; - struct glfs_object *new_object = NULL; + int ret = -1; + char *acl_s = NULL; + const char *acl_key = NULL; + struct glfs_object *new_object = NULL; - DECLARE_OLD_THIS; + DECLARE_OLD_THIS; - if (!object || !acl) { - errno = EINVAL; - return ret; - } + if (!object || !acl) { + errno = EINVAL; + return ret; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - acl_key = gf_posix_acl_get_key (type); - if (!acl_key) - goto out; + acl_key = gf_posix_acl_get_key(type); + if (!acl_key) + goto out; - acl_s = acl_to_any_text (acl, NULL, ',', - TEXT_ABBREVIATE | TEXT_NUMERIC_IDS); - if (!acl_s) - goto out; + acl_s = acl_to_any_text(acl, NULL, ',', TEXT_ABBREVIATE | TEXT_NUMERIC_IDS); + if (!acl_s) + goto out; - if (IA_ISLNK (object->inode->ia_type)) { - new_object = glfs_h_resolve_symlink (fs, object); - if (new_object == NULL) - goto out; - } else - new_object = object; + if (IA_ISLNK(object->inode->ia_type)) { + new_object = glfs_h_resolve_symlink(fs, object); + if (new_object == NULL) + goto out; + } else + new_object = object; - ret = pub_glfs_h_setxattrs (fs, new_object, acl_key, acl_s, - strlen (acl_s) + 1, 0); + ret = pub_glfs_h_setxattrs(fs, new_object, acl_key, acl_s, + strlen(acl_s) + 1, 0); - acl_free (acl_s); + acl_free(acl_s); out: - if (IA_ISLNK (object->inode->ia_type) && new_object) - glfs_h_close (new_object); + if (IA_ISLNK(object->inode->ia_type) && new_object) + glfs_h_close(new_object); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } acl_t -pub_glfs_h_acl_get (struct glfs *fs, struct glfs_object *object, - const acl_type_t type) +pub_glfs_h_acl_get(struct glfs *fs, struct glfs_object *object, + const acl_type_t type) { - int ret = 0; - acl_t acl = NULL; - char *acl_s = NULL; - dict_t *xattr = NULL; - const char *acl_key = NULL; - struct glfs_object *new_object = NULL; - - DECLARE_OLD_THIS; - - if (!object) { - errno = EINVAL; - return NULL; - } + int ret = 0; + acl_t acl = NULL; + char *acl_s = NULL; + dict_t *xattr = NULL; + const char *acl_key = NULL; + struct glfs_object *new_object = NULL; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; - acl_key = gf_posix_acl_get_key (type); - if (!acl_key) - goto out; + if (!object) { + errno = EINVAL; + return NULL; + } - if (IA_ISLNK (object->inode->ia_type)) { - new_object = glfs_h_resolve_symlink (fs, object); - if (new_object == NULL) - goto out; - } else - new_object = object; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - ret = glfs_h_getxattrs_common (fs, new_object, &xattr, acl_key, - _gf_false); - if (ret) - goto out; + acl_key = gf_posix_acl_get_key(type); + if (!acl_key) + goto out; - ret = dict_get_str (xattr, (char *)acl_key, &acl_s); - if (ret) - goto out; + if (IA_ISLNK(object->inode->ia_type)) { + new_object = glfs_h_resolve_symlink(fs, object); + if (new_object == NULL) + goto out; + } else + new_object = object; + + ret = glfs_h_getxattrs_common(fs, new_object, &xattr, acl_key, _gf_false); + if (ret) + goto out; - acl = acl_from_text (acl_s); + ret = dict_get_str(xattr, (char *)acl_key, &acl_s); + if (ret) + goto out; + + acl = acl_from_text(acl_s); out: - if (xattr) - dict_unref(xattr); + if (xattr) + dict_unref(xattr); - if (IA_ISLNK (object->inode->ia_type) && new_object) - glfs_h_close (new_object); + if (IA_ISLNK(object->inode->ia_type) && new_object) + glfs_h_close(new_object); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return acl; + return acl; } #else /* !HAVE_ACL_LIBACL_H */ acl_t -pub_glfs_h_acl_get (struct glfs *fs, struct glfs_object *object, - const acl_type_t type) +pub_glfs_h_acl_get(struct glfs *fs, struct glfs_object *object, + const acl_type_t type) { - errno = ENOTSUP; - return NULL; + errno = ENOTSUP; + return NULL; } int -pub_glfs_h_acl_set (struct glfs *fs, struct glfs_object *object, - const acl_type_t type, const acl_t acl) +pub_glfs_h_acl_set(struct glfs *fs, struct glfs_object *object, + const acl_type_t type, const acl_t acl) { - errno = ENOTSUP; - return -1; + errno = ENOTSUP; + return -1; } #endif GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_acl_set, 3.7.0); @@ -2379,153 +2393,158 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_acl_get, 3.7.0); /* The API to perform read using anonymous fd */ ssize_t -pub_glfs_h_anonymous_read (struct glfs *fs, struct glfs_object *object, - const void *buf, size_t count, off_t offset) +pub_glfs_h_anonymous_read(struct glfs *fs, struct glfs_object *object, + const void *buf, size_t count, off_t offset) { - struct iovec iov = {0, }; - ssize_t ret = 0; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } + struct iovec iov = { + 0, + }; + ssize_t ret = 0; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_anonymous_preadv (fs, object, &iov, 1, offset, 0); + ret = glfs_anonymous_preadv(fs, object, &iov, 1, offset, 0); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_anonymous_read, 3.7.0); /* The API to perform write using anonymous fd */ ssize_t -pub_glfs_h_anonymous_write (struct glfs *fs, struct glfs_object *object, - const void *buf, size_t count, off_t offset) +pub_glfs_h_anonymous_write(struct glfs *fs, struct glfs_object *object, + const void *buf, size_t count, off_t offset) { - struct iovec iov = {0, }; - ssize_t ret = 0; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } + struct iovec iov = { + 0, + }; + ssize_t ret = 0; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_anonymous_pwritev (fs, object, &iov, 1, offset, 0); + ret = glfs_anonymous_pwritev(fs, object, &iov, 1, offset, 0); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_anonymous_write, 3.7.0); -struct glfs_object* -pub_glfs_object_copy (struct glfs_object *src) +struct glfs_object * +pub_glfs_object_copy(struct glfs_object *src) { - struct glfs_object *object = NULL; + struct glfs_object *object = NULL; - GF_VALIDATE_OR_GOTO ("glfs_dup_object", src, out); + GF_VALIDATE_OR_GOTO("glfs_dup_object", src, out); - object = GF_CALLOC (1, sizeof(struct glfs_object), - glfs_mt_glfs_object_t); - if (object == NULL) { - errno = ENOMEM; - gf_msg (THIS->name, GF_LOG_WARNING, errno, - API_MSG_CREATE_HANDLE_FAILED, - "glfs_dup_object for gfid-%s failed", - uuid_utoa (src->inode->gfid)); - return NULL; - } + object = GF_CALLOC(1, sizeof(struct glfs_object), glfs_mt_glfs_object_t); + if (object == NULL) { + errno = ENOMEM; + gf_msg(THIS->name, GF_LOG_WARNING, errno, API_MSG_CREATE_HANDLE_FAILED, + "glfs_dup_object for gfid-%s failed", + uuid_utoa(src->inode->gfid)); + return NULL; + } - object->inode = inode_ref (src->inode); - gf_uuid_copy (object->gfid, src->inode->gfid); + object->inode = inode_ref(src->inode); + gf_uuid_copy(object->gfid, src->inode->gfid); out: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_object_copy, 3.11.0); -struct glfs_object* -pub_glfs_xreaddirplus_get_object (struct glfs_xreaddirp_stat *xstat) +struct glfs_object * +pub_glfs_xreaddirplus_get_object(struct glfs_xreaddirp_stat *xstat) { - GF_VALIDATE_OR_GOTO ("glfs_xreaddirplus_get_object", xstat, out); + GF_VALIDATE_OR_GOTO("glfs_xreaddirplus_get_object", xstat, out); - if (!(xstat->flags_handled & GFAPI_XREADDIRP_HANDLE)) - gf_msg (THIS->name, GF_LOG_ERROR, errno, - LG_MSG_INVALID_ARG, - "GFAPI_XREADDIRP_HANDLE is not set. Flags" - "handled for xstat(%p) are (%x)", - xstat, xstat->flags_handled); + if (!(xstat->flags_handled & GFAPI_XREADDIRP_HANDLE)) + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "GFAPI_XREADDIRP_HANDLE is not set. Flags" + "handled for xstat(%p) are (%x)", + xstat, xstat->flags_handled); - return xstat->object; + return xstat->object; out: - return NULL; + return NULL; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_get_object, 3.11.0); int -pub_glfs_h_lease (struct glfs *fs, struct glfs_object *object, - struct glfs_lease *lease) +pub_glfs_h_lease(struct glfs *fs, struct glfs_object *object, + struct glfs_lease *lease) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct gf_lease gf_lease = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct gf_lease gf_lease = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); - glfs_lease_to_gf_lease (lease, &gf_lease); + glfs_lease_to_gf_lease(lease, &gf_lease); - ret = syncop_lease (subvol, &loc, &gf_lease, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_lease(subvol, &loc, &gf_lease, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - gf_lease_to_glfs_lease (&gf_lease, lease); + gf_lease_to_glfs_lease(&gf_lease, lease); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_lease, 4.0.0); diff --git a/api/src/glfs-master.c b/api/src/glfs-master.c index 9648bbbc03a..969095a8224 100644 --- a/api/src/glfs-master.c +++ b/api/src/glfs-master.c @@ -22,166 +22,153 @@ #include "glfs-mem-types.h" #include "gfapi-messages.h" - int -graph_setup (struct glfs *fs, glusterfs_graph_t *graph) +graph_setup(struct glfs *fs, glusterfs_graph_t *graph) { - xlator_t *new_subvol = NULL; - xlator_t *old_subvol = NULL; - inode_table_t *itable = NULL; - int ret = -1; - - new_subvol = graph->top; - - /* This is called in a bottom-up context, it should specifically - NOT be glfs_lock() - */ - pthread_mutex_lock (&fs->mutex); - { - if (new_subvol->switched || - new_subvol == fs->active_subvol || - new_subvol == fs->next_subvol || - new_subvol == fs->mip_subvol) { - /* Spurious CHILD_UP event on old graph */ - ret = 0; - goto unlock; - } - - if (!new_subvol->itable) { - itable = inode_table_new (131072, new_subvol); - if (!itable) { - errno = ENOMEM; - ret = -1; - goto unlock; - } - - new_subvol->itable = itable; - } - - old_subvol = fs->next_subvol; - fs->next_subvol = new_subvol; - fs->next_subvol->winds++; /* first ref */ - ret = 0; - } + xlator_t *new_subvol = NULL; + xlator_t *old_subvol = NULL; + inode_table_t *itable = NULL; + int ret = -1; + + new_subvol = graph->top; + + /* This is called in a bottom-up context, it should specifically + NOT be glfs_lock() + */ + pthread_mutex_lock(&fs->mutex); + { + if (new_subvol->switched || new_subvol == fs->active_subvol || + new_subvol == fs->next_subvol || new_subvol == fs->mip_subvol) { + /* Spurious CHILD_UP event on old graph */ + ret = 0; + goto unlock; + } + + if (!new_subvol->itable) { + itable = inode_table_new(131072, new_subvol); + if (!itable) { + errno = ENOMEM; + ret = -1; + goto unlock; + } + + new_subvol->itable = itable; + } + + old_subvol = fs->next_subvol; + fs->next_subvol = new_subvol; + fs->next_subvol->winds++; /* first ref */ + ret = 0; + } unlock: - pthread_mutex_unlock (&fs->mutex); + pthread_mutex_unlock(&fs->mutex); - if (old_subvol) - /* wasn't picked up so far, skip */ - glfs_subvol_done (fs, old_subvol); + if (old_subvol) + /* wasn't picked up so far, skip */ + glfs_subvol_done(fs, old_subvol); - return ret; + return ret; } - int -notify (xlator_t *this, int event, void *data, ...) +notify(xlator_t *this, int event, void *data, ...) { - glusterfs_graph_t *graph = NULL; - struct glfs *fs = NULL; - - graph = data; - fs = this->private; - - switch (event) { - case GF_EVENT_GRAPH_NEW: - gf_msg (this->name, GF_LOG_INFO, 0, API_MSG_NEW_GRAPH, - "New graph %s (%d) coming up", - uuid_utoa ((unsigned char *)graph->graph_uuid), - graph->id); - break; - case GF_EVENT_CHILD_UP: - pthread_mutex_lock (&fs->mutex); - { - graph->used = 1; - } - pthread_mutex_unlock (&fs->mutex); - graph_setup (fs, graph); - glfs_init_done (fs, 0); - break; - case GF_EVENT_CHILD_DOWN: - pthread_mutex_lock (&fs->mutex); - { - graph->used = 0; - pthread_cond_broadcast (&fs->child_down_cond); - } - pthread_mutex_unlock (&fs->mutex); - glfs_init_done (fs, 1); - break; - case GF_EVENT_CHILD_CONNECTING: - break; + glusterfs_graph_t *graph = NULL; + struct glfs *fs = NULL; + + graph = data; + fs = this->private; + + switch (event) { + case GF_EVENT_GRAPH_NEW: + gf_msg(this->name, GF_LOG_INFO, 0, API_MSG_NEW_GRAPH, + "New graph %s (%d) coming up", + uuid_utoa((unsigned char *)graph->graph_uuid), graph->id); + break; + case GF_EVENT_CHILD_UP: + pthread_mutex_lock(&fs->mutex); + { + graph->used = 1; + } + pthread_mutex_unlock(&fs->mutex); + graph_setup(fs, graph); + glfs_init_done(fs, 0); + break; + case GF_EVENT_CHILD_DOWN: + pthread_mutex_lock(&fs->mutex); + { + graph->used = 0; + pthread_cond_broadcast(&fs->child_down_cond); + } + pthread_mutex_unlock(&fs->mutex); + glfs_init_done(fs, 1); + break; + case GF_EVENT_CHILD_CONNECTING: + break; case GF_EVENT_UPCALL: - glfs_process_upcall_event (fs, data); - break; - default: - gf_msg_debug (this->name, 0, "got notify event %d", event); - break; - } - - return 0; + glfs_process_upcall_event(fs, data); + break; + default: + gf_msg_debug(this->name, 0, "got notify event %d", event); + break; + } + + return 0; } - int -mem_acct_init (xlator_t *this) +mem_acct_init(xlator_t *this) { - int ret = -1; + int ret = -1; - if (!this) - return ret; + if (!this) + return ret; - ret = xlator_mem_acct_init (this, glfs_mt_end + 1); - if (ret) { - gf_msg (this->name, GF_LOG_ERROR, ENOMEM, - API_MSG_MEM_ACCT_INIT_FAILED, "Failed to initialise " - "memory accounting"); - return ret; - } + ret = xlator_mem_acct_init(this, glfs_mt_end + 1); + if (ret) { + gf_msg(this->name, GF_LOG_ERROR, ENOMEM, API_MSG_MEM_ACCT_INIT_FAILED, + "Failed to initialise " + "memory accounting"); + return ret; + } - return 0; + return 0; } - int -init (xlator_t *this) +init(xlator_t *this) { - return 0; + return 0; } - void -fini (xlator_t *this) +fini(xlator_t *this) { - } /* place-holder fops */ int -glfs_forget (xlator_t *this, inode_t *inode) +glfs_forget(xlator_t *this, inode_t *inode) { - return 0; + return 0; } int -glfs_release (xlator_t *this, fd_t *fd) +glfs_release(xlator_t *this, fd_t *fd) { - return 0; + return 0; } int -glfs_releasedir (xlator_t *this, fd_t *fd) +glfs_releasedir(xlator_t *this, fd_t *fd) { - return 0; + return 0; } struct xlator_dumpops dumpops; - struct xlator_fops fops; - -struct xlator_cbks cbks = { - .forget = glfs_forget, - .release = glfs_release, - .releasedir = glfs_releasedir -}; +struct xlator_cbks cbks = {.forget = glfs_forget, + .release = glfs_release, + .releasedir = glfs_releasedir}; diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c index fac903b805a..87b62173689 100644 --- a/api/src/glfs-mgmt.c +++ b/api/src/glfs-mgmt.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - #include #include #include @@ -38,1063 +37,1034 @@ #include "gfapi-messages.h" #include "syscall.h" -int glfs_volfile_fetch (struct glfs *fs); -int32_t glfs_get_volume_info_rpc (call_frame_t *frame, xlator_t *this, - struct glfs *fs); +int +glfs_volfile_fetch(struct glfs *fs); +int32_t +glfs_get_volume_info_rpc(call_frame_t *frame, xlator_t *this, struct glfs *fs); int -glfs_process_volfp (struct glfs *fs, FILE *fp) +glfs_process_volfp(struct glfs *fs, FILE *fp) { - glusterfs_graph_t *graph = NULL; - int ret = -1; - xlator_t *trav = NULL; - glusterfs_ctx_t *ctx = NULL; - - ctx = fs->ctx; - graph = glusterfs_graph_construct (fp); - if (!graph) { - gf_msg ("glfs", GF_LOG_ERROR, errno, - API_MSG_GRAPH_CONSTRUCT_FAILED, - "failed to construct the graph"); - goto out; - } - - for (trav = graph->first; trav; trav = trav->next) { - if (strcmp (trav->type, "mount/api") == 0) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, - API_MSG_API_XLATOR_ERROR, - "api master xlator cannot be specified " - "in volume file"); - goto out; - } - } - - ret = glusterfs_graph_prepare (graph, ctx, fs->volname); - if (ret) { - glusterfs_graph_destroy (graph); - goto out; - } - - ret = glusterfs_graph_activate (graph, ctx); - - if (ret) { - glusterfs_graph_destroy (graph); - goto out; - } - - gf_log_dump_graph (fp, graph); - - ret = 0; + glusterfs_graph_t *graph = NULL; + int ret = -1; + xlator_t *trav = NULL; + glusterfs_ctx_t *ctx = NULL; + + ctx = fs->ctx; + graph = glusterfs_graph_construct(fp); + if (!graph) { + gf_msg("glfs", GF_LOG_ERROR, errno, API_MSG_GRAPH_CONSTRUCT_FAILED, + "failed to construct the graph"); + goto out; + } + + for (trav = graph->first; trav; trav = trav->next) { + if (strcmp(trav->type, "mount/api") == 0) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_API_XLATOR_ERROR, + "api master xlator cannot be specified " + "in volume file"); + goto out; + } + } + + ret = glusterfs_graph_prepare(graph, ctx, fs->volname); + if (ret) { + glusterfs_graph_destroy(graph); + goto out; + } + + ret = glusterfs_graph_activate(graph, ctx); + + if (ret) { + glusterfs_graph_destroy(graph); + goto out; + } + + gf_log_dump_graph(fp, graph); + + ret = 0; out: - if (fp) - fclose (fp); + if (fp) + fclose(fp); - if (!ctx->active) { - ret = -1; - } + if (!ctx->active) { + ret = -1; + } - return ret; + return ret; } - int -mgmt_cbk_spec (struct rpc_clnt *rpc, void *mydata, void *data) +mgmt_cbk_spec(struct rpc_clnt *rpc, void *mydata, void *data) { - struct glfs *fs = NULL; - xlator_t *this = NULL; + struct glfs *fs = NULL; + xlator_t *this = NULL; - this = mydata; - fs = this->private; + this = mydata; + fs = this->private; - glfs_volfile_fetch (fs); + glfs_volfile_fetch(fs); - return 0; + return 0; } - int -mgmt_cbk_event (struct rpc_clnt *rpc, void *mydata, void *data) +mgmt_cbk_event(struct rpc_clnt *rpc, void *mydata, void *data) { - return 0; + return 0; } static int -mgmt_cbk_statedump (struct rpc_clnt *rpc, void *mydata, void *data) +mgmt_cbk_statedump(struct rpc_clnt *rpc, void *mydata, void *data) { - struct glfs *fs = NULL; - xlator_t *this = NULL; - gf_statedump target_pid = {0, }; - struct iovec *iov = NULL; - int ret = -1; - - this = mydata; - if (!this) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, - API_MSG_STATEDUMP_FAILED, "NULL mydata"); - errno = EINVAL; - goto out; - } - - fs = this->private; - if (!fs) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, - API_MSG_STATEDUMP_FAILED, "NULL glfs"); - errno = EINVAL; - goto out; - } - - iov = (struct iovec *)data; - if (!iov) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, - API_MSG_STATEDUMP_FAILED, "NULL iovec data"); - errno = EINVAL; - goto out; - } - - ret = xdr_to_generic (*iov, &target_pid, - (xdrproc_t)xdr_gf_statedump); + struct glfs *fs = NULL; + xlator_t *this = NULL; + gf_statedump target_pid = { + 0, + }; + struct iovec *iov = NULL; + int ret = -1; + + this = mydata; + if (!this) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_STATEDUMP_FAILED, + "NULL mydata"); + errno = EINVAL; + goto out; + } + + fs = this->private; + if (!fs) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_STATEDUMP_FAILED, + "NULL glfs"); + errno = EINVAL; + goto out; + } + + iov = (struct iovec *)data; + if (!iov) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_STATEDUMP_FAILED, + "NULL iovec data"); + errno = EINVAL; + goto out; + } + + ret = xdr_to_generic(*iov, &target_pid, (xdrproc_t)xdr_gf_statedump); + if (ret < 0) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_STATEDUMP_FAILED, + "Failed to decode xdr response for GF_CBK_STATEDUMP"); + goto out; + } + + gf_msg_trace("glfs", 0, "statedump requested for pid: %d", target_pid.pid); + + if ((uint64_t)getpid() == target_pid.pid) { + gf_msg_debug("glfs", 0, "Taking statedump for pid: %d", target_pid.pid); + + ret = glfs_sysrq(fs, GLFS_SYSRQ_STATEDUMP); if (ret < 0) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, - API_MSG_STATEDUMP_FAILED, - "Failed to decode xdr response for GF_CBK_STATEDUMP"); - goto out; - } - - gf_msg_trace ("glfs", 0, "statedump requested for pid: %d", - target_pid.pid); - - if ((uint64_t)getpid() == target_pid.pid) { - gf_msg_debug ("glfs", 0, "Taking statedump for pid: %d", - target_pid.pid); - - ret = glfs_sysrq (fs, GLFS_SYSRQ_STATEDUMP); - if (ret < 0) { - gf_msg ("glfs", GF_LOG_INFO, 0, - API_MSG_STATEDUMP_FAILED, - "statedump failed"); - } + gf_msg("glfs", GF_LOG_INFO, 0, API_MSG_STATEDUMP_FAILED, + "statedump failed"); } + } out: - return ret; + return ret; } rpcclnt_cb_actor_t mgmt_cbk_actors[GF_CBK_MAXVALUE] = { - [GF_CBK_FETCHSPEC] = {"FETCHSPEC", GF_CBK_FETCHSPEC, mgmt_cbk_spec }, - [GF_CBK_EVENT_NOTIFY] = {"EVENTNOTIFY", GF_CBK_EVENT_NOTIFY, - mgmt_cbk_event}, - [GF_CBK_STATEDUMP] = {"STATEDUMP", GF_CBK_STATEDUMP, mgmt_cbk_statedump}, + [GF_CBK_FETCHSPEC] = {"FETCHSPEC", GF_CBK_FETCHSPEC, mgmt_cbk_spec}, + [GF_CBK_EVENT_NOTIFY] = {"EVENTNOTIFY", GF_CBK_EVENT_NOTIFY, + mgmt_cbk_event}, + [GF_CBK_STATEDUMP] = {"STATEDUMP", GF_CBK_STATEDUMP, mgmt_cbk_statedump}, }; - struct rpcclnt_cb_program mgmt_cbk_prog = { - .progname = "GlusterFS Callback", - .prognum = GLUSTER_CBK_PROGRAM, - .progver = GLUSTER_CBK_VERSION, - .actors = mgmt_cbk_actors, - .numactors = GF_CBK_MAXVALUE, + .progname = "GlusterFS Callback", + .prognum = GLUSTER_CBK_PROGRAM, + .progver = GLUSTER_CBK_VERSION, + .actors = mgmt_cbk_actors, + .numactors = GF_CBK_MAXVALUE, }; char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { - [GF_HNDSK_NULL] = "NULL", - [GF_HNDSK_SETVOLUME] = "SETVOLUME", - [GF_HNDSK_GETSPEC] = "GETSPEC", - [GF_HNDSK_PING] = "PING", - [GF_HNDSK_EVENT_NOTIFY] = "EVENTNOTIFY", - [GF_HNDSK_GET_VOLUME_INFO] = "GETVOLUMEINFO", + [GF_HNDSK_NULL] = "NULL", + [GF_HNDSK_SETVOLUME] = "SETVOLUME", + [GF_HNDSK_GETSPEC] = "GETSPEC", + [GF_HNDSK_PING] = "PING", + [GF_HNDSK_EVENT_NOTIFY] = "EVENTNOTIFY", + [GF_HNDSK_GET_VOLUME_INFO] = "GETVOLUMEINFO", }; rpc_clnt_prog_t clnt_handshake_prog = { - .progname = "GlusterFS Handshake", - .prognum = GLUSTER_HNDSK_PROGRAM, - .progver = GLUSTER_HNDSK_VERSION, - .procnames = clnt_handshake_procs, + .progname = "GlusterFS Handshake", + .prognum = GLUSTER_HNDSK_PROGRAM, + .progver = GLUSTER_HNDSK_VERSION, + .procnames = clnt_handshake_procs, }; - int -mgmt_submit_request (void *req, call_frame_t *frame, - glusterfs_ctx_t *ctx, - rpc_clnt_prog_t *prog, int procnum, - fop_cbk_fn_t cbkfn, xdrproc_t xdrproc) +mgmt_submit_request(void *req, call_frame_t *frame, glusterfs_ctx_t *ctx, + rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbkfn, + xdrproc_t xdrproc) { - int ret = -1; - int count = 0; - struct iovec iov = {0, }; - struct iobuf *iobuf = NULL; - struct iobref *iobref = NULL; - ssize_t xdr_size = 0; - - iobref = iobref_new (); - if (!iobref) { - goto out; - } - - if (req) { - xdr_size = xdr_sizeof (xdrproc, req); - - iobuf = iobuf_get2 (ctx->iobuf_pool, xdr_size); - if (!iobuf) { - goto out; - }; - - iobref_add (iobref, iobuf); - - iov.iov_base = iobuf->ptr; - iov.iov_len = iobuf_pagesize (iobuf); - - /* Create the xdr payload */ - ret = xdr_serialize_generic (iov, req, xdrproc); - if (ret == -1) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - API_MSG_XDR_PAYLOAD_FAILED, - "failed to create XDR payload"); - goto out; - } - iov.iov_len = ret; - count = 1; - } - - /* Send the msg */ - ret = rpc_clnt_submit (ctx->mgmt, prog, procnum, cbkfn, - &iov, count, - NULL, 0, iobref, frame, NULL, 0, NULL, 0, NULL); + int ret = -1; + int count = 0; + struct iovec iov = { + 0, + }; + struct iobuf *iobuf = NULL; + struct iobref *iobref = NULL; + ssize_t xdr_size = 0; + + iobref = iobref_new(); + if (!iobref) { + goto out; + } + + if (req) { + xdr_size = xdr_sizeof(xdrproc, req); + + iobuf = iobuf_get2(ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto out; + }; + + iobref_add(iobref, iobuf); + + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_pagesize(iobuf); + + /* Create the xdr payload */ + ret = xdr_serialize_generic(iov, req, xdrproc); + if (ret == -1) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, API_MSG_XDR_PAYLOAD_FAILED, + "failed to create XDR payload"); + goto out; + } + iov.iov_len = ret; + count = 1; + } + + /* Send the msg */ + ret = rpc_clnt_submit(ctx->mgmt, prog, procnum, cbkfn, &iov, count, NULL, 0, + iobref, frame, NULL, 0, NULL, 0, NULL); out: - if (iobref) - iobref_unref (iobref); + if (iobref) + iobref_unref(iobref); - if (iobuf) - iobuf_unref (iobuf); - return ret; + if (iobuf) + iobuf_unref(iobuf); + return ret; } /* * Callback routine for 'GF_HNDSK_GET_VOLUME_INFO' rpc request */ int -mgmt_get_volinfo_cbk (struct rpc_req *req, struct iovec *iov, - int count, void *myframe) +mgmt_get_volinfo_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - int ret = 0; - char *volume_id_str = NULL; - dict_t *dict = NULL; - char key[1024] = {0}; - gf_get_volume_info_rsp rsp = {0,}; - call_frame_t *frame = NULL; - glusterfs_ctx_t *ctx = NULL; - struct glfs *fs = NULL; - struct syncargs *args; - - frame = myframe; - ctx = frame->this->ctx; - args = frame->local; - - if (!ctx) { - gf_msg (frame->this->name, GF_LOG_ERROR, EINVAL, - API_MSG_INVALID_ENTRY, "NULL context"); - errno = EINVAL; - ret = -1; - goto out; - } - - fs = ((xlator_t *)ctx->master)->private; - - if (-1 == req->rpc_status) { - gf_msg (frame->this->name, GF_LOG_ERROR, EINVAL, - API_MSG_INVALID_ENTRY, - "GET_VOLUME_INFO RPC call is not successful"); - errno = EINVAL; - ret = -1; - goto out; - } - - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_get_volume_info_rsp); - - if (ret < 0) { - gf_msg (frame->this->name, GF_LOG_ERROR, 0, - API_MSG_XDR_RESPONSE_DECODE_FAILED, - "Failed to decode xdr response for GET_VOLUME_INFO"); - goto out; - } - - gf_msg_debug (frame->this->name, 0, "Received resp to GET_VOLUME_INFO " - "RPC: %d", rsp.op_ret); - - if (rsp.op_ret == -1) { - errno = rsp.op_errno; - ret = -1; - goto out; - } - - if (!rsp.dict.dict_len) { - gf_msg (frame->this->name, GF_LOG_ERROR, EINVAL, - API_MSG_INVALID_ENTRY, "Response received for " - "GET_VOLUME_INFO RPC call is not valid"); - ret = -1; - errno = EINVAL; - goto out; - } - - dict = dict_new (); - - if (!dict) { - ret = -1; - errno = ENOMEM; - goto out; - } - - ret = dict_unserialize (rsp.dict.dict_val, - rsp.dict.dict_len, - &dict); - - if (ret) { - errno = ENOMEM; - goto out; - } - - snprintf (key, sizeof (key), "volume_id"); - ret = dict_get_str (dict, key, &volume_id_str); - if (ret) { - errno = EINVAL; - goto out; - } - - ret = 0; + int ret = 0; + char *volume_id_str = NULL; + dict_t *dict = NULL; + char key[1024] = {0}; + gf_get_volume_info_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + glusterfs_ctx_t *ctx = NULL; + struct glfs *fs = NULL; + struct syncargs *args; + + frame = myframe; + ctx = frame->this->ctx; + args = frame->local; + + if (!ctx) { + gf_msg(frame->this->name, GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "NULL context"); + errno = EINVAL; + ret = -1; + goto out; + } + + fs = ((xlator_t *)ctx->master)->private; + + if (-1 == req->rpc_status) { + gf_msg(frame->this->name, GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "GET_VOLUME_INFO RPC call is not successful"); + errno = EINVAL; + ret = -1; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_get_volume_info_rsp); + + if (ret < 0) { + gf_msg(frame->this->name, GF_LOG_ERROR, 0, + API_MSG_XDR_RESPONSE_DECODE_FAILED, + "Failed to decode xdr response for GET_VOLUME_INFO"); + goto out; + } + + gf_msg_debug(frame->this->name, 0, + "Received resp to GET_VOLUME_INFO " + "RPC: %d", + rsp.op_ret); + + if (rsp.op_ret == -1) { + errno = rsp.op_errno; + ret = -1; + goto out; + } + + if (!rsp.dict.dict_len) { + gf_msg(frame->this->name, GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "Response received for " + "GET_VOLUME_INFO RPC call is not valid"); + ret = -1; + errno = EINVAL; + goto out; + } + + dict = dict_new(); + + if (!dict) { + ret = -1; + errno = ENOMEM; + goto out; + } + + ret = dict_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict); + + if (ret) { + errno = ENOMEM; + goto out; + } + + snprintf(key, sizeof(key), "volume_id"); + ret = dict_get_str(dict, key, &volume_id_str); + if (ret) { + errno = EINVAL; + goto out; + } + + ret = 0; out: - if (volume_id_str) { - gf_msg_debug (frame->this->name, 0, - "Volume Id: %s", volume_id_str); - pthread_mutex_lock (&fs->mutex); - gf_uuid_parse (volume_id_str, fs->vol_uuid); - pthread_mutex_unlock (&fs->mutex); - } + if (volume_id_str) { + gf_msg_debug(frame->this->name, 0, "Volume Id: %s", volume_id_str); + pthread_mutex_lock(&fs->mutex); + gf_uuid_parse(volume_id_str, fs->vol_uuid); + pthread_mutex_unlock(&fs->mutex); + } - if (ret) { - gf_msg (frame->this->name, GF_LOG_ERROR, errno, - API_MSG_GET_VOLINFO_CBK_FAILED, "In GET_VOLUME_INFO " - "cbk, received error: %s", strerror(errno)); - } + if (ret) { + gf_msg(frame->this->name, GF_LOG_ERROR, errno, + API_MSG_GET_VOLINFO_CBK_FAILED, + "In GET_VOLUME_INFO " + "cbk, received error: %s", + strerror(errno)); + } - if (dict) - dict_unref (dict); + if (dict) + dict_unref(dict); - if (rsp.dict.dict_val) - free (rsp.dict.dict_val); + if (rsp.dict.dict_val) + free(rsp.dict.dict_val); - if (rsp.op_errstr) - free (rsp.op_errstr); + if (rsp.op_errstr) + free(rsp.op_errstr); - gf_msg_debug (frame->this->name, 0, "Returning: %d", ret); + gf_msg_debug(frame->this->name, 0, "Returning: %d", ret); - __wake (args); + __wake(args); - return ret; + return ret; } int -pub_glfs_get_volumeid (struct glfs *fs, char *volid, size_t size) +pub_glfs_get_volumeid(struct glfs *fs, char *volid, size_t size) { - /* TODO: Define a global macro to store UUID size */ - size_t uuid_size = 16; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - pthread_mutex_lock (&fs->mutex); - { - /* check if the volume uuid is initialized */ - if (!gf_uuid_is_null (fs->vol_uuid)) { - pthread_mutex_unlock (&fs->mutex); - goto done; - } + /* TODO: Define a global macro to store UUID size */ + size_t uuid_size = 16; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + pthread_mutex_lock(&fs->mutex); + { + /* check if the volume uuid is initialized */ + if (!gf_uuid_is_null(fs->vol_uuid)) { + pthread_mutex_unlock(&fs->mutex); + goto done; } - pthread_mutex_unlock (&fs->mutex); + } + pthread_mutex_unlock(&fs->mutex); - /* Need to fetch volume_uuid */ - glfs_get_volume_info (fs); + /* Need to fetch volume_uuid */ + glfs_get_volume_info(fs); - if (gf_uuid_is_null (fs->vol_uuid)) { - gf_msg (THIS->name, GF_LOG_ERROR, EINVAL, - API_MSG_FETCH_VOLUUID_FAILED, "Unable to fetch " - "volume UUID"); - goto out; - } + if (gf_uuid_is_null(fs->vol_uuid)) { + gf_msg(THIS->name, GF_LOG_ERROR, EINVAL, API_MSG_FETCH_VOLUUID_FAILED, + "Unable to fetch " + "volume UUID"); + goto out; + } done: - if (!volid || !size) { - gf_msg_debug (THIS->name, 0, "volumeid/size is null"); - __GLFS_EXIT_FS; - return uuid_size; - } + if (!volid || !size) { + gf_msg_debug(THIS->name, 0, "volumeid/size is null"); + __GLFS_EXIT_FS; + return uuid_size; + } - if (size < uuid_size) { - gf_msg (THIS->name, GF_LOG_ERROR, ERANGE, API_MSG_INSUFF_SIZE, - "Insufficient size passed"); - errno = ERANGE; - goto out; - } + if (size < uuid_size) { + gf_msg(THIS->name, GF_LOG_ERROR, ERANGE, API_MSG_INSUFF_SIZE, + "Insufficient size passed"); + errno = ERANGE; + goto out; + } - memcpy (volid, fs->vol_uuid, uuid_size); + memcpy(volid, fs->vol_uuid, uuid_size); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return uuid_size; + return uuid_size; out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_get_volumeid, 3.5.0); int -glfs_get_volume_info (struct glfs *fs) +glfs_get_volume_info(struct glfs *fs) { - call_frame_t *frame = NULL; - glusterfs_ctx_t *ctx = NULL; - struct syncargs args = {0, }; - int ret = 0; - - ctx = fs->ctx; - frame = create_frame (THIS, ctx->pool); - if (!frame) { - gf_msg ("glfs", GF_LOG_ERROR, ENOMEM, - API_MSG_FRAME_CREAT_FAILED, - "failed to create the frame"); - ret = -1; - goto out; - } + call_frame_t *frame = NULL; + glusterfs_ctx_t *ctx = NULL; + struct syncargs args = { + 0, + }; + int ret = 0; - frame->local = &args; + ctx = fs->ctx; + frame = create_frame(THIS, ctx->pool); + if (!frame) { + gf_msg("glfs", GF_LOG_ERROR, ENOMEM, API_MSG_FRAME_CREAT_FAILED, + "failed to create the frame"); + ret = -1; + goto out; + } - __yawn ((&args)); + frame->local = &args; - ret = glfs_get_volume_info_rpc (frame, THIS, fs); - if (ret) - goto out; + __yawn((&args)); - __yield ((&args)); + ret = glfs_get_volume_info_rpc(frame, THIS, fs); + if (ret) + goto out; - frame->local = NULL; - STACK_DESTROY (frame->root); + __yield((&args)); + + frame->local = NULL; + STACK_DESTROY(frame->root); out: - return ret; + return ret; } int32_t -glfs_get_volume_info_rpc (call_frame_t *frame, xlator_t *this, - struct glfs *fs) +glfs_get_volume_info_rpc(call_frame_t *frame, xlator_t *this, struct glfs *fs) { - gf_get_volume_info_req req = {{0,}}; - int ret = 0; - glusterfs_ctx_t *ctx = NULL; - dict_t *dict = NULL; - int32_t flags = 0; - - if (!frame || !this || !fs) { - ret = -1; - goto out; - } - - ctx = fs->ctx; - - dict = dict_new (); - if (!dict) { - ret = -1; - goto out; - } - - if (fs->volname) { - ret = dict_set_str (dict, "volname", fs->volname); - if (ret) - goto out; - } - - // Set the flags for the fields which we are interested in - flags = (int32_t)GF_GET_VOLUME_UUID; //ctx->flags; - ret = dict_set_int32 (dict, "flags", flags); - if (ret) { - gf_msg (frame->this->name, GF_LOG_ERROR, EINVAL, - API_MSG_DICT_SET_FAILED, "failed to set flags"); - goto out; - } - - ret = dict_allocate_and_serialize (dict, &req.dict.dict_val, - &req.dict.dict_len); - - - ret = mgmt_submit_request (&req, frame, ctx, &clnt_handshake_prog, - GF_HNDSK_GET_VOLUME_INFO, - mgmt_get_volinfo_cbk, - (xdrproc_t)xdr_gf_get_volume_info_req); + gf_get_volume_info_req req = {{ + 0, + }}; + int ret = 0; + glusterfs_ctx_t *ctx = NULL; + dict_t *dict = NULL; + int32_t flags = 0; + + if (!frame || !this || !fs) { + ret = -1; + goto out; + } + + ctx = fs->ctx; + + dict = dict_new(); + if (!dict) { + ret = -1; + goto out; + } + + if (fs->volname) { + ret = dict_set_str(dict, "volname", fs->volname); + if (ret) + goto out; + } + + // Set the flags for the fields which we are interested in + flags = (int32_t)GF_GET_VOLUME_UUID; // ctx->flags; + ret = dict_set_int32(dict, "flags", flags); + if (ret) { + gf_msg(frame->this->name, GF_LOG_ERROR, EINVAL, API_MSG_DICT_SET_FAILED, + "failed to set flags"); + goto out; + } + + ret = dict_allocate_and_serialize(dict, &req.dict.dict_val, + &req.dict.dict_len); + + ret = mgmt_submit_request(&req, frame, ctx, &clnt_handshake_prog, + GF_HNDSK_GET_VOLUME_INFO, mgmt_get_volinfo_cbk, + (xdrproc_t)xdr_gf_get_volume_info_req); out: - if (dict) { - dict_unref (dict); - } + if (dict) { + dict_unref(dict); + } - GF_FREE (req.dict.dict_val); + GF_FREE(req.dict.dict_val); - return ret; + return ret; } static int -glusterfs_oldvolfile_update (struct glfs *fs, char *volfile, ssize_t size) +glusterfs_oldvolfile_update(struct glfs *fs, char *volfile, ssize_t size) { - int ret = -1; - - pthread_mutex_lock (&fs->mutex); - - fs->oldvollen = size; - if (!fs->oldvolfile) { - fs->oldvolfile = CALLOC (1, size+1); - } else { - fs->oldvolfile = REALLOC (fs->oldvolfile, size+1); - } - - if (!fs->oldvolfile) { - fs->oldvollen = 0; - } else { - memcpy (fs->oldvolfile, volfile, size); - fs->oldvollen = size; - ret = 0; - } + int ret = -1; + + pthread_mutex_lock(&fs->mutex); + + fs->oldvollen = size; + if (!fs->oldvolfile) { + fs->oldvolfile = CALLOC(1, size + 1); + } else { + fs->oldvolfile = REALLOC(fs->oldvolfile, size + 1); + } + + if (!fs->oldvolfile) { + fs->oldvollen = 0; + } else { + memcpy(fs->oldvolfile, volfile, size); + fs->oldvollen = size; + ret = 0; + } - pthread_mutex_unlock (&fs->mutex); + pthread_mutex_unlock(&fs->mutex); - return ret; + return ret; } - int -glfs_mgmt_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) +glfs_mgmt_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) { - gf_getspec_rsp rsp = {0,}; - call_frame_t *frame = NULL; - glusterfs_ctx_t *ctx = NULL; - int ret = 0; - ssize_t size = 0; - FILE *tmpfp = NULL; - int need_retry = 0; - struct glfs *fs = NULL; - dict_t *dict = NULL; - char *servers_list = NULL; - int tmp_fd = -1; - char template[] = "/tmp/gfapi.volfile.XXXXXX"; - - frame = myframe; - ctx = frame->this->ctx; - - if (!ctx) { - gf_msg (frame->this->name, GF_LOG_ERROR, EINVAL, - API_MSG_INVALID_ENTRY, "NULL context"); - errno = EINVAL; - ret = -1; - goto out; - } - - fs = ((xlator_t *)ctx->master)->private; - - if (-1 == req->rpc_status) { - ret = -1; - need_retry = 1; - goto out; - } - - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_getspec_rsp); - if (ret < 0) { - gf_msg (frame->this->name, GF_LOG_ERROR, 0, - API_MSG_XDR_DECODE_FAILED, "XDR decoding error"); - ret = -1; - goto out; - } - - if (-1 == rsp.op_ret) { - gf_msg (frame->this->name, GF_LOG_ERROR, rsp.op_errno, - API_MSG_GET_VOLFILE_FAILED, - "failed to get the 'volume file' from server"); - ret = -1; - errno = rsp.op_errno; - goto out; - } - - if (!rsp.xdata.xdata_len) { - goto volfile; - } - - dict = dict_new (); - if (!dict) { - ret = -1; - errno = ENOMEM; - goto out; - } - - ret = dict_unserialize (rsp.xdata.xdata_val, rsp.xdata.xdata_len, - &dict); - if (ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "failed to unserialize xdata to dictionary"); - goto out; - } - dict->extra_stdfree = rsp.xdata.xdata_val; - - /* glusterd2 only */ - ret = dict_get_str (dict, "servers-list", &servers_list); - if (ret) { - goto volfile; - } - - gf_log (frame->this->name, GF_LOG_INFO, - "Received list of available volfile servers: %s", - servers_list); - - ret = gf_process_getspec_servers_list(&ctx->cmd_args, servers_list); - if (ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "Failed (%s) to process servers list: %s", - strerror (errno), servers_list); - } + gf_getspec_rsp rsp = { + 0, + }; + call_frame_t *frame = NULL; + glusterfs_ctx_t *ctx = NULL; + int ret = 0; + ssize_t size = 0; + FILE *tmpfp = NULL; + int need_retry = 0; + struct glfs *fs = NULL; + dict_t *dict = NULL; + char *servers_list = NULL; + int tmp_fd = -1; + char template[] = "/tmp/gfapi.volfile.XXXXXX"; + + frame = myframe; + ctx = frame->this->ctx; + + if (!ctx) { + gf_msg(frame->this->name, GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "NULL context"); + errno = EINVAL; + ret = -1; + goto out; + } + + fs = ((xlator_t *)ctx->master)->private; + + if (-1 == req->rpc_status) { + ret = -1; + need_retry = 1; + goto out; + } + + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t)xdr_gf_getspec_rsp); + if (ret < 0) { + gf_msg(frame->this->name, GF_LOG_ERROR, 0, API_MSG_XDR_DECODE_FAILED, + "XDR decoding error"); + ret = -1; + goto out; + } + + if (-1 == rsp.op_ret) { + gf_msg(frame->this->name, GF_LOG_ERROR, rsp.op_errno, + API_MSG_GET_VOLFILE_FAILED, + "failed to get the 'volume file' from server"); + ret = -1; + errno = rsp.op_errno; + goto out; + } + + if (!rsp.xdata.xdata_len) { + goto volfile; + } + + dict = dict_new(); + if (!dict) { + ret = -1; + errno = ENOMEM; + goto out; + } + + ret = dict_unserialize(rsp.xdata.xdata_val, rsp.xdata.xdata_len, &dict); + if (ret) { + gf_log(frame->this->name, GF_LOG_ERROR, + "failed to unserialize xdata to dictionary"); + goto out; + } + dict->extra_stdfree = rsp.xdata.xdata_val; + + /* glusterd2 only */ + ret = dict_get_str(dict, "servers-list", &servers_list); + if (ret) { + goto volfile; + } + + gf_log(frame->this->name, GF_LOG_INFO, + "Received list of available volfile servers: %s", servers_list); + + ret = gf_process_getspec_servers_list(&ctx->cmd_args, servers_list); + if (ret) { + gf_log(frame->this->name, GF_LOG_ERROR, + "Failed (%s) to process servers list: %s", strerror(errno), + servers_list); + } volfile: - ret = 0; - size = rsp.op_ret; - - if ((size == fs->oldvollen) && - (memcmp (fs->oldvolfile, rsp.spec, size) == 0)) { - gf_msg (frame->this->name, GF_LOG_INFO, 0, - API_MSG_VOLFILE_INFO, - "No change in volfile, continuing"); - goto out; - } - - /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ - tmp_fd = mkstemp (template); - if (-1 == tmp_fd) { - ret = -1; - goto out; - } - - /* Calling unlink so that when the file is closed or program - * terminates the temporary file is deleted. - */ - ret = sys_unlink (template); - if (ret < 0) { - gf_msg (frame->this->name, GF_LOG_INFO, 0, API_MSG_VOLFILE_INFO, - "Unable to delete file: %s", template); - ret = 0; + ret = 0; + size = rsp.op_ret; + + if ((size == fs->oldvollen) && + (memcmp(fs->oldvolfile, rsp.spec, size) == 0)) { + gf_msg(frame->this->name, GF_LOG_INFO, 0, API_MSG_VOLFILE_INFO, + "No change in volfile, continuing"); + goto out; + } + + /* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */ + tmp_fd = mkstemp(template); + if (-1 == tmp_fd) { + ret = -1; + goto out; + } + + /* Calling unlink so that when the file is closed or program + * terminates the temporary file is deleted. + */ + ret = sys_unlink(template); + if (ret < 0) { + gf_msg(frame->this->name, GF_LOG_INFO, 0, API_MSG_VOLFILE_INFO, + "Unable to delete file: %s", template); + ret = 0; + } + + tmpfp = fdopen(tmp_fd, "w+b"); + if (!tmpfp) { + ret = -1; + goto out; + } + + fwrite(rsp.spec, size, 1, tmpfp); + fflush(tmpfp); + if (ferror(tmpfp)) { + ret = -1; + goto out; + } + + /* Check if only options have changed. No need to reload the + * volfile if topology hasn't changed. + * glusterfs_volfile_reconfigure returns 3 possible return states + * 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 + */ + + ret = gf_volfile_reconfigure(fs->oldvollen, tmpfp, fs->ctx, fs->oldvolfile); + if (ret == 0) { + gf_msg_debug("glusterfsd-mgmt", 0, + "No need to re-load " + "volfile, reconfigure done"); + ret = glusterfs_oldvolfile_update(fs, rsp.spec, size); + goto out; + } + + if (ret < 0) { + gf_msg_debug("glusterfsd-mgmt", 0, "Reconfigure failed !!"); + goto out; + } + + ret = glfs_process_volfp(fs, tmpfp); + /* tmpfp closed */ + tmpfp = NULL; + tmp_fd = -1; + if (ret) + goto out; + + ret = glusterfs_oldvolfile_update(fs, rsp.spec, size); +out: + STACK_DESTROY(frame->root); + + if (rsp.spec) + free(rsp.spec); + + if (dict) + dict_unref(dict); + + // Stop if server is running at an unsupported op-version + if (ENOTSUP == ret) { + gf_msg("mgmt", GF_LOG_ERROR, ENOTSUP, API_MSG_WRONG_OPVERSION, + "Server is operating at an op-version which is not " + "supported"); + errno = ENOTSUP; + glfs_init_done(fs, -1); + } + + if (ret && ctx && !ctx->active) { + /* Do it only for the first time */ + /* Failed to get the volume file, something wrong, + restart the process */ + gf_msg("glfs-mgmt", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "failed to fetch volume file (key:%s)", + ctx->cmd_args.volfile_id); + if (!need_retry) { + if (!errno) + errno = EINVAL; + glfs_init_done(fs, -1); } + } - tmpfp = fdopen (tmp_fd, "w+b"); - if (!tmpfp) { - ret = -1; - goto out; - } + if (tmpfp) + fclose(tmpfp); + else if (tmp_fd != -1) + sys_close(tmp_fd); - fwrite (rsp.spec, size, 1, tmpfp); - fflush (tmpfp); - if (ferror (tmpfp)) { - ret = -1; - goto out; - } - - /* Check if only options have changed. No need to reload the - * volfile if topology hasn't changed. - * glusterfs_volfile_reconfigure returns 3 possible return states - * 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 - */ - - ret = gf_volfile_reconfigure (fs->oldvollen, tmpfp, fs->ctx, - fs->oldvolfile); - if (ret == 0) { - gf_msg_debug ("glusterfsd-mgmt", 0, "No need to re-load " - "volfile, reconfigure done"); - ret = glusterfs_oldvolfile_update (fs, rsp.spec, size); - goto out; - } - - if (ret < 0) { - gf_msg_debug ("glusterfsd-mgmt", 0, "Reconfigure failed !!"); - goto out; - } - - ret = glfs_process_volfp (fs, tmpfp); - /* tmpfp closed */ - tmpfp = NULL; - tmp_fd = -1; - if (ret) - goto out; - - ret = glusterfs_oldvolfile_update (fs, rsp.spec, size); -out: - STACK_DESTROY (frame->root); - - if (rsp.spec) - free (rsp.spec); - - if (dict) - dict_unref (dict); - - // Stop if server is running at an unsupported op-version - if (ENOTSUP == ret) { - gf_msg ("mgmt", GF_LOG_ERROR, ENOTSUP, API_MSG_WRONG_OPVERSION, - "Server is operating at an op-version which is not " - "supported"); - errno = ENOTSUP; - glfs_init_done (fs, -1); - } - - if (ret && ctx && !ctx->active) { - /* Do it only for the first time */ - /* Failed to get the volume file, something wrong, - restart the process */ - gf_msg ("glfs-mgmt", GF_LOG_ERROR, EINVAL, - API_MSG_INVALID_ENTRY, - "failed to fetch volume file (key:%s)", - ctx->cmd_args.volfile_id); - if (!need_retry) { - if (!errno) - errno = EINVAL; - glfs_init_done (fs, -1); - } - } - - if (tmpfp) - fclose (tmpfp); - else if (tmp_fd != -1) - sys_close (tmp_fd); - - return 0; + return 0; } - int -glfs_volfile_fetch (struct glfs *fs) +glfs_volfile_fetch(struct glfs *fs) { - cmd_args_t *cmd_args = NULL; - gf_getspec_req req = {0, }; - int ret = 0; - call_frame_t *frame = NULL; - glusterfs_ctx_t *ctx = NULL; - dict_t *dict = NULL; - - ctx = fs->ctx; - cmd_args = &ctx->cmd_args; - - frame = create_frame (THIS, ctx->pool); - - req.key = cmd_args->volfile_id; - req.flags = 0; - - dict = dict_new (); - if (!dict) { - ret = -1; - goto out; - } - - // Set the supported min and max op-versions, so glusterd can make a - // decision - ret = dict_set_int32 (dict, "min-op-version", GD_OP_VERSION_MIN); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, EINVAL, - API_MSG_DICT_SET_FAILED, - "Failed to set min-op-version in request dict"); - goto out; - } - - ret = dict_set_int32 (dict, "max-op-version", GD_OP_VERSION_MAX); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, EINVAL, - API_MSG_DICT_SET_FAILED, - "Failed to set max-op-version in request dict"); - goto out; - } - - /* Ask for a list of volfile (glusterd2 only) servers */ - if (GF_CLIENT_PROCESS == ctx->process_mode) { - req.flags = req.flags | GF_GETSPEC_FLAG_SERVERS_LIST; - } - - ret = dict_allocate_and_serialize (dict, &req.xdata.xdata_val, - &req.xdata.xdata_len); - if (ret < 0) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, - API_MSG_DICT_SERIALIZE_FAILED, - "Failed to serialize dictionary"); - goto out; - } - - ret = mgmt_submit_request (&req, frame, ctx, &clnt_handshake_prog, - GF_HNDSK_GETSPEC, glfs_mgmt_getspec_cbk, - (xdrproc_t)xdr_gf_getspec_req); + cmd_args_t *cmd_args = NULL; + gf_getspec_req req = { + 0, + }; + int ret = 0; + call_frame_t *frame = NULL; + glusterfs_ctx_t *ctx = NULL; + dict_t *dict = NULL; + + ctx = fs->ctx; + cmd_args = &ctx->cmd_args; + + frame = create_frame(THIS, ctx->pool); + + req.key = cmd_args->volfile_id; + req.flags = 0; + + dict = dict_new(); + if (!dict) { + ret = -1; + goto out; + } + + // Set the supported min and max op-versions, so glusterd can make a + // decision + ret = dict_set_int32(dict, "min-op-version", GD_OP_VERSION_MIN); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, EINVAL, API_MSG_DICT_SET_FAILED, + "Failed to set min-op-version in request dict"); + goto out; + } + + ret = dict_set_int32(dict, "max-op-version", GD_OP_VERSION_MAX); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, EINVAL, API_MSG_DICT_SET_FAILED, + "Failed to set max-op-version in request dict"); + goto out; + } + + /* Ask for a list of volfile (glusterd2 only) servers */ + if (GF_CLIENT_PROCESS == ctx->process_mode) { + req.flags = req.flags | GF_GETSPEC_FLAG_SERVERS_LIST; + } + + ret = dict_allocate_and_serialize(dict, &req.xdata.xdata_val, + &req.xdata.xdata_len); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, API_MSG_DICT_SERIALIZE_FAILED, + "Failed to serialize dictionary"); + goto out; + } + + ret = mgmt_submit_request(&req, frame, ctx, &clnt_handshake_prog, + GF_HNDSK_GETSPEC, glfs_mgmt_getspec_cbk, + (xdrproc_t)xdr_gf_getspec_req); out: - if (req.xdata.xdata_val) - GF_FREE(req.xdata.xdata_val); - if (dict) - dict_unref (dict); + if (req.xdata.xdata_val) + GF_FREE(req.xdata.xdata_val); + if (dict) + dict_unref(dict); - return ret; + return ret; } - static int -mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, - void *data) +mgmt_rpc_notify(struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, + void *data) { - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - server_cmdline_t *server = NULL; - rpc_transport_t *rpc_trans = NULL; - struct glfs *fs = NULL; - int ret = 0; - struct dnscache6 *dnscache = NULL; - - this = mydata; - rpc_trans = rpc->conn.trans; - - ctx = this->ctx; - if (!ctx) - goto out; - - fs = ((xlator_t *)ctx->master)->private; - - switch (event) { - case RPC_CLNT_DISCONNECT: - if (!ctx->active) { - if (rpc_trans->connect_failed) - gf_msg ("glfs-mgmt", GF_LOG_ERROR, 0, - API_MSG_REMOTE_HOST_CONN_FAILED, - "failed to connect to remote-host: %s", - ctx->cmd_args.volfile_server); - else - gf_msg ("glfs-mgmt", GF_LOG_INFO, 0, - API_MSG_REMOTE_HOST_CONN_FAILED, - "disconnected from remote-host: %s", - ctx->cmd_args.volfile_server); - - if (!rpc->disabled) { - /* - * Check if dnscache is exhausted for current server - * and continue until cache is exhausted - */ - dnscache = rpc_trans->dnscache; - if (dnscache && dnscache->next) { - break; - } - } - server = ctx->cmd_args.curr_server; - if (server->list.next == &ctx->cmd_args.volfile_servers) { - errno = ENOTCONN; - gf_msg ("glfs-mgmt", GF_LOG_INFO, ENOTCONN, - API_MSG_VOLFILE_SERVER_EXHAUST, - "Exhausted all volfile servers"); - glfs_init_done (fs, -1); - break; - } - server = list_entry (server->list.next, typeof(*server), - list); - ctx->cmd_args.curr_server = server; - ctx->cmd_args.volfile_server_port = server->port; - ctx->cmd_args.volfile_server = server->volfile_server; - ctx->cmd_args.volfile_server_transport = server->transport; - - ret = dict_set_str (rpc_trans->options, - "transport-type", - server->transport); - if (ret != 0) { - gf_msg ("glfs-mgmt", GF_LOG_ERROR, ENOTCONN, - API_MSG_DICT_SET_FAILED, - "failed to set transport-type: %s", - server->transport); - errno = ENOTCONN; - glfs_init_done (fs, -1); - break; - } - - if (strcmp(server->transport, "unix") == 0) { - ret = dict_set_str (rpc_trans->options, - "transport.socket.connect-path", - server->volfile_server); - if (ret != 0) { - gf_msg ("glfs-mgmt", GF_LOG_ERROR, - ENOTCONN, - API_MSG_DICT_SET_FAILED, - "failed to set socket.connect-path: %s", - server->volfile_server); - errno = ENOTCONN; - glfs_init_done (fs, -1); - break; - } - /* delete the remote-host and remote-port keys - * in case they were set while looping through - * list of volfile servers previously - */ - dict_del (rpc_trans->options, "remote-host"); - dict_del (rpc_trans->options, "remote-port"); - } else { - ret = dict_set_int32 (rpc_trans->options, - "remote-port", - server->port); - if (ret != 0) { - gf_msg ("glfs-mgmt", GF_LOG_ERROR, - ENOTCONN, - API_MSG_DICT_SET_FAILED, - "failed to set remote-port: %d", - server->port); - errno = ENOTCONN; - glfs_init_done (fs, -1); - break; - } - - ret = dict_set_str (rpc_trans->options, - "remote-host", - server->volfile_server); - if (ret != 0) { - gf_msg ("glfs-mgmt", GF_LOG_ERROR, - ENOTCONN, - API_MSG_DICT_SET_FAILED, - "failed to set remote-host: %s", - server->volfile_server); - errno = ENOTCONN; - glfs_init_done (fs, -1); - break; - } - /* delete the "transport.socket.connect-path" - * key in case if it was set while looping - * through list of volfile servers previously - */ - dict_del (rpc_trans->options, - "transport.socket.connect-path"); - } - - gf_msg ("glfs-mgmt", GF_LOG_INFO, 0, - API_MSG_VOLFILE_CONNECTING, - "connecting to next volfile server %s" - " at port %d with transport: %s", - server->volfile_server, server->port, - server->transport); + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + server_cmdline_t *server = NULL; + rpc_transport_t *rpc_trans = NULL; + struct glfs *fs = NULL; + int ret = 0; + struct dnscache6 *dnscache = NULL; + + this = mydata; + rpc_trans = rpc->conn.trans; + + ctx = this->ctx; + if (!ctx) + goto out; + + fs = ((xlator_t *)ctx->master)->private; + + switch (event) { + case RPC_CLNT_DISCONNECT: + if (!ctx->active) { + if (rpc_trans->connect_failed) + gf_msg("glfs-mgmt", GF_LOG_ERROR, 0, + API_MSG_REMOTE_HOST_CONN_FAILED, + "failed to connect to remote-host: %s", + ctx->cmd_args.volfile_server); + else + gf_msg("glfs-mgmt", GF_LOG_INFO, 0, + API_MSG_REMOTE_HOST_CONN_FAILED, + "disconnected from remote-host: %s", + ctx->cmd_args.volfile_server); + + if (!rpc->disabled) { + /* + * Check if dnscache is exhausted for current server + * and continue until cache is exhausted + */ + dnscache = rpc_trans->dnscache; + if (dnscache && dnscache->next) { + break; + } } - break; - case RPC_CLNT_CONNECT: - ret = glfs_volfile_fetch (fs); - if (ret && (ctx->active == NULL)) { - /* Do it only for the first time */ - /* Exit the process.. there are some wrong options */ - gf_msg ("glfs-mgmt", GF_LOG_ERROR, EINVAL, - API_MSG_INVALID_ENTRY, - "failed to fetch volume file (key:%s)", - ctx->cmd_args.volfile_id); - errno = EINVAL; - glfs_init_done (fs, -1); + server = ctx->cmd_args.curr_server; + if (server->list.next == &ctx->cmd_args.volfile_servers) { + errno = ENOTCONN; + gf_msg("glfs-mgmt", GF_LOG_INFO, ENOTCONN, + API_MSG_VOLFILE_SERVER_EXHAUST, + "Exhausted all volfile servers"); + glfs_init_done(fs, -1); + break; + } + server = list_entry(server->list.next, typeof(*server), list); + ctx->cmd_args.curr_server = server; + ctx->cmd_args.volfile_server_port = server->port; + ctx->cmd_args.volfile_server = server->volfile_server; + ctx->cmd_args.volfile_server_transport = server->transport; + + ret = dict_set_str(rpc_trans->options, "transport-type", + server->transport); + if (ret != 0) { + gf_msg("glfs-mgmt", GF_LOG_ERROR, ENOTCONN, + API_MSG_DICT_SET_FAILED, + "failed to set transport-type: %s", + server->transport); + errno = ENOTCONN; + glfs_init_done(fs, -1); + break; } - break; - default: - break; - } + if (strcmp(server->transport, "unix") == 0) { + ret = dict_set_str(rpc_trans->options, + "transport.socket.connect-path", + server->volfile_server); + if (ret != 0) { + gf_msg("glfs-mgmt", GF_LOG_ERROR, ENOTCONN, + API_MSG_DICT_SET_FAILED, + "failed to set socket.connect-path: %s", + server->volfile_server); + errno = ENOTCONN; + glfs_init_done(fs, -1); + break; + } + /* delete the remote-host and remote-port keys + * in case they were set while looping through + * list of volfile servers previously + */ + dict_del(rpc_trans->options, "remote-host"); + dict_del(rpc_trans->options, "remote-port"); + } else { + ret = dict_set_int32(rpc_trans->options, "remote-port", + server->port); + if (ret != 0) { + gf_msg("glfs-mgmt", GF_LOG_ERROR, ENOTCONN, + API_MSG_DICT_SET_FAILED, + "failed to set remote-port: %d", server->port); + errno = ENOTCONN; + glfs_init_done(fs, -1); + break; + } + + ret = dict_set_str(rpc_trans->options, "remote-host", + server->volfile_server); + if (ret != 0) { + gf_msg("glfs-mgmt", GF_LOG_ERROR, ENOTCONN, + API_MSG_DICT_SET_FAILED, + "failed to set remote-host: %s", + server->volfile_server); + errno = ENOTCONN; + glfs_init_done(fs, -1); + break; + } + /* delete the "transport.socket.connect-path" + * key in case if it was set while looping + * through list of volfile servers previously + */ + dict_del(rpc_trans->options, + "transport.socket.connect-path"); + } + + gf_msg("glfs-mgmt", GF_LOG_INFO, 0, API_MSG_VOLFILE_CONNECTING, + "connecting to next volfile server %s" + " at port %d with transport: %s", + server->volfile_server, server->port, server->transport); + } + break; + case RPC_CLNT_CONNECT: + ret = glfs_volfile_fetch(fs); + if (ret && (ctx->active == NULL)) { + /* Do it only for the first time */ + /* Exit the process.. there are some wrong options */ + gf_msg("glfs-mgmt", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "failed to fetch volume file (key:%s)", + ctx->cmd_args.volfile_id); + errno = EINVAL; + glfs_init_done(fs, -1); + } + + break; + default: + break; + } out: - return 0; + return 0; } - int -glusterfs_mgmt_notify (int32_t op, void *data, ...) +glusterfs_mgmt_notify(int32_t op, void *data, ...) { - int ret = 0; + int ret = 0; - switch (op) - { - case GF_EN_DEFRAG_STATUS: - break; + switch (op) { + case GF_EN_DEFRAG_STATUS: + break; - default: - break; - } + default: + break; + } - return ret; + return ret; } - int -glfs_mgmt_init (struct glfs *fs) +glfs_mgmt_init(struct glfs *fs) { - cmd_args_t *cmd_args = NULL; - struct rpc_clnt *rpc = NULL; - dict_t *options = NULL; - int ret = -1; - int port = GF_DEFAULT_BASE_PORT; - char *host = NULL; - glusterfs_ctx_t *ctx = NULL; - - ctx = fs->ctx; - cmd_args = &ctx->cmd_args; - - if (ctx->mgmt) - return 0; - - if (cmd_args->volfile_server_port) - port = cmd_args->volfile_server_port; - - if (cmd_args->volfile_server) { - host = cmd_args->volfile_server; - } else if (cmd_args->volfile_server_transport && - !strcmp (cmd_args->volfile_server_transport, "unix")) { - host = DEFAULT_GLUSTERD_SOCKFILE; - } else { - host = "localhost"; - } - - if (cmd_args->volfile_server_transport && - !strcmp (cmd_args->volfile_server_transport, "unix")) { - ret = rpc_transport_unix_options_build (&options, host, 0); - } else { - ret = rpc_transport_inet_options_build (&options, host, port); - } - - if (ret) - goto out; - - if (sys_access (SECURE_ACCESS_FILE, F_OK) == 0) { - ctx->secure_mgmt = 1; - ctx->ssl_cert_depth = glusterfs_read_secure_access_file (); - } - - rpc = rpc_clnt_new (options, THIS, THIS->name, 8); - if (!rpc) { - ret = -1; - gf_msg (THIS->name, GF_LOG_WARNING, 0, - API_MSG_CREATE_RPC_CLIENT_FAILED, - "failed to create rpc clnt"); - goto out; - } - - ret = rpc_clnt_register_notify (rpc, mgmt_rpc_notify, THIS); - if (ret) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - API_MSG_REG_NOTIFY_FUNC_FAILED, - "failed to register notify function"); - goto out; - } - - ret = rpcclnt_cbk_program_register (rpc, &mgmt_cbk_prog, THIS); - if (ret) { - gf_msg (THIS->name, GF_LOG_WARNING, 0, - API_MSG_REG_CBK_FUNC_FAILED, - "failed to register callback function"); - goto out; - } - - ctx->notify = glusterfs_mgmt_notify; - - /* This value should be set before doing the 'rpc_clnt_start()' as - the notify function uses this variable */ - ctx->mgmt = rpc; - - ret = rpc_clnt_start (rpc); + cmd_args_t *cmd_args = NULL; + struct rpc_clnt *rpc = NULL; + dict_t *options = NULL; + int ret = -1; + int port = GF_DEFAULT_BASE_PORT; + char *host = NULL; + glusterfs_ctx_t *ctx = NULL; + + ctx = fs->ctx; + cmd_args = &ctx->cmd_args; + + if (ctx->mgmt) + return 0; + + if (cmd_args->volfile_server_port) + port = cmd_args->volfile_server_port; + + if (cmd_args->volfile_server) { + host = cmd_args->volfile_server; + } else if (cmd_args->volfile_server_transport && + !strcmp(cmd_args->volfile_server_transport, "unix")) { + host = DEFAULT_GLUSTERD_SOCKFILE; + } else { + host = "localhost"; + } + + if (cmd_args->volfile_server_transport && + !strcmp(cmd_args->volfile_server_transport, "unix")) { + ret = rpc_transport_unix_options_build(&options, host, 0); + } else { + ret = rpc_transport_inet_options_build(&options, host, port); + } + + if (ret) + goto out; + + if (sys_access(SECURE_ACCESS_FILE, F_OK) == 0) { + ctx->secure_mgmt = 1; + ctx->ssl_cert_depth = glusterfs_read_secure_access_file(); + } + + rpc = rpc_clnt_new(options, THIS, THIS->name, 8); + if (!rpc) { + ret = -1; + gf_msg(THIS->name, GF_LOG_WARNING, 0, API_MSG_CREATE_RPC_CLIENT_FAILED, + "failed to create rpc clnt"); + goto out; + } + + ret = rpc_clnt_register_notify(rpc, mgmt_rpc_notify, THIS); + if (ret) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, API_MSG_REG_NOTIFY_FUNC_FAILED, + "failed to register notify function"); + goto out; + } + + ret = rpcclnt_cbk_program_register(rpc, &mgmt_cbk_prog, THIS); + if (ret) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, API_MSG_REG_CBK_FUNC_FAILED, + "failed to register callback function"); + goto out; + } + + ctx->notify = glusterfs_mgmt_notify; + + /* This value should be set before doing the 'rpc_clnt_start()' as + the notify function uses this variable */ + ctx->mgmt = rpc; + + ret = rpc_clnt_start(rpc); out: - return ret; + return ret; } diff --git a/api/src/glfs-resolve.c b/api/src/glfs-resolve.c index 0c4b9651bd4..34794b605e4 100644 --- a/api/src/glfs-resolve.c +++ b/api/src/glfs-resolve.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - #include #include #include @@ -28,46 +27,47 @@ #include "inode.h" #include "glfs-internal.h" -#define graphid_str(subvol) (uuid_utoa((unsigned char *)subvol->graph->graph_uuid)) +#define graphid_str(subvol) \ + (uuid_utoa((unsigned char *)subvol->graph->graph_uuid)) int -glfs_first_lookup_safe (xlator_t *subvol) +glfs_first_lookup_safe(xlator_t *subvol) { - loc_t loc = {0, }; - int ret = -1; + loc_t loc = { + 0, + }; + int ret = -1; - loc.inode = subvol->itable->root; - memset (loc.gfid, 0, 16); - loc.gfid[15] = 1; - loc.path = "/"; - loc.name = ""; + loc.inode = subvol->itable->root; + memset(loc.gfid, 0, 16); + loc.gfid[15] = 1; + loc.path = "/"; + loc.name = ""; - ret = syncop_lookup (subvol, &loc, 0, 0, 0, 0); - DECODE_SYNCOP_ERR (ret); + ret = syncop_lookup(subvol, &loc, 0, 0, 0, 0); + DECODE_SYNCOP_ERR(ret); - gf_msg_debug (subvol->name, 0, "first lookup complete %d", ret); + gf_msg_debug(subvol->name, 0, "first lookup complete %d", ret); - return ret; + return ret; } - int -__glfs_first_lookup (struct glfs *fs, xlator_t *subvol) +__glfs_first_lookup(struct glfs *fs, xlator_t *subvol) { - int ret = -1; - - fs->migration_in_progress = 1; - pthread_mutex_unlock (&fs->mutex); - { - ret = glfs_first_lookup_safe (subvol); - } - pthread_mutex_lock (&fs->mutex); - fs->migration_in_progress = 0; - pthread_cond_broadcast (&fs->cond); - - return ret; + int ret = -1; + + fs->migration_in_progress = 1; + pthread_mutex_unlock(&fs->mutex); + { + ret = glfs_first_lookup_safe(subvol); + } + pthread_mutex_lock(&fs->mutex); + fs->migration_in_progress = 0; + pthread_cond_broadcast(&fs->cond); + + return ret; } - /** * We have to check if need_lookup flag is set in both old and the new inodes. * If its set in oldinode, then directly go ahead and do an explicit lookup. @@ -76,842 +76,819 @@ __glfs_first_lookup (struct glfs *fs, xlator_t *subvol) * below xlators can set their respective contexts. */ inode_t * -glfs_refresh_inode_safe (xlator_t *subvol, inode_t *oldinode, - gf_boolean_t need_lookup) +glfs_refresh_inode_safe(xlator_t *subvol, inode_t *oldinode, + gf_boolean_t need_lookup) { - loc_t loc = {0, }; - int ret = -1; - struct iatt iatt = {0, }; - inode_t *newinode = NULL; - gf_boolean_t lookup_needed = _gf_false; - uint64_t ctx_value = LOOKUP_NOT_NEEDED; - - - if (!oldinode) - return NULL; - - if (!need_lookup && oldinode->table->xl == subvol) - return inode_ref (oldinode); - - newinode = inode_find (subvol->itable, oldinode->gfid); - if (!need_lookup && newinode) { - - lookup_needed = inode_needs_lookup (newinode, THIS); - if (!lookup_needed) - return newinode; - } - - gf_uuid_copy (loc.gfid, oldinode->gfid); - if (!newinode) - loc.inode = inode_new (subvol->itable); - else - loc.inode = newinode; - - if (!loc.inode) - return NULL; - - ret = syncop_lookup (subvol, &loc, &iatt, 0, 0, 0); - DECODE_SYNCOP_ERR (ret); - - if (ret) { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_REFRESH_FAILED, - "inode refresh of %s failed: %s", - uuid_utoa (oldinode->gfid), strerror (errno)); - loc_wipe (&loc); - return NULL; - } - - newinode = inode_link (loc.inode, 0, 0, &iatt); - if (newinode) { - if (newinode == loc.inode) - inode_ctx_set (newinode, THIS, &ctx_value); - inode_lookup (newinode); - } else { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_LINK_FAILED, - "inode linking of %s failed", - uuid_utoa ((unsigned char *)&iatt.ia_gfid)); - } - - loc_wipe (&loc); - - return newinode; + loc_t loc = { + 0, + }; + int ret = -1; + struct iatt iatt = { + 0, + }; + inode_t *newinode = NULL; + gf_boolean_t lookup_needed = _gf_false; + uint64_t ctx_value = LOOKUP_NOT_NEEDED; + + if (!oldinode) + return NULL; + + if (!need_lookup && oldinode->table->xl == subvol) + return inode_ref(oldinode); + + newinode = inode_find(subvol->itable, oldinode->gfid); + if (!need_lookup && newinode) { + lookup_needed = inode_needs_lookup(newinode, THIS); + if (!lookup_needed) + return newinode; + } + + gf_uuid_copy(loc.gfid, oldinode->gfid); + if (!newinode) + loc.inode = inode_new(subvol->itable); + else + loc.inode = newinode; + + if (!loc.inode) + return NULL; + + ret = syncop_lookup(subvol, &loc, &iatt, 0, 0, 0); + DECODE_SYNCOP_ERR(ret); + + if (ret) { + gf_msg(subvol->name, GF_LOG_WARNING, errno, + API_MSG_INODE_REFRESH_FAILED, "inode refresh of %s failed: %s", + uuid_utoa(oldinode->gfid), strerror(errno)); + loc_wipe(&loc); + return NULL; + } + + newinode = inode_link(loc.inode, 0, 0, &iatt); + if (newinode) { + if (newinode == loc.inode) + inode_ctx_set(newinode, THIS, &ctx_value); + inode_lookup(newinode); + } else { + gf_msg(subvol->name, GF_LOG_WARNING, errno, API_MSG_INODE_LINK_FAILED, + "inode linking of %s failed", + uuid_utoa((unsigned char *)&iatt.ia_gfid)); + } + + loc_wipe(&loc); + + return newinode; } - inode_t * -__glfs_refresh_inode (struct glfs *fs, xlator_t *subvol, inode_t *inode, - gf_boolean_t need_lookup) +__glfs_refresh_inode(struct glfs *fs, xlator_t *subvol, inode_t *inode, + gf_boolean_t need_lookup) { - inode_t *newinode = NULL; - - fs->migration_in_progress = 1; - pthread_mutex_unlock (&fs->mutex); - { - newinode = glfs_refresh_inode_safe (subvol, inode, need_lookup); - } - pthread_mutex_lock (&fs->mutex); - fs->migration_in_progress = 0; - pthread_cond_broadcast (&fs->cond); - - return newinode; + inode_t *newinode = NULL; + + fs->migration_in_progress = 1; + pthread_mutex_unlock(&fs->mutex); + { + newinode = glfs_refresh_inode_safe(subvol, inode, need_lookup); + } + pthread_mutex_lock(&fs->mutex); + fs->migration_in_progress = 0; + pthread_cond_broadcast(&fs->cond); + + return newinode; } int -priv_glfs_loc_touchup (loc_t *loc) +priv_glfs_loc_touchup(loc_t *loc) { - int ret = 0; + int ret = 0; - ret = loc_touchup (loc, loc->name); - if (ret < 0) { - errno = -ret; - ret = -1; - } + ret = loc_touchup(loc, loc->name); + if (ret < 0) { + errno = -ret; + ret = -1; + } - return ret; + return ret; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_loc_touchup, 3.4.0); int -glfs_resolve_symlink (struct glfs *fs, xlator_t *subvol, inode_t *inode, - char **lpath) +glfs_resolve_symlink(struct glfs *fs, xlator_t *subvol, inode_t *inode, + char **lpath) { - loc_t loc = {0, }; - char *path = NULL; - char *rpath = NULL; - int ret = -1; - - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - ret = inode_path (inode, NULL, &rpath); - if (ret < 0) - goto out; - loc.path = rpath; - - ret = syncop_readlink (subvol, &loc, &path, 4096, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret < 0) - goto out; - - if (lpath) - *lpath = path; + loc_t loc = { + 0, + }; + char *path = NULL; + char *rpath = NULL; + int ret = -1; + + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + ret = inode_path(inode, NULL, &rpath); + if (ret < 0) + goto out; + loc.path = rpath; + + ret = syncop_readlink(subvol, &loc, &path, 4096, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret < 0) + goto out; + + if (lpath) + *lpath = path; out: - loc_wipe (&loc); - return ret; + loc_wipe(&loc); + return ret; } - int -glfs_resolve_base (struct glfs *fs, xlator_t *subvol, inode_t *inode, - struct iatt *iatt) +glfs_resolve_base(struct glfs *fs, xlator_t *subvol, inode_t *inode, + struct iatt *iatt) { - loc_t loc = {0, }; - int ret = -1; - char *path = NULL; - - loc.inode = inode_ref (inode); - gf_uuid_copy (loc.gfid, inode->gfid); - - ret = inode_path (loc.inode, NULL, &path); - loc.path = path; - if (ret < 0) - goto out; - - ret = syncop_lookup (subvol, &loc, iatt, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + loc_t loc = { + 0, + }; + int ret = -1; + char *path = NULL; + + loc.inode = inode_ref(inode); + gf_uuid_copy(loc.gfid, inode->gfid); + + ret = inode_path(loc.inode, NULL, &path); + loc.path = path; + if (ret < 0) + goto out; + + ret = syncop_lookup(subvol, &loc, iatt, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - return ret; + return ret; } /* * This function can be used to call named lookup on root. * If you use glfs_resolve_base, that will be a nameless lookup. */ static int -glfs_resolve_root (struct glfs *fs, xlator_t *subvol, inode_t *inode, - struct iatt *iatt) +glfs_resolve_root(struct glfs *fs, xlator_t *subvol, inode_t *inode, + struct iatt *iatt) { - loc_t loc = {0, }; - int ret = -1; - char *path = NULL; - - loc.inode = inode_ref (inode); - - ret = inode_path (loc.inode, ".", &path); - loc.path = path; - loc.name = "."; - /* Having a value in loc.name will help to bypass md-cache check for - * nameless lookup. - * TODO: Re-visit on nameless lookup and md-cache. - * Github issue : https://github.com/gluster/glusterfs/issues/232 - */ - loc.parent = inode_ref (inode); - if (ret < 0) - goto out; - - ret = syncop_lookup (subvol, &loc, iatt, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + loc_t loc = { + 0, + }; + int ret = -1; + char *path = NULL; + + loc.inode = inode_ref(inode); + + ret = inode_path(loc.inode, ".", &path); + loc.path = path; + loc.name = "."; + /* Having a value in loc.name will help to bypass md-cache check for + * nameless lookup. + * TODO: Re-visit on nameless lookup and md-cache. + * Github issue : https://github.com/gluster/glusterfs/issues/232 + */ + loc.parent = inode_ref(inode); + if (ret < 0) + goto out; + + ret = syncop_lookup(subvol, &loc, iatt, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - return ret; + return ret; } inode_t * -glfs_resolve_component (struct glfs *fs, xlator_t *subvol, inode_t *parent, - const char *component, struct iatt *iatt, - int force_lookup) +glfs_resolve_component(struct glfs *fs, xlator_t *subvol, inode_t *parent, + const char *component, struct iatt *iatt, + int force_lookup) { - loc_t loc = {0, }; - inode_t *inode = NULL; - inode_t *temp_parent = NULL; - int reval = 0; - int ret = -1; - int glret = -1; - struct iatt ciatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - uint64_t ctx_value = LOOKUP_NOT_NEEDED; - - loc.parent = inode_ref (parent); - gf_uuid_copy (loc.pargfid, parent->gfid); - - if (__is_root_gfid (parent->gfid) && - ((strcmp (component, ".") == 0) || - (strcmp (component, "..") == 0) || - (strcmp (component, "") == 0))) { - if (!force_lookup) { - inode = inode_ref (parent); - } else { - ret = glfs_resolve_root (fs, subvol, parent, &ciatt); - if (!ret) - inode = inode_ref (parent); - } - goto found; + loc_t loc = { + 0, + }; + inode_t *inode = NULL; + inode_t *temp_parent = NULL; + int reval = 0; + int ret = -1; + int glret = -1; + struct iatt ciatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + uint64_t ctx_value = LOOKUP_NOT_NEEDED; + + loc.parent = inode_ref(parent); + gf_uuid_copy(loc.pargfid, parent->gfid); + + if (__is_root_gfid(parent->gfid) && + ((strcmp(component, ".") == 0) || (strcmp(component, "..") == 0) || + (strcmp(component, "") == 0))) { + if (!force_lookup) { + inode = inode_ref(parent); + } else { + ret = glfs_resolve_root(fs, subvol, parent, &ciatt); + if (!ret) + inode = inode_ref(parent); + } + goto found; + } + /* * + * if the component name is either "." or "..", it will try to + * resolve that if inode has a proper parent (named lookup). + * + * Below condition works like this + * + * Example 1 : + * Path /out_dir/dir/in_dir/. + * In put values : + * parent = in_dir + * component : "." + * + * Out put values: + * parent : dir + * component : "in_dir" + * + * Example 2 : + * Path /out_dir/dir/in_dir/.. + * In put values : + * parent = in_dir + * component : ".." + * + * Out put values: + * parent : output_dir + * component : "dir" + * + * In case of nameless lookup, both "." and ".." retained + */ + + if (strcmp(component, ".") == 0) { + loc.inode = inode_ref(parent); + temp_parent = inode_parent(loc.inode, 0, 0); + if (temp_parent) { + inode_unref(loc.parent); + loc.parent = temp_parent; + inode_find_directory_name(loc.inode, &loc.name); } - /* * - * if the component name is either "." or "..", it will try to - * resolve that if inode has a proper parent (named lookup). - * - * Below condition works like this - * - * Example 1 : - * Path /out_dir/dir/in_dir/. - * In put values : - * parent = in_dir - * component : "." - * - * Out put values: - * parent : dir - * component : "in_dir" - * - * Example 2 : - * Path /out_dir/dir/in_dir/.. - * In put values : - * parent = in_dir - * component : ".." - * - * Out put values: - * parent : output_dir - * component : "dir" - * - * In case of nameless lookup, both "." and ".." retained - */ - if (strcmp (component, ".") == 0) { - loc.inode = inode_ref (parent); - temp_parent = inode_parent (loc.inode, 0, 0); - if (temp_parent) { - inode_unref (loc.parent); - loc.parent = temp_parent; - inode_find_directory_name (loc.inode, &loc.name); - } + } else if (strcmp(component, "..") == 0) { + loc.inode = inode_parent(parent, 0, 0); + if (loc.inode) { + temp_parent = inode_parent(loc.inode, 0, 0); + if (temp_parent) { + inode_unref(loc.parent); + loc.parent = temp_parent; + inode_find_directory_name(loc.inode, &loc.name); + } else if (__is_root_gfid(loc.inode->gfid)) { + inode_unref(loc.parent); + loc.parent = inode_ref(loc.inode); + loc.name = ""; + } else { + inode_unref(loc.inode); + loc.inode = NULL; + } + } + } else + loc.inode = inode_grep(parent->table, parent, component); - } else if (strcmp (component, "..") == 0) { - loc.inode = inode_parent (parent, 0, 0); - if (loc.inode) { - temp_parent = inode_parent (loc.inode, 0, 0); - if (temp_parent) { - inode_unref (loc.parent); - loc.parent = temp_parent; - inode_find_directory_name (loc.inode, &loc.name); - } else if (__is_root_gfid (loc.inode->gfid)) { - inode_unref (loc.parent); - loc.parent = inode_ref (loc.inode); - loc.name = ""; - } else { - inode_unref (loc.inode); - loc.inode = NULL; - } + if (!loc.name) + loc.name = component; - } - } else - loc.inode = inode_grep (parent->table, parent, component); - - if (!loc.name) - loc.name = component; - - if (loc.inode) { - gf_uuid_copy (loc.gfid, loc.inode->gfid); - reval = 1; - - if (!(force_lookup || inode_needs_lookup (loc.inode, THIS))) { - inode = inode_ref (loc.inode); - goto found; - } - } else { - gf_uuid_generate (gfid); - loc.inode = inode_new (parent->table); - if (!loc.inode) { - errno = ENOMEM; - goto out; - } + if (loc.inode) { + gf_uuid_copy(loc.gfid, loc.inode->gfid); + reval = 1; - xattr_req = dict_new (); - if (!xattr_req) { - errno = ENOMEM; - goto out; - } + if (!(force_lookup || inode_needs_lookup(loc.inode, THIS))) { + inode = inode_ref(loc.inode); + goto found; + } + } else { + gf_uuid_generate(gfid); + loc.inode = inode_new(parent->table); + if (!loc.inode) { + errno = ENOMEM; + goto out; + } - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - errno = ENOMEM; - goto out; - } + xattr_req = dict_new(); + if (!xattr_req) { + errno = ENOMEM; + goto out; + } - } - - glret = priv_glfs_loc_touchup (&loc); - if (glret < 0) { - ret = -1; - goto out; - } - - ret = syncop_lookup (subvol, &loc, &ciatt, NULL, xattr_req, NULL); - if (ret && reval) { - /* - * A stale mapping might exist for a dentry/inode that has been - * removed from another client. - */ - if (-ret == ENOENT) { - inode_unlink(loc.inode, loc.parent, - loc.name); - if (!inode_has_dentry (loc.inode)) - inode_forget (loc.inode, 0); - } + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + errno = ENOMEM; + goto out; + } + } + + glret = priv_glfs_loc_touchup(&loc); + if (glret < 0) { + ret = -1; + goto out; + } + + ret = syncop_lookup(subvol, &loc, &ciatt, NULL, xattr_req, NULL); + if (ret && reval) { + /* + * A stale mapping might exist for a dentry/inode that has been + * removed from another client. + */ + if (-ret == ENOENT) { + inode_unlink(loc.inode, loc.parent, loc.name); + if (!inode_has_dentry(loc.inode)) + inode_forget(loc.inode, 0); + } - inode_unref (loc.inode); - gf_uuid_clear (loc.gfid); - loc.inode = inode_new (parent->table); - if (!loc.inode) { - errno = ENOMEM; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - errno = ENOMEM; - goto out; - } - - ret = syncop_lookup (subvol, &loc, &ciatt, NULL, - xattr_req, NULL); - } - DECODE_SYNCOP_ERR (ret); - if (ret) - goto out; - - inode = inode_link (loc.inode, loc.parent, component, &ciatt); + inode_unref(loc.inode); + gf_uuid_clear(loc.gfid); + loc.inode = inode_new(parent->table); + if (!loc.inode) { + errno = ENOMEM; + goto out; + } - if (!inode) { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_LINK_FAILED, - "inode linking of %s failed", - uuid_utoa ((unsigned char *)&ciatt.ia_gfid)); - goto out; - } else if (inode == loc.inode) - inode_ctx_set (inode, THIS, &ctx_value); -found: - if (inode) { - ciatt.ia_type = inode->ia_type; - inode_lookup (inode); + xattr_req = dict_new(); + if (!xattr_req) { + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + errno = ENOMEM; + goto out; } - if (iatt) - *iatt = ciatt; + + ret = syncop_lookup(subvol, &loc, &ciatt, NULL, xattr_req, NULL); + } + DECODE_SYNCOP_ERR(ret); + if (ret) + goto out; + + inode = inode_link(loc.inode, loc.parent, component, &ciatt); + + if (!inode) { + gf_msg(subvol->name, GF_LOG_WARNING, errno, API_MSG_INODE_LINK_FAILED, + "inode linking of %s failed", + uuid_utoa((unsigned char *)&ciatt.ia_gfid)); + goto out; + } else if (inode == loc.inode) + inode_ctx_set(inode, THIS, &ctx_value); +found: + if (inode) { + ciatt.ia_type = inode->ia_type; + inode_lookup(inode); + } + if (iatt) + *iatt = ciatt; out: - if (xattr_req) - dict_unref (xattr_req); - loc_wipe (&loc); + if (xattr_req) + dict_unref(xattr_req); + loc_wipe(&loc); - return inode; + return inode; } - int -priv_glfs_resolve_at (struct glfs *fs, xlator_t *subvol, inode_t *at, - const char *origpath, loc_t *loc, struct iatt *iatt, - int follow, int reval) +priv_glfs_resolve_at(struct glfs *fs, xlator_t *subvol, inode_t *at, + const char *origpath, loc_t *loc, struct iatt *iatt, + int follow, int reval) { - inode_t *inode = NULL; - inode_t *parent = NULL; - char *saveptr = NULL; - char *path = NULL; - char *component = NULL; - char *next_component = NULL; - int ret = -1; - struct iatt ciatt = {0, }; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - - if (origpath[0] == '\0') { - errno = EINVAL; - goto invalid_fs; + inode_t *inode = NULL; + inode_t *parent = NULL; + char *saveptr = NULL; + char *path = NULL; + char *component = NULL; + char *next_component = NULL; + int ret = -1; + struct iatt ciatt = { + 0, + }; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (origpath[0] == '\0') { + errno = EINVAL; + goto invalid_fs; + } + + parent = NULL; + if (at && origpath[0] != '/') { + /* A relative resolution of a path which starts with '/' + is equal to an absolute path resolution. + */ + inode = inode_ref(at); + } else { + inode = inode_ref(subvol->itable->root); + + if (strcmp(origpath, "/") == 0) + glfs_resolve_root(fs, subvol, inode, &ciatt); + } + + path = gf_strdup(origpath); + if (!path) + goto invalid_fs; + + for (component = strtok_r(path, "/", &saveptr); component; + component = next_component) { + next_component = strtok_r(NULL, "/", &saveptr); + + if (parent) + inode_unref(parent); + parent = inode; + inode = glfs_resolve_component(fs, subvol, parent, component, &ciatt, + /* force hard lookup on the last + component, as the caller + wants proper iatt filled + */ + (reval || (!next_component && iatt))); + if (!inode) { + ret = -1; + break; } - parent = NULL; - if (at && origpath[0] != '/') { - /* A relative resolution of a path which starts with '/' - is equal to an absolute path resolution. - */ - inode = inode_ref (at); - } else { - inode = inode_ref (subvol->itable->root); - - if (strcmp (origpath, "/") == 0) - glfs_resolve_root (fs, subvol, inode, &ciatt); - } - - path = gf_strdup (origpath); - if (!path) - goto invalid_fs; - - for (component = strtok_r (path, "/", &saveptr); - component; component = next_component) { - - next_component = strtok_r (NULL, "/", &saveptr); - - if (parent) - inode_unref (parent); - parent = inode; - inode = glfs_resolve_component (fs, subvol, parent, - component, &ciatt, - /* force hard lookup on the last - component, as the caller - wants proper iatt filled - */ - (reval || (!next_component && - iatt))); - if (!inode) { - ret = -1; - break; + if (IA_ISLNK(ciatt.ia_type) && (next_component || follow)) { + /* If the component is not the last piece, + then following it is necessary even if + not requested by the caller + */ + char *lpath = NULL; + loc_t sym_loc = { + 0, + }; + + if (follow > GLFS_SYMLINK_MAX_FOLLOW) { + errno = ELOOP; + ret = -1; + if (inode) { + inode_unref(inode); + inode = NULL; } + break; + } + + ret = glfs_resolve_symlink(fs, subvol, inode, &lpath); + inode_unref(inode); + inode = NULL; + if (ret < 0) + break; + + ret = priv_glfs_resolve_at(fs, subvol, parent, lpath, &sym_loc, + /* followed iatt becomes the + component iatt + */ + &ciatt, + /* always recurisvely follow while + following symlink + */ + follow + 1, reval); + if (ret == 0) + inode = inode_ref(sym_loc.inode); + loc_wipe(&sym_loc); + GF_FREE(lpath); + } - if (IA_ISLNK (ciatt.ia_type) && (next_component || follow)) { - /* If the component is not the last piece, - then following it is necessary even if - not requested by the caller - */ - char *lpath = NULL; - loc_t sym_loc = {0,}; - - if (follow > GLFS_SYMLINK_MAX_FOLLOW) { - errno = ELOOP; - ret = -1; - if (inode) { - inode_unref (inode); - inode = NULL; - } - break; - } - - ret = glfs_resolve_symlink (fs, subvol, inode, &lpath); - inode_unref (inode); - inode = NULL; - if (ret < 0) - break; - - ret = priv_glfs_resolve_at (fs, subvol, parent, lpath, - &sym_loc, - /* followed iatt becomes the - component iatt - */ - &ciatt, - /* always recurisvely follow while - following symlink - */ - follow + 1, reval); - if (ret == 0) - inode = inode_ref (sym_loc.inode); - loc_wipe (&sym_loc); - GF_FREE (lpath); - } - - if (!next_component) - break; - - if (!IA_ISDIR (ciatt.ia_type)) { - /* next_component exists and this component is - not a directory - */ - inode_unref (inode); - inode = NULL; - ret = -1; - errno = ENOTDIR; - break; - } - } - - if (parent && next_component) - /* resolution failed mid-way */ - goto out; - - /* At this point, all components up to the last parent directory - have been resolved successfully (@parent). Resolution of basename - might have failed (@inode) if at all. - */ - - loc->parent = parent; - if (parent) { - gf_uuid_copy (loc->pargfid, parent->gfid); - loc->name = component; - } - - loc->inode = inode; - if (inode) { - gf_uuid_copy (loc->gfid, inode->gfid); - if (iatt) - *iatt = ciatt; - ret = 0; - } - - if (priv_glfs_loc_touchup (loc) < 0) { - ret = -1; + if (!next_component) + break; + + if (!IA_ISDIR(ciatt.ia_type)) { + /* next_component exists and this component is + not a directory + */ + inode_unref(inode); + inode = NULL; + ret = -1; + errno = ENOTDIR; + break; } + } + + if (parent && next_component) + /* resolution failed mid-way */ + goto out; + + /* At this point, all components up to the last parent directory + have been resolved successfully (@parent). Resolution of basename + might have failed (@inode) if at all. + */ + + loc->parent = parent; + if (parent) { + gf_uuid_copy(loc->pargfid, parent->gfid); + loc->name = component; + } + + loc->inode = inode; + if (inode) { + gf_uuid_copy(loc->gfid, inode->gfid); + if (iatt) + *iatt = ciatt; + ret = 0; + } + + if (priv_glfs_loc_touchup(loc) < 0) { + ret = -1; + } out: - GF_FREE (path); - __GLFS_EXIT_FS; + GF_FREE(path); + __GLFS_EXIT_FS; - /* do NOT loc_wipe here as only last component might be missing */ + /* do NOT loc_wipe here as only last component might be missing */ invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_resolve_at, 3.4.0); - int -glfs_resolve_path (struct glfs *fs, xlator_t *subvol, const char *origpath, - loc_t *loc, struct iatt *iatt, int follow, int reval) +glfs_resolve_path(struct glfs *fs, xlator_t *subvol, const char *origpath, + loc_t *loc, struct iatt *iatt, int follow, int reval) { - int ret = -1; - inode_t *cwd = NULL; - - if (origpath[0] == '/') - return priv_glfs_resolve_at (fs, subvol, NULL, origpath, loc, - iatt, follow, reval); - - cwd = glfs_cwd_get (fs); - if (NULL == cwd) { - gf_msg (subvol->name, GF_LOG_WARNING, EIO, - API_MSG_GET_CWD_FAILED, "Failed to get cwd"); - errno = EIO; - goto out; - } + int ret = -1; + inode_t *cwd = NULL; - ret = priv_glfs_resolve_at (fs, subvol, cwd, origpath, loc, iatt, + if (origpath[0] == '/') + return priv_glfs_resolve_at(fs, subvol, NULL, origpath, loc, iatt, follow, reval); - if (cwd) - inode_unref (cwd); + + cwd = glfs_cwd_get(fs); + if (NULL == cwd) { + gf_msg(subvol->name, GF_LOG_WARNING, EIO, API_MSG_GET_CWD_FAILED, + "Failed to get cwd"); + errno = EIO; + goto out; + } + + ret = priv_glfs_resolve_at(fs, subvol, cwd, origpath, loc, iatt, follow, + reval); + if (cwd) + inode_unref(cwd); out: - return ret; + return ret; } - int -priv_glfs_resolve (struct glfs *fs, xlator_t *subvol, const char *origpath, - loc_t *loc, struct iatt *iatt, int reval) +priv_glfs_resolve(struct glfs *fs, xlator_t *subvol, const char *origpath, + loc_t *loc, struct iatt *iatt, int reval) { - int ret = -1; + int ret = -1; - ret = glfs_resolve_path (fs, subvol, origpath, loc, iatt, 1, reval); + ret = glfs_resolve_path(fs, subvol, origpath, loc, iatt, 1, reval); - return ret; + return ret; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_resolve, 3.7.0); int -glfs_lresolve (struct glfs *fs, xlator_t *subvol, const char *origpath, - loc_t *loc, struct iatt *iatt, int reval) +glfs_lresolve(struct glfs *fs, xlator_t *subvol, const char *origpath, + loc_t *loc, struct iatt *iatt, int reval) { - int ret = -1; + int ret = -1; - ret = glfs_resolve_path (fs, subvol, origpath, loc, iatt, 0, reval); + ret = glfs_resolve_path(fs, subvol, origpath, loc, iatt, 0, reval); - return ret; + return ret; } - int -glfs_migrate_fd_locks_safe (struct glfs *fs, xlator_t *oldsubvol, fd_t *oldfd, - xlator_t *newsubvol, fd_t *newfd) +glfs_migrate_fd_locks_safe(struct glfs *fs, xlator_t *oldsubvol, fd_t *oldfd, + xlator_t *newsubvol, fd_t *newfd) { - dict_t *lockinfo = NULL; - int ret = 0; - char uuid1[64]; - - if (!oldfd->lk_ctx || fd_lk_ctx_empty (oldfd->lk_ctx)) - return 0; - - newfd->lk_ctx = fd_lk_ctx_ref (oldfd->lk_ctx); - - ret = syncop_fgetxattr (oldsubvol, oldfd, &lockinfo, - GF_XATTR_LOCKINFO_KEY, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret < 0) { - gf_msg (fs->volname, GF_LOG_WARNING, errno, - API_MSG_FGETXATTR_FAILED, - "fgetxattr (%s) failed (%s) on graph %s (%d)", - uuid_utoa_r (oldfd->inode->gfid, uuid1), - strerror (errno), - graphid_str (oldsubvol), oldsubvol->graph->id); - goto out; - } - - if (!dict_get (lockinfo, GF_XATTR_LOCKINFO_KEY)) { - gf_msg (fs->volname, GF_LOG_WARNING, 0, - API_MSG_LOCKINFO_KEY_MISSING, - "missing lockinfo key (%s) on graph %s (%d)", - uuid_utoa_r (oldfd->inode->gfid, uuid1), - graphid_str (oldsubvol), oldsubvol->graph->id); - goto out; - } - - ret = syncop_fsetxattr (newsubvol, newfd, lockinfo, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret < 0) { - gf_msg (fs->volname, GF_LOG_WARNING, 0, - API_MSG_FSETXATTR_FAILED, - "fsetxattr (%s) failed (%s) on graph %s (%d)", - uuid_utoa_r (newfd->inode->gfid, uuid1), - strerror (errno), - graphid_str (newsubvol), newsubvol->graph->id); - goto out; - } + dict_t *lockinfo = NULL; + int ret = 0; + char uuid1[64]; + + if (!oldfd->lk_ctx || fd_lk_ctx_empty(oldfd->lk_ctx)) + return 0; + + newfd->lk_ctx = fd_lk_ctx_ref(oldfd->lk_ctx); + + ret = syncop_fgetxattr(oldsubvol, oldfd, &lockinfo, GF_XATTR_LOCKINFO_KEY, + NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret < 0) { + gf_msg(fs->volname, GF_LOG_WARNING, errno, API_MSG_FGETXATTR_FAILED, + "fgetxattr (%s) failed (%s) on graph %s (%d)", + uuid_utoa_r(oldfd->inode->gfid, uuid1), strerror(errno), + graphid_str(oldsubvol), oldsubvol->graph->id); + goto out; + } + + if (!dict_get(lockinfo, GF_XATTR_LOCKINFO_KEY)) { + gf_msg(fs->volname, GF_LOG_WARNING, 0, API_MSG_LOCKINFO_KEY_MISSING, + "missing lockinfo key (%s) on graph %s (%d)", + uuid_utoa_r(oldfd->inode->gfid, uuid1), graphid_str(oldsubvol), + oldsubvol->graph->id); + goto out; + } + + ret = syncop_fsetxattr(newsubvol, newfd, lockinfo, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret < 0) { + gf_msg(fs->volname, GF_LOG_WARNING, 0, API_MSG_FSETXATTR_FAILED, + "fsetxattr (%s) failed (%s) on graph %s (%d)", + uuid_utoa_r(newfd->inode->gfid, uuid1), strerror(errno), + graphid_str(newsubvol), newsubvol->graph->id); + goto out; + } out: - if (lockinfo) - dict_unref (lockinfo); - return ret; + if (lockinfo) + dict_unref(lockinfo); + return ret; } - fd_t * -glfs_migrate_fd_safe (struct glfs *fs, xlator_t *newsubvol, fd_t *oldfd) +glfs_migrate_fd_safe(struct glfs *fs, xlator_t *newsubvol, fd_t *oldfd) { - fd_t *newfd = NULL; - inode_t *oldinode = NULL; - inode_t *newinode = NULL; - xlator_t *oldsubvol = NULL; - int ret = -1; - loc_t loc = {0, }; - char uuid1[64]; - - - oldinode = oldfd->inode; - oldsubvol = oldinode->table->xl; - - if (oldsubvol == newsubvol) - return fd_ref (oldfd); - - if (!oldsubvol->switched) { - ret = syncop_fsync (oldsubvol, oldfd, 0, NULL, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret) { - gf_msg (fs->volname, GF_LOG_WARNING, errno, - API_MSG_FSYNC_FAILED, "fsync() failed " - "(%s) on %s graph %s (%d)", strerror (errno), - uuid_utoa_r (oldfd->inode->gfid, uuid1), - graphid_str (oldsubvol), oldsubvol->graph->id); - } - } - - newinode = glfs_refresh_inode_safe (newsubvol, oldinode, _gf_false); - if (!newinode) { - gf_msg (fs->volname, GF_LOG_WARNING, errno, - API_MSG_INODE_REFRESH_FAILED, - "inode (%s) refresh failed (%s) on graph %s (%d)", - uuid_utoa_r (oldinode->gfid, uuid1), - strerror (errno), - graphid_str (newsubvol), newsubvol->graph->id); - goto out; - } - - newfd = fd_create (newinode, getpid()); - if (!newfd) { - gf_msg (fs->volname, GF_LOG_WARNING, errno, - API_MSG_FDCREATE_FAILED, - "fd_create (%s) failed (%s) on graph %s (%d)", - uuid_utoa_r (newinode->gfid, uuid1), - strerror (errno), - graphid_str (newsubvol), newsubvol->graph->id); - goto out; - } - - loc.inode = inode_ref (newinode); - - ret = inode_path (oldfd->inode, NULL, (char **)&loc.path); - if (ret < 0) { - gf_msg (fs->volname, GF_LOG_INFO, 0, API_MSG_INODE_PATH_FAILED, - "inode_path failed"); - goto out; + fd_t *newfd = NULL; + inode_t *oldinode = NULL; + inode_t *newinode = NULL; + xlator_t *oldsubvol = NULL; + int ret = -1; + loc_t loc = { + 0, + }; + char uuid1[64]; + + oldinode = oldfd->inode; + oldsubvol = oldinode->table->xl; + + if (oldsubvol == newsubvol) + return fd_ref(oldfd); + + if (!oldsubvol->switched) { + ret = syncop_fsync(oldsubvol, oldfd, 0, NULL, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret) { + gf_msg(fs->volname, GF_LOG_WARNING, errno, API_MSG_FSYNC_FAILED, + "fsync() failed " + "(%s) on %s graph %s (%d)", + strerror(errno), uuid_utoa_r(oldfd->inode->gfid, uuid1), + graphid_str(oldsubvol), oldsubvol->graph->id); } - - gf_uuid_copy (loc.gfid, oldinode->gfid); - - - if (IA_ISDIR (oldinode->ia_type)) - ret = syncop_opendir (newsubvol, &loc, newfd, NULL, NULL); - else - ret = syncop_open (newsubvol, &loc, - oldfd->flags & ~(O_TRUNC|O_EXCL|O_CREAT), - newfd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - loc_wipe (&loc); - - if (ret) { - gf_msg (fs->volname, GF_LOG_WARNING, errno, - API_MSG_SYNCOP_OPEN_FAILED, - "syncop_open%s (%s) failed (%s) on graph %s (%d)", - IA_ISDIR (oldinode->ia_type) ? "dir" : "", - uuid_utoa_r (newinode->gfid, uuid1), - strerror (errno), - graphid_str (newsubvol), newsubvol->graph->id); - goto out; - } - - ret = glfs_migrate_fd_locks_safe (fs, oldsubvol, oldfd, newsubvol, - newfd); - - if (ret) { - gf_msg (fs->volname, GF_LOG_WARNING, errno, - API_MSG_LOCK_MIGRATE_FAILED, - "lock migration (%s) failed (%s) on graph %s (%d)", - uuid_utoa_r (newinode->gfid, uuid1), - strerror (errno), - graphid_str (newsubvol), newsubvol->graph->id); - goto out; - } - - newfd->flags = oldfd->flags; - fd_bind (newfd); + } + + newinode = glfs_refresh_inode_safe(newsubvol, oldinode, _gf_false); + if (!newinode) { + gf_msg(fs->volname, GF_LOG_WARNING, errno, API_MSG_INODE_REFRESH_FAILED, + "inode (%s) refresh failed (%s) on graph %s (%d)", + uuid_utoa_r(oldinode->gfid, uuid1), strerror(errno), + graphid_str(newsubvol), newsubvol->graph->id); + goto out; + } + + newfd = fd_create(newinode, getpid()); + if (!newfd) { + gf_msg(fs->volname, GF_LOG_WARNING, errno, API_MSG_FDCREATE_FAILED, + "fd_create (%s) failed (%s) on graph %s (%d)", + uuid_utoa_r(newinode->gfid, uuid1), strerror(errno), + graphid_str(newsubvol), newsubvol->graph->id); + goto out; + } + + loc.inode = inode_ref(newinode); + + ret = inode_path(oldfd->inode, NULL, (char **)&loc.path); + if (ret < 0) { + gf_msg(fs->volname, GF_LOG_INFO, 0, API_MSG_INODE_PATH_FAILED, + "inode_path failed"); + goto out; + } + + gf_uuid_copy(loc.gfid, oldinode->gfid); + + if (IA_ISDIR(oldinode->ia_type)) + ret = syncop_opendir(newsubvol, &loc, newfd, NULL, NULL); + else + ret = syncop_open(newsubvol, &loc, + oldfd->flags & ~(O_TRUNC | O_EXCL | O_CREAT), newfd, + NULL, NULL); + DECODE_SYNCOP_ERR(ret); + loc_wipe(&loc); + + if (ret) { + gf_msg(fs->volname, GF_LOG_WARNING, errno, API_MSG_SYNCOP_OPEN_FAILED, + "syncop_open%s (%s) failed (%s) on graph %s (%d)", + IA_ISDIR(oldinode->ia_type) ? "dir" : "", + uuid_utoa_r(newinode->gfid, uuid1), strerror(errno), + graphid_str(newsubvol), newsubvol->graph->id); + goto out; + } + + ret = glfs_migrate_fd_locks_safe(fs, oldsubvol, oldfd, newsubvol, newfd); + + if (ret) { + gf_msg(fs->volname, GF_LOG_WARNING, errno, API_MSG_LOCK_MIGRATE_FAILED, + "lock migration (%s) failed (%s) on graph %s (%d)", + uuid_utoa_r(newinode->gfid, uuid1), strerror(errno), + graphid_str(newsubvol), newsubvol->graph->id); + goto out; + } + + newfd->flags = oldfd->flags; + fd_bind(newfd); out: - if (newinode) - inode_unref (newinode); + if (newinode) + inode_unref(newinode); - if (ret) { - fd_unref (newfd); - newfd = NULL; - } + if (ret) { + fd_unref(newfd); + newfd = NULL; + } - return newfd; + return newfd; } - fd_t * -__glfs_migrate_fd (struct glfs *fs, xlator_t *newsubvol, struct glfs_fd *glfd) +__glfs_migrate_fd(struct glfs *fs, xlator_t *newsubvol, struct glfs_fd *glfd) { - fd_t *oldfd = NULL; - fd_t *newfd = NULL; + fd_t *oldfd = NULL; + fd_t *newfd = NULL; - oldfd = glfd->fd; + oldfd = glfd->fd; - fs->migration_in_progress = 1; - pthread_mutex_unlock (&fs->mutex); - { - newfd = glfs_migrate_fd_safe (fs, newsubvol, oldfd); - } - pthread_mutex_lock (&fs->mutex); - fs->migration_in_progress = 0; - pthread_cond_broadcast (&fs->cond); + fs->migration_in_progress = 1; + pthread_mutex_unlock(&fs->mutex); + { + newfd = glfs_migrate_fd_safe(fs, newsubvol, oldfd); + } + pthread_mutex_lock(&fs->mutex); + fs->migration_in_progress = 0; + pthread_cond_broadcast(&fs->cond); - return newfd; + return newfd; } - fd_t * -__glfs_resolve_fd (struct glfs *fs, xlator_t *subvol, struct glfs_fd *glfd) +__glfs_resolve_fd(struct glfs *fs, xlator_t *subvol, struct glfs_fd *glfd) { - fd_t *fd = NULL; + fd_t *fd = NULL; - if (glfd->fd->inode->table->xl == subvol) - return fd_ref (glfd->fd); + if (glfd->fd->inode->table->xl == subvol) + return fd_ref(glfd->fd); - fd = __glfs_migrate_fd (fs, subvol, glfd); - if (!fd) - return NULL; + fd = __glfs_migrate_fd(fs, subvol, glfd); + if (!fd) + return NULL; - if (subvol == fs->active_subvol) { - fd_unref (glfd->fd); - glfd->fd = fd_ref (fd); - } + if (subvol == fs->active_subvol) { + fd_unref(glfd->fd); + glfd->fd = fd_ref(fd); + } - return fd; + return fd; } - fd_t * -glfs_resolve_fd (struct glfs *fs, xlator_t *subvol, struct glfs_fd *glfd) +glfs_resolve_fd(struct glfs *fs, xlator_t *subvol, struct glfs_fd *glfd) { - fd_t *fd = NULL; + fd_t *fd = NULL; - glfs_lock (fs, _gf_true); - { - fd = __glfs_resolve_fd (fs, subvol, glfd); - } - glfs_unlock (fs); + glfs_lock(fs, _gf_true); + { + fd = __glfs_resolve_fd(fs, subvol, glfd); + } + glfs_unlock(fs); - return fd; + return fd; } - void -__glfs_migrate_openfds (struct glfs *fs, xlator_t *subvol) +__glfs_migrate_openfds(struct glfs *fs, xlator_t *subvol) { - struct glfs_fd *glfd = NULL; - fd_t *fd = NULL; - - list_for_each_entry (glfd, &fs->openfds, openfds) { - if (gf_uuid_is_null (glfd->fd->inode->gfid)) { - gf_msg (fs->volname, GF_LOG_INFO, 0, - API_MSG_OPENFD_SKIPPED, - "skipping openfd %p/%p in graph %s (%d)", - glfd, glfd->fd, graphid_str(subvol), - subvol->graph->id); - /* create in progress, defer */ - continue; - } - - fd = __glfs_migrate_fd (fs, subvol, glfd); - if (fd) { - fd_unref (glfd->fd); - glfd->fd = fd; - } - } -} + struct glfs_fd *glfd = NULL; + fd_t *fd = NULL; + + list_for_each_entry(glfd, &fs->openfds, openfds) + { + if (gf_uuid_is_null(glfd->fd->inode->gfid)) { + gf_msg(fs->volname, GF_LOG_INFO, 0, API_MSG_OPENFD_SKIPPED, + "skipping openfd %p/%p in graph %s (%d)", glfd, glfd->fd, + graphid_str(subvol), subvol->graph->id); + /* create in progress, defer */ + continue; + } + fd = __glfs_migrate_fd(fs, subvol, glfd); + if (fd) { + fd_unref(glfd->fd); + glfd->fd = fd; + } + } +} /* Note that though it appears that this function executes under fs->mutex, * it is not fully executed under fs->mutex. i.e. there are functions like @@ -921,290 +898,284 @@ __glfs_migrate_openfds (struct glfs *fs, xlator_t *subvol) * function need not have the same value by the end of the function. */ xlator_t * -__glfs_active_subvol (struct glfs *fs) +__glfs_active_subvol(struct glfs *fs) { - xlator_t *new_subvol = NULL; - int ret = -1; - inode_t *new_cwd = NULL; - - if (!fs->next_subvol) - return fs->active_subvol; - - new_subvol = fs->mip_subvol = fs->next_subvol; - fs->next_subvol = NULL; - - ret = __glfs_first_lookup (fs, new_subvol); - if (ret) { - gf_msg (fs->volname, GF_LOG_INFO, errno, - API_MSG_FIRST_LOOKUP_GRAPH_FAILED, - "first lookup on graph %s (%d) failed (%s)", - graphid_str (new_subvol), new_subvol->graph->id, - strerror (errno)); - return NULL; - } - - if (fs->cwd) { - new_cwd = __glfs_refresh_inode (fs, new_subvol, fs->cwd, - _gf_false); - - if (!new_cwd) { - char buf1[64]; - gf_msg (fs->volname, GF_LOG_INFO, errno, - API_MSG_CWD_GRAPH_REF_FAILED, - "cwd refresh of %s graph %s (%d) failed (%s)", - uuid_utoa_r (fs->cwd->gfid, buf1), - graphid_str (new_subvol), - new_subvol->graph->id, strerror (errno)); - return NULL; - } - } - - __glfs_migrate_openfds (fs, new_subvol); - /* TODO: Migrate the fds and inodes which have leases to the new graph (issue #350)*/ - - /* switching @active_subvol and @cwd - should be atomic - */ - fs->old_subvol = fs->active_subvol; - fs->active_subvol = fs->mip_subvol; - fs->mip_subvol = NULL; - - if (new_cwd) { - __glfs_cwd_set (fs, new_cwd); - inode_unref (new_cwd); - } - - gf_msg (fs->volname, GF_LOG_INFO, 0, API_MSG_SWITCHED_GRAPH, - "switched to graph %s (%d)", - graphid_str (new_subvol), new_subvol->graph->id); - - return new_subvol; -} + xlator_t *new_subvol = NULL; + int ret = -1; + inode_t *new_cwd = NULL; + + if (!fs->next_subvol) + return fs->active_subvol; + + new_subvol = fs->mip_subvol = fs->next_subvol; + fs->next_subvol = NULL; + + ret = __glfs_first_lookup(fs, new_subvol); + if (ret) { + gf_msg(fs->volname, GF_LOG_INFO, errno, + API_MSG_FIRST_LOOKUP_GRAPH_FAILED, + "first lookup on graph %s (%d) failed (%s)", + graphid_str(new_subvol), new_subvol->graph->id, strerror(errno)); + return NULL; + } + + if (fs->cwd) { + new_cwd = __glfs_refresh_inode(fs, new_subvol, fs->cwd, _gf_false); + + if (!new_cwd) { + char buf1[64]; + gf_msg(fs->volname, GF_LOG_INFO, errno, + API_MSG_CWD_GRAPH_REF_FAILED, + "cwd refresh of %s graph %s (%d) failed (%s)", + uuid_utoa_r(fs->cwd->gfid, buf1), graphid_str(new_subvol), + new_subvol->graph->id, strerror(errno)); + return NULL; + } + } + __glfs_migrate_openfds(fs, new_subvol); + /* TODO: Migrate the fds and inodes which have leases to the new graph + * (issue #350)*/ -void -priv_glfs_subvol_done (struct glfs *fs, xlator_t *subvol) -{ - int ref = 0; - xlator_t *active_subvol = NULL; + /* switching @active_subvol and @cwd + should be atomic + */ + fs->old_subvol = fs->active_subvol; + fs->active_subvol = fs->mip_subvol; + fs->mip_subvol = NULL; - if (!subvol) - return; + if (new_cwd) { + __glfs_cwd_set(fs, new_cwd); + inode_unref(new_cwd); + } - /* For decrementing subvol->wind ref count we need not check/wait for - * migration-in-progress flag. - * Also glfs_subvol_done is called in call-back path therefore waiting - * for migration-in-progress flag can lead to dead-lock. - */ - glfs_lock (fs, _gf_false); - { - ref = (--subvol->winds); - active_subvol = fs->active_subvol; - } - glfs_unlock (fs); - - if (ref == 0) { - assert (subvol != active_subvol); - xlator_notify (subvol, GF_EVENT_PARENT_DOWN, subvol, NULL); - } + gf_msg(fs->volname, GF_LOG_INFO, 0, API_MSG_SWITCHED_GRAPH, + "switched to graph %s (%d)", graphid_str(new_subvol), + new_subvol->graph->id); + + return new_subvol; } -GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_subvol_done, 3.4.0); +void +priv_glfs_subvol_done(struct glfs *fs, xlator_t *subvol) +{ + int ref = 0; + xlator_t *active_subvol = NULL; + + if (!subvol) + return; + + /* For decrementing subvol->wind ref count we need not check/wait for + * migration-in-progress flag. + * Also glfs_subvol_done is called in call-back path therefore waiting + * for migration-in-progress flag can lead to dead-lock. + */ + glfs_lock(fs, _gf_false); + { + ref = (--subvol->winds); + active_subvol = fs->active_subvol; + } + glfs_unlock(fs); + + if (ref == 0) { + assert(subvol != active_subvol); + xlator_notify(subvol, GF_EVENT_PARENT_DOWN, subvol, NULL); + } +} +GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_subvol_done, 3.4.0); xlator_t * -priv_glfs_active_subvol (struct glfs *fs) +priv_glfs_active_subvol(struct glfs *fs) { - xlator_t *subvol = NULL; - xlator_t *old_subvol = NULL; + xlator_t *subvol = NULL; + xlator_t *old_subvol = NULL; - glfs_lock (fs, _gf_true); - { - subvol = __glfs_active_subvol (fs); + glfs_lock(fs, _gf_true); + { + subvol = __glfs_active_subvol(fs); - if (subvol) - subvol->winds++; + if (subvol) + subvol->winds++; - if (fs->old_subvol) { - old_subvol = fs->old_subvol; - fs->old_subvol = NULL; - old_subvol->switched = 1; - } - } - glfs_unlock (fs); + if (fs->old_subvol) { + old_subvol = fs->old_subvol; + fs->old_subvol = NULL; + old_subvol->switched = 1; + } + } + glfs_unlock(fs); - if (old_subvol) - priv_glfs_subvol_done (fs, old_subvol); + if (old_subvol) + priv_glfs_subvol_done(fs, old_subvol); - return subvol; + return subvol; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_active_subvol, 3.4.0); int -__glfs_cwd_set (struct glfs *fs, inode_t *inode) +__glfs_cwd_set(struct glfs *fs, inode_t *inode) { - if (inode->table->xl != fs->active_subvol) { - inode = __glfs_refresh_inode (fs, fs->active_subvol, inode, - _gf_false); - if (!inode) - return -1; - } else { - inode_ref (inode); - } + if (inode->table->xl != fs->active_subvol) { + inode = __glfs_refresh_inode(fs, fs->active_subvol, inode, _gf_false); + if (!inode) + return -1; + } else { + inode_ref(inode); + } - if (fs->cwd) - inode_unref (fs->cwd); + if (fs->cwd) + inode_unref(fs->cwd); - fs->cwd = inode; + fs->cwd = inode; - return 0; + return 0; } - int -glfs_cwd_set (struct glfs *fs, inode_t *inode) +glfs_cwd_set(struct glfs *fs, inode_t *inode) { - int ret = 0; + int ret = 0; - glfs_lock (fs, _gf_true); - { - ret = __glfs_cwd_set (fs, inode); - } - glfs_unlock (fs); + glfs_lock(fs, _gf_true); + { + ret = __glfs_cwd_set(fs, inode); + } + glfs_unlock(fs); - return ret; + return ret; } - inode_t * -__glfs_cwd_get (struct glfs *fs) +__glfs_cwd_get(struct glfs *fs) { - inode_t *cwd = NULL; + inode_t *cwd = NULL; - if (!fs->cwd) - return NULL; + if (!fs->cwd) + return NULL; - if (fs->cwd->table->xl == fs->active_subvol) { - cwd = inode_ref (fs->cwd); - return cwd; - } + if (fs->cwd->table->xl == fs->active_subvol) { + cwd = inode_ref(fs->cwd); + return cwd; + } - cwd = __glfs_refresh_inode (fs, fs->active_subvol, fs->cwd, _gf_false); + cwd = __glfs_refresh_inode(fs, fs->active_subvol, fs->cwd, _gf_false); - return cwd; + return cwd; } inode_t * -glfs_cwd_get (struct glfs *fs) +glfs_cwd_get(struct glfs *fs) { - inode_t *cwd = NULL; + inode_t *cwd = NULL; - glfs_lock (fs, _gf_true); - { - cwd = __glfs_cwd_get (fs); - } - glfs_unlock (fs); + glfs_lock(fs, _gf_true); + { + cwd = __glfs_cwd_get(fs); + } + glfs_unlock(fs); - return cwd; + return cwd; } inode_t * -__glfs_resolve_inode (struct glfs *fs, xlator_t *subvol, - struct glfs_object *object) +__glfs_resolve_inode(struct glfs *fs, xlator_t *subvol, + struct glfs_object *object) { - inode_t *inode = NULL; - gf_boolean_t lookup_needed = _gf_false; + inode_t *inode = NULL; + gf_boolean_t lookup_needed = _gf_false; - lookup_needed = inode_needs_lookup (object->inode, THIS); + lookup_needed = inode_needs_lookup(object->inode, THIS); - if (!lookup_needed && object->inode->table->xl == subvol) - return inode_ref (object->inode); + if (!lookup_needed && object->inode->table->xl == subvol) + return inode_ref(object->inode); - inode = __glfs_refresh_inode (fs, fs->active_subvol, - object->inode, lookup_needed); - if (!inode) - return NULL; + inode = __glfs_refresh_inode(fs, fs->active_subvol, object->inode, + lookup_needed); + if (!inode) + return NULL; - if (subvol == fs->active_subvol) { - inode_unref (object->inode); - object->inode = inode_ref (inode); - } + if (subvol == fs->active_subvol) { + inode_unref(object->inode); + object->inode = inode_ref(inode); + } - return inode; + return inode; } inode_t * -glfs_resolve_inode (struct glfs *fs, xlator_t *subvol, - struct glfs_object *object) +glfs_resolve_inode(struct glfs *fs, xlator_t *subvol, + struct glfs_object *object) { - inode_t *inode = NULL; + inode_t *inode = NULL; - glfs_lock (fs, _gf_true); - { - inode = __glfs_resolve_inode(fs, subvol, object); - } - glfs_unlock (fs); + glfs_lock(fs, _gf_true); + { + inode = __glfs_resolve_inode(fs, subvol, object); + } + glfs_unlock(fs); - return inode; + return inode; } int -glfs_create_object (loc_t *loc, struct glfs_object **retobject) +glfs_create_object(loc_t *loc, struct glfs_object **retobject) { - struct glfs_object *object = NULL; + struct glfs_object *object = NULL; - object = GF_CALLOC (1, sizeof(struct glfs_object), - glfs_mt_glfs_object_t); - if (object == NULL) { - errno = ENOMEM; - return -1; - } + object = GF_CALLOC(1, sizeof(struct glfs_object), glfs_mt_glfs_object_t); + if (object == NULL) { + errno = ENOMEM; + return -1; + } - object->inode = loc->inode; - gf_uuid_copy (object->gfid, object->inode->gfid); + object->inode = loc->inode; + gf_uuid_copy(object->gfid, object->inode->gfid); - /* we hold the reference */ - loc->inode = NULL; + /* we hold the reference */ + loc->inode = NULL; - *retobject = object; + *retobject = object; - return 0; + return 0; } struct glfs_object * -glfs_h_resolve_symlink (struct glfs *fs, struct glfs_object *object) +glfs_h_resolve_symlink(struct glfs *fs, struct glfs_object *object) { - - xlator_t *subvol = NULL; - loc_t sym_loc = {0,}; - struct iatt iatt = {0,}; - char *lpath = NULL; - int ret = 0; - struct glfs_object *target_object = NULL; - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - ret = glfs_resolve_symlink (fs, subvol, object->inode, &lpath); - if (ret < 0) - goto out; - - ret = glfs_resolve_at (fs, subvol, NULL, lpath, - &sym_loc, &iatt, - /* always recurisvely follow while - following symlink - */ - 1, 0); - if (ret == 0) - ret = glfs_create_object (&sym_loc, &target_object); + xlator_t *subvol = NULL; + loc_t sym_loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + char *lpath = NULL; + int ret = 0; + struct glfs_object *target_object = NULL; + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + ret = glfs_resolve_symlink(fs, subvol, object->inode, &lpath); + if (ret < 0) + goto out; + + ret = glfs_resolve_at(fs, subvol, NULL, lpath, &sym_loc, &iatt, + /* always recurisvely follow while + following symlink + */ + 1, 0); + if (ret == 0) + ret = glfs_create_object(&sym_loc, &target_object); out: - loc_wipe (&sym_loc); - GF_FREE (lpath); - return target_object; + loc_wipe(&sym_loc); + GF_FREE(lpath); + return target_object; } diff --git a/api/src/glfs.c b/api/src/glfs.c index 8ae3af61edb..d21cb8b334f 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -8,7 +8,6 @@ cases as published by the Free Software Foundation. */ - /* TODO: - set proper pid/lk_owner to call frames (currently buried in syncop) @@ -51,444 +50,422 @@ #include "glfs.h" #include "glfs-internal.h" - static gf_boolean_t -vol_assigned (cmd_args_t *args) +vol_assigned(cmd_args_t *args) { - return args->volfile || args->volfile_server; + return args->volfile || args->volfile_server; } - static int -glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) +glusterfs_ctx_defaults_init(glusterfs_ctx_t *ctx) { - call_pool_t *pool = NULL; - int ret = -1; - - if (!ctx) { - goto err; - } - - ret = xlator_mem_acct_init (THIS, glfs_mt_end + 1); - if (ret != 0) { - gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM, - API_MSG_MEM_ACCT_INIT_FAILED, - "Memory accounting init failed"); - return ret; - } - - /* reset ret to -1 so that we don't need to explicitly - * set it in all error paths before "goto err" - */ + call_pool_t *pool = NULL; + int ret = -1; - ret = -1; + if (!ctx) { + goto err; + } - ctx->process_uuid = generate_glusterfs_ctx_id (); - if (!ctx->process_uuid) { - goto err; - } - - ctx->page_size = 128 * GF_UNIT_KB; - - ctx->iobuf_pool = iobuf_pool_new (); - if (!ctx->iobuf_pool) { - goto err; - } - - ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE, - STARTING_EVENT_THREADS); - if (!ctx->event_pool) { - goto err; - } - - ctx->env = syncenv_new (0, 0, 0); - if (!ctx->env) { - goto err; - } - - pool = GF_CALLOC (1, sizeof (call_pool_t), - glfs_mt_call_pool_t); - if (!pool) { - goto err; - } - - /* frame_mem_pool size 112 * 4k */ - pool->frame_mem_pool = mem_pool_new (call_frame_t, 4096); - if (!pool->frame_mem_pool) { - goto err; - } - /* stack_mem_pool size 256 * 1024 */ - pool->stack_mem_pool = mem_pool_new (call_stack_t, 1024); - if (!pool->stack_mem_pool) { - goto err; - } - - ctx->stub_mem_pool = mem_pool_new (call_stub_t, 1024); - if (!ctx->stub_mem_pool) { - goto err; - } - - ctx->dict_pool = mem_pool_new (dict_t, GF_MEMPOOL_COUNT_OF_DICT_T); - if (!ctx->dict_pool) - goto err; - - ctx->dict_pair_pool = mem_pool_new (data_pair_t, - GF_MEMPOOL_COUNT_OF_DATA_PAIR_T); - if (!ctx->dict_pair_pool) - goto err; - - ctx->dict_data_pool = mem_pool_new (data_t, GF_MEMPOOL_COUNT_OF_DATA_T); - if (!ctx->dict_data_pool) - goto err; - - ctx->logbuf_pool = mem_pool_new (log_buf_t, - GF_MEMPOOL_COUNT_OF_LRU_BUF_T); - if (!ctx->logbuf_pool) - goto err; - - INIT_LIST_HEAD (&pool->all_frames); - INIT_LIST_HEAD (&ctx->cmd_args.xlator_options); - INIT_LIST_HEAD (&ctx->cmd_args.volfile_servers); - - LOCK_INIT (&pool->lock); - ctx->pool = pool; - - ret = 0; + ret = xlator_mem_acct_init(THIS, glfs_mt_end + 1); + if (ret != 0) { + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_MEM_ACCT_INIT_FAILED, + "Memory accounting init failed"); + return ret; + } + + /* reset ret to -1 so that we don't need to explicitly + * set it in all error paths before "goto err" + */ + + ret = -1; + + ctx->process_uuid = generate_glusterfs_ctx_id(); + if (!ctx->process_uuid) { + goto err; + } + + ctx->page_size = 128 * GF_UNIT_KB; + + ctx->iobuf_pool = iobuf_pool_new(); + if (!ctx->iobuf_pool) { + goto err; + } + + ctx->event_pool = event_pool_new(DEFAULT_EVENT_POOL_SIZE, + STARTING_EVENT_THREADS); + if (!ctx->event_pool) { + goto err; + } + + ctx->env = syncenv_new(0, 0, 0); + if (!ctx->env) { + goto err; + } + + pool = GF_CALLOC(1, sizeof(call_pool_t), glfs_mt_call_pool_t); + if (!pool) { + goto err; + } + + /* frame_mem_pool size 112 * 4k */ + pool->frame_mem_pool = mem_pool_new(call_frame_t, 4096); + if (!pool->frame_mem_pool) { + goto err; + } + /* stack_mem_pool size 256 * 1024 */ + pool->stack_mem_pool = mem_pool_new(call_stack_t, 1024); + if (!pool->stack_mem_pool) { + goto err; + } + + ctx->stub_mem_pool = mem_pool_new(call_stub_t, 1024); + if (!ctx->stub_mem_pool) { + goto err; + } + + ctx->dict_pool = mem_pool_new(dict_t, GF_MEMPOOL_COUNT_OF_DICT_T); + if (!ctx->dict_pool) + goto err; + + ctx->dict_pair_pool = mem_pool_new(data_pair_t, + GF_MEMPOOL_COUNT_OF_DATA_PAIR_T); + if (!ctx->dict_pair_pool) + goto err; + + ctx->dict_data_pool = mem_pool_new(data_t, GF_MEMPOOL_COUNT_OF_DATA_T); + if (!ctx->dict_data_pool) + goto err; + + ctx->logbuf_pool = mem_pool_new(log_buf_t, GF_MEMPOOL_COUNT_OF_LRU_BUF_T); + if (!ctx->logbuf_pool) + goto err; + + INIT_LIST_HEAD(&pool->all_frames); + INIT_LIST_HEAD(&ctx->cmd_args.xlator_options); + INIT_LIST_HEAD(&ctx->cmd_args.volfile_servers); + + LOCK_INIT(&pool->lock); + ctx->pool = pool; + + ret = 0; err: - if (ret && pool) { - if (pool->frame_mem_pool) - mem_pool_destroy (pool->frame_mem_pool); - if (pool->stack_mem_pool) - mem_pool_destroy (pool->stack_mem_pool); - GF_FREE (pool); - } - - if (ret && ctx) { - if (ctx->stub_mem_pool) - mem_pool_destroy (ctx->stub_mem_pool); - if (ctx->dict_pool) - mem_pool_destroy (ctx->dict_pool); - if (ctx->dict_data_pool) - mem_pool_destroy (ctx->dict_data_pool); - if (ctx->dict_pair_pool) - mem_pool_destroy (ctx->dict_pair_pool); - if (ctx->logbuf_pool) - mem_pool_destroy (ctx->logbuf_pool); - } - - return ret; -} + if (ret && pool) { + if (pool->frame_mem_pool) + mem_pool_destroy(pool->frame_mem_pool); + if (pool->stack_mem_pool) + mem_pool_destroy(pool->stack_mem_pool); + GF_FREE(pool); + } + + if (ret && ctx) { + if (ctx->stub_mem_pool) + mem_pool_destroy(ctx->stub_mem_pool); + if (ctx->dict_pool) + mem_pool_destroy(ctx->dict_pool); + if (ctx->dict_data_pool) + mem_pool_destroy(ctx->dict_data_pool); + if (ctx->dict_pair_pool) + mem_pool_destroy(ctx->dict_pair_pool); + if (ctx->logbuf_pool) + mem_pool_destroy(ctx->logbuf_pool); + } + return ret; +} static int -create_master (struct glfs *fs) +create_master(struct glfs *fs) { - int ret = 0; - xlator_t *master = NULL; - - master = GF_CALLOC (1, sizeof (*master), - glfs_mt_xlator_t); - if (!master) - goto err; - - master->name = gf_strdup ("gfapi"); - if (!master->name) - goto err; - - if (xlator_set_type (master, "mount/api") == -1) { - gf_msg ("glfs", GF_LOG_ERROR, 0, - API_MSG_MASTER_XLATOR_INIT_FAILED, "master xlator " - "for %s initialization failed", fs->volname); - goto err; - } - - master->ctx = fs->ctx; - master->private = fs; - master->options = get_new_dict (); - if (!master->options) - goto err; - - - ret = xlator_init (master); - if (ret) { - gf_msg ("glfs", GF_LOG_ERROR, 0, - API_MSG_GFAPI_XLATOR_INIT_FAILED, - "failed to initialize gfapi translator"); - goto err; - } - - fs->ctx->master = master; - THIS = master; - - return 0; + int ret = 0; + xlator_t *master = NULL; + + master = GF_CALLOC(1, sizeof(*master), glfs_mt_xlator_t); + if (!master) + goto err; + + master->name = gf_strdup("gfapi"); + if (!master->name) + goto err; + + if (xlator_set_type(master, "mount/api") == -1) { + gf_msg("glfs", GF_LOG_ERROR, 0, API_MSG_MASTER_XLATOR_INIT_FAILED, + "master xlator " + "for %s initialization failed", + fs->volname); + goto err; + } + + master->ctx = fs->ctx; + master->private = fs; + master->options = get_new_dict(); + if (!master->options) + goto err; + + ret = xlator_init(master); + if (ret) { + gf_msg("glfs", GF_LOG_ERROR, 0, API_MSG_GFAPI_XLATOR_INIT_FAILED, + "failed to initialize gfapi translator"); + goto err; + } + + fs->ctx->master = master; + THIS = master; + + return 0; err: - if (master) { - xlator_destroy (master); - } + if (master) { + xlator_destroy(master); + } - return -1; + return -1; } - static FILE * -get_volfp (struct glfs *fs) +get_volfp(struct glfs *fs) { - cmd_args_t *cmd_args = NULL; - FILE *specfp = NULL; + cmd_args_t *cmd_args = NULL; + FILE *specfp = NULL; - cmd_args = &fs->ctx->cmd_args; + cmd_args = &fs->ctx->cmd_args; - if ((specfp = fopen (cmd_args->volfile, "r")) == NULL) { - gf_msg ("glfs", GF_LOG_ERROR, errno, - API_MSG_VOLFILE_OPEN_FAILED, - "volume file %s open failed: %s", - cmd_args->volfile, - strerror (errno)); - return NULL; - } + if ((specfp = fopen(cmd_args->volfile, "r")) == NULL) { + gf_msg("glfs", GF_LOG_ERROR, errno, API_MSG_VOLFILE_OPEN_FAILED, + "volume file %s open failed: %s", cmd_args->volfile, + strerror(errno)); + return NULL; + } - gf_msg_debug ("glfs", 0, "loading volume file %s", cmd_args->volfile); + gf_msg_debug("glfs", 0, "loading volume file %s", cmd_args->volfile); - return specfp; + return specfp; } - int -glfs_volumes_init (struct glfs *fs) +glfs_volumes_init(struct glfs *fs) { - FILE *fp = NULL; - cmd_args_t *cmd_args = NULL; - int ret = 0; + FILE *fp = NULL; + cmd_args_t *cmd_args = NULL; + int ret = 0; - cmd_args = &fs->ctx->cmd_args; + cmd_args = &fs->ctx->cmd_args; - if (!vol_assigned (cmd_args)) - return -1; + if (!vol_assigned(cmd_args)) + return -1; - if (cmd_args->volfile_server) { - ret = glfs_mgmt_init (fs); - goto out; - } + if (cmd_args->volfile_server) { + ret = glfs_mgmt_init(fs); + goto out; + } - fp = get_volfp (fs); + fp = get_volfp(fs); - if (!fp) { - gf_msg ("glfs", GF_LOG_ERROR, ENOENT, - API_MSG_VOL_SPEC_FILE_ERROR, - "Cannot reach volume specification file"); - ret = -1; - goto out; - } + if (!fp) { + gf_msg("glfs", GF_LOG_ERROR, ENOENT, API_MSG_VOL_SPEC_FILE_ERROR, + "Cannot reach volume specification file"); + ret = -1; + goto out; + } - ret = glfs_process_volfp (fs, fp); - if (ret) - goto out; + ret = glfs_process_volfp(fs, fp); + if (ret) + goto out; out: - return ret; + return ret; } - /////////////////////////////////////////////////////////////////////////////// - int -pub_glfs_set_xlator_option (struct glfs *fs, const char *xlator, - const char *key, const char *value) +pub_glfs_set_xlator_option(struct glfs *fs, const char *xlator, const char *key, + const char *value) { - xlator_cmdline_option_t *option = NULL; + xlator_cmdline_option_t *option = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - option = GF_CALLOC (1, sizeof (*option), - glfs_mt_xlator_cmdline_option_t); - if (!option) - goto enomem; + option = GF_CALLOC(1, sizeof(*option), glfs_mt_xlator_cmdline_option_t); + if (!option) + goto enomem; - INIT_LIST_HEAD (&option->cmd_args); + INIT_LIST_HEAD(&option->cmd_args); - option->volume = gf_strdup (xlator); - if (!option->volume) - goto enomem; - option->key = gf_strdup (key); - if (!option->key) - goto enomem; - option->value = gf_strdup (value); - if (!option->value) - goto enomem; + option->volume = gf_strdup(xlator); + if (!option->volume) + goto enomem; + option->key = gf_strdup(key); + if (!option->key) + goto enomem; + option->value = gf_strdup(value); + if (!option->value) + goto enomem; - list_add (&option->cmd_args, &fs->ctx->cmd_args.xlator_options); + list_add(&option->cmd_args, &fs->ctx->cmd_args.xlator_options); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return 0; + return 0; enomem: - errno = ENOMEM; + errno = ENOMEM; - if (!option) { - __GLFS_EXIT_FS; - return -1; - } + if (!option) { + __GLFS_EXIT_FS; + return -1; + } - GF_FREE (option->volume); - GF_FREE (option->key); - GF_FREE (option->value); - GF_FREE (option); + GF_FREE(option->volume); + GF_FREE(option->key); + GF_FREE(option->value); + GF_FREE(option); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_xlator_option, 3.4.0); - int -pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport, - const char *host, const int port) +pub_glfs_unset_volfile_server(struct glfs *fs, const char *transport, + const char *host, const int port) { - cmd_args_t *cmd_args = NULL; - server_cmdline_t *server = NULL; - server_cmdline_t *tmp = NULL; - char *transport_val = NULL; - int port_val = 0; - int ret = -1; - - if (!fs || !host) { - errno = EINVAL; - return ret; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - cmd_args = &fs->ctx->cmd_args; - - if (transport) { - transport_val = gf_strdup (transport); - } else { - transport_val = gf_strdup (GF_DEFAULT_VOLFILE_TRANSPORT); - } - - if (!transport_val) { - errno = ENOMEM; - goto out; - } - - if (port) { - port_val = port; - } else { - port_val = GF_DEFAULT_BASE_PORT; - } - - list_for_each_entry_safe (server, tmp, - &cmd_args->curr_server->list, - list) { - if ((!strcmp(server->volfile_server, host) && - !strcmp(server->transport, transport_val) && - (server->port == port_val))) { - list_del (&server->list); - ret = 0; - goto out; - } + cmd_args_t *cmd_args = NULL; + server_cmdline_t *server = NULL; + server_cmdline_t *tmp = NULL; + char *transport_val = NULL; + int port_val = 0; + int ret = -1; + + if (!fs || !host) { + errno = EINVAL; + return ret; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + cmd_args = &fs->ctx->cmd_args; + + if (transport) { + transport_val = gf_strdup(transport); + } else { + transport_val = gf_strdup(GF_DEFAULT_VOLFILE_TRANSPORT); + } + + if (!transport_val) { + errno = ENOMEM; + goto out; + } + + if (port) { + port_val = port; + } else { + port_val = GF_DEFAULT_BASE_PORT; + } + + list_for_each_entry_safe(server, tmp, &cmd_args->curr_server->list, list) + { + if ((!strcmp(server->volfile_server, host) && + !strcmp(server->transport, transport_val) && + (server->port == port_val))) { + list_del(&server->list); + ret = 0; + goto out; } + } out: - GF_FREE (transport_val); - __GLFS_EXIT_FS; + GF_FREE(transport_val); + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_unset_volfile_server, 3.5.1); - int -pub_glfs_set_volfile_server (struct glfs *fs, const char *transport, - const char *host, int port) +pub_glfs_set_volfile_server(struct glfs *fs, const char *transport, + const char *host, int port) { - cmd_args_t *cmd_args = NULL; - int ret = -1; - char *server_host = NULL; - char *server_transport = NULL; - - if (!fs || !host) { - errno = EINVAL; - return ret; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + cmd_args_t *cmd_args = NULL; + int ret = -1; + char *server_host = NULL; + char *server_transport = NULL; - cmd_args = &fs->ctx->cmd_args; - cmd_args->max_connect_attempts = 1; - - server_host = gf_strdup (host); - if (!server_host) { - errno = ENOMEM; - goto out; - } - - if (transport) { - /* volfile fetch support over tcp|unix only */ - if (!strcmp(transport, "tcp") || !strcmp(transport, "unix")) { - server_transport = gf_strdup (transport); - } else if (!strcmp(transport, "rdma")) { - server_transport = - gf_strdup (GF_DEFAULT_VOLFILE_TRANSPORT); - gf_msg ("glfs", GF_LOG_WARNING, EINVAL, - API_MSG_INVALID_ENTRY, - "transport RDMA is deprecated, " - "falling back to tcp"); - } else { - gf_msg ("glfs", GF_LOG_TRACE, EINVAL, - API_MSG_INVALID_ENTRY, - "transport %s is not supported, " - "possible values tcp|unix", - transport); - goto out; - } + if (!fs || !host) { + errno = EINVAL; + return ret; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + cmd_args = &fs->ctx->cmd_args; + cmd_args->max_connect_attempts = 1; + + server_host = gf_strdup(host); + if (!server_host) { + errno = ENOMEM; + goto out; + } + + if (transport) { + /* volfile fetch support over tcp|unix only */ + if (!strcmp(transport, "tcp") || !strcmp(transport, "unix")) { + server_transport = gf_strdup(transport); + } else if (!strcmp(transport, "rdma")) { + server_transport = gf_strdup(GF_DEFAULT_VOLFILE_TRANSPORT); + gf_msg("glfs", GF_LOG_WARNING, EINVAL, API_MSG_INVALID_ENTRY, + "transport RDMA is deprecated, " + "falling back to tcp"); } else { - server_transport = gf_strdup (GF_DEFAULT_VOLFILE_TRANSPORT); - } - - if (!server_transport) { - errno = ENOMEM; - goto out; - } - - if (!port) { - port = GF_DEFAULT_BASE_PORT; - } - - if (!strcmp(server_transport, "unix")) { - port = 0; - } - - ret = gf_set_volfile_server_common(cmd_args, server_host, - server_transport, port); - if (ret) { - gf_log ("glfs", GF_LOG_ERROR, - "failed to set volfile server: %s", strerror (errno)); + gf_msg("glfs", GF_LOG_TRACE, EINVAL, API_MSG_INVALID_ENTRY, + "transport %s is not supported, " + "possible values tcp|unix", + transport); + goto out; } + } else { + server_transport = gf_strdup(GF_DEFAULT_VOLFILE_TRANSPORT); + } + + if (!server_transport) { + errno = ENOMEM; + goto out; + } + + if (!port) { + port = GF_DEFAULT_BASE_PORT; + } + + if (!strcmp(server_transport, "unix")) { + port = 0; + } + + ret = gf_set_volfile_server_common(cmd_args, server_host, server_transport, + port); + if (ret) { + gf_log("glfs", GF_LOG_ERROR, "failed to set volfile server: %s", + strerror(errno)); + } out: - if (server_host) { - GF_FREE (server_host); - } + if (server_host) { + GF_FREE(server_host); + } - if (server_transport) { - GF_FREE (server_transport); - } + if (server_transport) { + GF_FREE(server_transport); + } - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile_server, 3.4.0); @@ -497,294 +474,288 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile_server, 3.4.0); * Used to free the arguments allocated by glfs_set_volfile_server() */ static void -glfs_free_volfile_servers (cmd_args_t *cmd_args) +glfs_free_volfile_servers(cmd_args_t *cmd_args) { - server_cmdline_t *server = NULL; - server_cmdline_t *tmp = NULL; - - GF_VALIDATE_OR_GOTO (THIS->name, cmd_args, out); - - list_for_each_entry_safe (server, tmp, &cmd_args->volfile_servers, - list) { - list_del_init (&server->list); - GF_FREE (server->volfile_server); - GF_FREE (server->transport); - GF_FREE (server); - } - cmd_args->curr_server = NULL; + server_cmdline_t *server = NULL; + server_cmdline_t *tmp = NULL; + + GF_VALIDATE_OR_GOTO(THIS->name, cmd_args, out); + + list_for_each_entry_safe(server, tmp, &cmd_args->volfile_servers, list) + { + list_del_init(&server->list); + GF_FREE(server->volfile_server); + GF_FREE(server->transport); + GF_FREE(server); + } + cmd_args->curr_server = NULL; out: - return; + return; } static void -glfs_free_xlator_options (cmd_args_t *cmd_args) +glfs_free_xlator_options(cmd_args_t *cmd_args) { - xlator_cmdline_option_t *xo = NULL; - xlator_cmdline_option_t *tmp_xo = NULL; - - if (!&(cmd_args->xlator_options)) - return; - - list_for_each_entry_safe (xo, tmp_xo, &cmd_args->xlator_options, - cmd_args) { - list_del_init (&xo->cmd_args); - GF_FREE (xo->volume); - GF_FREE (xo->key); - GF_FREE (xo->value); - GF_FREE (xo); - } + xlator_cmdline_option_t *xo = NULL; + xlator_cmdline_option_t *tmp_xo = NULL; + + if (!&(cmd_args->xlator_options)) + return; + + list_for_each_entry_safe(xo, tmp_xo, &cmd_args->xlator_options, cmd_args) + { + list_del_init(&xo->cmd_args); + GF_FREE(xo->volume); + GF_FREE(xo->key); + GF_FREE(xo->value); + GF_FREE(xo); + } } int -pub_glfs_setfsuid (uid_t fsuid) +pub_glfs_setfsuid(uid_t fsuid) { - /* TODO: - * - Set the THIS and restore it appropriately - */ - return syncopctx_setfsuid (&fsuid); + /* TODO: + * - Set the THIS and restore it appropriately + */ + return syncopctx_setfsuid(&fsuid); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsuid, 3.4.2); - int -pub_glfs_setfsgid (gid_t fsgid) +pub_glfs_setfsgid(gid_t fsgid) { - /* TODO: - * - Set the THIS and restore it appropriately - */ - return syncopctx_setfsgid (&fsgid); + /* TODO: + * - Set the THIS and restore it appropriately + */ + return syncopctx_setfsgid(&fsgid); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsgid, 3.4.2); - int -pub_glfs_setfsgroups (size_t size, const gid_t *list) +pub_glfs_setfsgroups(size_t size, const gid_t *list) { - /* TODO: - * - Set the THIS and restore it appropriately - */ - return syncopctx_setfsgroups(size, list); + /* TODO: + * - Set the THIS and restore it appropriately + */ + return syncopctx_setfsgroups(size, list); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsgroups, 3.4.2); int -pub_glfs_setfsleaseid (glfs_leaseid_t leaseid) +pub_glfs_setfsleaseid(glfs_leaseid_t leaseid) { - int ret = -1; - char *gleaseid = NULL; + int ret = -1; + char *gleaseid = NULL; - GF_VALIDATE_OR_GOTO (THIS->name, leaseid, out); + GF_VALIDATE_OR_GOTO(THIS->name, leaseid, out); - gleaseid = gf_leaseid_get(); - if (gleaseid) { - memcpy (gleaseid, leaseid, LEASE_ID_SIZE); - ret = 0; - } + gleaseid = gf_leaseid_get(); + if (gleaseid) { + memcpy(gleaseid, leaseid, LEASE_ID_SIZE); + ret = 0; + } out: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsleaseid, 4.0.0); int -get_fop_attr_glfd (dict_t **fop_attr, struct glfs_fd *glfd) +get_fop_attr_glfd(dict_t **fop_attr, struct glfs_fd *glfd) { - char *leaseid = NULL; - int ret = 0; - gf_boolean_t dict_create = _gf_false; - - leaseid = GF_MALLOC (LEASE_ID_SIZE, gf_common_mt_char); - GF_CHECK_ALLOC_AND_LOG("gfapi", leaseid, ret, "lease id alloc failed", out); - memcpy (leaseid, glfd->lease_id, LEASE_ID_SIZE); - if (*fop_attr == NULL) { - *fop_attr = dict_new (); - dict_create = _gf_true; - } - GF_CHECK_ALLOC_AND_LOG("gfapi", *fop_attr, ret, "dict_new failed", out); - ret = dict_set_static_bin (*fop_attr, "lease-id", leaseid, LEASE_ID_SIZE); + char *leaseid = NULL; + int ret = 0; + gf_boolean_t dict_create = _gf_false; + + leaseid = GF_MALLOC(LEASE_ID_SIZE, gf_common_mt_char); + GF_CHECK_ALLOC_AND_LOG("gfapi", leaseid, ret, "lease id alloc failed", out); + memcpy(leaseid, glfd->lease_id, LEASE_ID_SIZE); + if (*fop_attr == NULL) { + *fop_attr = dict_new(); + dict_create = _gf_true; + } + GF_CHECK_ALLOC_AND_LOG("gfapi", *fop_attr, ret, "dict_new failed", out); + ret = dict_set_static_bin(*fop_attr, "lease-id", leaseid, LEASE_ID_SIZE); out: - if (ret) { - GF_FREE (leaseid); - if (dict_create) { - if (*fop_attr) - dict_unref (*fop_attr); - *fop_attr = NULL; - } + if (ret) { + GF_FREE(leaseid); + if (dict_create) { + if (*fop_attr) + dict_unref(*fop_attr); + *fop_attr = NULL; } - return ret; + } + return ret; } int -set_fop_attr_glfd (struct glfs_fd *glfd) +set_fop_attr_glfd(struct glfs_fd *glfd) { - char *lease_id = NULL; - int ret = -1; + char *lease_id = NULL; + int ret = -1; - lease_id = gf_existing_leaseid (); - if (lease_id) { - memcpy (glfd->lease_id, lease_id, LEASE_ID_SIZE); - ret = 0; - } - return ret; + lease_id = gf_existing_leaseid(); + if (lease_id) { + memcpy(glfd->lease_id, lease_id, LEASE_ID_SIZE); + ret = 0; + } + return ret; } int -get_fop_attr_thrd_key (dict_t **fop_attr) +get_fop_attr_thrd_key(dict_t **fop_attr) { - char *lease_id = NULL; - int ret = 0; - gf_boolean_t dict_create = _gf_false; - - lease_id = gf_existing_leaseid (); - if (lease_id) { - if (*fop_attr == NULL) { - *fop_attr = dict_new (); - dict_create = _gf_true; - } - GF_CHECK_ALLOC_AND_LOG("gfapi", *fop_attr, ret, "dict_new failed", out); - ret = dict_set_bin (*fop_attr, "lease-id", gf_strdup (lease_id), - LEASE_ID_SIZE); + char *lease_id = NULL; + int ret = 0; + gf_boolean_t dict_create = _gf_false; + + lease_id = gf_existing_leaseid(); + if (lease_id) { + if (*fop_attr == NULL) { + *fop_attr = dict_new(); + dict_create = _gf_true; } + GF_CHECK_ALLOC_AND_LOG("gfapi", *fop_attr, ret, "dict_new failed", out); + ret = dict_set_bin(*fop_attr, "lease-id", gf_strdup(lease_id), + LEASE_ID_SIZE); + } out: - if (ret && dict_create) { - if (*fop_attr) - dict_unref (*fop_attr); - *fop_attr = NULL; - } - return ret; + if (ret && dict_create) { + if (*fop_attr) + dict_unref(*fop_attr); + *fop_attr = NULL; + } + return ret; } void -unset_fop_attr (dict_t **fop_attr) +unset_fop_attr(dict_t **fop_attr) { - char *lease_id = NULL; - lease_id = gf_existing_leaseid (); - if (lease_id) - memset (lease_id, 0, LEASE_ID_SIZE); - if (*fop_attr) { - dict_unref (*fop_attr); - *fop_attr = NULL; - } + char *lease_id = NULL; + lease_id = gf_existing_leaseid(); + if (lease_id) + memset(lease_id, 0, LEASE_ID_SIZE); + if (*fop_attr) { + dict_unref(*fop_attr); + *fop_attr = NULL; + } } struct glfs * -pub_glfs_from_glfd (struct glfs_fd *glfd) +pub_glfs_from_glfd(struct glfs_fd *glfd) { - return glfd->fs; + return glfd->fs; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_from_glfd, 3.4.0); static void -glfs_fd_destroy (struct glfs_fd *glfd) +glfs_fd_destroy(struct glfs_fd *glfd) { - if (!glfd) - return; + if (!glfd) + return; - glfs_lock (glfd->fs, _gf_true); - { - list_del_init (&glfd->openfds); - } - glfs_unlock (glfd->fs); + glfs_lock(glfd->fs, _gf_true); + { + list_del_init(&glfd->openfds); + } + glfs_unlock(glfd->fs); - if (glfd->fd) { - fd_unref (glfd->fd); - glfd->fd = NULL; - } + if (glfd->fd) { + fd_unref(glfd->fd); + glfd->fd = NULL; + } - GF_FREE (glfd->readdirbuf); + GF_FREE(glfd->readdirbuf); - GF_FREE (glfd); + GF_FREE(glfd); } - struct glfs_fd * -glfs_fd_new (struct glfs *fs) +glfs_fd_new(struct glfs *fs) { - struct glfs_fd *glfd = NULL; + struct glfs_fd *glfd = NULL; - glfd = GF_CALLOC (1, sizeof (*glfd), glfs_mt_glfs_fd_t); - if (!glfd) - return NULL; + glfd = GF_CALLOC(1, sizeof(*glfd), glfs_mt_glfs_fd_t); + if (!glfd) + return NULL; - glfd->fs = fs; + glfd->fs = fs; - INIT_LIST_HEAD (&glfd->openfds); + INIT_LIST_HEAD(&glfd->openfds); - GF_REF_INIT (glfd, glfs_fd_destroy); + GF_REF_INIT(glfd, glfs_fd_destroy); - return glfd; + return glfd; } - void -glfs_fd_bind (struct glfs_fd *glfd) +glfs_fd_bind(struct glfs_fd *glfd) { - struct glfs *fs = NULL; + struct glfs *fs = NULL; - fs = glfd->fs; + fs = glfd->fs; - glfs_lock (fs, _gf_true); - { - list_add_tail (&glfd->openfds, &fs->openfds); - } - glfs_unlock (fs); + glfs_lock(fs, _gf_true); + { + list_add_tail(&glfd->openfds, &fs->openfds); + } + glfs_unlock(fs); } - static void * -glfs_poller (void *data) +glfs_poller(void *data) { - struct glfs *fs = NULL; + struct glfs *fs = NULL; - fs = data; + fs = data; - event_dispatch (fs->ctx->event_pool); + event_dispatch(fs->ctx->event_pool); - return NULL; + return NULL; } static struct glfs * -glfs_new_fs (const char *volname) +glfs_new_fs(const char *volname) { - struct glfs *fs = NULL; + struct glfs *fs = NULL; - fs = CALLOC (1, sizeof (*fs)); - if (!fs) - return NULL; + fs = CALLOC(1, sizeof(*fs)); + if (!fs) + return NULL; - INIT_LIST_HEAD (&fs->openfds); - INIT_LIST_HEAD (&fs->upcall_list); + INIT_LIST_HEAD(&fs->openfds); + INIT_LIST_HEAD(&fs->upcall_list); - PTHREAD_MUTEX_INIT (&fs->mutex, NULL, fs->pthread_flags, - GLFS_INIT_MUTEX, err); + PTHREAD_MUTEX_INIT(&fs->mutex, NULL, fs->pthread_flags, GLFS_INIT_MUTEX, + err); - PTHREAD_COND_INIT (&fs->cond, NULL, fs->pthread_flags, - GLFS_INIT_COND, err); + PTHREAD_COND_INIT(&fs->cond, NULL, fs->pthread_flags, GLFS_INIT_COND, err); - PTHREAD_COND_INIT (&fs->child_down_cond, NULL, fs->pthread_flags, - GLFS_INIT_COND_CHILD, err); + PTHREAD_COND_INIT(&fs->child_down_cond, NULL, fs->pthread_flags, + GLFS_INIT_COND_CHILD, err); - PTHREAD_MUTEX_INIT (&fs->upcall_list_mutex, NULL, fs->pthread_flags, - GLFS_INIT_MUTEX_UPCALL, err); + PTHREAD_MUTEX_INIT(&fs->upcall_list_mutex, NULL, fs->pthread_flags, + GLFS_INIT_MUTEX_UPCALL, err); - fs->volname = strdup (volname); - if (!fs->volname) - goto err; + fs->volname = strdup(volname); + if (!fs->volname) + goto err; - fs->pin_refcnt = 0; - fs->upcall_events = 0; - fs->up_cbk = NULL; - fs->up_data = NULL; + fs->pin_refcnt = 0; + fs->upcall_events = 0; + fs->up_cbk = NULL; + fs->up_data = NULL; - return fs; + return fs; err: - glfs_free_from_ctx (fs); - return NULL; + glfs_free_from_ctx(fs); + return NULL; } extern xlator_t global_xlator; @@ -792,785 +763,769 @@ extern glusterfs_ctx_t *global_ctx; extern pthread_mutex_t global_ctx_mutex; static int -glfs_init_global_ctx () +glfs_init_global_ctx() { - int ret = 0; - glusterfs_ctx_t *ctx = NULL; + int ret = 0; + glusterfs_ctx_t *ctx = NULL; - pthread_mutex_lock (&global_ctx_mutex); - { - if (global_xlator.ctx) - goto unlock; + pthread_mutex_lock(&global_ctx_mutex); + { + if (global_xlator.ctx) + goto unlock; - ctx = glusterfs_ctx_new (); - if (!ctx) { - ret = -1; - goto unlock; - } + ctx = glusterfs_ctx_new(); + if (!ctx) { + ret = -1; + goto unlock; + } - gf_log_globals_init (ctx, GF_LOG_NONE); + gf_log_globals_init(ctx, GF_LOG_NONE); - global_ctx = ctx; - global_xlator.ctx = global_ctx; + global_ctx = ctx; + global_xlator.ctx = global_ctx; - ret = glusterfs_ctx_defaults_init (ctx); - if (ret) { - global_ctx = NULL; - global_xlator.ctx = NULL; - goto unlock; - } + ret = glusterfs_ctx_defaults_init(ctx); + if (ret) { + global_ctx = NULL; + global_xlator.ctx = NULL; + goto unlock; } + } unlock: - pthread_mutex_unlock (&global_ctx_mutex); + pthread_mutex_unlock(&global_ctx_mutex); - if (ret) - FREE (ctx); + if (ret) + FREE(ctx); - return ret; + return ret; } - struct glfs * -pub_glfs_new (const char *volname) +pub_glfs_new(const char *volname) { - struct glfs *fs = NULL; - int ret = -1; - glusterfs_ctx_t *ctx = NULL; - xlator_t *old_THIS = NULL; - char pname[16] = ""; - char msg[32] = ""; - - if (!volname) { - errno = EINVAL; - return NULL; - } - - /* - * Do this as soon as possible in case something else depends on - * pool allocations. - */ - mem_pools_init_early (); - mem_pools_init_late (); + struct glfs *fs = NULL; + int ret = -1; + glusterfs_ctx_t *ctx = NULL; + xlator_t *old_THIS = NULL; + char pname[16] = ""; + char msg[32] = ""; + + if (!volname) { + errno = EINVAL; + return NULL; + } - fs = glfs_new_fs (volname); - if (!fs) - goto out; + /* + * Do this as soon as possible in case something else depends on + * pool allocations. + */ + mem_pools_init_early(); + mem_pools_init_late(); - ctx = glusterfs_ctx_new (); - if (!ctx) - goto out; + fs = glfs_new_fs(volname); + if (!fs) + goto out; - /* first globals init, for gf_mem_acct_enable_set () */ + ctx = glusterfs_ctx_new(); + if (!ctx) + goto out; - ret = glusterfs_globals_init (ctx); - if (ret) - goto out; + /* first globals init, for gf_mem_acct_enable_set () */ - old_THIS = THIS; - ret = glfs_init_global_ctx (); - if (ret) - goto out; + ret = glusterfs_globals_init(ctx); + if (ret) + goto out; - /* then ctx_defaults_init, for xlator_mem_acct_init(THIS) */ + old_THIS = THIS; + ret = glfs_init_global_ctx(); + if (ret) + goto out; - ret = glusterfs_ctx_defaults_init (ctx); - if (ret) - goto out; + /* then ctx_defaults_init, for xlator_mem_acct_init(THIS) */ - fs->ctx = ctx; - fs->ctx->process_mode = GF_CLIENT_PROCESS; + ret = glusterfs_ctx_defaults_init(ctx); + if (ret) + goto out; - ret = glfs_set_logging (fs, "/dev/null", 0); - if (ret) - goto out; + fs->ctx = ctx; + fs->ctx->process_mode = GF_CLIENT_PROCESS; - fs->ctx->cmd_args.volfile_id = gf_strdup (volname); - if (!(fs->ctx->cmd_args.volfile_id)) { - ret = -1; - goto out; - } + ret = glfs_set_logging(fs, "/dev/null", 0); + if (ret) + goto out; + fs->ctx->cmd_args.volfile_id = gf_strdup(volname); + if (!(fs->ctx->cmd_args.volfile_id)) { ret = -1; + goto out; + } + + ret = -1; #ifdef GF_LINUX_HOST_OS - ret = prctl (PR_GET_NAME, (unsigned long) pname, 0, 0, 0); + ret = prctl(PR_GET_NAME, (unsigned long)pname, 0, 0, 0); #endif - if (ret) - fs->ctx->cmd_args.process_name = gf_strdup ("gfapi"); - else { - snprintf (msg, sizeof(msg), "gfapi.%s", pname); - fs->ctx->cmd_args.process_name = gf_strdup (msg); - } - ret = 0; + if (ret) + fs->ctx->cmd_args.process_name = gf_strdup("gfapi"); + else { + snprintf(msg, sizeof(msg), "gfapi.%s", pname); + fs->ctx->cmd_args.process_name = gf_strdup(msg); + } + ret = 0; out: - if (ret) { - if (fs) { - glfs_fini (fs); - fs = NULL; - } else { - /* glfs_fini() calls mem_pools_fini() too */ - mem_pools_fini (); - } + if (ret) { + if (fs) { + glfs_fini(fs); + fs = NULL; + } else { + /* glfs_fini() calls mem_pools_fini() too */ + mem_pools_fini(); } + } - if (old_THIS) - THIS = old_THIS; + if (old_THIS) + THIS = old_THIS; - return fs; + return fs; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_new, 3.4.0); - struct glfs * -priv_glfs_new_from_ctx (glusterfs_ctx_t *ctx) +priv_glfs_new_from_ctx(glusterfs_ctx_t *ctx) { - struct glfs *fs = NULL; + struct glfs *fs = NULL; - if (!ctx) - goto out; + if (!ctx) + goto out; - fs = glfs_new_fs (""); - if (!fs) - goto out; + fs = glfs_new_fs(""); + if (!fs) + goto out; - fs->ctx = ctx; + fs->ctx = ctx; out: - return fs; + return fs; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_new_from_ctx, 3.7.0); - void -priv_glfs_free_from_ctx (struct glfs *fs) +priv_glfs_free_from_ctx(struct glfs *fs) { - upcall_entry *u_list = NULL; - upcall_entry *tmp = NULL; - - if (!fs) - return; - - /* cleanup upcall structures */ - list_for_each_entry_safe (u_list, tmp, - &fs->upcall_list, - upcall_list) { - list_del_init (&u_list->upcall_list); - GF_FREE (u_list->upcall_data.data); - GF_FREE (u_list); - } + upcall_entry *u_list = NULL; + upcall_entry *tmp = NULL; + + if (!fs) + return; - PTHREAD_MUTEX_DESTROY (&fs->mutex, fs->pthread_flags, GLFS_INIT_MUTEX); + /* cleanup upcall structures */ + list_for_each_entry_safe(u_list, tmp, &fs->upcall_list, upcall_list) + { + list_del_init(&u_list->upcall_list); + GF_FREE(u_list->upcall_data.data); + GF_FREE(u_list); + } - PTHREAD_COND_DESTROY (&fs->cond, fs->pthread_flags, GLFS_INIT_COND); + PTHREAD_MUTEX_DESTROY(&fs->mutex, fs->pthread_flags, GLFS_INIT_MUTEX); - PTHREAD_COND_DESTROY (&fs->child_down_cond, fs->pthread_flags, - GLFS_INIT_COND_CHILD); + PTHREAD_COND_DESTROY(&fs->cond, fs->pthread_flags, GLFS_INIT_COND); - PTHREAD_MUTEX_DESTROY (&fs->upcall_list_mutex, fs->pthread_flags, - GLFS_INIT_MUTEX_UPCALL); + PTHREAD_COND_DESTROY(&fs->child_down_cond, fs->pthread_flags, + GLFS_INIT_COND_CHILD); - if (fs->oldvolfile) - FREE (fs->oldvolfile); + PTHREAD_MUTEX_DESTROY(&fs->upcall_list_mutex, fs->pthread_flags, + GLFS_INIT_MUTEX_UPCALL); - FREE (fs->volname); + if (fs->oldvolfile) + FREE(fs->oldvolfile); - FREE (fs); + FREE(fs->volname); + + FREE(fs); } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_free_from_ctx, 3.7.0); - int -pub_glfs_set_volfile (struct glfs *fs, const char *volfile) +pub_glfs_set_volfile(struct glfs *fs, const char *volfile) { - cmd_args_t *cmd_args = NULL; + cmd_args_t *cmd_args = NULL; - cmd_args = &fs->ctx->cmd_args; + cmd_args = &fs->ctx->cmd_args; - if (vol_assigned (cmd_args)) - return -1; + if (vol_assigned(cmd_args)) + return -1; - cmd_args->volfile = gf_strdup (volfile); - if (!cmd_args->volfile) - return -1; - return 0; + cmd_args->volfile = gf_strdup(volfile); + if (!cmd_args->volfile) + return -1; + return 0; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile, 3.4.0); - int -pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel) +pub_glfs_set_logging(struct glfs *fs, const char *logfile, int loglevel) { - int ret = -1; - char *tmplog = NULL; + int ret = -1; + char *tmplog = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - if (!logfile) { - ret = gf_set_log_file_path (&fs->ctx->cmd_args, fs->ctx); - if (ret) - goto out; - tmplog = fs->ctx->cmd_args.log_file; - } else { - tmplog = (char *)logfile; - } + if (!logfile) { + ret = gf_set_log_file_path(&fs->ctx->cmd_args, fs->ctx); + if (ret) + goto out; + tmplog = fs->ctx->cmd_args.log_file; + } else { + tmplog = (char *)logfile; + } - /* finish log set parameters before init */ - if (loglevel >= 0) - gf_log_set_loglevel (fs->ctx, loglevel); + /* finish log set parameters before init */ + if (loglevel >= 0) + gf_log_set_loglevel(fs->ctx, loglevel); - ret = gf_log_init (fs->ctx, tmplog, NULL); - if (ret) - goto out; + ret = gf_log_init(fs->ctx, tmplog, NULL); + if (ret) + goto out; - ret = gf_log_inject_timer_event (fs->ctx); - if (ret) - goto out; + ret = gf_log_inject_timer_event(fs->ctx); + if (ret) + goto out; out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_logging, 3.4.0); - int -glfs_init_wait (struct glfs *fs) +glfs_init_wait(struct glfs *fs) { - int ret = -1; - - /* Always a top-down call, use glfs_lock() */ - glfs_lock (fs, _gf_true); - { - while (!fs->init) - pthread_cond_wait (&fs->cond, - &fs->mutex); - ret = fs->ret; - errno = fs->err; - } - glfs_unlock (fs); - - return ret; + int ret = -1; + + /* Always a top-down call, use glfs_lock() */ + glfs_lock(fs, _gf_true); + { + while (!fs->init) + pthread_cond_wait(&fs->cond, &fs->mutex); + ret = fs->ret; + errno = fs->err; + } + glfs_unlock(fs); + + return ret; } - void -priv_glfs_init_done (struct glfs *fs, int ret) +priv_glfs_init_done(struct glfs *fs, int ret) { - glfs_init_cbk init_cbk; - - if (!fs) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, API_MSG_GLFS_FSOBJ_NULL, - "fs is NULL"); - goto out; - } - - init_cbk = fs->init_cbk; - - /* Always a bottom-up call, use mutex_lock() */ - pthread_mutex_lock (&fs->mutex); - { - fs->init = 1; - fs->ret = ret; - fs->err = errno; - - if (!init_cbk) - pthread_cond_broadcast (&fs->cond); - } - pthread_mutex_unlock (&fs->mutex); - - if (init_cbk) - init_cbk (fs, ret); + glfs_init_cbk init_cbk; + + if (!fs) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_GLFS_FSOBJ_NULL, + "fs is NULL"); + goto out; + } + + init_cbk = fs->init_cbk; + + /* Always a bottom-up call, use mutex_lock() */ + pthread_mutex_lock(&fs->mutex); + { + fs->init = 1; + fs->ret = ret; + fs->err = errno; + + if (!init_cbk) + pthread_cond_broadcast(&fs->cond); + } + pthread_mutex_unlock(&fs->mutex); + + if (init_cbk) + init_cbk(fs, ret); out: - return; + return; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_init_done, 3.4.0); - int -glfs_init_common (struct glfs *fs) +glfs_init_common(struct glfs *fs) { - int ret = -1; + int ret = -1; - ret = create_master (fs); - if (ret) - return ret; + ret = create_master(fs); + if (ret) + return ret; - ret = gf_thread_create (&fs->poller, NULL, glfs_poller, fs, "glfspoll"); - if (ret) - return ret; + ret = gf_thread_create(&fs->poller, NULL, glfs_poller, fs, "glfspoll"); + if (ret) + return ret; - ret = glfs_volumes_init (fs); - if (ret) - return ret; + ret = glfs_volumes_init(fs); + if (ret) + return ret; - fs->dev_id = gf_dm_hashfn (fs->volname, strlen (fs->volname)); - return ret; + fs->dev_id = gf_dm_hashfn(fs->volname, strlen(fs->volname)); + return ret; } - int -glfs_init_async (struct glfs *fs, glfs_init_cbk cbk) +glfs_init_async(struct glfs *fs, glfs_init_cbk cbk) { - int ret = -1; + int ret = -1; - if (!fs || !fs->ctx) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, - "fs is not properly initialized."); - errno = EINVAL; - return ret; - } + if (!fs || !fs->ctx) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "fs is not properly initialized."); + errno = EINVAL; + return ret; + } - fs->init_cbk = cbk; + fs->init_cbk = cbk; - ret = glfs_init_common (fs); + ret = glfs_init_common(fs); - return ret; + return ret; } - int -pub_glfs_init (struct glfs *fs) +pub_glfs_init(struct glfs *fs) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; + DECLARE_OLD_THIS; - if (!fs || !fs->ctx) { - gf_msg ("glfs", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, - "fs is not properly initialized."); - errno = EINVAL; - return ret; - } + if (!fs || !fs->ctx) { + gf_msg("glfs", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY, + "fs is not properly initialized."); + errno = EINVAL; + return ret; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - ret = glfs_init_common (fs); - if (ret) - goto out; + ret = glfs_init_common(fs); + if (ret) + goto out; - ret = glfs_init_wait (fs); + ret = glfs_init_wait(fs); out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - /* Set the initial current working directory to "/" */ - if (ret >= 0) { - ret = glfs_chdir (fs, "/"); - } + /* Set the initial current working directory to "/" */ + if (ret >= 0) { + ret = glfs_chdir(fs, "/"); + } invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_init, 3.4.0); static int -glusterfs_ctx_destroy (glusterfs_ctx_t *ctx) +glusterfs_ctx_destroy(glusterfs_ctx_t *ctx) { - call_pool_t *pool = NULL; - int ret = 0; - glusterfs_graph_t *trav_graph = NULL; - glusterfs_graph_t *tmp = NULL; - - if (ctx == NULL) - return 0; - - if (ctx->cmd_args.curr_server) - glfs_free_volfile_servers (&ctx->cmd_args); - - glfs_free_xlator_options (&ctx->cmd_args); - - /* For all the graphs, crawl through the xlator_t structs and free - * all its members except for the mem_acct member, - * as GF_FREE will be referencing it. - */ - list_for_each_entry_safe (trav_graph, tmp, &ctx->graphs, list) { - xlator_tree_free_members (trav_graph->first); - } - - /* Free the memory pool */ - if (ctx->stub_mem_pool) - mem_pool_destroy (ctx->stub_mem_pool); - if (ctx->dict_pool) - mem_pool_destroy (ctx->dict_pool); - if (ctx->dict_data_pool) - mem_pool_destroy (ctx->dict_data_pool); - if (ctx->dict_pair_pool) - mem_pool_destroy (ctx->dict_pair_pool); - if (ctx->logbuf_pool) - mem_pool_destroy (ctx->logbuf_pool); - - pool = ctx->pool; - if (pool) { - if (pool->frame_mem_pool) - mem_pool_destroy (pool->frame_mem_pool); - if (pool->stack_mem_pool) - mem_pool_destroy (pool->stack_mem_pool); - LOCK_DESTROY (&pool->lock); - GF_FREE (pool); - } - - /* Free the event pool */ - ret = event_pool_destroy (ctx->event_pool); - - /* Free the iobuf pool */ - iobuf_pool_destroy (ctx->iobuf_pool); - - GF_FREE (ctx->process_uuid); - GF_FREE (ctx->cmd_args.volfile_id); - GF_FREE (ctx->cmd_args.process_name); - - LOCK_DESTROY (&ctx->lock); - pthread_mutex_destroy (&ctx->notify_lock); - pthread_cond_destroy (&ctx->notify_cond); - - /* Free all the graph structs and its containing xlator_t structs - * from this point there should be no reference to GF_FREE/GF_CALLOC - * as it will try to access mem_acct and the below function would - * have freed the same. - */ - list_for_each_entry_safe (trav_graph, tmp, &ctx->graphs, list) { - glusterfs_graph_destroy_residual (trav_graph); - } - - FREE (ctx); - - return ret; + call_pool_t *pool = NULL; + int ret = 0; + glusterfs_graph_t *trav_graph = NULL; + glusterfs_graph_t *tmp = NULL; + + if (ctx == NULL) + return 0; + + if (ctx->cmd_args.curr_server) + glfs_free_volfile_servers(&ctx->cmd_args); + + glfs_free_xlator_options(&ctx->cmd_args); + + /* For all the graphs, crawl through the xlator_t structs and free + * all its members except for the mem_acct member, + * as GF_FREE will be referencing it. + */ + list_for_each_entry_safe(trav_graph, tmp, &ctx->graphs, list) + { + xlator_tree_free_members(trav_graph->first); + } + + /* Free the memory pool */ + if (ctx->stub_mem_pool) + mem_pool_destroy(ctx->stub_mem_pool); + if (ctx->dict_pool) + mem_pool_destroy(ctx->dict_pool); + if (ctx->dict_data_pool) + mem_pool_destroy(ctx->dict_data_pool); + if (ctx->dict_pair_pool) + mem_pool_destroy(ctx->dict_pair_pool); + if (ctx->logbuf_pool) + mem_pool_destroy(ctx->logbuf_pool); + + pool = ctx->pool; + if (pool) { + if (pool->frame_mem_pool) + mem_pool_destroy(pool->frame_mem_pool); + if (pool->stack_mem_pool) + mem_pool_destroy(pool->stack_mem_pool); + LOCK_DESTROY(&pool->lock); + GF_FREE(pool); + } + + /* Free the event pool */ + ret = event_pool_destroy(ctx->event_pool); + + /* Free the iobuf pool */ + iobuf_pool_destroy(ctx->iobuf_pool); + + GF_FREE(ctx->process_uuid); + GF_FREE(ctx->cmd_args.volfile_id); + GF_FREE(ctx->cmd_args.process_name); + + LOCK_DESTROY(&ctx->lock); + pthread_mutex_destroy(&ctx->notify_lock); + pthread_cond_destroy(&ctx->notify_cond); + + /* Free all the graph structs and its containing xlator_t structs + * from this point there should be no reference to GF_FREE/GF_CALLOC + * as it will try to access mem_acct and the below function would + * have freed the same. + */ + list_for_each_entry_safe(trav_graph, tmp, &ctx->graphs, list) + { + glusterfs_graph_destroy_residual(trav_graph); + } + + FREE(ctx); + + return ret; } int -pub_glfs_fini (struct glfs *fs) +pub_glfs_fini(struct glfs *fs) { - int ret = -1; - int countdown = 100; - xlator_t *subvol = NULL; - glusterfs_ctx_t *ctx = NULL; - glusterfs_graph_t *graph = NULL; - call_pool_t *call_pool = NULL; - int fs_init = 0; - int err = -1; - - DECLARE_OLD_THIS; - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - ctx = fs->ctx; - if (!ctx) { - goto free_fs; - } - - if (ctx->mgmt) { - rpc_clnt_disable (ctx->mgmt); - rpc_clnt_unref (ctx->mgmt); - ctx->mgmt = NULL; - } - - call_pool = fs->ctx->pool; - - while (countdown--) { - /* give some time for background frames to finish */ - pthread_mutex_lock (&fs->mutex); - { - /* Do we need to increase countdown? */ - if ((!call_pool->cnt) && (!fs->pin_refcnt)) { - gf_msg_trace ("glfs", 0, - "call_pool_cnt - %"PRId64"," - "pin_refcnt - %d", - call_pool->cnt, fs->pin_refcnt); - - ctx->cleanup_started = 1; - pthread_mutex_unlock (&fs->mutex); - break; - } - } - pthread_mutex_unlock (&fs->mutex); - usleep (100000); - } - - /* leaked frames may exist, we ignore */ - - /*We deem glfs_fini as successful if there are no pending frames in the call - *pool*/ - ret = (call_pool->cnt == 0)? 0: -1; - - pthread_mutex_lock (&fs->mutex); + int ret = -1; + int countdown = 100; + xlator_t *subvol = NULL; + glusterfs_ctx_t *ctx = NULL; + glusterfs_graph_t *graph = NULL; + call_pool_t *call_pool = NULL; + int fs_init = 0; + int err = -1; + + DECLARE_OLD_THIS; + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + ctx = fs->ctx; + if (!ctx) { + goto free_fs; + } + + if (ctx->mgmt) { + rpc_clnt_disable(ctx->mgmt); + rpc_clnt_unref(ctx->mgmt); + ctx->mgmt = NULL; + } + + call_pool = fs->ctx->pool; + + while (countdown--) { + /* give some time for background frames to finish */ + pthread_mutex_lock(&fs->mutex); { - fs_init = fs->init; + /* Do we need to increase countdown? */ + if ((!call_pool->cnt) && (!fs->pin_refcnt)) { + gf_msg_trace("glfs", 0, + "call_pool_cnt - %" PRId64 + "," + "pin_refcnt - %d", + call_pool->cnt, fs->pin_refcnt); + + ctx->cleanup_started = 1; + pthread_mutex_unlock(&fs->mutex); + break; + } } - pthread_mutex_unlock (&fs->mutex); - - if (fs_init != 0) { - subvol = glfs_active_subvol (fs); - if (subvol) { - /* PARENT_DOWN within glfs_subvol_done() is issued - only on graph switch (new graph should activiate - and decrement the extra @winds count taken in - glfs_graph_setup() - - Since we are explicitly destroying, - PARENT_DOWN is necessary - */ - xlator_notify (subvol, GF_EVENT_PARENT_DOWN, subvol, 0); - /* Here we wait for GF_EVENT_CHILD_DOWN before exiting, - in case of asynchrnous cleanup - */ - graph = subvol->graph; - err = pthread_mutex_lock (&fs->mutex); - if (err != 0) { - gf_msg ("glfs", GF_LOG_ERROR, err, - API_MSG_FSMUTEX_LOCK_FAILED, - "pthread lock on glfs mutex, " - "returned error: (%s)", strerror (err)); - goto fail; - } - /* check and wait for CHILD_DOWN for active subvol*/ - { - while (graph->used) { - err = pthread_cond_wait (&fs->child_down_cond, - &fs->mutex); - if (err != 0) - gf_msg ("glfs", GF_LOG_INFO, err, - API_MSG_COND_WAIT_FAILED, - "%s cond wait failed %s", - subvol->name, - strerror (err)); - } - } - - err = pthread_mutex_unlock (&fs->mutex); - if (err != 0) { - gf_msg ("glfs", GF_LOG_ERROR, err, - API_MSG_FSMUTEX_UNLOCK_FAILED, - "pthread unlock on glfs mutex, " - "returned error: (%s)", strerror (err)); - goto fail; - } + pthread_mutex_unlock(&fs->mutex); + usleep(100000); + } + + /* leaked frames may exist, we ignore */ + + /*We deem glfs_fini as successful if there are no pending frames in the call + *pool*/ + ret = (call_pool->cnt == 0) ? 0 : -1; + + pthread_mutex_lock(&fs->mutex); + { + fs_init = fs->init; + } + pthread_mutex_unlock(&fs->mutex); + + if (fs_init != 0) { + subvol = glfs_active_subvol(fs); + if (subvol) { + /* PARENT_DOWN within glfs_subvol_done() is issued + only on graph switch (new graph should activiate + and decrement the extra @winds count taken in + glfs_graph_setup() + + Since we are explicitly destroying, + PARENT_DOWN is necessary + */ + xlator_notify(subvol, GF_EVENT_PARENT_DOWN, subvol, 0); + /* Here we wait for GF_EVENT_CHILD_DOWN before exiting, + in case of asynchrnous cleanup + */ + graph = subvol->graph; + err = pthread_mutex_lock(&fs->mutex); + if (err != 0) { + gf_msg("glfs", GF_LOG_ERROR, err, API_MSG_FSMUTEX_LOCK_FAILED, + "pthread lock on glfs mutex, " + "returned error: (%s)", + strerror(err)); + goto fail; + } + /* check and wait for CHILD_DOWN for active subvol*/ + { + while (graph->used) { + err = pthread_cond_wait(&fs->child_down_cond, &fs->mutex); + if (err != 0) + gf_msg("glfs", GF_LOG_INFO, err, + API_MSG_COND_WAIT_FAILED, + "%s cond wait failed %s", subvol->name, + strerror(err)); } - glfs_subvol_done (fs, subvol); - } - - ctx->cleanup_started = 1; - - if (fs_init != 0) { - /* Destroy all the inode tables of all the graphs. - * NOTE: - * - inode objects should be destroyed before calling fini() - * of each xlator, as fini() and forget() of the xlators - * can share few common locks or data structures, calling - * fini first might destroy those required by forget - * ( eg: in quick-read) - * - The call to inode_table_destroy_all is not required when - * the cleanup during graph switch is implemented to perform - * inode table destroy. - */ - inode_table_destroy_all (ctx); - - /* Call fini() of all the xlators in the active graph - * NOTE: - * - xlator fini() should be called before destroying any of - * the threads. (eg: fini() in protocol-client uses timer - * thread) */ - glusterfs_graph_deactivate (ctx->active); - - /* Join the syncenv_processor threads and cleanup - * syncenv resources*/ - syncenv_destroy (ctx->env); - - /* Join the poller thread */ - if (event_dispatch_destroy (ctx->event_pool) < 0) - ret = -1; + } + + err = pthread_mutex_unlock(&fs->mutex); + if (err != 0) { + gf_msg("glfs", GF_LOG_ERROR, err, API_MSG_FSMUTEX_UNLOCK_FAILED, + "pthread unlock on glfs mutex, " + "returned error: (%s)", + strerror(err)); + goto fail; + } } - - /* log infra has to be brought down before destroying - * timer registry, as logging uses timer infra + glfs_subvol_done(fs, subvol); + } + + ctx->cleanup_started = 1; + + if (fs_init != 0) { + /* Destroy all the inode tables of all the graphs. + * NOTE: + * - inode objects should be destroyed before calling fini() + * of each xlator, as fini() and forget() of the xlators + * can share few common locks or data structures, calling + * fini first might destroy those required by forget + * ( eg: in quick-read) + * - The call to inode_table_destroy_all is not required when + * the cleanup during graph switch is implemented to perform + * inode table destroy. */ - if (gf_log_fini (ctx) != 0) - ret = -1; + inode_table_destroy_all(ctx); + + /* Call fini() of all the xlators in the active graph + * NOTE: + * - xlator fini() should be called before destroying any of + * the threads. (eg: fini() in protocol-client uses timer + * thread) */ + glusterfs_graph_deactivate(ctx->active); + + /* Join the syncenv_processor threads and cleanup + * syncenv resources*/ + syncenv_destroy(ctx->env); + + /* Join the poller thread */ + if (event_dispatch_destroy(ctx->event_pool) < 0) + ret = -1; + } + + /* log infra has to be brought down before destroying + * timer registry, as logging uses timer infra + */ + if (gf_log_fini(ctx) != 0) + ret = -1; - /* Join the timer thread */ - if (fs_init != 0) { - gf_timer_registry_destroy (ctx); - } + /* Join the timer thread */ + if (fs_init != 0) { + gf_timer_registry_destroy(ctx); + } - /* Destroy the context and the global pools */ - if (glusterfs_ctx_destroy (ctx) != 0) - ret = -1; + /* Destroy the context and the global pools */ + if (glusterfs_ctx_destroy(ctx) != 0) + ret = -1; free_fs: - glfs_free_from_ctx (fs); + glfs_free_from_ctx(fs); - /* - * Do this as late as possible in case anything else has (or - * grows) a dependency on mem-pool allocations. - */ - mem_pools_fini (); + /* + * Do this as late as possible in case anything else has (or + * grows) a dependency on mem-pool allocations. + */ + mem_pools_fini(); fail: - if (!ret) - ret = err; + if (!ret) + ret = err; - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fini, 3.4.0); - ssize_t -pub_glfs_get_volfile (struct glfs *fs, void *buf, size_t len) +pub_glfs_get_volfile(struct glfs *fs, void *buf, size_t len) { - ssize_t res = -1; + ssize_t res = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - glfs_lock(fs, _gf_true); - if (len >= fs->oldvollen) { - gf_msg_trace ("glfs", 0, "copying %zu to %p", len, buf); - memcpy(buf,fs->oldvolfile,len); - res = len; - } - else { - res = len - fs->oldvollen; - gf_msg_trace ("glfs", 0, "buffer is %zd too short", -res); - } - glfs_unlock(fs); + glfs_lock(fs, _gf_true); + if (len >= fs->oldvollen) { + gf_msg_trace("glfs", 0, "copying %zu to %p", len, buf); + memcpy(buf, fs->oldvolfile, len); + res = len; + } else { + res = len - fs->oldvollen; + gf_msg_trace("glfs", 0, "buffer is %zd too short", -res); + } + glfs_unlock(fs); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return res; + return res; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_get_volfile, 3.6.0); int -priv_glfs_ipc (struct glfs *fs, int opcode, void *xd_in, void **xd_out) +priv_glfs_ipc(struct glfs *fs, int opcode, void *xd_in, void **xd_out) { - xlator_t *subvol = NULL; - int ret = -1; + xlator_t *subvol = NULL; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - ret = syncop_ipc (subvol, opcode, (dict_t *) xd_in, (dict_t **) xd_out); - DECODE_SYNCOP_ERR (ret); + ret = syncop_ipc(subvol, opcode, (dict_t *)xd_in, (dict_t **)xd_out); + DECODE_SYNCOP_ERR(ret); out: - glfs_subvol_done (fs, subvol); - __GLFS_EXIT_FS; + glfs_subvol_done(fs, subvol); + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_ipc, 3.12.0); - void -pub_glfs_free (void *ptr) +pub_glfs_free(void *ptr) { - GLFS_FREE (ptr); + GLFS_FREE(ptr); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_free, 3.7.16); - -struct glfs* -pub_glfs_upcall_get_fs (struct glfs_upcall *arg) +struct glfs * +pub_glfs_upcall_get_fs(struct glfs_upcall *arg) { - return arg->fs; + return arg->fs; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_fs, 3.7.16); enum glfs_upcall_reason -pub_glfs_upcall_get_reason (struct glfs_upcall *arg) +pub_glfs_upcall_get_reason(struct glfs_upcall *arg) { - return arg->reason; + return arg->reason; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_reason, 3.7.16); -void* -pub_glfs_upcall_get_event (struct glfs_upcall *arg) +void * +pub_glfs_upcall_get_event(struct glfs_upcall *arg) { - return arg->event; + return arg->event; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_get_event, 3.7.16); -struct glfs_object* -pub_glfs_upcall_inode_get_object (struct glfs_upcall_inode *arg) +struct glfs_object * +pub_glfs_upcall_inode_get_object(struct glfs_upcall_inode *arg) { - return arg->object; + return arg->object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_object, 3.7.16); uint64_t -pub_glfs_upcall_inode_get_flags (struct glfs_upcall_inode *arg) +pub_glfs_upcall_inode_get_flags(struct glfs_upcall_inode *arg) { - return arg->flags; + return arg->flags; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_flags, 3.7.16); -struct stat* -pub_glfs_upcall_inode_get_stat (struct glfs_upcall_inode *arg) +struct stat * +pub_glfs_upcall_inode_get_stat(struct glfs_upcall_inode *arg) { - return &arg->buf; + return &arg->buf; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_stat, 3.7.16); uint64_t -pub_glfs_upcall_inode_get_expire (struct glfs_upcall_inode *arg) +pub_glfs_upcall_inode_get_expire(struct glfs_upcall_inode *arg) { - return arg->expire_time_attr; + return arg->expire_time_attr; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_expire, 3.7.16); -struct glfs_object* -pub_glfs_upcall_inode_get_pobject (struct glfs_upcall_inode *arg) +struct glfs_object * +pub_glfs_upcall_inode_get_pobject(struct glfs_upcall_inode *arg) { - return arg->p_object; + return arg->p_object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_pobject, 3.7.16); -struct stat* -pub_glfs_upcall_inode_get_pstat (struct glfs_upcall_inode *arg) +struct stat * +pub_glfs_upcall_inode_get_pstat(struct glfs_upcall_inode *arg) { - return &arg->p_buf; + return &arg->p_buf; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_pstat, 3.7.16); -struct glfs_object* -pub_glfs_upcall_inode_get_oldpobject (struct glfs_upcall_inode *arg) +struct glfs_object * +pub_glfs_upcall_inode_get_oldpobject(struct glfs_upcall_inode *arg) { - return arg->oldp_object; + return arg->oldp_object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_oldpobject, 3.7.16); -struct stat* -pub_glfs_upcall_inode_get_oldpstat (struct glfs_upcall_inode *arg) +struct stat * +pub_glfs_upcall_inode_get_oldpstat(struct glfs_upcall_inode *arg) { - return &arg->oldp_buf; + return &arg->oldp_buf; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_inode_get_oldpstat, 3.7.16); - /*struct glfs_object* pub_glfs_upcall_lease_get_object (struct glfs_upcall_recall_inode *arg) { @@ -1581,169 +1536,166 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_object, 4.0.0); */ uint32_t -pub_glfs_upcall_lease_get_lease_type (struct glfs_upcall_lease *arg) +pub_glfs_upcall_lease_get_lease_type(struct glfs_upcall_lease *arg) { - return arg->lease_type; + return arg->lease_type; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_lease_get_lease_type, 4.0.0); /* definitions of the GLFS_SYSRQ_* chars are in glfs.h */ static struct glfs_sysrq_help { - char sysrq; - char *msg; -} glfs_sysrq_help[] = { - { GLFS_SYSRQ_HELP, "(H)elp" }, - { GLFS_SYSRQ_STATEDUMP, "(S)tatedump" }, - { 0, NULL } -}; + char sysrq; + char *msg; +} glfs_sysrq_help[] = {{GLFS_SYSRQ_HELP, "(H)elp"}, + {GLFS_SYSRQ_STATEDUMP, "(S)tatedump"}, + {0, NULL}}; int -pub_glfs_sysrq (struct glfs *fs, char sysrq) +pub_glfs_sysrq(struct glfs *fs, char sysrq) { - glusterfs_ctx_t *ctx = NULL; - int ret = 0; - int msg_len; - char msg[1024] = {0,}; /* should not exceed 1024 chars */ - - if (!fs || !fs->ctx) { - ret = -1; - errno = EINVAL; - goto out; - } + glusterfs_ctx_t *ctx = NULL; + int ret = 0; + int msg_len; + char msg[1024] = { + 0, + }; /* should not exceed 1024 chars */ + + if (!fs || !fs->ctx) { + ret = -1; + errno = EINVAL; + goto out; + } - ctx = fs->ctx; + ctx = fs->ctx; - switch (sysrq) { - case GLFS_SYSRQ_HELP: - { - struct glfs_sysrq_help *usage = NULL; - - for (usage = glfs_sysrq_help; usage->sysrq; usage++) { - msg_len = strlen(msg); - snprintf (msg + msg_len, /* append to msg */ - sizeof (msg) - msg_len - 2, - /* - 2 for the " " + terminating \0 */ - " %s", usage->msg); - } + switch (sysrq) { + case GLFS_SYSRQ_HELP: { + struct glfs_sysrq_help *usage = NULL; - /* not really an 'error', but make sure it gets logged */ - gf_log ("glfs", GF_LOG_ERROR, "available events: %s", msg); + for (usage = glfs_sysrq_help; usage->sysrq; usage++) { + msg_len = strlen(msg); + snprintf(msg + msg_len, /* append to msg */ + sizeof(msg) - msg_len - 2, + /* - 2 for the " " + terminating \0 */ + " %s", usage->msg); + } - break; + /* not really an 'error', but make sure it gets logged */ + gf_log("glfs", GF_LOG_ERROR, "available events: %s", msg); + + break; } case GLFS_SYSRQ_STATEDUMP: - gf_proc_dump_info (SIGUSR1, ctx); - break; + gf_proc_dump_info(SIGUSR1, ctx); + break; default: - gf_msg ("glfs", GF_LOG_ERROR, ENOTSUP, API_MSG_INVALID_ENTRY, - "'%c' is not a valid sysrq", sysrq); - errno = ENOTSUP; - ret = -1; - } + gf_msg("glfs", GF_LOG_ERROR, ENOTSUP, API_MSG_INVALID_ENTRY, + "'%c' is not a valid sysrq", sysrq); + errno = ENOTSUP; + ret = -1; + } out: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_sysrq, 3.10.0); int -pub_glfs_upcall_register (struct glfs *fs, uint32_t event_list, - glfs_upcall_cbk cbk, void *data) +pub_glfs_upcall_register(struct glfs *fs, uint32_t event_list, + glfs_upcall_cbk cbk, void *data) { - int ret = 0; - - /* list of supported upcall events */ - uint32_t up_events = GLFS_EVENT_INODE_INVALIDATE; + int ret = 0; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + /* list of supported upcall events */ + uint32_t up_events = GLFS_EVENT_INODE_INVALIDATE; - GF_VALIDATE_OR_GOTO (THIS->name, cbk, out); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* Event list should be either GLFS_EVENT_ANY - * or list of supported individual events (up_events) - */ - if ((event_list != GLFS_EVENT_ANY) && - (event_list & ~up_events)) { - errno = EINVAL; - ret = -1; - gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, - "invalid event_list (0x%08x)", event_list); - goto out; - } + GF_VALIDATE_OR_GOTO(THIS->name, cbk, out); - /* in case other thread does unregister */ - pthread_mutex_lock (&fs->mutex); - { - if (event_list & GLFS_EVENT_INODE_INVALIDATE) { - /* @todo: Check if features.cache-invalidation is - * enabled. - */ - fs->upcall_events |= GF_UPCALL_CACHE_INVALIDATION; - ret |= GF_UPCALL_CACHE_INVALIDATION; - } else if (event_list & GLFS_EVENT_INODE_INVALIDATE) { - fs->upcall_events |= GF_UPCALL_RECALL_LEASE; - ret |= GF_UPCALL_RECALL_LEASE; - } - /* Override cbk function if existing */ - fs->up_cbk = cbk; - fs->up_data = data; - fs->cache_upcalls = _gf_true; + /* Event list should be either GLFS_EVENT_ANY + * or list of supported individual events (up_events) + */ + if ((event_list != GLFS_EVENT_ANY) && (event_list & ~up_events)) { + errno = EINVAL; + ret = -1; + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "invalid event_list (0x%08x)", event_list); + goto out; + } + + /* in case other thread does unregister */ + pthread_mutex_lock(&fs->mutex); + { + if (event_list & GLFS_EVENT_INODE_INVALIDATE) { + /* @todo: Check if features.cache-invalidation is + * enabled. + */ + fs->upcall_events |= GF_UPCALL_CACHE_INVALIDATION; + ret |= GF_UPCALL_CACHE_INVALIDATION; + } else if (event_list & GLFS_EVENT_INODE_INVALIDATE) { + fs->upcall_events |= GF_UPCALL_RECALL_LEASE; + ret |= GF_UPCALL_RECALL_LEASE; } - pthread_mutex_unlock (&fs->mutex); + /* Override cbk function if existing */ + fs->up_cbk = cbk; + fs->up_data = data; + fs->cache_upcalls = _gf_true; + } + pthread_mutex_unlock(&fs->mutex); out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_register, 3.13.0); int -pub_glfs_upcall_unregister (struct glfs *fs, uint32_t event_list) +pub_glfs_upcall_unregister(struct glfs *fs, uint32_t event_list) { - int ret = 0; - /* list of supported upcall events */ - uint32_t up_events = GLFS_EVENT_INODE_INVALIDATE; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* Event list should be either GLFS_EVENT_ANY - * or list of supported individual events (up_events) - */ - if ((event_list != GLFS_EVENT_ANY) && - (event_list & ~up_events)) { - errno = EINVAL; - ret = -1; - gf_msg (THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, - "invalid event_list (0x%08x)", event_list); - goto out; + int ret = 0; + /* list of supported upcall events */ + uint32_t up_events = GLFS_EVENT_INODE_INVALIDATE; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* Event list should be either GLFS_EVENT_ANY + * or list of supported individual events (up_events) + */ + if ((event_list != GLFS_EVENT_ANY) && (event_list & ~up_events)) { + errno = EINVAL; + ret = -1; + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "invalid event_list (0x%08x)", event_list); + goto out; + } + + pthread_mutex_lock(&fs->mutex); + { + if (event_list & GLFS_EVENT_INODE_INVALIDATE) { + fs->upcall_events &= ~GF_UPCALL_CACHE_INVALIDATION; + ret |= GF_UPCALL_CACHE_INVALIDATION; } - pthread_mutex_lock (&fs->mutex); - { - if (event_list & GLFS_EVENT_INODE_INVALIDATE) { - fs->upcall_events &= ~GF_UPCALL_CACHE_INVALIDATION; - ret |= GF_UPCALL_CACHE_INVALIDATION; - } - - /* If there are no upcall events registered, reset cbk */ - if (fs->upcall_events == 0) { - fs->up_cbk = NULL; - fs->up_data = NULL; - fs->cache_upcalls = _gf_false; - } + /* If there are no upcall events registered, reset cbk */ + if (fs->upcall_events == 0) { + fs->up_cbk = NULL; + fs->up_data = NULL; + fs->cache_upcalls = _gf_false; } - pthread_mutex_unlock (&fs->mutex); + } + pthread_mutex_unlock(&fs->mutex); out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_upcall_unregister, 3.13.0); diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c index 3c8ae227ca7..e1bedf13542 100644 --- a/cli/src/cli-cmd-global.c +++ b/cli/src/cli-cmd-global.c @@ -30,111 +30,109 @@ extern rpc_clnt_prog_t *cli_rpc_prog; int -cli_cmd_global_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount); +cli_cmd_global_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); int -cli_cmd_get_state_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount); +cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount); struct cli_cmd global_cmds[] = { - { "global help", - cli_cmd_global_help_cbk, - "list global commands", - }, - { "get-state [] [[odir ] " - "[file ]] [detail|volumeoptions]", - cli_cmd_get_state_cbk, - "Get local state representation of mentioned daemon", - }, - {NULL, NULL, NULL} -}; + { + "global help", + cli_cmd_global_help_cbk, + "list global commands", + }, + { + "get-state [] [[odir ] " + "[file ]] [detail|volumeoptions]", + cli_cmd_get_state_cbk, + "Get local state representation of mentioned daemon", + }, + {NULL, NULL, NULL}}; int -cli_cmd_global_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount) +cli_cmd_global_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount) { - struct cli_cmd *cmd = NULL; - struct cli_cmd *global_cmd = NULL; - int count = 0; - - cmd = GF_MALLOC (sizeof (global_cmds), cli_mt_cli_cmd); - memcpy (cmd, global_cmds, sizeof (global_cmds)); - count = (sizeof (global_cmds) / sizeof (struct cli_cmd)); - cli_cmd_sort (cmd, count); - - cli_out ("\ngluster global commands"); - cli_out ("========================\n"); - for (global_cmd = cmd; global_cmd->pattern; global_cmd++) - if (_gf_false == global_cmd->disable) - cli_out ("%s - %s", global_cmd->pattern, - global_cmd->desc); - - cli_out ("\n"); - GF_FREE (cmd); - return 0; + struct cli_cmd *cmd = NULL; + struct cli_cmd *global_cmd = NULL; + int count = 0; + + cmd = GF_MALLOC(sizeof(global_cmds), cli_mt_cli_cmd); + memcpy(cmd, global_cmds, sizeof(global_cmds)); + count = (sizeof(global_cmds) / sizeof(struct cli_cmd)); + cli_cmd_sort(cmd, count); + + cli_out("\ngluster global commands"); + cli_out("========================\n"); + for (global_cmd = cmd; global_cmd->pattern; global_cmd++) + if (_gf_false == global_cmd->disable) + cli_out("%s - %s", global_cmd->pattern, global_cmd->desc); + + cli_out("\n"); + GF_FREE(cmd); + return 0; } int -cli_cmd_global_register (struct cli_state *state) +cli_cmd_global_register(struct cli_state *state) { - int ret = 0; - struct cli_cmd *cmd = NULL; - for (cmd = global_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd); - if (ret) - goto out; - } + int ret = 0; + struct cli_cmd *cmd = NULL; + for (cmd = global_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register(&state->tree, cmd); + if (ret) + goto out; + } out: - return ret; - + return ret; } int -cli_cmd_get_state_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_get_state_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int sent = 0; - int parse_error = 0; - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - dict_t *options = NULL; - cli_local_t *local = NULL; - char *op_errstr = NULL; - - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - - ret = cli_cmd_get_state_parse (state, words, wordcount, &options, - &op_errstr); - - if (ret) { - if (op_errstr) { - cli_err ("%s", op_errstr); - cli_usage_out (word->pattern); - GF_FREE (op_errstr); - } else - cli_usage_out (word->pattern); - - parse_error = 1; - goto out; - } - - CLI_LOCAL_INIT (local, words, frame, options); - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_STATE]; - if (proc->fn) - ret = proc->fn (frame, THIS, options); + int sent = 0; + int parse_error = 0; + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *options = NULL; + cli_local_t *local = NULL; + char *op_errstr = NULL; + + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_get_state_parse(state, words, wordcount, &options, + &op_errstr); + + if (ret) { + if (op_errstr) { + cli_err("%s", op_errstr); + cli_usage_out(word->pattern); + GF_FREE(op_errstr); + } else + cli_usage_out(word->pattern); + + parse_error = 1; + goto out; + } + + CLI_LOCAL_INIT(local, words, frame, options); + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GET_STATE]; + if (proc->fn) + ret = proc->fn(frame, THIS, options); out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("Getting daemon state failed"); - } + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out("Getting daemon state failed"); + } - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - return ret; + return ret; } - diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c index c887515af85..04dd2efc220 100644 --- a/cli/src/cli-cmd-misc.c +++ b/cli/src/cli-cmd-misc.c @@ -35,107 +35,98 @@ extern struct cli_cmd global_cmds[]; struct cli_cmd cli_misc_cmds[]; int -cli_cmd_quit_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_quit_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - exit (0); + exit(0); } - static gf_boolean_t -cli_is_help_command (const char *pattern) +cli_is_help_command(const char *pattern) { - /* FixFixFix - * This is not the best way to determine whether - * this is a help command - */ - if (strstr (pattern, "help")) - return _gf_true; - - return _gf_false; + /* FixFixFix + * This is not the best way to determine whether + * this is a help command + */ + if (strstr(pattern, "help")) + return _gf_true; + + return _gf_false; } - int -cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount) +cli_cmd_display_help(struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount) { - struct cli_cmd *cmd[] = {cli_misc_cmds, cli_probe_cmds, - volume_cmds, bitrot_cmds, quota_cmds, + struct cli_cmd *cmd[] = { + cli_misc_cmds, + cli_probe_cmds, + volume_cmds, + bitrot_cmds, + quota_cmds, #if !defined(__NetBSD__) - tier_cmds, + tier_cmds, #endif - snapshot_cmds, global_cmds, NULL}; - struct cli_cmd *cmd_ind = NULL; - int i = 0; - gf_boolean_t list_all = _gf_false; - - /* cli_system_cmds commands for internal usage - they are not exposed - */ - - /* If "help all" */ - if (wordcount == 2) - list_all = _gf_true; - - for (i = 0; cmd[i] != NULL; i++) { - for (cmd_ind = cmd[i]; cmd_ind->pattern; cmd_ind++) { - if ((_gf_false == cmd_ind->disable) && - cli_is_help_command (cmd_ind->pattern)) { - if (list_all && (cmd_ind->cbk)) { - cmd_ind->cbk (state, in_word, words, - wordcount); - } else { - cli_out (" %-25s- %s", cmd_ind->pattern, - cmd_ind->desc); - } - } + snapshot_cmds, + global_cmds, + NULL + }; + struct cli_cmd *cmd_ind = NULL; + int i = 0; + gf_boolean_t list_all = _gf_false; + + /* cli_system_cmds commands for internal usage + they are not exposed + */ + + /* If "help all" */ + if (wordcount == 2) + list_all = _gf_true; + + for (i = 0; cmd[i] != NULL; i++) { + for (cmd_ind = cmd[i]; cmd_ind->pattern; cmd_ind++) { + if ((_gf_false == cmd_ind->disable) && + cli_is_help_command(cmd_ind->pattern)) { + if (list_all && (cmd_ind->cbk)) { + cmd_ind->cbk(state, in_word, words, wordcount); + } else { + cli_out(" %-25s- %s", cmd_ind->pattern, cmd_ind->desc); } + } } + } - cli_out ("\n"); - return 0; + cli_out("\n"); + return 0; } - struct cli_cmd cli_help_cmds[] = { - { "help [all]", - cli_cmd_display_help, - "display help for command classes"}, - - { NULL, NULL, NULL } -}; - + {"help [all]", cli_cmd_display_help, "display help for command classes"}, -struct cli_cmd cli_misc_cmds[] = { - { "quit", - cli_cmd_quit_cbk, - "quit"}, - { "exit", - cli_cmd_quit_cbk, - "exit"}, + {NULL, NULL, NULL}}; - { NULL, NULL, NULL } -}; +struct cli_cmd cli_misc_cmds[] = {{"quit", cli_cmd_quit_cbk, "quit"}, + {"exit", cli_cmd_quit_cbk, "exit"}, + {NULL, NULL, NULL}}; int -cli_cmd_misc_register (struct cli_state *state) +cli_cmd_misc_register(struct cli_state *state) { - int ret = 0; - struct cli_cmd *cmd = NULL; - - for (cmd = cli_misc_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd); - if (ret) - goto out; - } - - for (cmd = cli_help_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd); - if (ret) - goto out; - } + int ret = 0; + struct cli_cmd *cmd = NULL; + + for (cmd = cli_misc_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register(&state->tree, cmd); + if (ret) + goto out; + } + + for (cmd = cli_help_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register(&state->tree, cmd); + if (ret) + goto out; + } out: - return ret; + return ret; } diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 48d6ebd64a7..3f9056b5d9e 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -27,2726 +27,2794 @@ #define MAX_SNAP_DESCRIPTION_LEN 1024 struct snap_config_opt_vals_ snap_confopt_vals[] = { - {.op_name = "snap-max-hard-limit", - .question = "Changing snapshot-max-hard-limit " - "will limit the creation of new snapshots " - "if they exceed the new limit.\n" - "Do you want to continue?" - }, - {.op_name = "snap-max-soft-limit", - .question = "If Auto-delete is enabled, snap-max-soft-limit will" - " trigger deletion of oldest snapshot, on the " - "creation of new snapshot, when the " - "snap-max-soft-limit is reached.\n" - "Do you want to change the snap-max-soft-limit?" - }, - {.op_name = "both", - .question = "Changing snapshot-max-hard-limit " - "will limit the creation of new snapshots " - "if they exceed the new snapshot-max-hard-limit.\n" - "If Auto-delete is enabled, snap-max-soft-limit will" - " trigger deletion of oldest snapshot, on the " - "creation of new snapshot, when the " - "snap-max-soft-limit is reached.\n" - "Do you want to continue?" - }, - {.op_name = NULL, - } -}; + {.op_name = "snap-max-hard-limit", + .question = "Changing snapshot-max-hard-limit " + "will limit the creation of new snapshots " + "if they exceed the new limit.\n" + "Do you want to continue?"}, + {.op_name = "snap-max-soft-limit", + .question = "If Auto-delete is enabled, snap-max-soft-limit will" + " trigger deletion of oldest snapshot, on the " + "creation of new snapshot, when the " + "snap-max-soft-limit is reached.\n" + "Do you want to change the snap-max-soft-limit?"}, + {.op_name = "both", + .question = "Changing snapshot-max-hard-limit " + "will limit the creation of new snapshots " + "if they exceed the new snapshot-max-hard-limit.\n" + "If Auto-delete is enabled, snap-max-soft-limit will" + " trigger deletion of oldest snapshot, on the " + "creation of new snapshot, when the " + "snap-max-soft-limit is reached.\n" + "Do you want to continue?"}, + { + .op_name = NULL, + }}; enum cli_snap_config_set_types { - GF_SNAP_CONFIG_SET_HARD = 0, - GF_SNAP_CONFIG_SET_SOFT = 1, - GF_SNAP_CONFIG_SET_BOTH = 2, + GF_SNAP_CONFIG_SET_HARD = 0, + GF_SNAP_CONFIG_SET_SOFT = 1, + GF_SNAP_CONFIG_SET_BOTH = 2, }; typedef enum cli_snap_config_set_types cli_snap_config_set_types; typedef struct _cli_brick { - struct list_head list; - const char *name; - int32_t len; + struct list_head list; + const char *name; + int32_t len; } cli_brick_t; int -cli_cmd_validate_volume (char *volname); +cli_cmd_validate_volume(char *volname); static const char * -id_sel (void *wcon) +id_sel(void *wcon) { - return (const char *)wcon; + return (const char *)wcon; } static char * -str_getunamb (const char *tok, char **opwords) +str_getunamb(const char *tok, char **opwords) { - return (char *)cli_getunamb (tok, (void **)opwords, id_sel); + return (char *)cli_getunamb(tok, (void **)opwords, id_sel); } int32_t -cli_cmd_bricks_parse (const char **words, int wordcount, int brick_index, - char **bricks, int *brick_count) +cli_cmd_bricks_parse(const char **words, int wordcount, int brick_index, + char **bricks, int *brick_count) { - int ret = 0; - char *delimiter = NULL; - char *host_name = NULL; - char *tmp_host = NULL; - char *bricks_str = NULL; - int len = 0; - int brick_list_len = 1; /* For initial space */ - struct list_head brick_list = { 0, }; - cli_brick_t *brick = NULL; - - GF_ASSERT (words); - GF_ASSERT (wordcount); - GF_ASSERT (bricks); - GF_ASSERT (brick_index > 0); - GF_ASSERT (brick_index < wordcount); - - INIT_LIST_HEAD(&brick_list); - - while (brick_index < wordcount) { - if (validate_brick_name ((char *)words[brick_index])) { - cli_err ("Wrong brick type: %s, use :" - "", words[brick_index]); - ret = -1; - goto out; - } else { - delimiter = strrchr (words[brick_index], ':'); - ret = gf_canonicalize_path (delimiter + 1); - if (ret) - goto out; - } - - tmp_host = gf_strdup ((char *)words[brick_index]); - if (!tmp_host) { - gf_log ("cli", GF_LOG_ERROR, "Out of memory"); - ret = -1; - goto out; - } - get_host_name (tmp_host, &host_name); - if (!host_name) { - ret = -1; - gf_log("cli",GF_LOG_ERROR, "Unable to allocate " - "memory"); - GF_FREE (tmp_host); - goto out; - } - - if (!(strcmp (host_name, "localhost") && - strcmp (host_name, "127.0.0.1") && - strncmp (host_name, "0.", 2))) { - cli_err ("Please provide a valid hostname/ip other " - "than localhost, 127.0.0.1 or loopback " - "address (0.0.0.0 to 0.255.255.255)."); - ret = -1; - GF_FREE (tmp_host); - goto out; - } - if (!valid_internet_address (host_name, _gf_false)) { - cli_err ("internet address '%s' does not conform to " - "standards", host_name); - } - GF_FREE (tmp_host); - list_for_each_entry(brick, &brick_list, list) { - if (strcmp(brick->name, words[brick_index]) == 0) { - ret = -1; - cli_err("Found duplicate exports %s", - words[brick_index]); - goto out; - } - } - - brick = GF_MALLOC(sizeof(cli_brick_t), gf_common_list_node); - if (brick == NULL) { - ret = -1; - gf_log("cli", GF_LOG_ERROR, "Out of memory"); - goto out; - } - len = strlen(words[brick_index]); - brick->name = words[brick_index]; - brick->len = len; - list_add_tail(&brick->list, &brick_list); - - brick_list_len += len + 1; /* Brick name + space */ - ++(*brick_count); - ++brick_index; - } - - /* If brick count is not valid exit here */ - if (!*brick_count) { - cli_err ("No bricks specified"); - ret = -1; + int ret = 0; + char *delimiter = NULL; + char *host_name = NULL; + char *tmp_host = NULL; + char *bricks_str = NULL; + int len = 0; + int brick_list_len = 1; /* For initial space */ + struct list_head brick_list = { + 0, + }; + cli_brick_t *brick = NULL; + + GF_ASSERT(words); + GF_ASSERT(wordcount); + GF_ASSERT(bricks); + GF_ASSERT(brick_index > 0); + GF_ASSERT(brick_index < wordcount); + + INIT_LIST_HEAD(&brick_list); + + while (brick_index < wordcount) { + if (validate_brick_name((char *)words[brick_index])) { + cli_err( + "Wrong brick type: %s, use :" + "", + words[brick_index]); + ret = -1; + goto out; + } else { + delimiter = strrchr(words[brick_index], ':'); + ret = gf_canonicalize_path(delimiter + 1); + if (ret) goto out; } - brick_list_len++; /* For terminating null char */ - - bricks_str = GF_MALLOC(brick_list_len, gf_common_mt_char); - if (bricks_str == NULL) { + tmp_host = gf_strdup((char *)words[brick_index]); + if (!tmp_host) { + gf_log("cli", GF_LOG_ERROR, "Out of memory"); + ret = -1; + goto out; + } + get_host_name(tmp_host, &host_name); + if (!host_name) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, + "Unable to allocate " + "memory"); + GF_FREE(tmp_host); + goto out; + } + + if (!(strcmp(host_name, "localhost") && + strcmp(host_name, "127.0.0.1") && strncmp(host_name, "0.", 2))) { + cli_err( + "Please provide a valid hostname/ip other " + "than localhost, 127.0.0.1 or loopback " + "address (0.0.0.0 to 0.255.255.255)."); + ret = -1; + GF_FREE(tmp_host); + goto out; + } + if (!valid_internet_address(host_name, _gf_false)) { + cli_err( + "internet address '%s' does not conform to " + "standards", + host_name); + } + GF_FREE(tmp_host); + list_for_each_entry(brick, &brick_list, list) + { + if (strcmp(brick->name, words[brick_index]) == 0) { ret = -1; - gf_log("cli", GF_LOG_ERROR, "Out of memory"); + cli_err("Found duplicate exports %s", words[brick_index]); goto out; + } } - *bricks = bricks_str; - *bricks_str = ' '; - bricks_str++; - while (!list_empty(&brick_list)) { - brick = list_first_entry(&brick_list, cli_brick_t, list); - list_del_init(&brick->list); - memcpy(bricks_str, brick->name, brick->len); - bricks_str[brick->len] = ' '; - bricks_str += brick->len + 1; - GF_FREE(brick); + + brick = GF_MALLOC(sizeof(cli_brick_t), gf_common_list_node); + if (brick == NULL) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Out of memory"); + goto out; } - *bricks_str = 0; + len = strlen(words[brick_index]); + brick->name = words[brick_index]; + brick->len = len; + list_add_tail(&brick->list, &brick_list); + + brick_list_len += len + 1; /* Brick name + space */ + ++(*brick_count); + ++brick_index; + } + + /* If brick count is not valid exit here */ + if (!*brick_count) { + cli_err("No bricks specified"); + ret = -1; + goto out; + } + + brick_list_len++; /* For terminating null char */ + + bricks_str = GF_MALLOC(brick_list_len, gf_common_mt_char); + if (bricks_str == NULL) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Out of memory"); + goto out; + } + *bricks = bricks_str; + *bricks_str = ' '; + bricks_str++; + while (!list_empty(&brick_list)) { + brick = list_first_entry(&brick_list, cli_brick_t, list); + list_del_init(&brick->list); + memcpy(bricks_str, brick->name, brick->len); + bricks_str[brick->len] = ' '; + bricks_str += brick->len + 1; + GF_FREE(brick); + } + *bricks_str = 0; out: - while (!list_empty(&brick_list)) { - brick = list_first_entry(&brick_list, cli_brick_t, list); - list_del_init(&brick->list); - GF_FREE(brick); - } + while (!list_empty(&brick_list)) { + brick = list_first_entry(&brick_list, cli_brick_t, list); + list_del_init(&brick->list); + GF_FREE(brick); + } - return ret; + return ret; } int32_t -cli_cmd_create_disperse_check (struct cli_state *state, int *disperse, - int *redundancy, int *data, int count) +cli_cmd_create_disperse_check(struct cli_state *state, int *disperse, + int *redundancy, int *data, int count) { - int i = 0; - int tmp = 0; - gf_answer_t answer = GF_ANSWER_NO; - char question[128]; - - const char *question1 = "There isn't an optimal redundancy value " - "for this configuration. Do you want to " - "create the volume with redundancy 1 ?"; - - const char *question2 = "The optimal redundancy for this " - "configuration is %d. Do you want to create " - "the volume with this value ?"; - - const char *question3 = "This configuration is not optimal on most " - "workloads. Do you want to use it ?"; - - const char *question4 = "Redundancy for this configuration is %d. " - "Do you want to create " - "the volume with this value ?"; - - if (*data > 0) { - if (*disperse > 0 && *redundancy > 0) { - if (*disperse != (*data + *redundancy)) { - cli_err ("Disperse count(%d) should be equal " - "to sum of disperse-data count(%d) and " - "redundancy count(%d)", *disperse, - *data, *redundancy); - return -1; - } - } else if (*redundancy > 0) { - *disperse = *data + *redundancy; - } else if (*disperse > 0) { - *redundancy = *disperse - *data; - } else { - if ((count - *data) >= *data) { - cli_err ("Please provide redundancy count " - "along with disperse-data count"); - return -1; - } else { - sprintf (question, question4, count - *data); - answer = cli_cmd_get_confirmation (state, - question); - if (answer == GF_ANSWER_NO) - return -1; - *redundancy = count - *data; - *disperse = count; - } - } + int i = 0; + int tmp = 0; + gf_answer_t answer = GF_ANSWER_NO; + char question[128]; + + const char *question1 = + "There isn't an optimal redundancy value " + "for this configuration. Do you want to " + "create the volume with redundancy 1 ?"; + + const char *question2 = + "The optimal redundancy for this " + "configuration is %d. Do you want to create " + "the volume with this value ?"; + + const char *question3 = + "This configuration is not optimal on most " + "workloads. Do you want to use it ?"; + + const char *question4 = + "Redundancy for this configuration is %d. " + "Do you want to create " + "the volume with this value ?"; + + if (*data > 0) { + if (*disperse > 0 && *redundancy > 0) { + if (*disperse != (*data + *redundancy)) { + cli_err( + "Disperse count(%d) should be equal " + "to sum of disperse-data count(%d) and " + "redundancy count(%d)", + *disperse, *data, *redundancy); + return -1; + } + } else if (*redundancy > 0) { + *disperse = *data + *redundancy; + } else if (*disperse > 0) { + *redundancy = *disperse - *data; + } else { + if ((count - *data) >= *data) { + cli_err( + "Please provide redundancy count " + "along with disperse-data count"); + return -1; + } else { + sprintf(question, question4, count - *data); + answer = cli_cmd_get_confirmation(state, question); + if (answer == GF_ANSWER_NO) + return -1; + *redundancy = count - *data; + *disperse = count; + } } + } - if (*disperse <= 0) { - if (count < 3) { - cli_err ("number of bricks must be greater " - "than 2"); + if (*disperse <= 0) { + if (count < 3) { + cli_err( + "number of bricks must be greater " + "than 2"); - return -1; - } - *disperse = count; + return -1; } + *disperse = count; + } - if (*redundancy == -1) { - tmp = *disperse - 1; - for (i = tmp / 2; - (i > 0) && ((tmp & -tmp) != tmp); - i--, tmp--); - - if (i == 0) { - answer = cli_cmd_get_confirmation(state, question1); - if (answer == GF_ANSWER_NO) - return -1; + if (*redundancy == -1) { + tmp = *disperse - 1; + for (i = tmp / 2; (i > 0) && ((tmp & -tmp) != tmp); i--, tmp--) + ; - *redundancy = 1; - } - else - { - *redundancy = *disperse - tmp; - if (*redundancy > 1) { - sprintf(question, question2, *redundancy); - answer = cli_cmd_get_confirmation(state, - question); - if (answer == GF_ANSWER_NO) - return -1; - } - } + if (i == 0) { + answer = cli_cmd_get_confirmation(state, question1); + if (answer == GF_ANSWER_NO) + return -1; - tmp = 0; + *redundancy = 1; } else { - tmp = *disperse - *redundancy; + *redundancy = *disperse - tmp; + if (*redundancy > 1) { + sprintf(question, question2, *redundancy); + answer = cli_cmd_get_confirmation(state, question); + if (answer == GF_ANSWER_NO) + return -1; + } } - if (*redundancy > (*disperse - 1) / 2) { - cli_err ("redundancy must be less than %d for a " - "disperse %d volume", - (*disperse + 1) / 2, *disperse); + tmp = 0; + } else { + tmp = *disperse - *redundancy; + } - return -1; - } + if (*redundancy > (*disperse - 1) / 2) { + cli_err( + "redundancy must be less than %d for a " + "disperse %d volume", + (*disperse + 1) / 2, *disperse); - if ((tmp & -tmp) != tmp) { - answer = cli_cmd_get_confirmation(state, question3); - if (answer == GF_ANSWER_NO) - return -1; - } + return -1; + } - return 0; + if ((tmp & -tmp) != tmp) { + answer = cli_cmd_get_confirmation(state, question3); + if (answer == GF_ANSWER_NO) + return -1; + } + + return 0; } static int32_t -cli_validate_disperse_volume (char *word, gf1_cluster_type type, - const char **words, int32_t wordcount, - int32_t index, int32_t *disperse_count, - int32_t *redundancy_count, - int32_t *data_count) +cli_validate_disperse_volume(char *word, gf1_cluster_type type, + const char **words, int32_t wordcount, + int32_t index, int32_t *disperse_count, + int32_t *redundancy_count, int32_t *data_count) { - int ret = -1; + int ret = -1; - switch (type) { + switch (type) { case GF_CLUSTER_TYPE_NONE: case GF_CLUSTER_TYPE_DISPERSE: - if (strcmp (word, "disperse") == 0) { - if (*disperse_count >= 0) { - cli_err ("disperse option given twice"); - goto out; - } - if (wordcount < (index+2)) { - goto out; - } - ret = gf_string2int (words[index + 1], disperse_count); - if (ret == -1 && errno == EINVAL) { - *disperse_count = 0; - ret = 1; - } else if (ret == -1) { - goto out; - } else { - if (*disperse_count < 3) { - cli_err ("disperse count must " - "be greater than 2"); - goto out; - } - ret = 2; - } - } else if (strcmp (word, "disperse-data") == 0) { - if (*data_count >= 0) { - cli_err ("disperse-data option given twice"); - goto out; - } - if (wordcount < (index+2)) { - goto out; - } - ret = gf_string2int (words[index+1], data_count); - if (ret == -1 || *data_count < 2) { - cli_err ("disperse-data must be greater than 1"); - goto out; - } - ret = 2; - } else if (strcmp (word, "redundancy") == 0) { - if (*redundancy_count >= 0) { - cli_err ("redundancy option given twice"); - goto out; - } - if (wordcount < (index+2)) { - goto out; - } - ret = gf_string2int (words[index+1], redundancy_count); - if (ret == -1 || *redundancy_count < 1) { - cli_err ("redundancy must be greater than 0"); - goto out; - } - ret = 2; - } - break; + if (strcmp(word, "disperse") == 0) { + if (*disperse_count >= 0) { + cli_err("disperse option given twice"); + goto out; + } + if (wordcount < (index + 2)) { + goto out; + } + ret = gf_string2int(words[index + 1], disperse_count); + if (ret == -1 && errno == EINVAL) { + *disperse_count = 0; + ret = 1; + } else if (ret == -1) { + goto out; + } else { + if (*disperse_count < 3) { + cli_err( + "disperse count must " + "be greater than 2"); + goto out; + } + ret = 2; + } + } else if (strcmp(word, "disperse-data") == 0) { + if (*data_count >= 0) { + cli_err("disperse-data option given twice"); + goto out; + } + if (wordcount < (index + 2)) { + goto out; + } + ret = gf_string2int(words[index + 1], data_count); + if (ret == -1 || *data_count < 2) { + cli_err("disperse-data must be greater than 1"); + goto out; + } + ret = 2; + } else if (strcmp(word, "redundancy") == 0) { + if (*redundancy_count >= 0) { + cli_err("redundancy option given twice"); + goto out; + } + if (wordcount < (index + 2)) { + goto out; + } + ret = gf_string2int(words[index + 1], redundancy_count); + if (ret == -1 || *redundancy_count < 1) { + cli_err("redundancy must be greater than 0"); + goto out; + } + ret = 2; + } + break; case GF_CLUSTER_TYPE_STRIPE_REPLICATE: - cli_err ("striped-replicated-dispersed volume " - "is not supported"); - goto out; + cli_err( + "striped-replicated-dispersed volume " + "is not supported"); + goto out; case GF_CLUSTER_TYPE_TIER: - cli_err ("tier-dispersed volume is not " - "supported"); - goto out; + cli_err( + "tier-dispersed volume is not " + "supported"); + goto out; case GF_CLUSTER_TYPE_STRIPE: - cli_err ("striped-dispersed volume is not " - "supported"); - goto out; + cli_err( + "striped-dispersed volume is not " + "supported"); + goto out; case GF_CLUSTER_TYPE_REPLICATE: - cli_err ("replicated-dispersed volume is not " - "supported"); - goto out; + cli_err( + "replicated-dispersed volume is not " + "supported"); + goto out; default: - cli_err ("Invalid type given"); - break; - } + cli_err("Invalid type given"); + break; + } out: - return ret; + return ret; } int32_t -cli_validate_volname (const char *volname) +cli_validate_volname(const char *volname) { - int32_t ret = -1; - int32_t i = -1; - int volname_len; - static const char * const invalid_volnames[] = { - "volume", "type", "subvolumes", "option", - "end-volume", "all", "volume_not_in_ring", - "description", "force", - "snap-max-hard-limit", - "snap-max-soft-limit", "auto-delete", - "activate-on-create", NULL}; - - if (volname[0] == '-') - goto out; - - for (i = 0; invalid_volnames[i]; i++) { - if (!strcmp (volname, invalid_volnames[i])) { - cli_err ("\"%s\" cannot be the name of a volume.", - volname); - goto out; - } - } + int32_t ret = -1; + int32_t i = -1; + int volname_len; + static const char *const invalid_volnames[] = {"volume", + "type", + "subvolumes", + "option", + "end-volume", + "all", + "volume_not_in_ring", + "description", + "force", + "snap-max-hard-limit", + "snap-max-soft-limit", + "auto-delete", + "activate-on-create", + NULL}; - if (strchr (volname, '/')) - goto out; + if (volname[0] == '-') + goto out; - volname_len = strlen (volname); - if (volname_len > GD_VOLUME_NAME_MAX) { - cli_err("Volume name exceeds %d characters.", - GD_VOLUME_NAME_MAX); - goto out; + for (i = 0; invalid_volnames[i]; i++) { + if (!strcmp(volname, invalid_volnames[i])) { + cli_err("\"%s\" cannot be the name of a volume.", volname); + goto out; } + } - for (i = 0; i < volname_len; i++) { - if (!isalnum (volname[i]) && (volname[i] != '_') && - (volname[i] != '-')) { - cli_err ("Volume name should not contain \"%c\"" - " character.\nVolume names can only" - "contain alphanumeric, '-' and '_' " - "characters.", volname[i]); - goto out; - } - } + if (strchr(volname, '/')) + goto out; - ret = 0; + volname_len = strlen(volname); + if (volname_len > GD_VOLUME_NAME_MAX) { + cli_err("Volume name exceeds %d characters.", GD_VOLUME_NAME_MAX); + goto out; + } + + for (i = 0; i < volname_len; i++) { + if (!isalnum(volname[i]) && (volname[i] != '_') && + (volname[i] != '-')) { + cli_err( + "Volume name should not contain \"%c\"" + " character.\nVolume names can only" + "contain alphanumeric, '-' and '_' " + "characters.", + volname[i]); + goto out; + } + } + + ret = 0; out: - return ret; + return ret; } int32_t -cli_cmd_volume_create_parse (struct cli_state *state, const char **words, - int wordcount, dict_t **options, char **brick_list) +cli_cmd_volume_create_parse(struct cli_state *state, const char **words, + int wordcount, dict_t **options, char **brick_list) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; - int sub_count = 1; - int brick_index = 0; - char *trans_type = NULL; - int32_t index = 0; - char *bricks = NULL; - int32_t brick_count = 0; - char *opwords[] = { "replica", "stripe", "transport", "disperse", - "redundancy", "disperse-data", "arbiter", NULL }; - - char *w = NULL; - int op_count = 0; - int32_t replica_count = 1; - int32_t arbiter_count = 0; - int32_t stripe_count = 1; - int32_t disperse_count = -1; - int32_t redundancy_count = -1; - int32_t disperse_data_count = -1; - gf_boolean_t is_force = _gf_false; - int wc = wordcount; - gf_answer_t answer = GF_ANSWER_NO; - const char *question = NULL; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - - if (!dict) - goto out; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; + int sub_count = 1; + int brick_index = 0; + char *trans_type = NULL; + int32_t index = 0; + char *bricks = NULL; + int32_t brick_count = 0; + char *opwords[] = {"replica", "stripe", "transport", "disperse", + "redundancy", "disperse-data", "arbiter", NULL}; + + char *w = NULL; + int op_count = 0; + int32_t replica_count = 1; + int32_t arbiter_count = 0; + int32_t stripe_count = 1; + int32_t disperse_count = -1; + int32_t redundancy_count = -1; + int32_t disperse_data_count = -1; + gf_boolean_t is_force = _gf_false; + int wc = wordcount; + gf_answer_t answer = GF_ANSWER_NO; + const char *question = NULL; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + + if (!dict) + goto out; - if (wordcount < 3) - goto out; + if (wordcount < 3) + goto out; - volname = (char *)words[2]; + volname = (char *)words[2]; - GF_ASSERT (volname); + GF_ASSERT(volname); - /* Validate the volume name here itself */ - if (cli_validate_volname (volname) < 0) - goto out; + /* Validate the volume name here itself */ + if (cli_validate_volname(volname) < 0) + goto out; - if (wordcount < 4) { - ret = -1; - goto out; - } + if (wordcount < 4) { + ret = -1; + goto out; + } - type = GF_CLUSTER_TYPE_NONE; - index = 3; + type = GF_CLUSTER_TYPE_NONE; + index = 3; - while (op_count < 3) { + while (op_count < 3) { + ret = -1; + w = str_getunamb(words[index], opwords); + if (!w) { + break; + } else if ((strcmp(w, "replica")) == 0) { + switch (type) { + case GF_CLUSTER_TYPE_STRIPE_REPLICATE: + case GF_CLUSTER_TYPE_REPLICATE: + cli_err("replica option given twice"); + goto out; + case GF_CLUSTER_TYPE_NONE: + type = GF_CLUSTER_TYPE_REPLICATE; + break; + case GF_CLUSTER_TYPE_STRIPE: + type = GF_CLUSTER_TYPE_STRIPE_REPLICATE; + break; + case GF_CLUSTER_TYPE_TIER: + cli_err( + "replicated-tiered volume is not " + "supported"); + goto out; + break; + case GF_CLUSTER_TYPE_DISPERSE: + cli_err( + "replicated-dispersed volume is not " + "supported"); + goto out; + default: + cli_err("Invalid type given"); + goto out; + } + + if (wordcount < (index + 2)) { ret = -1; - w = str_getunamb (words[index], opwords); - if (!w) { - break; - } else if ((strcmp (w, "replica")) == 0) { - switch (type) { - case GF_CLUSTER_TYPE_STRIPE_REPLICATE: - case GF_CLUSTER_TYPE_REPLICATE: - cli_err ("replica option given twice"); - goto out; - case GF_CLUSTER_TYPE_NONE: - type = GF_CLUSTER_TYPE_REPLICATE; - break; - case GF_CLUSTER_TYPE_STRIPE: - type = GF_CLUSTER_TYPE_STRIPE_REPLICATE; - break; - case GF_CLUSTER_TYPE_TIER: - cli_err ("replicated-tiered volume is not " - "supported"); - goto out; - break; - case GF_CLUSTER_TYPE_DISPERSE: - cli_err ("replicated-dispersed volume is not " - "supported"); - goto out; - default: - cli_err ("Invalid type given"); - goto out; - } - - if (wordcount < (index+2)) { - ret = -1; - goto out; - } - - replica_count = strtol (words[index+1], NULL, 0); - if (replica_count < 2) { - cli_err ("replica count should be greater" - " than 1"); - ret = -1; - goto out; - } - - index += 2; - if (words[index]) { - if (!strcmp (words[index], "arbiter")) { - ret = gf_string2int (words[index+1], - &arbiter_count); - if ((ret == -1) || (arbiter_count != 1)) { - cli_err ("For arbiter " - "configuration, " - "replica count must be" - " 2 and arbiter count " - "must be 1. The 3rd " - "brick of the replica " - "will be the arbiter"); - ret = -1; - goto out; - } - ret = dict_set_int32 (dict, "arbiter-count", - arbiter_count); - if (ret) - goto out; - index += 2; - } - } - - /* Do this to keep glusterd happy with sending - "replica 3 arbiter 1" options to server */ - if ((arbiter_count == 1) && (replica_count == 2)) - replica_count += arbiter_count; - - if (replica_count == 2) { - if (strcmp (words[wordcount - 1], "force")) { - question = "Replica 2 volumes are prone" - " to split-brain. Use " - "Arbiter or Replica 3 to " - "avoid this. See: " - "http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/." - "\nDo you still want to " - "continue?\n"; - answer = cli_cmd_get_confirmation (state, - question); - if (GF_ANSWER_NO == answer) { - gf_log ("cli", GF_LOG_ERROR, - "Volume create " - "cancelled, exiting"); - ret = -1; - goto out; - } - } - } - ret = dict_set_int32 (dict, "replica-count", replica_count); - if (ret) - goto out; - - } else if ((strcmp (w, "stripe")) == 0) { - switch (type) { - case GF_CLUSTER_TYPE_STRIPE_REPLICATE: - case GF_CLUSTER_TYPE_STRIPE: - cli_err ("stripe option given twice"); - goto out; - case GF_CLUSTER_TYPE_NONE: - type = GF_CLUSTER_TYPE_STRIPE; - break; - case GF_CLUSTER_TYPE_REPLICATE: - type = GF_CLUSTER_TYPE_STRIPE_REPLICATE; - break; - case GF_CLUSTER_TYPE_DISPERSE: - cli_err ("striped-dispersed volume is not " - "supported"); - goto out; - case GF_CLUSTER_TYPE_TIER: - cli_err ("striped-tier volume is not " - "supported"); - goto out; - default: - cli_err ("Invalid type given"); - goto out; - } - if (wordcount < (index + 2)) { - ret = -1; - goto out; - } - stripe_count = strtol (words[index+1], NULL, 0); - if (stripe_count < 2) { - cli_err ("stripe count should be greater" - " than 1"); - ret = -1; - goto out; - } - ret = dict_set_int32 (dict, "stripe-count", stripe_count); - if (ret) - goto out; - - index += 2; + goto out; + } - } else if ((strcmp (w, "transport")) == 0) { - if (trans_type) { - cli_err ("'transport' option given more" - " than one time"); - goto out; - } - if ((strcasecmp (words[index+1], "tcp") == 0)) { - trans_type = gf_strdup ("tcp"); - } else if ((strcasecmp (words[index+1], "rdma") == 0)) { - trans_type = gf_strdup ("rdma"); - } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) || - (strcasecmp (words[index+1], "rdma,tcp") == 0)) { - trans_type = gf_strdup ("tcp,rdma"); - } else { - gf_log ("", GF_LOG_ERROR, "incorrect transport" - " protocol specified"); - ret = -1; - goto out; - } - index += 2; - - } else if ((strcmp (w, "disperse") == 0) || - (strcmp (w, "redundancy") == 0) || - (strcmp (w, "disperse-data") == 0)) { - ret = cli_validate_disperse_volume (w, type, words, - wordcount, index, &disperse_count, - &redundancy_count, &disperse_data_count); - if (ret < 0) - goto out; - index += ret; - type = GF_CLUSTER_TYPE_DISPERSE; - } else if ((strcmp (w, "arbiter") == 0)) { - cli_err ("arbiter option must be preceded by replica " - "option."); + replica_count = strtol(words[index + 1], NULL, 0); + if (replica_count < 2) { + cli_err( + "replica count should be greater" + " than 1"); + ret = -1; + goto out; + } + + index += 2; + if (words[index]) { + if (!strcmp(words[index], "arbiter")) { + ret = gf_string2int(words[index + 1], &arbiter_count); + if ((ret == -1) || (arbiter_count != 1)) { + cli_err( + "For arbiter " + "configuration, " + "replica count must be" + " 2 and arbiter count " + "must be 1. The 3rd " + "brick of the replica " + "will be the arbiter"); ret = -1; goto out; - } else { - GF_ASSERT (!"opword mismatch"); + } + ret = dict_set_int32(dict, "arbiter-count", arbiter_count); + if (ret) + goto out; + index += 2; + } + } + + /* Do this to keep glusterd happy with sending + "replica 3 arbiter 1" options to server */ + if ((arbiter_count == 1) && (replica_count == 2)) + replica_count += arbiter_count; + + if (replica_count == 2) { + if (strcmp(words[wordcount - 1], "force")) { + question = + "Replica 2 volumes are prone" + " to split-brain. Use " + "Arbiter or Replica 3 to " + "avoid this. See: " + "http://docs.gluster.org/en/latest/" + "Administrator%20Guide/" + "Split%20brain%20and%20ways%20to%20deal%20with%20it/." + "\nDo you still want to " + "continue?\n"; + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + gf_log("cli", GF_LOG_ERROR, + "Volume create " + "cancelled, exiting"); ret = -1; goto out; - } - op_count++; - } - - if (!trans_type) - trans_type = gf_strdup ("tcp"); - - if (index >= wordcount) { + } + } + } + ret = dict_set_int32(dict, "replica-count", replica_count); + if (ret) + goto out; + + } else if ((strcmp(w, "stripe")) == 0) { + switch (type) { + case GF_CLUSTER_TYPE_STRIPE_REPLICATE: + case GF_CLUSTER_TYPE_STRIPE: + cli_err("stripe option given twice"); + goto out; + case GF_CLUSTER_TYPE_NONE: + type = GF_CLUSTER_TYPE_STRIPE; + break; + case GF_CLUSTER_TYPE_REPLICATE: + type = GF_CLUSTER_TYPE_STRIPE_REPLICATE; + break; + case GF_CLUSTER_TYPE_DISPERSE: + cli_err( + "striped-dispersed volume is not " + "supported"); + goto out; + case GF_CLUSTER_TYPE_TIER: + cli_err( + "striped-tier volume is not " + "supported"); + goto out; + default: + cli_err("Invalid type given"); + goto out; + } + if (wordcount < (index + 2)) { + ret = -1; + goto out; + } + stripe_count = strtol(words[index + 1], NULL, 0); + if (stripe_count < 2) { + cli_err( + "stripe count should be greater" + " than 1"); ret = -1; goto out; + } + ret = dict_set_int32(dict, "stripe-count", stripe_count); + if (ret) + goto out; + + index += 2; + + } else if ((strcmp(w, "transport")) == 0) { + if (trans_type) { + cli_err( + "'transport' option given more" + " than one time"); + goto out; + } + if ((strcasecmp(words[index + 1], "tcp") == 0)) { + trans_type = gf_strdup("tcp"); + } else if ((strcasecmp(words[index + 1], "rdma") == 0)) { + trans_type = gf_strdup("rdma"); + } else if ((strcasecmp(words[index + 1], "tcp,rdma") == 0) || + (strcasecmp(words[index + 1], "rdma,tcp") == 0)) { + trans_type = gf_strdup("tcp,rdma"); + } else { + gf_log("", GF_LOG_ERROR, + "incorrect transport" + " protocol specified"); + ret = -1; + goto out; + } + index += 2; + + } else if ((strcmp(w, "disperse") == 0) || + (strcmp(w, "redundancy") == 0) || + (strcmp(w, "disperse-data") == 0)) { + ret = cli_validate_disperse_volume( + w, type, words, wordcount, index, &disperse_count, + &redundancy_count, &disperse_data_count); + if (ret < 0) + goto out; + index += ret; + type = GF_CLUSTER_TYPE_DISPERSE; + } else if ((strcmp(w, "arbiter") == 0)) { + cli_err( + "arbiter option must be preceded by replica " + "option."); + ret = -1; + goto out; + } else { + GF_ASSERT(!"opword mismatch"); + ret = -1; + goto out; } + op_count++; + } - brick_index = index; - - if (strcmp (words[wordcount - 1], "force") == 0) { - is_force = _gf_true; - wc = wordcount - 1; - } + if (!trans_type) + trans_type = gf_strdup("tcp"); - ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks, - &brick_count); - if (ret) - goto out; + if (index >= wordcount) { + ret = -1; + goto out; + } - if (type == GF_CLUSTER_TYPE_DISPERSE) { - ret = cli_cmd_create_disperse_check (state, &disperse_count, - &redundancy_count, - &disperse_data_count, - brick_count); - if (!ret) - ret = dict_set_int32 (dict, "disperse-count", - disperse_count); - if (!ret) - ret = dict_set_int32 (dict, "redundancy-count", - redundancy_count); - if (ret) - goto out; + brick_index = index; - sub_count = disperse_count; - } else - sub_count = stripe_count * replica_count; - - if (brick_count % sub_count) { - if (type == GF_CLUSTER_TYPE_STRIPE) - cli_err ("number of bricks is not a multiple of " - "stripe count"); - else if (type == GF_CLUSTER_TYPE_REPLICATE) - cli_err ("number of bricks is not a multiple of " - "replica count"); - else if (type == GF_CLUSTER_TYPE_DISPERSE) - cli_err ("number of bricks is not a multiple of " - "disperse count"); - else - cli_err ("number of bricks given doesn't match " - "required count"); + if (strcmp(words[wordcount - 1], "force") == 0) { + is_force = _gf_true; + wc = wordcount - 1; + } - ret = -1; - goto out; - } + ret = cli_cmd_bricks_parse(words, wc, brick_index, &bricks, &brick_count); + if (ret) + goto out; - /* Everything is parsed fine. start setting info in dict */ - ret = dict_set_str (dict, "volname", volname); + if (type == GF_CLUSTER_TYPE_DISPERSE) { + ret = cli_cmd_create_disperse_check(state, &disperse_count, + &redundancy_count, + &disperse_data_count, brick_count); + if (!ret) + ret = dict_set_int32(dict, "disperse-count", disperse_count); + if (!ret) + ret = dict_set_int32(dict, "redundancy-count", redundancy_count); if (ret) - goto out; + goto out; + + sub_count = disperse_count; + } else + sub_count = stripe_count * replica_count; + + if (brick_count % sub_count) { + if (type == GF_CLUSTER_TYPE_STRIPE) + cli_err( + "number of bricks is not a multiple of " + "stripe count"); + else if (type == GF_CLUSTER_TYPE_REPLICATE) + cli_err( + "number of bricks is not a multiple of " + "replica count"); + else if (type == GF_CLUSTER_TYPE_DISPERSE) + cli_err( + "number of bricks is not a multiple of " + "disperse count"); + else + cli_err( + "number of bricks given doesn't match " + "required count"); - ret = dict_set_int32 (dict, "type", type); - if (ret) - goto out; + ret = -1; + goto out; + } - ret = dict_set_dynstr (dict, "transport", trans_type); - if (ret) - goto out; - trans_type = NULL; + /* Everything is parsed fine. start setting info in dict */ + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - ret = dict_set_dynstr (dict, "bricks", bricks); - if (ret) - goto out; + ret = dict_set_int32(dict, "type", type); + if (ret) + goto out; - ret = dict_set_int32 (dict, "count", brick_count); - if (ret) - goto out; + ret = dict_set_dynstr(dict, "transport", trans_type); + if (ret) + goto out; + trans_type = NULL; - ret = dict_set_int32 (dict, "force", is_force); - if (ret) - goto out; + ret = dict_set_dynstr(dict, "bricks", bricks); + if (ret) + goto out; - *options = dict; - *brick_list = bricks; + ret = dict_set_int32(dict, "count", brick_count); + if (ret) + goto out; + + ret = dict_set_int32(dict, "force", is_force); + if (ret) + goto out; + + *options = dict; + *brick_list = bricks; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse create volume CLI"); + if (dict) + dict_unref(dict); + } - GF_FREE (trans_type); + GF_FREE(trans_type); - return ret; + return ret; } int32_t -cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_volume_reset_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); + dict = dict_new(); - if (!dict) - goto out; + if (!dict) + goto out; - if (wordcount < 3) - goto out; + if (wordcount < 3) + goto out; - if (wordcount > 5) - goto out; + if (wordcount > 5) + goto out; - volname = (char *)words[2]; + volname = (char *)words[2]; - if (!volname) { - ret = -1; - goto out; - } + if (!volname) { + ret = -1; + goto out; + } - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - if (wordcount == 3) { - ret = dict_set_str (dict, "key", "all"); - if (ret) - goto out; - } + if (wordcount == 3) { + ret = dict_set_str(dict, "key", "all"); + if (ret) + goto out; + } - if (wordcount >= 4) { - if (!strcmp ("force", (char*)words[3])) { - ret = dict_set_int32 (dict, "force", 1); - if (ret) - goto out; - ret = dict_set_str (dict, "key", "all"); - if (ret) - goto out; - } else { - ret = dict_set_str (dict, "key", (char *)words[3]); - if (ret) - goto out; - } + if (wordcount >= 4) { + if (!strcmp("force", (char *)words[3])) { + ret = dict_set_int32(dict, "force", 1); + if (ret) + goto out; + ret = dict_set_str(dict, "key", "all"); + if (ret) + goto out; + } else { + ret = dict_set_str(dict, "key", (char *)words[3]); + if (ret) + goto out; } + } - if (wordcount == 5) { - if (strcmp ("force", (char*)words[4])) { - ret = -1; - goto out; - } else { - ret = dict_set_int32 (dict, "force", 1); - if (ret) - goto out; - } + if (wordcount == 5) { + if (strcmp("force", (char *)words[4])) { + ret = -1; + goto out; + } else { + ret = dict_set_int32(dict, "force", 1); + if (ret) + goto out; } + } - *options = dict; + *options = dict; out: - if (ret && dict) { - dict_unref (dict); - } + if (ret && dict) { + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_get_state_parse (struct cli_state *state, - const char **words, int wordcount, - dict_t **options, char **op_errstr) +cli_cmd_get_state_parse(struct cli_state *state, const char **words, + int wordcount, dict_t **options, char **op_errstr) { - dict_t *dict = NULL; - int ret = -1; - char *odir = NULL; - char *filename = NULL; - char *daemon_name = NULL; - int count = 0; - uint32_t cmd = 0; - - GF_VALIDATE_OR_GOTO ("cli", options, out); - GF_VALIDATE_OR_GOTO ("cli", words, out); - - dict = dict_new (); - if (!dict) - goto out; - - if (wordcount < 1 || wordcount > 7) { - *op_errstr = gf_strdup ("Problem parsing arguments." - " Check usage."); - goto out; - } - - if (wordcount >= 1) { - gf_asprintf (&daemon_name, "%s", "glusterd"); - - for (count = 1; count < wordcount; count++) { - if (strcmp (words[count], "odir") == 0 || - strcmp (words[count], "file") == 0) { - if (strcmp (words[count], "odir") == 0) { - if (++count < wordcount) { - odir = (char *) words[count]; - continue; - } else { - ret = -1; - goto out; - } - } else if (strcmp (words[count], "file") == 0) { - if (++count < wordcount) { - filename = (char *) words[count]; - continue; - } else { - ret = -1; - goto out; - } - } - } else { - if (count > 1) { - if (count == wordcount-1) { - if (strcmp (words[count], - "detail") == 0) { - cmd = GF_CLI_GET_STATE_DETAIL; - continue; - } else if (strcmp (words[count], - "volumeoptions") == 0) { - cmd = GF_CLI_GET_STATE_VOLOPTS; - continue; - } - } else { - *op_errstr = gf_strdup ("Problem" - " parsing arguments. " - "Check usage."); - ret = -1; - goto out; - } - - } - if (strcmp (words[count], "glusterd") == 0) { - continue; - } else { - if (count == wordcount-1) { - if (strcmp (words[count], - "detail") == 0) { - cmd = GF_CLI_GET_STATE_DETAIL; - continue; - } else if (strcmp (words[count], - "volumeoptions") == 0) { - cmd = GF_CLI_GET_STATE_VOLOPTS; - continue; - } - } - - *op_errstr = gf_strdup ("glusterd is " - "the only supported daemon."); - ret = -1; - goto out; - } - } - } + dict_t *dict = NULL; + int ret = -1; + char *odir = NULL; + char *filename = NULL; + char *daemon_name = NULL; + int count = 0; + uint32_t cmd = 0; + + GF_VALIDATE_OR_GOTO("cli", options, out); + GF_VALIDATE_OR_GOTO("cli", words, out); + + dict = dict_new(); + if (!dict) + goto out; - ret = dict_set_dynstr (dict, "daemon", daemon_name); - if (ret) { - *op_errstr = gf_strdup ("Command failed. Please check " - " log file for more details."); - gf_log (THIS->name, GF_LOG_ERROR, - "Setting daemon name to dictionary failed"); + if (wordcount < 1 || wordcount > 7) { + *op_errstr = gf_strdup( + "Problem parsing arguments." + " Check usage."); + goto out; + } + + if (wordcount >= 1) { + gf_asprintf(&daemon_name, "%s", "glusterd"); + + for (count = 1; count < wordcount; count++) { + if (strcmp(words[count], "odir") == 0 || + strcmp(words[count], "file") == 0) { + if (strcmp(words[count], "odir") == 0) { + if (++count < wordcount) { + odir = (char *)words[count]; + continue; + } else { + ret = -1; goto out; - } - daemon_name = NULL; - - if (odir) { - ret = dict_set_str (dict, "odir", odir); - if (ret) { - *op_errstr = gf_strdup ("Command failed. Please" - " check log file for" - " more details."); - gf_log (THIS->name, GF_LOG_ERROR, - "Setting output directory to" - "dictionary failed"); - goto out; + } + } else if (strcmp(words[count], "file") == 0) { + if (++count < wordcount) { + filename = (char *)words[count]; + continue; + } else { + ret = -1; + goto out; + } + } + } else { + if (count > 1) { + if (count == wordcount - 1) { + if (strcmp(words[count], "detail") == 0) { + cmd = GF_CLI_GET_STATE_DETAIL; + continue; + } else if (strcmp(words[count], "volumeoptions") == 0) { + cmd = GF_CLI_GET_STATE_VOLOPTS; + continue; } + } else { + *op_errstr = gf_strdup( + "Problem" + " parsing arguments. " + "Check usage."); + ret = -1; + goto out; + } } - - if (filename) { - ret = dict_set_str (dict, "filename", filename); - if (ret) { - *op_errstr = gf_strdup ("Command failed. Please" - " check log file for" - " more details."); - gf_log (THIS->name, GF_LOG_ERROR, - "Setting filename to dictionary failed"); - goto out; + if (strcmp(words[count], "glusterd") == 0) { + continue; + } else { + if (count == wordcount - 1) { + if (strcmp(words[count], "detail") == 0) { + cmd = GF_CLI_GET_STATE_DETAIL; + continue; + } else if (strcmp(words[count], "volumeoptions") == 0) { + cmd = GF_CLI_GET_STATE_VOLOPTS; + continue; } - } + } - if (cmd) { - ret = dict_set_uint32 (dict, "getstate-cmd", cmd); - if (ret) { - *op_errstr = gf_strdup ("Command failed. Please" - " check log file for" - " more details."); - gf_log (THIS->name, GF_LOG_ERROR, "Setting " - "get-state command type to dictionary " - "failed"); - goto out; - } + *op_errstr = gf_strdup( + "glusterd is " + "the only supported daemon."); + ret = -1; + goto out; } + } } - out: - if (dict) - *options = dict; + ret = dict_set_dynstr(dict, "daemon", daemon_name); + if (ret) { + *op_errstr = gf_strdup( + "Command failed. Please check " + " log file for more details."); + gf_log(THIS->name, GF_LOG_ERROR, + "Setting daemon name to dictionary failed"); + goto out; + } + daemon_name = NULL; + + if (odir) { + ret = dict_set_str(dict, "odir", odir); + if (ret) { + *op_errstr = gf_strdup( + "Command failed. Please" + " check log file for" + " more details."); + gf_log(THIS->name, GF_LOG_ERROR, + "Setting output directory to" + "dictionary failed"); + goto out; + } + } + + if (filename) { + ret = dict_set_str(dict, "filename", filename); + if (ret) { + *op_errstr = gf_strdup( + "Command failed. Please" + " check log file for" + " more details."); + gf_log(THIS->name, GF_LOG_ERROR, + "Setting filename to dictionary failed"); + goto out; + } + } + + if (cmd) { + ret = dict_set_uint32(dict, "getstate-cmd", cmd); + if (ret) { + *op_errstr = gf_strdup( + "Command failed. Please" + " check log file for" + " more details."); + gf_log(THIS->name, GF_LOG_ERROR, + "Setting " + "get-state command type to dictionary " + "failed"); + goto out; + } + } + } - if (ret && dict) - dict_unref (dict); +out: + if (dict) + *options = dict; - GF_FREE(daemon_name); + if (ret && dict) + dict_unref(dict); - return ret; + GF_FREE(daemon_name); + + return ret; } int32_t -cli_cmd_inode_quota_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_inode_quota_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); - if (!dict) { - gf_log ("cli", GF_LOG_ERROR, "dict_new failed"); - goto out; - } + dict = dict_new(); + if (!dict) { + gf_log("cli", GF_LOG_ERROR, "dict_new failed"); + goto out; + } - if (wordcount != 4) - goto out; + if (wordcount != 4) + goto out; - volname = (char *)words[2]; - if (!volname) { - ret = -1; - goto out; - } + volname = (char *)words[2]; + if (!volname) { + ret = -1; + goto out; + } - /* Validate the volume name here itself */ - if (cli_validate_volname (volname) < 0) - goto out; + /* Validate the volume name here itself */ + if (cli_validate_volname(volname) < 0) + goto out; - ret = dict_set_str (dict, "volname", volname); - if (ret < 0) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret < 0) + goto out; - if (strcmp (words[3], "enable") != 0) { - cli_out ("Invalid quota option : %s", words[3]); - ret = -1; - goto out; - } + if (strcmp(words[3], "enable") != 0) { + cli_out("Invalid quota option : %s", words[3]); + ret = -1; + goto out; + } - ret = dict_set_int32 (dict, "type", - GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS); - if (ret < 0) - goto out; + ret = dict_set_int32(dict, "type", GF_QUOTA_OPTION_TYPE_ENABLE_OBJECTS); + if (ret < 0) + goto out; - *options = dict; + *options = dict; out: - if (ret < 0) { - if (dict) - dict_unref (dict); - } + if (ret < 0) { + if (dict) + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_quota_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - int i = -1; - char key[20] = {0, }; - int64_t value = 0; - gf_quota_type type = GF_QUOTA_OPTION_TYPE_NONE; - char *opwords[] = { "enable", "disable", "limit-usage", - "remove", "list", "alert-time", - "soft-timeout", "hard-timeout", - "default-soft-limit", "limit-objects", - "list-objects", "remove-objects", NULL}; - char *w = NULL; - uint32_t time = 0; - double percent = 0; - char *end_ptr = NULL; - int64_t limit = 0; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) { - gf_log ("cli", GF_LOG_ERROR, "dict_new failed"); - goto out; - } - - if (wordcount < 4) { - - if ((wordcount == 3) && !(strcmp (words[2], "help"))) { - ret = 1; - } - goto out; - } + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + int i = -1; + char key[20] = { + 0, + }; + int64_t value = 0; + gf_quota_type type = GF_QUOTA_OPTION_TYPE_NONE; + char *opwords[] = {"enable", + "disable", + "limit-usage", + "remove", + "list", + "alert-time", + "soft-timeout", + "hard-timeout", + "default-soft-limit", + "limit-objects", + "list-objects", + "remove-objects", + NULL}; + char *w = NULL; + uint32_t time = 0; + double percent = 0; + char *end_ptr = NULL; + int64_t limit = 0; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + if (!dict) { + gf_log("cli", GF_LOG_ERROR, "dict_new failed"); + goto out; + } - volname = (char *)words[2]; - if (!volname) { - ret = -1; - goto out; + if (wordcount < 4) { + if ((wordcount == 3) && !(strcmp(words[2], "help"))) { + ret = 1; } + goto out; + } - /* Validate the volume name here itself */ - if (cli_validate_volname (volname) < 0) - goto out; + volname = (char *)words[2]; + if (!volname) { + ret = -1; + goto out; + } - ret = dict_set_str (dict, "volname", volname); - if (ret < 0) - goto out; + /* Validate the volume name here itself */ + if (cli_validate_volname(volname) < 0) + goto out; - w = str_getunamb (words[3], opwords); - if (!w) { - cli_out ("Invalid quota option : %s", words[3]); - ret = - 1; - goto out; - } + ret = dict_set_str(dict, "volname", volname); + if (ret < 0) + goto out; - if (strcmp (w, "enable") == 0) { - if (wordcount == 4) { - type = GF_QUOTA_OPTION_TYPE_ENABLE; - ret = 0; - goto set_type; - } else { - ret = -1; - goto out; - } - } + w = str_getunamb(words[3], opwords); + if (!w) { + cli_out("Invalid quota option : %s", words[3]); + ret = -1; + goto out; + } - if (strcmp (w, "disable") == 0) { - if (wordcount == 4) { - type = GF_QUOTA_OPTION_TYPE_DISABLE; - ret = 0; - goto set_type; - } else { - ret = -1; - goto out; - } + if (strcmp(w, "enable") == 0) { + if (wordcount == 4) { + type = GF_QUOTA_OPTION_TYPE_ENABLE; + ret = 0; + goto set_type; + } else { + ret = -1; + goto out; } + } - if (strcmp (w, "limit-usage") == 0) { - type = GF_QUOTA_OPTION_TYPE_LIMIT_USAGE; - } else if (strcmp (w, "limit-objects") == 0) { - type = GF_QUOTA_OPTION_TYPE_LIMIT_OBJECTS; + if (strcmp(w, "disable") == 0) { + if (wordcount == 4) { + type = GF_QUOTA_OPTION_TYPE_DISABLE; + ret = 0; + goto set_type; + } else { + ret = -1; + goto out; } + } - if (type == GF_QUOTA_OPTION_TYPE_LIMIT_USAGE || - type == GF_QUOTA_OPTION_TYPE_LIMIT_OBJECTS) { + if (strcmp(w, "limit-usage") == 0) { + type = GF_QUOTA_OPTION_TYPE_LIMIT_USAGE; + } else if (strcmp(w, "limit-objects") == 0) { + type = GF_QUOTA_OPTION_TYPE_LIMIT_OBJECTS; + } - if (wordcount < 6 || wordcount > 7) { - ret = -1; - goto out; - } + if (type == GF_QUOTA_OPTION_TYPE_LIMIT_USAGE || + type == GF_QUOTA_OPTION_TYPE_LIMIT_OBJECTS) { + if (wordcount < 6 || wordcount > 7) { + ret = -1; + goto out; + } - if (words[4][0] != '/') { - cli_err ("Please enter absolute path"); - ret = -1; - goto out; - } - ret = dict_set_str (dict, "path", (char *) words[4]); - if (ret) - goto out; + if (words[4][0] != '/') { + cli_err("Please enter absolute path"); + ret = -1; + goto out; + } + ret = dict_set_str(dict, "path", (char *)words[4]); + if (ret) + goto out; + + if (!words[5]) { + cli_err("Please enter the limit value to be set"); + ret = -1; + goto out; + } + + if (type == GF_QUOTA_OPTION_TYPE_LIMIT_USAGE) { + ret = gf_string2bytesize_int64(words[5], &value); + if (ret != 0 || value <= 0) { + if (errno == ERANGE || value <= 0) { + ret = -1; + cli_err( + "Please enter an integer " + "value in the range of " + "(1 - %" PRId64 ")", + INT64_MAX); + } else + cli_err( + "Please enter a correct " + "value"); + goto out; + } + } else { + errno = 0; + limit = strtol(words[5], &end_ptr, 10); + if (errno == ERANGE || errno == EINVAL || limit <= 0 || + strcmp(end_ptr, "") != 0) { + ret = -1; + cli_err( + "Please enter an integer value in " + "the range 1 - %" PRId64, + INT64_MAX); + goto out; + } + } - if (!words[5]) { - cli_err ("Please enter the limit value to be set"); - ret = -1; - goto out; - } + ret = dict_set_str(dict, "hard-limit", (char *)words[5]); + if (ret < 0) + goto out; - if (type == GF_QUOTA_OPTION_TYPE_LIMIT_USAGE) { - ret = gf_string2bytesize_int64 (words[5], &value); - if (ret != 0 || value <= 0) { - if (errno == ERANGE || value <= 0) { - ret = -1; - cli_err ("Please enter an integer " - "value in the range of " - "(1 - %"PRId64 ")", - INT64_MAX); - } else - cli_err ("Please enter a correct " - "value"); - goto out; - } - } else { - errno = 0; - limit = strtol (words[5], &end_ptr, 10); - if (errno == ERANGE || errno == EINVAL || limit <= 0 - || strcmp (end_ptr, "") != 0) { - ret = -1; - cli_err ("Please enter an integer value in " - "the range 1 - %"PRId64, INT64_MAX); - goto out; - } - } + if (wordcount == 7) { + ret = gf_string2percent(words[6], &percent); + if (ret != 0 || percent > 100) { + ret = -1; + cli_err( + "Please enter a correct value " + "in the range of 0 to 100"); + goto out; + } - ret = dict_set_str (dict, "hard-limit", (char *) words[5]); - if (ret < 0) - goto out; + ret = dict_set_str(dict, "soft-limit", (char *)words[6]); + if (ret < 0) + goto out; + } - if (wordcount == 7) { + goto set_type; + } - ret = gf_string2percent (words[6], &percent); - if (ret != 0 || percent > 100) { - ret = -1; - cli_err ("Please enter a correct value " - "in the range of 0 to 100"); - goto out; - } + if (strcmp(w, "remove") == 0) { + if (wordcount != 5) { + ret = -1; + goto out; + } - ret = dict_set_str (dict, "soft-limit", - (char *) words[6]); - if (ret < 0) - goto out; - } + type = GF_QUOTA_OPTION_TYPE_REMOVE; - goto set_type; + if (words[4][0] != '/') { + cli_err("Please enter absolute path"); + ret = -1; + goto out; } - if (strcmp (w, "remove") == 0) { - if (wordcount != 5) { - ret = -1; - goto out; - } + ret = dict_set_str(dict, "path", (char *)words[4]); + if (ret < 0) + goto out; + goto set_type; + } - type = GF_QUOTA_OPTION_TYPE_REMOVE; + if (strcmp(w, "remove-objects") == 0) { + if (wordcount != 5) { + ret = -1; + goto out; + } - if (words[4][0] != '/') { - cli_err ("Please enter absolute path"); - ret = -1; - goto out; - } + type = GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS; - ret = dict_set_str (dict, "path", (char *) words[4]); - if (ret < 0) - goto out; - goto set_type; + if (words[4][0] != '/') { + cli_err("Please enter absolute path"); + ret = -1; + goto out; } - if (strcmp (w, "remove-objects") == 0) { - if (wordcount != 5) { - ret = -1; - goto out; - } - - type = GF_QUOTA_OPTION_TYPE_REMOVE_OBJECTS; + ret = dict_set_str(dict, "path", (char *)words[4]); + if (ret < 0) + goto out; + goto set_type; + } - if (words[4][0] != '/') { - cli_err ("Please enter absolute path"); - ret = -1; - goto out; - } + if (strcmp(w, "list") == 0) { + type = GF_QUOTA_OPTION_TYPE_LIST; - ret = dict_set_str (dict, "path", (char *) words[4]); - if (ret < 0) - goto out; - goto set_type; + if (words[4] && words[4][0] != '/') { + cli_err("Please enter absolute path"); + ret = -1; + goto out; } - if (strcmp (w, "list") == 0) { + i = 4; + while (i < wordcount) { + snprintf(key, 20, "path%d", i - 4); - type = GF_QUOTA_OPTION_TYPE_LIST; + ret = dict_set_str(dict, key, (char *)words[i++]); + if (ret < 0) + goto out; + } - if (words[4] && words[4][0] != '/') { - cli_err ("Please enter absolute path"); - ret = -1; - goto out; - } + ret = dict_set_int32(dict, "count", i - 4); + if (ret < 0) + goto out; - i = 4; - while (i < wordcount) { - snprintf (key, 20, "path%d", i-4); + goto set_type; + } - ret = dict_set_str (dict, key, (char *) words [i++]); - if (ret < 0) - goto out; - } + if (strcmp(w, "list-objects") == 0) { + type = GF_QUOTA_OPTION_TYPE_LIST_OBJECTS; - ret = dict_set_int32 (dict, "count", i - 4); - if (ret < 0) - goto out; + i = 4; + while (i < wordcount) { + snprintf(key, 20, "path%d", i - 4); - goto set_type; + ret = dict_set_str(dict, key, (char *)words[i++]); + if (ret < 0) { + gf_log("cli", GF_LOG_ERROR, + "Failed to set " + "quota patch in request dictionary"); + goto out; + } } - if (strcmp (w, "list-objects") == 0) { - type = GF_QUOTA_OPTION_TYPE_LIST_OBJECTS; - - i = 4; - while (i < wordcount) { - snprintf (key, 20, "path%d", i-4); - - ret = dict_set_str (dict, key, (char *) words[i++]); - if (ret < 0) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set " - "quota patch in request dictionary"); - goto out; - } - } - - ret = dict_set_int32 (dict, "count", i - 4); - if (ret < 0) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set quota " - "limit count in request dictionary"); - goto out; - } - - goto set_type; + ret = dict_set_int32(dict, "count", i - 4); + if (ret < 0) { + gf_log("cli", GF_LOG_ERROR, + "Failed to set quota " + "limit count in request dictionary"); + goto out; } - if (strcmp (w, "alert-time") == 0) { - if (wordcount != 5) { - ret = -1; - goto out; - } - type = GF_QUOTA_OPTION_TYPE_ALERT_TIME; + goto set_type; + } - ret = gf_string2time (words[4], &time); - if (ret) { - cli_err ("Invalid argument %s. Please enter a valid " - "string", words[4]); - goto out; - } + if (strcmp(w, "alert-time") == 0) { + if (wordcount != 5) { + ret = -1; + goto out; + } + type = GF_QUOTA_OPTION_TYPE_ALERT_TIME; - ret = dict_set_str (dict, "value", (char *)words[4]); - if (ret < 0) - goto out; - goto set_type; + ret = gf_string2time(words[4], &time); + if (ret) { + cli_err( + "Invalid argument %s. Please enter a valid " + "string", + words[4]); + goto out; } - if (strcmp (w, "soft-timeout") == 0) { - if (wordcount != 5) { - ret = -1; - goto out; - } - type = GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT; + ret = dict_set_str(dict, "value", (char *)words[4]); + if (ret < 0) + goto out; + goto set_type; + } - ret = gf_string2time (words[4], &time); - if (ret) { - cli_err ("Invalid argument %s. Please enter a valid " - "string", words[4]); - goto out; - } + if (strcmp(w, "soft-timeout") == 0) { + if (wordcount != 5) { + ret = -1; + goto out; + } + type = GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT; - ret = dict_set_str (dict, "value", (char *)words[4]); - if (ret < 0) - goto out; - goto set_type; + ret = gf_string2time(words[4], &time); + if (ret) { + cli_err( + "Invalid argument %s. Please enter a valid " + "string", + words[4]); + goto out; } - if (strcmp (w, "hard-timeout") == 0) { - if(wordcount != 5) { - ret = -1; - goto out; - } - type = GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT; + ret = dict_set_str(dict, "value", (char *)words[4]); + if (ret < 0) + goto out; + goto set_type; + } - ret = gf_string2time (words[4], &time); - if (ret) { - cli_err ("Invalid argument %s. Please enter a valid " - "string", words[4]); - goto out; - } + if (strcmp(w, "hard-timeout") == 0) { + if (wordcount != 5) { + ret = -1; + goto out; + } + type = GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT; - ret = dict_set_str (dict, "value", (char *)words[4]); - if (ret < 0) - goto out; - goto set_type; + ret = gf_string2time(words[4], &time); + if (ret) { + cli_err( + "Invalid argument %s. Please enter a valid " + "string", + words[4]); + goto out; } - if (strcmp (w, "default-soft-limit") == 0) { - if(wordcount != 5) { - ret = -1; - goto out; - } - type = GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT; - ret = dict_set_str (dict, "value", (char *)words[4]); - if (ret < 0) - goto out; - goto set_type; - } else { - GF_ASSERT (!"opword mismatch"); + ret = dict_set_str(dict, "value", (char *)words[4]); + if (ret < 0) + goto out; + goto set_type; + } + if (strcmp(w, "default-soft-limit") == 0) { + if (wordcount != 5) { + ret = -1; + goto out; } + type = GF_QUOTA_OPTION_TYPE_DEFAULT_SOFT_LIMIT; -set_type: - ret = dict_set_int32 (dict, "type", type); + ret = dict_set_str(dict, "value", (char *)words[4]); if (ret < 0) - goto out; + goto out; + goto set_type; + } else { + GF_ASSERT(!"opword mismatch"); + } - *options = dict; +set_type: + ret = dict_set_int32(dict, "type", type); + if (ret < 0) + goto out; + + *options = dict; out: - if (ret < 0) { - if (dict) - dict_unref (dict); - } + if (ret < 0) { + if (dict) + dict_unref(dict); + } - return ret; + return ret; } static gf_boolean_t -cli_is_key_spl (char *key) +cli_is_key_spl(char *key) { - return (strcmp (key, "group") == 0); + return (strcmp(key, "group") == 0); } static int32_t cli_add_key_group_value(dict_t *dict, const char *name, const char *value, int32_t id, char **op_errstr) { - char *key = NULL; - char *data = NULL; - int32_t ret = -1; + char *key = NULL; + char *data = NULL; + int32_t ret = -1; - ret = gf_asprintf(&key, "%s%d", name, id); - if (ret < 0) { - goto out; - } - data = gf_strdup(value); - if (data == NULL) { - goto out; - } + ret = gf_asprintf(&key, "%s%d", name, id); + if (ret < 0) { + goto out; + } + data = gf_strdup(value); + if (data == NULL) { + goto out; + } - ret = dict_set_dynstr(dict, key, data); - if (ret == 0) { - data = NULL; - } + ret = dict_set_dynstr(dict, key, data); + if (ret == 0) { + data = NULL; + } out: - GF_FREE(key); - GF_FREE(data); + GF_FREE(key); + GF_FREE(data); - if ((ret != 0) && (op_errstr != NULL)) { - *op_errstr = gf_strdup("Failed to allocate memory"); - } + if ((ret != 0) && (op_errstr != NULL)) { + *op_errstr = gf_strdup("Failed to allocate memory"); + } - return ret; + return ret; } static int -cli_add_key_group (dict_t *dict, char *key, char *value, char **op_errstr) +cli_add_key_group(dict_t *dict, char *key, char *value, char **op_errstr) { - int ret = -1; - int opt_count = 0; - char *saveptr = NULL; - char *tok_key = NULL; - char *tok_val = NULL; - char *tagpath = NULL; - char line[PATH_MAX + 256] = {0,}; - FILE *fp = NULL; - - ret = gf_asprintf (&tagpath, "%s/groups/%s", - GLUSTERD_DEFAULT_WORKDIR, value); - if (ret == -1) { - tagpath = NULL; - goto out; - } - - fp = fopen (tagpath, "r"); - if (!fp) { - ret = -1; - if (op_errstr) { - gf_asprintf(op_errstr, "Unable to open file '%s'. " - "Error: %s", - tagpath, strerror(errno)); - } - goto out; - } - - opt_count = 0; - while (fgets(line, sizeof(line), fp) != NULL) { - if (strlen(line) >= sizeof(line) - 1) { - ret = -1; - if (op_errstr != NULL) { - *op_errstr = gf_strdup("Line too long"); - } - goto out; - } - opt_count++; - tok_key = strtok_r (line, "=", &saveptr); - tok_val = strtok_r (NULL, "\r\n", &saveptr); - if (!tok_key || !tok_val) { - ret = -1; - if (op_errstr) { - gf_asprintf(op_errstr, "'%s' file format " - "not valid.", - tagpath); - } - goto out; - } + int ret = -1; + int opt_count = 0; + char *saveptr = NULL; + char *tok_key = NULL; + char *tok_val = NULL; + char *tagpath = NULL; + char line[PATH_MAX + 256] = { + 0, + }; + FILE *fp = NULL; + + ret = gf_asprintf(&tagpath, "%s/groups/%s", GLUSTERD_DEFAULT_WORKDIR, + value); + if (ret == -1) { + tagpath = NULL; + goto out; + } - ret = cli_add_key_group_value(dict, "key", tok_key, opt_count, - op_errstr); - if (ret != 0) { - goto out; - } - ret = cli_add_key_group_value(dict, "value", tok_val, - opt_count, op_errstr); - if (ret != 0) { - goto out; - } + fp = fopen(tagpath, "r"); + if (!fp) { + ret = -1; + if (op_errstr) { + gf_asprintf(op_errstr, + "Unable to open file '%s'. " + "Error: %s", + tagpath, strerror(errno)); } - - if (!opt_count) { - ret = -1; - if (op_errstr) { - gf_asprintf(op_errstr, "'%s' file format not valid.", - tagpath); - } - goto out; + goto out; + } + + opt_count = 0; + while (fgets(line, sizeof(line), fp) != NULL) { + if (strlen(line) >= sizeof(line) - 1) { + ret = -1; + if (op_errstr != NULL) { + *op_errstr = gf_strdup("Line too long"); + } + goto out; + } + opt_count++; + tok_key = strtok_r(line, "=", &saveptr); + tok_val = strtok_r(NULL, "\r\n", &saveptr); + if (!tok_key || !tok_val) { + ret = -1; + if (op_errstr) { + gf_asprintf(op_errstr, + "'%s' file format " + "not valid.", + tagpath); + } + goto out; + } + + ret = cli_add_key_group_value(dict, "key", tok_key, opt_count, + op_errstr); + if (ret != 0) { + goto out; + } + ret = cli_add_key_group_value(dict, "value", tok_val, opt_count, + op_errstr); + if (ret != 0) { + goto out; + } + } + + if (!opt_count) { + ret = -1; + if (op_errstr) { + gf_asprintf(op_errstr, "'%s' file format not valid.", tagpath); } - ret = dict_set_int32 (dict, "count", opt_count); + goto out; + } + ret = dict_set_int32(dict, "count", opt_count); out: - GF_FREE (tagpath); + GF_FREE(tagpath); - if (fp) - fclose (fp); + if (fp) + fclose(fp); - return ret; + return ret; } int32_t -cli_cmd_volume_set_parse (struct cli_state *state, const char **words, - int wordcount, dict_t **options, char **op_errstr) +cli_cmd_volume_set_parse(struct cli_state *state, const char **words, + int wordcount, dict_t **options, char **op_errstr) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - int count = 0; - char *key = NULL; - char *value = NULL; - int i = 0; - char str[50] = {0,}; - const char *question = NULL; - gf_answer_t answer = GF_ANSWER_NO; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - - if (!dict) - goto out; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + int count = 0; + char *key = NULL; + char *value = NULL; + int i = 0; + char str[50] = { + 0, + }; + const char *question = NULL; + gf_answer_t answer = GF_ANSWER_NO; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + + if (!dict) + goto out; - if (wordcount < 3) - goto out; + if (wordcount < 3) + goto out; - volname = (char *)words[2]; + volname = (char *)words[2]; - GF_ASSERT (volname); + GF_ASSERT(volname); - ret = dict_set_str (dict, "volname", volname); + ret = dict_set_str(dict, "volname", volname); - if (ret) - goto out; + if (ret) + goto out; - if (!strcmp (volname, "all")) { - ret = dict_set_str (dict, "globalname", "All"); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "dict set on global key failed."); - goto out; - } + if (!strcmp(volname, "all")) { + ret = dict_set_str(dict, "globalname", "All"); + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "dict set on global key failed."); + goto out; + } - ret = dict_set_int32 (dict, "hold_global_locks", _gf_true); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "dict set on global key failed."); - goto out; - } + ret = dict_set_int32(dict, "hold_global_locks", _gf_true); + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "dict set on global key failed."); + goto out; } + } - if ((!strcmp (volname, "help") || !strcmp (volname, "help-xml")) - && wordcount == 3 ) { - ret = dict_set_str (dict, volname, volname); - if (ret) - goto out; + if ((!strcmp(volname, "help") || !strcmp(volname, "help-xml")) && + wordcount == 3) { + ret = dict_set_str(dict, volname, volname); + if (ret) + goto out; - } else if (wordcount < 5) { - ret = -1; - goto out; + } else if (wordcount < 5) { + ret = -1; + goto out; - } else if (wordcount == 5 && cli_is_key_spl ((char *)words[3])) { - key = (char *) words[3]; - value = (char *) words[4]; - if ( !key || !value) { - ret = -1; - goto out; - } - - ret = gf_strip_whitespace (value, strlen (value)); - if (ret == -1) - goto out; + } else if (wordcount == 5 && cli_is_key_spl((char *)words[3])) { + key = (char *)words[3]; + value = (char *)words[4]; + if (!key || !value) { + ret = -1; + goto out; + } - if (strlen (value) == 0) { - ret = -1; - goto out; - } + ret = gf_strip_whitespace(value, strlen(value)); + if (ret == -1) + goto out; - ret = cli_add_key_group (dict, key, value, op_errstr); - if (ret == 0) - *options = dict; - goto out; + if (strlen(value) == 0) { + ret = -1; + goto out; } - for (i = 3; i < wordcount; i+=2) { - - key = (char *) words[i]; - value = (char *) words[i+1]; + ret = cli_add_key_group(dict, key, value, op_errstr); + if (ret == 0) + *options = dict; + goto out; + } - if ( !key || !value) { - ret = -1; - goto out; - } + for (i = 3; i < wordcount; i += 2) { + key = (char *)words[i]; + value = (char *)words[i + 1]; - count++; + if (!key || !value) { + ret = -1; + goto out; + } - if (fnmatch ("user.*", key, FNM_NOESCAPE) != 0) { - ret = gf_strip_whitespace (value, strlen (value)); - if (ret == -1) - goto out; - } + count++; - if (strlen (value) == 0) { - ret = -1; - goto out; - } + if (fnmatch("user.*", key, FNM_NOESCAPE) != 0) { + ret = gf_strip_whitespace(value, strlen(value)); + if (ret == -1) + goto out; + } - if (cli_is_key_spl (key)) { - ret = -1; - goto out; - } + if (strlen(value) == 0) { + ret = -1; + goto out; + } - sprintf (str, "key%d", count); - ret = dict_set_str (dict, str, key); - if (ret) - goto out; + if (cli_is_key_spl(key)) { + ret = -1; + goto out; + } - sprintf (str, "value%d", count); - ret = dict_set_str (dict, str, value); + sprintf(str, "key%d", count); + ret = dict_set_str(dict, str, key); + if (ret) + goto out; - if (ret) - goto out; + sprintf(str, "value%d", count); + ret = dict_set_str(dict, str, value); - if ((!strcmp (key, "cluster.enable-shared-storage")) && - (!strcmp (value, "disable"))) { - question = "Disabling cluster.enable-shared-storage " - "will delete the shared storage volume" - "(gluster_shared_storage), which is used " - "by snapshot scheduler, geo-replication " - "and NFS-Ganesha. Do you still want to " - "continue?"; - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - gf_log ("cli", GF_LOG_ERROR, "Operation " - "cancelled, exiting"); - *op_errstr = gf_strdup ("Aborted by user."); - ret = -1; - goto out; - } - } - if ((!strcmp (key, "nfs.disable")) && - (!strcmp (value, "off"))) { - question = "Gluster NFS is being deprecated in favor " - "of NFS-Ganesha Enter \"yes\" to continue " - "using Gluster NFS"; - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - gf_log ("cli", GF_LOG_ERROR, "Operation " - "cancelled, exiting"); - *op_errstr = gf_strdup ("Aborted by user."); - ret = -1; - goto out; - } - } + if (ret) + goto out; + + if ((!strcmp(key, "cluster.enable-shared-storage")) && + (!strcmp(value, "disable"))) { + question = + "Disabling cluster.enable-shared-storage " + "will delete the shared storage volume" + "(gluster_shared_storage), which is used " + "by snapshot scheduler, geo-replication " + "and NFS-Ganesha. Do you still want to " + "continue?"; + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + gf_log("cli", GF_LOG_ERROR, + "Operation " + "cancelled, exiting"); + *op_errstr = gf_strdup("Aborted by user."); + ret = -1; + goto out; + } + } + if ((!strcmp(key, "nfs.disable")) && (!strcmp(value, "off"))) { + question = + "Gluster NFS is being deprecated in favor " + "of NFS-Ganesha Enter \"yes\" to continue " + "using Gluster NFS"; + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + gf_log("cli", GF_LOG_ERROR, + "Operation " + "cancelled, exiting"); + *op_errstr = gf_strdup("Aborted by user."); + ret = -1; + goto out; + } } + } - ret = dict_set_int32 (dict, "count", wordcount-3); + ret = dict_set_int32(dict, "count", wordcount - 3); - if (ret) - goto out; + if (ret) + goto out; - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } int32_t -cli_cmd_volume_add_brick_parse (struct cli_state *state, const char **words, - int wordcount, dict_t **options, int *ret_type) +cli_cmd_volume_add_brick_parse(struct cli_state *state, const char **words, + int wordcount, dict_t **options, int *ret_type) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - int brick_count = 0, brick_index = 0; - char *bricks = NULL; - char *opwords_cl[] = { "replica", "stripe", NULL }; - gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; - int count = 1; - int arbiter_count = 0; - char *w = NULL; - int index; - gf_boolean_t is_force = _gf_false; - int wc = wordcount; - gf_answer_t answer = GF_ANSWER_NO; - const char *question = NULL; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - - if (!dict) - goto out; - - if (wordcount < 3) - goto out; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + int brick_count = 0, brick_index = 0; + char *bricks = NULL; + char *opwords_cl[] = {"replica", "stripe", NULL}; + gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; + int count = 1; + int arbiter_count = 0; + char *w = NULL; + int index; + gf_boolean_t is_force = _gf_false; + int wc = wordcount; + gf_answer_t answer = GF_ANSWER_NO; + const char *question = NULL; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + + if (!dict) + goto out; - volname = (char *)words[2]; + if (wordcount < 3) + goto out; - GF_ASSERT (volname); + volname = (char *)words[2]; - ret = dict_set_str (dict, "volname", volname); + GF_ASSERT(volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); - if (wordcount < 4) { - ret = -1; - goto out; - } - if (wordcount < 6) { - /* seems no options are given, go directly to the parse_brick */ - brick_index = 3; - type = GF_CLUSTER_TYPE_NONE; - goto parse_bricks; - } + if (ret) + goto out; - w = str_getunamb (words[3], opwords_cl); - if (!w) { - type = GF_CLUSTER_TYPE_NONE; - index = 3; - } else if ((strcmp (w, "replica")) == 0) { - type = GF_CLUSTER_TYPE_REPLICATE; - count = strtol (words[4], NULL, 0); - if (!count || (count < 2)) { - cli_err ("replica count should be greater than 1"); - ret = -1; - goto out; - } - ret = dict_set_int32 (dict, "replica-count", count); - if (ret) - goto out; - index = 5; - if (words[index] && !strcmp (words[index], "arbiter")) { - arbiter_count = strtol (words[6], NULL, 0); - if (arbiter_count != 1 || count != 3) { - cli_err ("For arbiter configuration, replica " - "count must be 3 and arbiter count " - "must be 1. The 3rd brick of the " - "replica will be the arbiter"); - ret = -1; - goto out; - } - ret = dict_set_int32 (dict, "arbiter-count", - arbiter_count); - if (ret) - goto out; - index = 7; - } + if (wordcount < 4) { + ret = -1; + goto out; + } + if (wordcount < 6) { + /* seems no options are given, go directly to the parse_brick */ + brick_index = 3; + type = GF_CLUSTER_TYPE_NONE; + goto parse_bricks; + } - if (count == 2) { - if (strcmp (words[wordcount - 1], "force")) { - question = "Replica 2 volumes are prone to " - "split-brain. Use Arbiter or " - "Replica 3 to avaoid this. See: " - "http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/." - "\nDo you still want to continue?\n"; - answer = cli_cmd_get_confirmation (state, - question); - if (GF_ANSWER_NO == answer) { - gf_log ("cli", GF_LOG_ERROR, "Add brick" - " cancelled, exiting"); - ret = -1; - goto out; - } - } - } - } else if ((strcmp (w, "stripe")) == 0) { - type = GF_CLUSTER_TYPE_STRIPE; - count = strtol (words[4], NULL, 0); - if (!count || (count < 2)) { - cli_err ("stripe count should be greater than 1"); - ret = -1; - goto out; - } - ret = dict_set_int32 (dict, "stripe-count", count); - if (ret) - goto out; - index = 5; - } else { - GF_ASSERT (!"opword mismatch"); + w = str_getunamb(words[3], opwords_cl); + if (!w) { + type = GF_CLUSTER_TYPE_NONE; + index = 3; + } else if ((strcmp(w, "replica")) == 0) { + type = GF_CLUSTER_TYPE_REPLICATE; + count = strtol(words[4], NULL, 0); + if (!count || (count < 2)) { + cli_err("replica count should be greater than 1"); + ret = -1; + goto out; + } + ret = dict_set_int32(dict, "replica-count", count); + if (ret) + goto out; + index = 5; + if (words[index] && !strcmp(words[index], "arbiter")) { + arbiter_count = strtol(words[6], NULL, 0); + if (arbiter_count != 1 || count != 3) { + cli_err( + "For arbiter configuration, replica " + "count must be 3 and arbiter count " + "must be 1. The 3rd brick of the " + "replica will be the arbiter"); ret = -1; goto out; + } + ret = dict_set_int32(dict, "arbiter-count", arbiter_count); + if (ret) + goto out; + index = 7; } - brick_index = index; + if (count == 2) { + if (strcmp(words[wordcount - 1], "force")) { + question = + "Replica 2 volumes are prone to " + "split-brain. Use Arbiter or " + "Replica 3 to avaoid this. See: " + "http://docs.gluster.org/en/latest/Administrator%20Guide/" + "Split%20brain%20and%20ways%20to%20deal%20with%20it/." + "\nDo you still want to continue?\n"; + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + gf_log("cli", GF_LOG_ERROR, + "Add brick" + " cancelled, exiting"); + ret = -1; + goto out; + } + } + } + } else if ((strcmp(w, "stripe")) == 0) { + type = GF_CLUSTER_TYPE_STRIPE; + count = strtol(words[4], NULL, 0); + if (!count || (count < 2)) { + cli_err("stripe count should be greater than 1"); + ret = -1; + goto out; + } + ret = dict_set_int32(dict, "stripe-count", count); + if (ret) + goto out; + index = 5; + } else { + GF_ASSERT(!"opword mismatch"); + ret = -1; + goto out; + } + + brick_index = index; parse_bricks: - if (strcmp (words[wordcount - 1], "force") == 0) { - is_force = _gf_true; - wc = wordcount - 1; - } + if (strcmp(words[wordcount - 1], "force") == 0) { + is_force = _gf_true; + wc = wordcount - 1; + } - ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks, - &brick_count); - if (ret) - goto out; + ret = cli_cmd_bricks_parse(words, wc, brick_index, &bricks, &brick_count); + if (ret) + goto out; - ret = dict_set_dynstr (dict, "bricks", bricks); - if (ret) - goto out; + ret = dict_set_dynstr(dict, "bricks", bricks); + if (ret) + goto out; - ret = dict_set_int32 (dict, "count", brick_count); + ret = dict_set_int32(dict, "count", brick_count); - if (ret) - goto out; + if (ret) + goto out; - ret = dict_set_int32 (dict, "force", is_force); - if (ret) - goto out; + ret = dict_set_int32(dict, "force", is_force); + if (ret) + goto out; - *options = dict; + *options = dict; out: - if (ret_type) - *ret_type = type; + if (ret_type) + *ret_type = type; - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI"); + if (dict) + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_volume_tier_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_tier_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - int32_t command = GF_DEFRAG_CMD_NONE; - int32_t is_force = 0; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + int32_t command = GF_DEFRAG_CMD_NONE; + int32_t is_force = 0; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); + dict = dict_new(); - if (!dict) - goto out; + if (!dict) + goto out; - if (!(wordcount == 4 || wordcount == 5)) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - ret = -1; - goto out; - } + if (!(wordcount == 4 || wordcount == 5)) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + ret = -1; + goto out; + } - volname = (char *)words[2]; + volname = (char *)words[2]; - GF_ASSERT (volname); + GF_ASSERT(volname); - ret = cli_cmd_validate_volume (volname); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to validate volume name"); - goto out; - } + ret = cli_cmd_validate_volume(volname); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Failed to validate volume name"); + goto out; + } - ret = dict_set_str (dict, "volname", volname); + ret = dict_set_str(dict, "volname", volname); - if (ret) - goto out; + if (ret) + goto out; - volname = (char *)words[2]; - if (wordcount == 4) { - if (!strcmp(words[3], "status")) - command = GF_DEFRAG_CMD_STATUS_TIER; - else if (!strcmp(words[3], "start")) - command = GF_DEFRAG_CMD_START_TIER; - else if (!strcmp(words[3], "stop")) - command = GF_DEFRAG_CMD_STOP_TIER; - else { - ret = -1; - goto out; - } - } else if (wordcount == 5) { - if ((!strcmp (words[3], "start")) && - (!strcmp (words[4], "force"))) { - command = GF_DEFRAG_CMD_START_TIER; - is_force = 1; - ret = dict_set_int32 (dict, "force", is_force); - if (ret) - goto out; - } else { - ret = -1; - goto out; - } + volname = (char *)words[2]; + if (wordcount == 4) { + if (!strcmp(words[3], "status")) + command = GF_DEFRAG_CMD_STATUS_TIER; + else if (!strcmp(words[3], "start")) + command = GF_DEFRAG_CMD_START_TIER; + else if (!strcmp(words[3], "stop")) + command = GF_DEFRAG_CMD_STOP_TIER; + else { + ret = -1; + goto out; + } + } else if (wordcount == 5) { + if ((!strcmp(words[3], "start")) && (!strcmp(words[4], "force"))) { + command = GF_DEFRAG_CMD_START_TIER; + is_force = 1; + ret = dict_set_int32(dict, "force", is_force); + if (ret) + goto out; + } else { + ret = -1; + goto out; } + } - ret = dict_set_int32 (dict, "rebalance-command", command); - if (ret) - goto out; + ret = dict_set_int32(dict, "rebalance-command", command); + if (ret) + goto out; - *options = dict; + *options = dict; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse tier CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse tier CLI"); + if (dict) + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_volume_detach_tier_parse (const char **words, int wordcount, - dict_t **options, int *question) +cli_cmd_volume_detach_tier_parse(const char **words, int wordcount, + dict_t **options, int *question) { - int ret = -1; - char *word = NULL; - dict_t *dict = NULL; - int32_t command = GF_DEFRAG_CMD_NONE; - - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_set_str (dict, "volname", (char *)words[2]); - if (ret) - goto out; + int ret = -1; + char *word = NULL; + dict_t *dict = NULL; + int32_t command = GF_DEFRAG_CMD_NONE; - if (wordcount == 3 && !strcmp ((char *)words[2], "help")) { - return -1; - } + dict = dict_new(); + if (!dict) + goto out; - if (wordcount != 4) { - ret = -1; - goto out; - } + ret = dict_set_str(dict, "volname", (char *)words[2]); + if (ret) + goto out; - word = (char *)words[3]; + if (wordcount == 3 && !strcmp((char *)words[2], "help")) { + return -1; + } + if (wordcount != 4) { ret = -1; + goto out; + } + + word = (char *)words[3]; + + ret = -1; + + if (!strcmp(word, "start")) { + command = GF_DEFRAG_CMD_DETACH_START; + } else if (!strcmp(word, "commit")) { + *question = 1; + command = GF_DEFRAG_CMD_DETACH_COMMIT; + } else if (!strcmp(word, "force")) { + *question = 1; + command = GF_DEFRAG_CMD_DETACH_COMMIT_FORCE; + } else if (!strcmp(word, "stop")) + command = GF_DEFRAG_CMD_DETACH_STOP; + else if (!strcmp(word, "status")) + command = GF_DEFRAG_CMD_DETACH_STATUS; + else + goto out; - if (!strcmp(word, "start")) { - command = GF_DEFRAG_CMD_DETACH_START; - } else if (!strcmp(word, "commit")) { - *question = 1; - command = GF_DEFRAG_CMD_DETACH_COMMIT; - } else if (!strcmp(word, "force")) { - *question = 1; - command = GF_DEFRAG_CMD_DETACH_COMMIT_FORCE; - } else if (!strcmp(word, "stop")) - command = GF_DEFRAG_CMD_DETACH_STOP; - else if (!strcmp(word, "status")) - command = GF_DEFRAG_CMD_DETACH_STATUS; - else - goto out; - - ret = dict_set_int32 (dict, "command", command); - if (ret) - goto out; + ret = dict_set_int32(dict, "command", command); + if (ret) + goto out; - *options = dict; - ret = 0; + *options = dict; + ret = 0; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse detach tier CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse detach tier CLI"); + if (dict) + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_volume_remove_brick_parse (struct cli_state *state, const char **words, - int wordcount, dict_t **options, - int *question, int *brick_count, - int32_t *comm) +cli_cmd_volume_remove_brick_parse(struct cli_state *state, const char **words, + int wordcount, dict_t **options, + int *question, int *brick_count, + int32_t *comm) { - dict_t *dict = NULL; - char *volname = NULL; - char *delimiter = NULL; - int ret = -1; - char key[50]; - int brick_index = 0; - int32_t tmp_index = 0; - int32_t j = 0; - char *tmp_brick = NULL; - char *tmp_brick1 = NULL; - char *type_opword[] = { "replica", NULL }; - char *opwords[] = { "start", "commit", "stop", "status", - "force", NULL }; - char *w = NULL; - int32_t command = GF_OP_CMD_NONE; - long count = 0; - gf_answer_t answer = GF_ANSWER_NO; - const char *ques = NULL; - - GF_ASSERT (words); - GF_ASSERT (options); - - if (wordcount < 5) - goto out; - - dict = dict_new (); - if (!dict) - goto out; + dict_t *dict = NULL; + char *volname = NULL; + char *delimiter = NULL; + int ret = -1; + char key[50]; + int brick_index = 0; + int32_t tmp_index = 0; + int32_t j = 0; + char *tmp_brick = NULL; + char *tmp_brick1 = NULL; + char *type_opword[] = {"replica", NULL}; + char *opwords[] = {"start", "commit", "stop", "status", "force", NULL}; + char *w = NULL; + int32_t command = GF_OP_CMD_NONE; + long count = 0; + gf_answer_t answer = GF_ANSWER_NO; + const char *ques = NULL; + + GF_ASSERT(words); + GF_ASSERT(options); + + if (wordcount < 5) + goto out; - volname = (char *)words[2]; + dict = dict_new(); + if (!dict) + goto out; - GF_ASSERT (volname); + volname = (char *)words[2]; - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + GF_ASSERT(volname); - brick_index = 3; - w = str_getunamb (words[3], type_opword); - if (w && !strcmp ("replica", w)) { - if (wordcount < 6) { - ret = -1; - goto out; - } - count = strtol (words[4], NULL, 0); - if (count < 1) { - cli_err ("replica count should be greater than 0 in " - "case of remove-brick"); - ret = -1; - goto out; - } + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - if (count == 2) { - if (strcmp (words[wordcount - 1], "force")) { - ques = "Replica 2 volumes are prone to " - "split-brain. Use Arbiter or Replica 3 " - "to avaoid this. See: " - "http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/." - "\nDo you still want to continue?\n"; - answer = cli_cmd_get_confirmation (state, - ques); - if (GF_ANSWER_NO == answer) { - gf_log ("cli", GF_LOG_ERROR, "Remove " - "brick cancelled, exiting"); - ret = -1; - goto out; - } - } + brick_index = 3; + w = str_getunamb(words[3], type_opword); + if (w && !strcmp("replica", w)) { + if (wordcount < 6) { + ret = -1; + goto out; + } + count = strtol(words[4], NULL, 0); + if (count < 1) { + cli_err( + "replica count should be greater than 0 in " + "case of remove-brick"); + ret = -1; + goto out; + } + + if (count == 2) { + if (strcmp(words[wordcount - 1], "force")) { + ques = + "Replica 2 volumes are prone to " + "split-brain. Use Arbiter or Replica 3 " + "to avaoid this. See: " + "http://docs.gluster.org/en/latest/Administrator%20Guide/" + "Split%20brain%20and%20ways%20to%20deal%20with%20it/." + "\nDo you still want to continue?\n"; + answer = cli_cmd_get_confirmation(state, ques); + if (GF_ANSWER_NO == answer) { + gf_log("cli", GF_LOG_ERROR, + "Remove " + "brick cancelled, exiting"); + ret = -1; + goto out; } - - ret = dict_set_int32 (dict, "replica-count", count); - if (ret) - goto out; - brick_index = 5; - } else if (w) { - GF_ASSERT (!"opword mismatch"); + } } - w = str_getunamb (words[wordcount - 1], opwords); - if (!w) { - ret = -1; - goto out; + ret = dict_set_int32(dict, "replica-count", count); + if (ret) + goto out; + brick_index = 5; + } else if (w) { + GF_ASSERT(!"opword mismatch"); + } + + w = str_getunamb(words[wordcount - 1], opwords); + if (!w) { + ret = -1; + goto out; + } else { + /* handled this option */ + wordcount--; + if (!strcmp("start", w)) { + command = GF_OP_CMD_START; + if (question) + *question = 1; + } else if (!strcmp("commit", w)) { + command = GF_OP_CMD_COMMIT; + } else if (!strcmp("stop", w)) { + command = GF_OP_CMD_STOP; + } else if (!strcmp("status", w)) { + command = GF_OP_CMD_STATUS; + } else if (!strcmp("force", w)) { + command = GF_OP_CMD_COMMIT_FORCE; + if (question) + *question = 1; } else { - /* handled this option */ - wordcount--; - if (!strcmp ("start", w)) { - command = GF_OP_CMD_START; - if (question) - *question = 1; - } else if (!strcmp ("commit", w)) { - command = GF_OP_CMD_COMMIT; - } else if (!strcmp ("stop", w)) { - command = GF_OP_CMD_STOP; - } else if (!strcmp ("status", w)) { - command = GF_OP_CMD_STATUS; - } else if (!strcmp ("force", w)) { - command = GF_OP_CMD_COMMIT_FORCE; - if (question) - *question = 1; - } else { - GF_ASSERT (!"opword mismatch"); - ret = -1; - goto out; - } + GF_ASSERT(!"opword mismatch"); + ret = -1; + goto out; } + } - ret = dict_set_int32 (dict, "command", command); - if (ret) - gf_log ("cli", GF_LOG_INFO, "failed to set 'command' %d", - command); - + ret = dict_set_int32(dict, "command", command); + if (ret) + gf_log("cli", GF_LOG_INFO, "failed to set 'command' %d", command); - tmp_index = brick_index; - tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char); + tmp_index = brick_index; + tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char); - if (!tmp_brick) { - gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " - "Unable to get memory"); - ret = -1; - goto out; - } + if (!tmp_brick) { + gf_log("", GF_LOG_ERROR, + "cli_cmd_volume_remove_brick_parse: " + "Unable to get memory"); + ret = -1; + goto out; + } - tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char); + tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char); - if (!tmp_brick1) { - gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: " - "Unable to get memory"); + if (!tmp_brick1) { + gf_log("", GF_LOG_ERROR, + "cli_cmd_volume_remove_brick_parse: " + "Unable to get memory"); + ret = -1; + goto out; + } + + while (brick_index < wordcount) { + if (validate_brick_name((char *)words[brick_index])) { + cli_err( + "wrong brick type: %s, use :" + "", + words[brick_index]); + ret = -1; + goto out; + } else { + delimiter = strrchr(words[brick_index], ':'); + ret = gf_canonicalize_path(delimiter + 1); + if (ret) + goto out; + } + + j = tmp_index; + strcpy(tmp_brick, words[brick_index]); + while (j < brick_index) { + strcpy(tmp_brick1, words[j]); + if (!(strcmp(tmp_brick, tmp_brick1))) { + gf_log("", GF_LOG_ERROR, + "Duplicate bricks" + " found %s", + words[brick_index]); + cli_err("Duplicate bricks found %s", words[brick_index]); ret = -1; goto out; + } + j++; } + snprintf(key, 50, "brick%d", ++(*brick_count)); + ret = dict_set_str(dict, key, (char *)words[brick_index++]); - while (brick_index < wordcount) { - if (validate_brick_name ((char *)words[brick_index])) { - cli_err ("wrong brick type: %s, use :" - "", words[brick_index]); - ret = -1; - goto out; - } else { - delimiter = strrchr(words[brick_index], ':'); - ret = gf_canonicalize_path (delimiter + 1); - if (ret) - goto out; - } - - j = tmp_index; - strcpy(tmp_brick, words[brick_index]); - while ( j < brick_index) { - strcpy(tmp_brick1, words[j]); - if (!(strcmp (tmp_brick, tmp_brick1))) { - gf_log("",GF_LOG_ERROR, "Duplicate bricks" - " found %s", words[brick_index]); - cli_err("Duplicate bricks found %s", - words[brick_index]); - ret = -1; - goto out; - } - j++; - } - snprintf (key, 50, "brick%d", ++(*brick_count)); - ret = dict_set_str (dict, key, (char *)words[brick_index++]); - - if (ret) - goto out; - } + if (ret) + goto out; + } - if (command != GF_OP_CMD_STATUS && command != GF_OP_CMD_STOP) { - ret = dict_set_int32 (dict, "count", *brick_count); - if (ret) - goto out; - } + if (command != GF_OP_CMD_STATUS && command != GF_OP_CMD_STOP) { + ret = dict_set_int32(dict, "count", *brick_count); + if (ret) + goto out; + } - *options = dict; + *options = dict; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI"); + if (dict) + dict_unref(dict); + } - GF_FREE (tmp_brick); - GF_FREE (tmp_brick1); + GF_FREE(tmp_brick); + GF_FREE(tmp_brick1); - *comm = command; + *comm = command; - return ret; + return ret; } int32_t -cli_cmd_brick_op_validate_bricks (const char **words, dict_t *dict, - int src, int dst) +cli_cmd_brick_op_validate_bricks(const char **words, dict_t *dict, int src, + int dst) { - int ret = -1; - char *delimiter = NULL; + int ret = -1; + char *delimiter = NULL; + + if (validate_brick_name((char *)words[src])) { + cli_err( + "wrong brick type: %s, use " + ":", + words[3]); + ret = -1; + goto out; + } else { + delimiter = strrchr((char *)words[src], '/'); + ret = gf_canonicalize_path(delimiter); + if (ret) + goto out; + } - if (validate_brick_name ((char *)words[src])) { - cli_err ("wrong brick type: %s, use " - ":", words[3]); - ret = -1; - goto out; - } else { - delimiter = strrchr ((char *)words[src], '/'); - ret = gf_canonicalize_path (delimiter); - if (ret) - goto out; - } + ret = dict_set_str(dict, "src-brick", (char *)words[src]); + if (ret) + goto out; - ret = dict_set_str (dict, "src-brick", (char *)words[src]); + if (dst == -1) { + ret = 0; + goto out; + } + + if (validate_brick_name((char *)words[dst])) { + cli_err( + "wrong brick type: %s, use " + ":", + words[dst]); + ret = -1; + goto out; + } else { + delimiter = strrchr((char *)words[dst], '/'); + ret = gf_canonicalize_path(delimiter); if (ret) - goto out; + goto out; + } - if (dst == -1) { - ret = 0; - goto out; - } - - if (validate_brick_name ((char *)words[dst])) { - cli_err ("wrong brick type: %s, use " - ":", words[dst]); - ret = -1; - goto out; - } else { - delimiter = strrchr ((char *)words[dst], '/'); - ret = gf_canonicalize_path (delimiter); - if (ret) - goto out; - } - - ret = dict_set_str (dict, "dst-brick", (char *)words[dst]); - if (ret) - goto out; - ret = 0; -out: - return ret; -} + ret = dict_set_str(dict, "dst-brick", (char *)words[dst]); + if (ret) + goto out; + ret = 0; +out: + return ret; +} int32_t -cli_cmd_volume_reset_brick_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_reset_brick_parse(const char **words, int wordcount, + dict_t **options) { - int ret = -1; - char *volname = NULL; - dict_t *dict = NULL; - - if (wordcount < 5 || wordcount > 7) - goto out; + int ret = -1; + char *volname = NULL; + dict_t *dict = NULL; - dict = dict_new (); - - if (!dict) - goto out; + if (wordcount < 5 || wordcount > 7) + goto out; - volname = (char *)words[2]; + dict = dict_new(); - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + if (!dict) + goto out; - if (wordcount == 5) { - if (strcmp (words[4], "start")) { - cli_err ("Invalid option '%s' for reset-brick. Please " - "enter valid reset-brick command", words[4]); - ret = -1; - goto out; - } + volname = (char *)words[2]; - ret = cli_cmd_brick_op_validate_bricks (words, dict, 3, -1); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - ret = dict_set_str (dict, "operation", "GF_RESET_OP_START"); - if (ret) - goto out; - } else if (wordcount == 6) { - if (strcmp (words[5], "commit")) { - cli_err ("Invalid option '%s' for reset-brick. Please " - "enter valid reset-brick command", words[5]); - ret = -1; - goto out; - } + if (wordcount == 5) { + if (strcmp(words[4], "start")) { + cli_err( + "Invalid option '%s' for reset-brick. Please " + "enter valid reset-brick command", + words[4]); + ret = -1; + goto out; + } - ret = cli_cmd_brick_op_validate_bricks (words, dict, 3, 4); - if (ret) - goto out; + ret = cli_cmd_brick_op_validate_bricks(words, dict, 3, -1); + if (ret) + goto out; - ret = dict_set_str (dict, "operation", "GF_RESET_OP_COMMIT"); - if (ret) - goto out; - } else if (wordcount == 7) { - if (strcmp (words[5], "commit") || strcmp (words[6], "force")) { - cli_err ("Invalid option '%s %s' for reset-brick. Please " - "enter valid reset-brick command", - words[5], words[6]); - ret = -1; - goto out; - } + ret = dict_set_str(dict, "operation", "GF_RESET_OP_START"); + if (ret) + goto out; + } else if (wordcount == 6) { + if (strcmp(words[5], "commit")) { + cli_err( + "Invalid option '%s' for reset-brick. Please " + "enter valid reset-brick command", + words[5]); + ret = -1; + goto out; + } + + ret = cli_cmd_brick_op_validate_bricks(words, dict, 3, 4); + if (ret) + goto out; - ret = cli_cmd_brick_op_validate_bricks (words, dict, 3, 4); - if (ret) - goto out; + ret = dict_set_str(dict, "operation", "GF_RESET_OP_COMMIT"); + if (ret) + goto out; + } else if (wordcount == 7) { + if (strcmp(words[5], "commit") || strcmp(words[6], "force")) { + cli_err( + "Invalid option '%s %s' for reset-brick. Please " + "enter valid reset-brick command", + words[5], words[6]); + ret = -1; + goto out; + } + + ret = cli_cmd_brick_op_validate_bricks(words, dict, 3, 4); + if (ret) + goto out; - ret = dict_set_str (dict, "operation", - "GF_RESET_OP_COMMIT_FORCE"); - if (ret) - goto out; - } + ret = dict_set_str(dict, "operation", "GF_RESET_OP_COMMIT_FORCE"); + if (ret) + goto out; + } - *options = dict; + *options = dict; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, - "Unable to parse reset-brick CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse reset-brick CLI"); + if (dict) + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_replace_brick_parse(const char **words, int wordcount, + dict_t **options) { - int ret = -1; - char *volname = NULL; - dict_t *dict = NULL; + int ret = -1; + char *volname = NULL; + dict_t *dict = NULL; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - if (wordcount != 7) { - ret = -1; - goto out; - } + if (wordcount != 7) { + ret = -1; + goto out; + } - dict = dict_new (); + dict = dict_new(); - if (!dict) { - gf_log ("cli", GF_LOG_ERROR, "Failed to allocate dictionary"); - goto out; - } + if (!dict) { + gf_log("cli", GF_LOG_ERROR, "Failed to allocate dictionary"); + goto out; + } - volname = (char *)words[2]; + volname = (char *)words[2]; - GF_ASSERT (volname); + GF_ASSERT(volname); - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - ret = cli_cmd_brick_op_validate_bricks (words, dict, 3, 4); - if (ret) - goto out; + ret = cli_cmd_brick_op_validate_bricks(words, dict, 3, 4); + if (ret) + goto out; - /* commit force option */ - if (strcmp ("commit", words[5]) || strcmp ("force", words[6])) { - cli_err ("Invalid option '%s' '%s' for replace-brick. Please " - "enter valid replace-brick command", words[5], - words[6]); - ret = -1; - goto out; - } + /* commit force option */ + if (strcmp("commit", words[5]) || strcmp("force", words[6])) { + cli_err( + "Invalid option '%s' '%s' for replace-brick. Please " + "enter valid replace-brick command", + words[5], words[6]); + ret = -1; + goto out; + } - ret = dict_set_str (dict, "operation", "GF_REPLACE_OP_COMMIT_FORCE"); - if (ret) - goto out; + ret = dict_set_str(dict, "operation", "GF_REPLACE_OP_COMMIT_FORCE"); + if (ret) + goto out; - *options = dict; + *options = dict; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse reset-brick CLI"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse reset-brick CLI"); + if (dict) + dict_unref(dict); + } - return ret; + return ret; } int32_t -cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_log_filename_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - char *str = NULL; - int ret = -1; - char *delimiter = NULL; + dict_t *dict = NULL; + char *volname = NULL; + char *str = NULL; + int ret = -1; + char *delimiter = NULL; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - volname = (char *)words[3]; - GF_ASSERT (volname); + volname = (char *)words[3]; + GF_ASSERT(volname); - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - str = (char *)words[4]; - if (strchr (str, ':')) { - delimiter = strchr (words[4], ':'); - if (!delimiter || delimiter == words[4] - || *(delimiter+1) != '/') { - cli_err ("wrong brick type: %s, use :" - "", words[4]); - ret = -1; - goto out; - } else { - ret = gf_canonicalize_path (delimiter + 1); - if (ret) - goto out; - } - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; - /* Path */ - str = (char *)words[5]; - ret = dict_set_str (dict, "path", str); - if (ret) - goto out; + str = (char *)words[4]; + if (strchr(str, ':')) { + delimiter = strchr(words[4], ':'); + if (!delimiter || delimiter == words[4] || *(delimiter + 1) != '/') { + cli_err( + "wrong brick type: %s, use :" + "", + words[4]); + ret = -1; + goto out; } else { - ret = dict_set_str (dict, "path", str); - if (ret) - goto out; + ret = gf_canonicalize_path(delimiter + 1); + if (ret) + goto out; } + ret = dict_set_str(dict, "brick", str); + if (ret) + goto out; + /* Path */ + str = (char *)words[5]; + ret = dict_set_str(dict, "path", str); + if (ret) + goto out; + } else { + ret = dict_set_str(dict, "path", str); + if (ret) + goto out; + } - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } int32_t -cli_cmd_log_level_parse (const char **words, int worcount, dict_t **options) +cli_cmd_log_level_parse(const char **words, int worcount, dict_t **options) { - dict_t *dict = NULL; - int ret = -1; - - GF_ASSERT (words); - GF_ASSERT (options); - - /* - * loglevel command format: - * > volume log level - * > volume log level colon-o posix WARNING - * > volume log level colon-o replicate* DEBUG - * > volume log level coon-o * TRACE - */ - - GF_ASSERT ((strncmp(words[0], "volume", 6) == 0)); - GF_ASSERT ((strncmp(words[1], "log", 3) == 0)); - GF_ASSERT ((strncmp(words[2], "level", 5) == 0)); - - ret = glusterd_check_log_level(words[5]); - if (ret == -1) { - cli_err("Invalid log level [%s] specified", words[5]); - cli_err("Valid values for loglevel: (DEBUG|WARNING|ERROR" - "|CRITICAL|NONE|TRACE)"); - goto out; - } + dict_t *dict = NULL; + int ret = -1; + + GF_ASSERT(words); + GF_ASSERT(options); + + /* + * loglevel command format: + * > volume log level + * > volume log level colon-o posix WARNING + * > volume log level colon-o replicate* DEBUG + * > volume log level coon-o * TRACE + */ + + GF_ASSERT((strncmp(words[0], "volume", 6) == 0)); + GF_ASSERT((strncmp(words[1], "log", 3) == 0)); + GF_ASSERT((strncmp(words[2], "level", 5) == 0)); + + ret = glusterd_check_log_level(words[5]); + if (ret == -1) { + cli_err("Invalid log level [%s] specified", words[5]); + cli_err( + "Valid values for loglevel: (DEBUG|WARNING|ERROR" + "|CRITICAL|NONE|TRACE)"); + goto out; + } - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - GF_ASSERT(words[3]); - GF_ASSERT(words[4]); + GF_ASSERT(words[3]); + GF_ASSERT(words[4]); - ret = dict_set_str (dict, "volname", (char *)words[3]); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", (char *)words[3]); + if (ret) + goto out; - ret = dict_set_str (dict, "xlator", (char *)words[4]); - if (ret) - goto out; + ret = dict_set_str(dict, "xlator", (char *)words[4]); + if (ret) + goto out; - ret = dict_set_str (dict, "loglevel", (char *)words[5]); - if (ret) - goto out; + ret = dict_set_str(dict, "loglevel", (char *)words[5]); + if (ret) + goto out; - *options = dict; + *options = dict; - out: - if (ret && dict) - dict_unref (dict); +out: + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } int32_t -cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_log_locate_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - char *str = NULL; - int ret = -1; - char *delimiter = NULL; + dict_t *dict = NULL; + char *volname = NULL; + char *str = NULL; + int ret = -1; + char *delimiter = NULL; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - volname = (char *)words[3]; - GF_ASSERT (volname); + volname = (char *)words[3]; + GF_ASSERT(volname); - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - if (words[4]) { - delimiter = strchr (words[4], ':'); - if (!delimiter || delimiter == words[4] - || *(delimiter+1) != '/') { - cli_err ("wrong brick type: %s, use :" - "", words[4]); - ret = -1; - goto out; - } else { - ret = gf_canonicalize_path (delimiter + 1); - if (ret) - goto out; - } - str = (char *)words[4]; - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; + if (words[4]) { + delimiter = strchr(words[4], ':'); + if (!delimiter || delimiter == words[4] || *(delimiter + 1) != '/') { + cli_err( + "wrong brick type: %s, use :" + "", + words[4]); + ret = -1; + goto out; + } else { + ret = gf_canonicalize_path(delimiter + 1); + if (ret) + goto out; } + str = (char *)words[4]; + ret = dict_set_str(dict, "brick", str); + if (ret) + goto out; + } - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } int32_t -cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_log_rotate_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - char *str = NULL; - int ret = -1; - char *delimiter = NULL; + dict_t *dict = NULL; + char *volname = NULL; + char *str = NULL; + int ret = -1; + char *delimiter = NULL; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - if (strcmp ("rotate", words[3]) == 0) - volname = (char *)words[2]; - else if (strcmp ("rotate", words[2]) == 0) - volname = (char *)words[3]; - GF_ASSERT (volname); + if (strcmp("rotate", words[3]) == 0) + volname = (char *)words[2]; + else if (strcmp("rotate", words[2]) == 0) + volname = (char *)words[3]; + GF_ASSERT(volname); - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - if (words[4]) { - delimiter = strchr (words[4], ':'); - if (!delimiter || delimiter == words[4] - || *(delimiter+1) != '/') { - cli_err ("wrong brick type: %s, use :" - "", words[4]); - ret = -1; - goto out; - } else { - ret = gf_canonicalize_path (delimiter + 1); - if (ret) - goto out; - } - str = (char *)words[4]; - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; + if (words[4]) { + delimiter = strchr(words[4], ':'); + if (!delimiter || delimiter == words[4] || *(delimiter + 1) != '/') { + cli_err( + "wrong brick type: %s, use :" + "", + words[4]); + ret = -1; + goto out; + } else { + ret = gf_canonicalize_path(delimiter + 1); + if (ret) + goto out; } + str = (char *)words[4]; + ret = dict_set_str(dict, "brick", str); + if (ret) + goto out; + } - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } static gf_boolean_t -gsyncd_url_check (const char *w) +gsyncd_url_check(const char *w) { - return !!strpbrk (w, ":/"); + return !!strpbrk(w, ":/"); } static gf_boolean_t -gsyncd_glob_check (const char *w) +gsyncd_glob_check(const char *w) { - return !!strpbrk (w, "*?["); + return !!strpbrk(w, "*?["); } static int -config_parse (const char **words, int wordcount, dict_t *dict, - unsigned cmdi, unsigned glob) +config_parse(const char **words, int wordcount, dict_t *dict, unsigned cmdi, + unsigned glob) { - int32_t ret = -1; - int32_t i = -1; - char *append_str = NULL; - size_t append_len = 0; - char *subop = NULL; - char *ret_chkpt = NULL; - struct tm checkpoint_time; - char chkpt_buf[20] = ""; - - switch ((wordcount - 1) - cmdi) { + int32_t ret = -1; + int32_t i = -1; + char *append_str = NULL; + size_t append_len = 0; + char *subop = NULL; + char *ret_chkpt = NULL; + struct tm checkpoint_time; + char chkpt_buf[20] = ""; + + switch ((wordcount - 1) - cmdi) { case 0: - subop = gf_strdup ("get-all"); - break; + subop = gf_strdup("get-all"); + break; case 1: - if (words[cmdi + 1][0] == '!') { - (words[cmdi + 1])++; - if (gf_asprintf (&subop, "del%s", - glob ? "-glob" : "") == -1) - subop = NULL; - } else - subop = gf_strdup ("get"); + if (words[cmdi + 1][0] == '!') { + (words[cmdi + 1])++; + if (gf_asprintf(&subop, "del%s", glob ? "-glob" : "") == -1) + subop = NULL; + } else + subop = gf_strdup("get"); - ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1])); - if (ret < 0) - goto out; - break; + ret = dict_set_str(dict, "op_name", ((char *)words[cmdi + 1])); + if (ret < 0) + goto out; + break; default: - if (gf_asprintf (&subop, "set%s", glob ? "-glob" : "") == -1) - subop = NULL; + if (gf_asprintf(&subop, "set%s", glob ? "-glob" : "") == -1) + subop = NULL; - ret = dict_set_str (dict, "op_name", ((char *)words[cmdi + 1])); - if (ret < 0) - goto out; + ret = dict_set_str(dict, "op_name", ((char *)words[cmdi + 1])); + if (ret < 0) + goto out; - /* join the varargs by spaces to get the op_value */ + /* join the varargs by spaces to get the op_value */ - for (i = cmdi + 2; i < wordcount; i++) - append_len += (strlen (words[i]) + 1); - /* trailing strcat will add two bytes, make space for that */ - append_len++; + for (i = cmdi + 2; i < wordcount; i++) + append_len += (strlen(words[i]) + 1); + /* trailing strcat will add two bytes, make space for that */ + append_len++; - append_str = GF_MALLOC (append_len, cli_mt_append_str); - if (!append_str) { - ret = -1; - goto out; - } + append_str = GF_MALLOC(append_len, cli_mt_append_str); + if (!append_str) { + ret = -1; + goto out; + } + + for (i = cmdi + 2; i < wordcount; i++) { + strcat(append_str, words[i]); + strcat(append_str, " "); + } + append_str[append_len - 2] = '\0'; + /* "checkpoint now" is special: we resolve that "now" */ + if ((strcmp(words[cmdi + 1], "checkpoint") == 0) && + (strcmp(append_str, "now") == 0)) { + struct timeval tv = { + 0, + }; + + ret = gettimeofday(&tv, NULL); + if (ret == -1) + goto out; - for (i = cmdi + 2; i < wordcount; i++) { - strcat (append_str, words[i]); - strcat (append_str, " "); - } - append_str[append_len - 2] = '\0'; - /* "checkpoint now" is special: we resolve that "now" */ - if ((strcmp (words[cmdi + 1], "checkpoint") == 0) && - (strcmp (append_str, "now") == 0)) { - struct timeval tv = {0,}; - - ret = gettimeofday (&tv, NULL); - if (ret == -1) - goto out; - - GF_FREE (append_str); - append_str = GF_MALLOC (300, cli_mt_append_str); - if (!append_str) { - ret = -1; - goto out; - } - snprintf (append_str, 300, "%" GF_PRI_SECOND, - tv.tv_sec); - } else if ((strcmp (words[cmdi + 1], "checkpoint") == 0) && - (strcmp (append_str, "now") != 0)) { - memset(&checkpoint_time, 0, sizeof(struct tm)); - ret_chkpt = strptime(append_str, "%Y-%m-%d %H:%M:%S", - &checkpoint_time); - - if (ret_chkpt == NULL) { - ret = -1; - cli_err ("Invalid Checkpoint label. Use format " - "\"Y-m-d H:M:S\", Example: 2016-10-25 15:30:45"); - goto out; - } - GF_FREE (append_str); - append_str = GF_MALLOC (300, cli_mt_append_str); - if (!append_str) { - ret = -1; - goto out; - } - strftime (chkpt_buf, sizeof(chkpt_buf), "%s", - &checkpoint_time); - snprintf (append_str, 300, "%s", chkpt_buf); + GF_FREE(append_str); + append_str = GF_MALLOC(300, cli_mt_append_str); + if (!append_str) { + ret = -1; + goto out; + } + snprintf(append_str, 300, "%" GF_PRI_SECOND, tv.tv_sec); + } else if ((strcmp(words[cmdi + 1], "checkpoint") == 0) && + (strcmp(append_str, "now") != 0)) { + memset(&checkpoint_time, 0, sizeof(struct tm)); + ret_chkpt = strptime(append_str, "%Y-%m-%d %H:%M:%S", + &checkpoint_time); + + if (ret_chkpt == NULL) { + ret = -1; + cli_err( + "Invalid Checkpoint label. Use format " + "\"Y-m-d H:M:S\", Example: 2016-10-25 15:30:45"); + goto out; + } + GF_FREE(append_str); + append_str = GF_MALLOC(300, cli_mt_append_str); + if (!append_str) { + ret = -1; + goto out; } + strftime(chkpt_buf, sizeof(chkpt_buf), "%s", &checkpoint_time); + snprintf(append_str, 300, "%s", chkpt_buf); + } - ret = dict_set_dynstr (dict, "op_value", append_str); - if (ret != 0) { - goto out; - } - append_str = NULL; - } + ret = dict_set_dynstr(dict, "op_value", append_str); + if (ret != 0) { + goto out; + } + append_str = NULL; + } - ret = -1; - if (subop) { - ret = dict_set_dynstr (dict, "subop", subop); - if (!ret) - subop = NULL; - } + ret = -1; + if (subop) { + ret = dict_set_dynstr(dict, "subop", subop); + if (!ret) + subop = NULL; + } out: - GF_FREE (append_str); - GF_FREE (subop); + GF_FREE(append_str); + GF_FREE(subop); - gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); - return ret; + gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; } /* ssh_port_parse: Parses and validates when ssh_port is given. @@ -2755,1529 +2823,1493 @@ out: */ static int32_t -parse_ssh_port (const char **words, int wordcount, dict_t *dict, - unsigned *cmdi, int ssh_index, char *type) { - - int ret = 0; - char *end_ptr = NULL; - int64_t limit = 0; - - if (!strcmp ((char *)words[ssh_index], "ssh-port")) { - if (strcmp ((char *)words[ssh_index-1], "create")) { - ret = -1; - goto out; - } - (*cmdi)++; - limit = strtol (words[ssh_index+1], &end_ptr, 10); - if (errno == ERANGE || errno == EINVAL || limit <= 0 - || strcmp (end_ptr, "") != 0) { - ret = -1; - cli_err ("Please enter an integer value for ssh_port "); - goto out; - } +parse_ssh_port(const char **words, int wordcount, dict_t *dict, unsigned *cmdi, + int ssh_index, char *type) +{ + int ret = 0; + char *end_ptr = NULL; + int64_t limit = 0; - ret = dict_set_int32 (dict, "ssh_port", limit); - if (ret) - goto out; - (*cmdi)++; - } else if (strcmp ((char *)words[ssh_index+1], "create")) { - ret = -1; - goto out; + if (!strcmp((char *)words[ssh_index], "ssh-port")) { + if (strcmp((char *)words[ssh_index - 1], "create")) { + ret = -1; + goto out; + } + (*cmdi)++; + limit = strtol(words[ssh_index + 1], &end_ptr, 10); + if (errno == ERANGE || errno == EINVAL || limit <= 0 || + strcmp(end_ptr, "") != 0) { + ret = -1; + cli_err("Please enter an integer value for ssh_port "); + goto out; } - ret = dict_set_int32 (dict, type, 1); + ret = dict_set_int32(dict, "ssh_port", limit); if (ret) - goto out; + goto out; (*cmdi)++; + } else if (strcmp((char *)words[ssh_index + 1], "create")) { + ret = -1; + goto out; + } - out: - return ret; + ret = dict_set_int32(dict, type, 1); + if (ret) + goto out; + (*cmdi)++; + +out: + return ret; } static int32_t -force_push_pem_no_verify_parse (const char **words, int wordcount, - dict_t *dict, unsigned *cmdi) +force_push_pem_no_verify_parse(const char **words, int wordcount, dict_t *dict, + unsigned *cmdi) { - int32_t ret = 0; - - if (!strcmp ((char *)words[wordcount-1], "force")) { - if ((strcmp ((char *)words[wordcount-2], "start")) && - (strcmp ((char *)words[wordcount-2], "stop")) && - (strcmp ((char *)words[wordcount-2], "create")) && - (strcmp ((char *)words[wordcount-2], "no-verify")) && - (strcmp ((char *)words[wordcount-2], "push-pem")) && - (strcmp ((char *)words[wordcount-2], "pause")) && - (strcmp ((char *)words[wordcount-2], "resume"))) { - ret = -1; - goto out; - } - ret = dict_set_uint32 (dict, "force", - _gf_true); - if (ret) - goto out; - (*cmdi)++; - - if (!strcmp ((char *)words[wordcount-2], "push-pem")) { - ret = parse_ssh_port (words, wordcount, dict, cmdi, - wordcount-4, "push_pem"); - if (ret) - goto out; - } else if (!strcmp ((char *)words[wordcount-2], "no-verify")) { - ret = parse_ssh_port (words, wordcount, dict, cmdi, - wordcount-4, "no_verify"); - if (ret) - goto out; - } - } else if (!strcmp ((char *)words[wordcount-1], "push-pem")) { - ret = parse_ssh_port (words, wordcount, dict, cmdi, wordcount-3, - "push_pem"); - if (ret) - goto out; - } else if (!strcmp ((char *)words[wordcount-1], "no-verify")) { - ret = parse_ssh_port (words, wordcount, dict, cmdi, wordcount-3, - "no_verify"); - if (ret) - goto out; + int32_t ret = 0; + + if (!strcmp((char *)words[wordcount - 1], "force")) { + if ((strcmp((char *)words[wordcount - 2], "start")) && + (strcmp((char *)words[wordcount - 2], "stop")) && + (strcmp((char *)words[wordcount - 2], "create")) && + (strcmp((char *)words[wordcount - 2], "no-verify")) && + (strcmp((char *)words[wordcount - 2], "push-pem")) && + (strcmp((char *)words[wordcount - 2], "pause")) && + (strcmp((char *)words[wordcount - 2], "resume"))) { + ret = -1; + goto out; + } + ret = dict_set_uint32(dict, "force", _gf_true); + if (ret) + goto out; + (*cmdi)++; + + if (!strcmp((char *)words[wordcount - 2], "push-pem")) { + ret = parse_ssh_port(words, wordcount, dict, cmdi, wordcount - 4, + "push_pem"); + if (ret) + goto out; + } else if (!strcmp((char *)words[wordcount - 2], "no-verify")) { + ret = parse_ssh_port(words, wordcount, dict, cmdi, wordcount - 4, + "no_verify"); + if (ret) + goto out; } + } else if (!strcmp((char *)words[wordcount - 1], "push-pem")) { + ret = parse_ssh_port(words, wordcount, dict, cmdi, wordcount - 3, + "push_pem"); + if (ret) + goto out; + } else if (!strcmp((char *)words[wordcount - 1], "no-verify")) { + ret = parse_ssh_port(words, wordcount, dict, cmdi, wordcount - 3, + "no_verify"); + if (ret) + goto out; + } out: - gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); - return ret; + gf_log("cli", GF_LOG_DEBUG, "Returning %d", ret); + return ret; } - int32_t -cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options) { - int32_t ret = -1; - dict_t *dict = NULL; - gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE; - int i = 0; - unsigned masteri = 0; - unsigned slavei = 0; - unsigned glob = 0; - unsigned cmdi = 0; - char *opwords[] = { "create", "status", "start", "stop", - "config", "force", "delete", - "ssh-port", "no-verify", "push-pem", - "detail", "pause", "resume", NULL }; - char *w = NULL; - char *save_ptr = NULL; - char *slave_temp = NULL; - char *token = NULL; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) - goto out; - - /* new syntax: - * - * volume geo-replication $m $s create [[ssh-port n] [[no-verify] | [push-pem]]] [force] - * volume geo-replication [$m [$s]] status [detail] - * volume geo-replication [$m] $s config [[!]$opt [$val]] - * volume geo-replication $m $s start|stop [force] - * volume geo-replication $m $s delete [reset-sync-time] - * volume geo-replication $m $s pause [force] - * volume geo-replication $m $s resume [force] - */ + int32_t ret = -1; + dict_t *dict = NULL; + gf1_cli_gsync_set type = GF_GSYNC_OPTION_TYPE_NONE; + int i = 0; + unsigned masteri = 0; + unsigned slavei = 0; + unsigned glob = 0; + unsigned cmdi = 0; + char *opwords[] = {"create", "status", "start", "stop", "config", + "force", "delete", "ssh-port", "no-verify", "push-pem", + "detail", "pause", "resume", NULL}; + char *w = NULL; + char *save_ptr = NULL; + char *slave_temp = NULL; + char *token = NULL; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + if (!dict) + goto out; - if (wordcount < 3) - goto out; + /* new syntax: + * + * volume geo-replication $m $s create [[ssh-port n] [[no-verify] | + * [push-pem]]] [force] volume geo-replication [$m [$s]] status [detail] + * volume geo-replication [$m] $s config [[!]$opt [$val]] + * volume geo-replication $m $s start|stop [force] + * volume geo-replication $m $s delete [reset-sync-time] + * volume geo-replication $m $s pause [force] + * volume geo-replication $m $s resume [force] + */ + + if (wordcount < 3) + goto out; - for (i = 2; i <= 3 && i < wordcount - 1; i++) { - if (gsyncd_glob_check (words[i])) - glob = i; - if (gsyncd_url_check (words[i])) { - slavei = i; - break; - } + for (i = 2; i <= 3 && i < wordcount - 1; i++) { + if (gsyncd_glob_check(words[i])) + glob = i; + if (gsyncd_url_check(words[i])) { + slavei = i; + break; } + } - if (glob && !slavei) - /* glob is allowed only for config, thus it implies there is a - * slave argument; but that might have not been recognized on - * the first scan as it's url characteristics has been covered - * by the glob syntax. - * - * In this case, the slave is perforce the last glob-word -- the - * upcoming one is neither glob, nor url, so it's definitely not - * the slave. - */ - slavei = glob; - if (slavei) { - cmdi = slavei + 1; - if (slavei == 3) - masteri = 2; - } else if (i <= 4) { - if (strtail ("detail", (char *)words[wordcount-1])) { - cmdi = wordcount - 2; - if (i == 4) - masteri = 2; - } else { - /* no $s, can only be status cmd - * (with either a single $m before it or nothing) - * -- these conditions imply that i <= 3 after - * the iteration and that i is the successor of - * the (0 or 1 length) sequence of $m-s. - */ - cmdi = i; - if (i == 3) - masteri = 2; - } - } else - goto out; - - /* now check if input really complies syntax - * (in a somewhat redundant way, in favor - * transparent soundness) + if (glob && !slavei) + /* glob is allowed only for config, thus it implies there is a + * slave argument; but that might have not been recognized on + * the first scan as it's url characteristics has been covered + * by the glob syntax. + * + * In this case, the slave is perforce the last glob-word -- the + * upcoming one is neither glob, nor url, so it's definitely not + * the slave. */ + slavei = glob; + if (slavei) { + cmdi = slavei + 1; + if (slavei == 3) + masteri = 2; + } else if (i <= 4) { + if (strtail("detail", (char *)words[wordcount - 1])) { + cmdi = wordcount - 2; + if (i == 4) + masteri = 2; + } else { + /* no $s, can only be status cmd + * (with either a single $m before it or nothing) + * -- these conditions imply that i <= 3 after + * the iteration and that i is the successor of + * the (0 or 1 length) sequence of $m-s. + */ + cmdi = i; + if (i == 3) + masteri = 2; + } + } else + goto out; - if (masteri && gsyncd_url_check (words[masteri])) - goto out; - if (slavei && !glob && !gsyncd_url_check (words[slavei])) - goto out; + /* now check if input really complies syntax + * (in a somewhat redundant way, in favor + * transparent soundness) + */ - w = str_getunamb (words[cmdi], opwords); - if (!w) - goto out; + if (masteri && gsyncd_url_check(words[masteri])) + goto out; + if (slavei && !glob && !gsyncd_url_check(words[slavei])) + goto out; - if (strcmp (w, "create") == 0) { - type = GF_GSYNC_OPTION_TYPE_CREATE; - - if (!masteri || !slavei) - goto out; - } else if (strcmp (w, "status") == 0) { - type = GF_GSYNC_OPTION_TYPE_STATUS; - - if (slavei && !masteri) - goto out; - } else if (strcmp (w, "config") == 0) { - type = GF_GSYNC_OPTION_TYPE_CONFIG; - - if (!slavei) - goto out; - } else if (strcmp (w, "start") == 0) { - type = GF_GSYNC_OPTION_TYPE_START; - - if (!masteri || !slavei) - goto out; - } else if (strcmp (w, "stop") == 0) { - type = GF_GSYNC_OPTION_TYPE_STOP; - - if (!masteri || !slavei) - goto out; - } else if (strcmp (w, "delete") == 0) { - type = GF_GSYNC_OPTION_TYPE_DELETE; - - if (!masteri || !slavei) - goto out; - } else if (strcmp (w, "pause") == 0) { - type = GF_GSYNC_OPTION_TYPE_PAUSE; + w = str_getunamb(words[cmdi], opwords); + if (!w) + goto out; - if (!masteri || !slavei) - goto out; - } else if (strcmp (w, "resume") == 0) { - type = GF_GSYNC_OPTION_TYPE_RESUME; + if (strcmp(w, "create") == 0) { + type = GF_GSYNC_OPTION_TYPE_CREATE; + + if (!masteri || !slavei) + goto out; + } else if (strcmp(w, "status") == 0) { + type = GF_GSYNC_OPTION_TYPE_STATUS; + + if (slavei && !masteri) + goto out; + } else if (strcmp(w, "config") == 0) { + type = GF_GSYNC_OPTION_TYPE_CONFIG; + + if (!slavei) + goto out; + } else if (strcmp(w, "start") == 0) { + type = GF_GSYNC_OPTION_TYPE_START; + + if (!masteri || !slavei) + goto out; + } else if (strcmp(w, "stop") == 0) { + type = GF_GSYNC_OPTION_TYPE_STOP; + + if (!masteri || !slavei) + goto out; + } else if (strcmp(w, "delete") == 0) { + type = GF_GSYNC_OPTION_TYPE_DELETE; + + if (!masteri || !slavei) + goto out; + } else if (strcmp(w, "pause") == 0) { + type = GF_GSYNC_OPTION_TYPE_PAUSE; + + if (!masteri || !slavei) + goto out; + } else if (strcmp(w, "resume") == 0) { + type = GF_GSYNC_OPTION_TYPE_RESUME; + + if (!masteri || !slavei) + goto out; + } else + GF_ASSERT(!"opword mismatch"); + + ret = force_push_pem_no_verify_parse(words, wordcount, dict, &cmdi); + if (ret) + goto out; - if (!masteri || !slavei) - goto out; - } else - GF_ASSERT (!"opword mismatch"); + if (strtail("detail", (char *)words[wordcount - 1])) { + if (!strtail("status", (char *)words[wordcount - 2])) { + ret = -1; + goto out; + } - ret = force_push_pem_no_verify_parse (words, wordcount, dict, &cmdi); + ret = dict_set_uint32(dict, "status-detail", _gf_true); if (ret) - goto out; - - if (strtail ("detail", (char *)words[wordcount-1])) { - if (!strtail ("status", (char *)words[wordcount-2])) { - ret = -1; - goto out; - } - - ret = dict_set_uint32 (dict, "status-detail", _gf_true); - if (ret) - goto out; - cmdi++; - } + goto out; + cmdi++; + } - if (type == GF_GSYNC_OPTION_TYPE_DELETE && - !strcmp ((char *)words[wordcount-1], "reset-sync-time")) { - if (strcmp ((char *)words[wordcount-2], "delete")) { - ret = -1; - goto out; - } - ret = dict_set_uint32 (dict, "reset-sync-time", _gf_true); - if (ret) - goto out; - cmdi++; + if (type == GF_GSYNC_OPTION_TYPE_DELETE && + !strcmp((char *)words[wordcount - 1], "reset-sync-time")) { + if (strcmp((char *)words[wordcount - 2], "delete")) { + ret = -1; + goto out; } + ret = dict_set_uint32(dict, "reset-sync-time", _gf_true); + if (ret) + goto out; + cmdi++; + } - if (type != GF_GSYNC_OPTION_TYPE_CONFIG && - (cmdi < wordcount - 1 || glob)) - goto out; + if (type != GF_GSYNC_OPTION_TYPE_CONFIG && (cmdi < wordcount - 1 || glob)) + goto out; - /* If got so far, input is valid, assemble the message */ + /* If got so far, input is valid, assemble the message */ - ret = 0; + ret = 0; - if (masteri) { - ret = dict_set_str (dict, "master", (char *)words[masteri]); - if (!ret) - ret = dict_set_str (dict, "volname", - (char *)words[masteri]); - } - if (!ret && slavei) { - /* If geo-rep is created with root user using the syntax - * gluster vol geo-rep root@ ... - * pass down only else pass as it is. - */ - slave_temp = gf_strdup (words[slavei]); - if (slave_temp == NULL) { - ret = -1; - goto out; - } - token = strtok_r (slave_temp, "@", &save_ptr); - if (token && !strcmp (token, "root")) { - ret = dict_set_str (dict, "slave", - (char *)words[slavei]+5); - } else { - ret = dict_set_str (dict, "slave", - (char *)words[slavei]); - } - } + if (masteri) { + ret = dict_set_str(dict, "master", (char *)words[masteri]); if (!ret) - ret = dict_set_int32 (dict, "type", type); - if (!ret && type == GF_GSYNC_OPTION_TYPE_CONFIG) - ret = config_parse (words, wordcount, dict, cmdi, glob); + ret = dict_set_str(dict, "volname", (char *)words[masteri]); + } + if (!ret && slavei) { + /* If geo-rep is created with root user using the syntax + * gluster vol geo-rep root@ ... + * pass down only else pass as it is. + */ + slave_temp = gf_strdup(words[slavei]); + if (slave_temp == NULL) { + ret = -1; + goto out; + } + token = strtok_r(slave_temp, "@", &save_ptr); + if (token && !strcmp(token, "root")) { + ret = dict_set_str(dict, "slave", (char *)words[slavei] + 5); + } else { + ret = dict_set_str(dict, "slave", (char *)words[slavei]); + } + } + if (!ret) + ret = dict_set_int32(dict, "type", type); + if (!ret && type == GF_GSYNC_OPTION_TYPE_CONFIG) + ret = config_parse(words, wordcount, dict, cmdi, glob); out: - if (slave_temp) - GF_FREE (slave_temp); - if (ret) { - if (dict) - dict_unref (dict); - } else - *options = dict; - + if (slave_temp) + GF_FREE(slave_temp); + if (ret) { + if (dict) + dict_unref(dict); + } else + *options = dict; - return ret; + return ret; } int32_t -cli_cmd_volume_profile_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_profile_parse(const char **words, int wordcount, + dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - int ret = -1; - gf1_cli_stats_op op = GF_CLI_STATS_NONE; - gf1_cli_info_op info_op = GF_CLI_INFO_NONE; - gf_boolean_t is_peek = _gf_false; + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + gf1_cli_stats_op op = GF_CLI_STATS_NONE; + gf1_cli_info_op info_op = GF_CLI_INFO_NONE; + gf_boolean_t is_peek = _gf_false; - char *opwords[] = { "start", "stop", "info", NULL }; - char *w = NULL; + char *opwords[] = {"start", "stop", "info", NULL}; + char *w = NULL; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - if (wordcount < 4) - goto out; + if (wordcount < 4) + goto out; - volname = (char *)words[2]; + volname = (char *)words[2]; - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - w = str_getunamb (words[3], opwords); - if (!w) { - ret = -1; - goto out; - } + w = str_getunamb(words[3], opwords); + if (!w) { + ret = -1; + goto out; + } - if ((strcmp (w, "start") == 0 || strcmp (w, "stop") == 0) && - wordcount > 5) - goto out; + if ((strcmp(w, "start") == 0 || strcmp(w, "stop") == 0) && wordcount > 5) + goto out; - if (strcmp (w, "info") == 0 && wordcount > 7) - goto out; + if (strcmp(w, "info") == 0 && wordcount > 7) + goto out; - if (strcmp (w, "start") == 0) { - op = GF_CLI_STATS_START; - } else if (strcmp (w, "stop") == 0) { - op = GF_CLI_STATS_STOP; - } else if (strcmp (w, "info") == 0) { - op = GF_CLI_STATS_INFO; - info_op = GF_CLI_INFO_ALL; - if (wordcount > 4) { - if (strcmp (words[4], "incremental") == 0) { - info_op = GF_CLI_INFO_INCREMENTAL; - if (wordcount > 5 && - strcmp (words[5], "peek") == 0) { - is_peek = _gf_true; - } - } else if (strcmp (words[4], "cumulative") == 0) { - info_op = GF_CLI_INFO_CUMULATIVE; - } else if (strcmp (words[4], "clear") == 0) { - info_op = GF_CLI_INFO_CLEAR; - } else if (strcmp (words[4], "peek") == 0) { - is_peek = _gf_true; - } - } - } else - GF_ASSERT (!"opword mismatch"); + if (strcmp(w, "start") == 0) { + op = GF_CLI_STATS_START; + } else if (strcmp(w, "stop") == 0) { + op = GF_CLI_STATS_STOP; + } else if (strcmp(w, "info") == 0) { + op = GF_CLI_STATS_INFO; + info_op = GF_CLI_INFO_ALL; + if (wordcount > 4) { + if (strcmp(words[4], "incremental") == 0) { + info_op = GF_CLI_INFO_INCREMENTAL; + if (wordcount > 5 && strcmp(words[5], "peek") == 0) { + is_peek = _gf_true; + } + } else if (strcmp(words[4], "cumulative") == 0) { + info_op = GF_CLI_INFO_CUMULATIVE; + } else if (strcmp(words[4], "clear") == 0) { + info_op = GF_CLI_INFO_CLEAR; + } else if (strcmp(words[4], "peek") == 0) { + is_peek = _gf_true; + } + } + } else + GF_ASSERT(!"opword mismatch"); + + ret = dict_set_int32(dict, "op", (int32_t)op); + if (ret) + goto out; - ret = dict_set_int32 (dict, "op", (int32_t)op); - if (ret) - goto out; + ret = dict_set_int32(dict, "info-op", (int32_t)info_op); + if (ret) + goto out; - ret = dict_set_int32 (dict, "info-op", (int32_t)info_op); - if (ret) - goto out; + ret = dict_set_int32(dict, "peek", is_peek); + if (ret) + goto out; - ret = dict_set_int32 (dict, "peek", is_peek); + if (!strcmp(words[wordcount - 1], "nfs")) { + ret = dict_set_int32(dict, "nfs", _gf_true); if (ret) - goto out; - - if (!strcmp (words[wordcount - 1], "nfs")) { - ret = dict_set_int32 (dict, "nfs", _gf_true); - if (ret) - goto out; - } + goto out; + } - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); - return ret; + if (ret && dict) + dict_unref(dict); + return ret; } int32_t -cli_cmd_volume_top_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_top_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - char *volname = NULL; - char *value = NULL; - char *key = NULL; - int ret = -1; - gf1_cli_stats_op op = GF_CLI_STATS_NONE; - gf1_cli_top_op top_op = GF_CLI_TOP_NONE; - int32_t list_cnt = -1; - int index = 0; - int perf = 0; - int32_t blk_size = 0; - int count = 0; - gf_boolean_t nfs = _gf_false; - char *delimiter = NULL; - char *opwords[] = { "open", "read", "write", "opendir", - "readdir", "read-perf", "write-perf", - "clear", NULL }; - char *w = NULL; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) - goto out; + dict_t *dict = NULL; + char *volname = NULL; + char *value = NULL; + char *key = NULL; + int ret = -1; + gf1_cli_stats_op op = GF_CLI_STATS_NONE; + gf1_cli_top_op top_op = GF_CLI_TOP_NONE; + int32_t list_cnt = -1; + int index = 0; + int perf = 0; + int32_t blk_size = 0; + int count = 0; + gf_boolean_t nfs = _gf_false; + char *delimiter = NULL; + char *opwords[] = {"open", "read", "write", "opendir", "readdir", + "read-perf", "write-perf", "clear", NULL}; + char *w = NULL; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + if (!dict) + goto out; - if (wordcount < 4) - goto out; + if (wordcount < 4) + goto out; - volname = (char *)words[2]; + volname = (char *)words[2]; - ret = dict_set_str (dict, "volname", volname); - if (ret) - goto out; + ret = dict_set_str(dict, "volname", volname); + if (ret) + goto out; - op = GF_CLI_STATS_TOP; - ret = dict_set_int32 (dict, "op", (int32_t)op); - if (ret) - goto out; + op = GF_CLI_STATS_TOP; + ret = dict_set_int32(dict, "op", (int32_t)op); + if (ret) + goto out; - w = str_getunamb (words[3], opwords); - if (!w) { - ret = -1; - goto out; + w = str_getunamb(words[3], opwords); + if (!w) { + ret = -1; + goto out; + } + if (strcmp(w, "open") == 0) { + top_op = GF_CLI_TOP_OPEN; + } else if (strcmp(w, "read") == 0) { + top_op = GF_CLI_TOP_READ; + } else if (strcmp(w, "write") == 0) { + top_op = GF_CLI_TOP_WRITE; + } else if (strcmp(w, "opendir") == 0) { + top_op = GF_CLI_TOP_OPENDIR; + } else if (strcmp(w, "readdir") == 0) { + top_op = GF_CLI_TOP_READDIR; + } else if (strcmp(w, "read-perf") == 0) { + top_op = GF_CLI_TOP_READ_PERF; + perf = 1; + } else if (strcmp(w, "write-perf") == 0) { + top_op = GF_CLI_TOP_WRITE_PERF; + perf = 1; + } else if (strcmp(w, "clear") == 0) { + ret = dict_set_int32(dict, "clear-stats", 1); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Could not set clear-stats in dict"); + goto out; } - if (strcmp (w, "open") == 0) { - top_op = GF_CLI_TOP_OPEN; - } else if (strcmp (w, "read") == 0) { - top_op = GF_CLI_TOP_READ; - } else if (strcmp (w, "write") == 0) { - top_op = GF_CLI_TOP_WRITE; - } else if (strcmp (w, "opendir") == 0) { - top_op = GF_CLI_TOP_OPENDIR; - } else if (strcmp (w, "readdir") == 0) { - top_op = GF_CLI_TOP_READDIR; - } else if (strcmp (w, "read-perf") == 0) { - top_op = GF_CLI_TOP_READ_PERF; - perf = 1; - } else if (strcmp (w, "write-perf") == 0) { - top_op = GF_CLI_TOP_WRITE_PERF; - perf = 1; - } else if (strcmp (w, "clear") == 0) { - ret = dict_set_int32 (dict, "clear-stats", 1); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, - "Could not set clear-stats in dict"); - goto out; - } - } else - GF_ASSERT (!"opword mismatch"); - ret = dict_set_int32 (dict, "top-op", (int32_t)top_op); + } else + GF_ASSERT(!"opword mismatch"); + ret = dict_set_int32(dict, "top-op", (int32_t)top_op); + if (ret) + goto out; + + if ((wordcount > 4) && !strcmp(words[4], "nfs")) { + nfs = _gf_true; + ret = dict_set_int32(dict, "nfs", nfs); if (ret) + goto out; + index = 5; + } else { + index = 4; + } + + for (; index < wordcount; index += 2) { + key = (char *)words[index]; + value = (char *)words[index + 1]; + + if (!key || !value) { + ret = -1; + goto out; + } + if (!strcmp(key, "brick")) { + delimiter = strchr(value, ':'); + if (!delimiter || delimiter == value || *(delimiter + 1) != '/') { + cli_err( + "wrong brick type: %s, use :" + "", + value); + ret = -1; goto out; - - if ((wordcount > 4) && !strcmp (words[4], "nfs")) { - nfs = _gf_true; - ret = dict_set_int32 (dict, "nfs", nfs); + } else { + ret = gf_canonicalize_path(delimiter + 1); if (ret) - goto out; - index = 5; - } else { - index = 4; - } - - for (; index < wordcount; index+=2) { - - key = (char *) words[index]; - value = (char *) words[index+1]; - - if (!key || !value) { - ret = -1; - goto out; - } - if (!strcmp (key, "brick")) { - delimiter = strchr (value, ':'); - if (!delimiter || delimiter == value - || *(delimiter+1) != '/') { - cli_err ("wrong brick type: %s, use :" - "", value); - ret = -1; - goto out; - } else { - ret = gf_canonicalize_path (delimiter + 1); - if (ret) - goto out; - } - ret = dict_set_str (dict, "brick", value); - - } else if (!strcmp (key, "list-cnt")) { - ret = gf_is_str_int (value); - if (!ret) - list_cnt = atoi (value); - if (ret || (list_cnt < 0) || (list_cnt > 100)) { - cli_err ("list-cnt should be between 0 to 100"); - ret = -1; - goto out; - } - } else if (perf && !nfs && !strcmp (key, "bs")) { - ret = gf_is_str_int (value); - if (!ret) - blk_size = atoi (value); - if (ret || (blk_size <= 0)) { - if (blk_size < 0) - cli_err ("block size is an invalid" - " number"); - else - cli_err ("block size should be an " - "integer greater than zero"); - ret = -1; - goto out; - } - ret = dict_set_uint32 (dict, "blk-size", - (uint32_t)blk_size); - } else if (perf && !nfs && !strcmp (key, "count")) { - ret = gf_is_str_int (value); - if (!ret) - count = atoi(value); - if (ret || (count <= 0)) { - if (count < 0) - cli_err ("count is an invalid number"); - else - cli_err ("count should be an integer " - "greater than zero"); - - ret = -1; - goto out; - } - ret = dict_set_uint32 (dict, "blk-cnt", count); - } else { - ret = -1; - goto out; - } - if (ret) { - gf_log ("", GF_LOG_WARNING, "Dict set failed for " - "key %s", key); - goto out; - } - } - if (list_cnt == -1) - list_cnt = 100; - ret = dict_set_int32 (dict, "list-cnt", list_cnt); - if (ret) { - gf_log ("", GF_LOG_WARNING, "Dict set failed for list_cnt"); + goto out; + } + ret = dict_set_str(dict, "brick", value); + + } else if (!strcmp(key, "list-cnt")) { + ret = gf_is_str_int(value); + if (!ret) + list_cnt = atoi(value); + if (ret || (list_cnt < 0) || (list_cnt > 100)) { + cli_err("list-cnt should be between 0 to 100"); + ret = -1; goto out; - } - - if ((blk_size > 0) ^ (count > 0)) { - cli_err ("Need to give both 'bs' and 'count'"); + } + } else if (perf && !nfs && !strcmp(key, "bs")) { + ret = gf_is_str_int(value); + if (!ret) + blk_size = atoi(value); + if (ret || (blk_size <= 0)) { + if (blk_size < 0) + cli_err( + "block size is an invalid" + " number"); + else + cli_err( + "block size should be an " + "integer greater than zero"); ret = -1; goto out; - } else if (((uint64_t)blk_size * count) > (10 * GF_UNIT_GB)) { - cli_err ("'bs * count' value %"PRIu64" is greater than " - "maximum allowed value of 10GB", - ((uint64_t)blk_size * count)); + } + ret = dict_set_uint32(dict, "blk-size", (uint32_t)blk_size); + } else if (perf && !nfs && !strcmp(key, "count")) { + ret = gf_is_str_int(value); + if (!ret) + count = atoi(value); + if (ret || (count <= 0)) { + if (count < 0) + cli_err("count is an invalid number"); + else + cli_err( + "count should be an integer " + "greater than zero"); + ret = -1; goto out; + } + ret = dict_set_uint32(dict, "blk-cnt", count); + } else { + ret = -1; + goto out; } + if (ret) { + gf_log("", GF_LOG_WARNING, + "Dict set failed for " + "key %s", + key); + goto out; + } + } + if (list_cnt == -1) + list_cnt = 100; + ret = dict_set_int32(dict, "list-cnt", list_cnt); + if (ret) { + gf_log("", GF_LOG_WARNING, "Dict set failed for list_cnt"); + goto out; + } - *options = dict; + if ((blk_size > 0) ^ (count > 0)) { + cli_err("Need to give both 'bs' and 'count'"); + ret = -1; + goto out; + } else if (((uint64_t)blk_size * count) > (10 * GF_UNIT_GB)) { + cli_err("'bs * count' value %" PRIu64 + " is greater than " + "maximum allowed value of 10GB", + ((uint64_t)blk_size * count)); + ret = -1; + goto out; + } + + *options = dict; out: - if (ret && dict) - dict_unref (dict); - return ret; + if (ret && dict) + dict_unref(dict); + return ret; } uint32_t -cli_cmd_get_statusop (const char *arg) +cli_cmd_get_statusop(const char *arg) { - int i = 0; - uint32_t ret = GF_CLI_STATUS_NONE; - char *w = NULL; - char *opwords[] = {"detail", "mem", "clients", "fd", - "inode", "callpool", "tasks", "client-list", - NULL}; - struct { - char *opname; - uint32_t opcode; - } optable[] = { - { "detail", GF_CLI_STATUS_DETAIL }, - { "mem", GF_CLI_STATUS_MEM }, - { "clients", GF_CLI_STATUS_CLIENTS }, - { "fd", GF_CLI_STATUS_FD }, - { "inode", GF_CLI_STATUS_INODE }, - { "callpool", GF_CLI_STATUS_CALLPOOL }, - { "tasks", GF_CLI_STATUS_TASKS }, - { "client-list", GF_CLI_STATUS_CLIENT_LIST }, - { NULL } - }; - - w = str_getunamb (arg, opwords); - if (!w) { - gf_log ("cli", GF_LOG_DEBUG, - "Not a status op %s", arg); - goto out; - } + int i = 0; + uint32_t ret = GF_CLI_STATUS_NONE; + char *w = NULL; + char *opwords[] = {"detail", "mem", "clients", "fd", "inode", + "callpool", "tasks", "client-list", NULL}; + struct { + char *opname; + uint32_t opcode; + } optable[] = {{"detail", GF_CLI_STATUS_DETAIL}, + {"mem", GF_CLI_STATUS_MEM}, + {"clients", GF_CLI_STATUS_CLIENTS}, + {"fd", GF_CLI_STATUS_FD}, + {"inode", GF_CLI_STATUS_INODE}, + {"callpool", GF_CLI_STATUS_CALLPOOL}, + {"tasks", GF_CLI_STATUS_TASKS}, + {"client-list", GF_CLI_STATUS_CLIENT_LIST}, + {NULL}}; + + w = str_getunamb(arg, opwords); + if (!w) { + gf_log("cli", GF_LOG_DEBUG, "Not a status op %s", arg); + goto out; + } - for (i = 0; optable[i].opname; i++) { - if (!strcmp (w, optable[i].opname)) { - ret = optable[i].opcode; - break; - } + for (i = 0; optable[i].opname; i++) { + if (!strcmp(w, optable[i].opname)) { + ret = optable[i].opcode; + break; } + } - out: - return ret; +out: + return ret; } int -cli_cmd_volume_status_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_status_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - int ret = -1; - uint32_t cmd = 0; - - GF_ASSERT (options); + dict_t *dict = NULL; + int ret = -1; + uint32_t cmd = 0; - dict = dict_new (); - if (!dict) - goto out; + GF_ASSERT(options); - switch (wordcount) { + dict = dict_new(); + if (!dict) + goto out; + switch (wordcount) { case 2: - cmd = GF_CLI_STATUS_ALL; - ret = 0; - break; + cmd = GF_CLI_STATUS_ALL; + ret = 0; + break; case 3: - if (!strcmp (words[2], "all")) { - cmd = GF_CLI_STATUS_ALL; - ret = 0; + if (!strcmp(words[2], "all")) { + cmd = GF_CLI_STATUS_ALL; + ret = 0; - } else { - cmd = GF_CLI_STATUS_VOL; - ret = dict_set_str (dict, "volname", (char *)words[2]); - } + } else { + cmd = GF_CLI_STATUS_VOL; + ret = dict_set_str(dict, "volname", (char *)words[2]); + } - break; + break; case 4: - cmd = cli_cmd_get_statusop (words[3]); - - if (!strcmp (words[2], "all")) { - if (cmd == GF_CLI_STATUS_NONE) { - cli_err ("%s is not a valid status option", - words[3]); - ret = -1; - goto out; - } - cmd |= GF_CLI_STATUS_ALL; - ret = 0; - - } else { - ret = dict_set_str (dict, "volname", - (char *)words[2]); - if (ret) - goto out; - - if (cmd == GF_CLI_STATUS_NONE) { - if (!strcmp (words[3], "nfs")) { - cmd |= GF_CLI_STATUS_NFS; - } else if (!strcmp (words[3], "shd")) { - cmd |= GF_CLI_STATUS_SHD; - } else if (!strcmp (words[3], "quotad")) { - cmd |= GF_CLI_STATUS_QUOTAD; - } else if (!strcmp (words[3], "snapd")) { - cmd |= GF_CLI_STATUS_SNAPD; - } else if (!strcmp (words[3], "tierd")) { - cmd |= GF_CLI_STATUS_TIERD; - } else if (!strcmp (words[3], "bitd")) { - cmd |= GF_CLI_STATUS_BITD; - } else if (!strcmp (words[3], "scrub")) { - cmd |= GF_CLI_STATUS_SCRUB; - } else { - cmd = GF_CLI_STATUS_BRICK; - ret = dict_set_str (dict, "brick", - (char *)words[3]); - } - - } else { - cmd |= GF_CLI_STATUS_VOL; - ret = 0; - } - } - - break; - - case 5: - if (!strcmp (words[2], "all")) { - cli_err ("Cannot specify brick/nfs for \"all\""); - ret = -1; - goto out; - } + cmd = cli_cmd_get_statusop(words[3]); - cmd = cli_cmd_get_statusop (words[4]); + if (!strcmp(words[2], "all")) { if (cmd == GF_CLI_STATUS_NONE) { - cli_err ("%s is not a valid status option", - words[4]); - ret = -1; - goto out; + cli_err("%s is not a valid status option", words[3]); + ret = -1; + goto out; } + cmd |= GF_CLI_STATUS_ALL; + ret = 0; - - ret = dict_set_str (dict, "volname", (char *)words[2]); + } else { + ret = dict_set_str(dict, "volname", (char *)words[2]); if (ret) - goto out; + goto out; - if (!strcmp (words[3], "nfs")) { - if (cmd == GF_CLI_STATUS_FD || - cmd == GF_CLI_STATUS_DETAIL || - cmd == GF_CLI_STATUS_TASKS) { - cli_err ("Detail/FD/Tasks status not available" - " for NFS Servers"); - ret = -1; - goto out; - } + if (cmd == GF_CLI_STATUS_NONE) { + if (!strcmp(words[3], "nfs")) { cmd |= GF_CLI_STATUS_NFS; - } else if (!strcmp (words[3], "shd")){ - if (cmd == GF_CLI_STATUS_FD || - cmd == GF_CLI_STATUS_CLIENTS || - cmd == GF_CLI_STATUS_DETAIL || - cmd == GF_CLI_STATUS_TASKS) { - cli_err ("Detail/FD/Clients/Tasks status not " - "available for Self-heal Daemons"); - ret = -1; - goto out; - } + } else if (!strcmp(words[3], "shd")) { cmd |= GF_CLI_STATUS_SHD; - } else if (!strcmp (words[3], "quotad")) { - if (cmd == GF_CLI_STATUS_FD || - cmd == GF_CLI_STATUS_CLIENTS || - cmd == GF_CLI_STATUS_DETAIL || - cmd == GF_CLI_STATUS_INODE) { - cli_err ("Detail/FD/Clients/Inode status not " - "available for Quota Daemon"); - ret = -1; - goto out; - } + } else if (!strcmp(words[3], "quotad")) { cmd |= GF_CLI_STATUS_QUOTAD; - } else if (!strcmp (words[3], "snapd")) { - if (cmd == GF_CLI_STATUS_FD || - cmd == GF_CLI_STATUS_CLIENTS || - cmd == GF_CLI_STATUS_DETAIL || - cmd == GF_CLI_STATUS_INODE) { - cli_err ("Detail/FD/Clients/Inode status not " - "available for snap daemon"); - ret = -1; - goto out; - } + } else if (!strcmp(words[3], "snapd")) { cmd |= GF_CLI_STATUS_SNAPD; - } else if (!strcmp (words[3], "tierd")) { - if (cmd == GF_CLI_STATUS_FD || - cmd == GF_CLI_STATUS_CLIENTS || - cmd == GF_CLI_STATUS_DETAIL || - cmd == GF_CLI_STATUS_INODE) { - cli_err ("Detail/FD/Clients/Inode status not " - "available for tier daemon"); - ret = -1; - goto out; - } + } else if (!strcmp(words[3], "tierd")) { cmd |= GF_CLI_STATUS_TIERD; + } else if (!strcmp(words[3], "bitd")) { + cmd |= GF_CLI_STATUS_BITD; + } else if (!strcmp(words[3], "scrub")) { + cmd |= GF_CLI_STATUS_SCRUB; + } else { + cmd = GF_CLI_STATUS_BRICK; + ret = dict_set_str(dict, "brick", (char *)words[3]); + } + } else { - if (cmd == GF_CLI_STATUS_TASKS) { - cli_err ("Tasks status not available for " - "bricks"); - ret = -1; - goto out; - } - cmd |= GF_CLI_STATUS_BRICK; - ret = dict_set_str (dict, "brick", (char *)words[3]); + cmd |= GF_CLI_STATUS_VOL; + ret = 0; } - break; + } - default: - goto out; - } + break; - if (ret) + case 5: + if (!strcmp(words[2], "all")) { + cli_err("Cannot specify brick/nfs for \"all\""); + ret = -1; goto out; + } - ret = dict_set_int32 (dict, "cmd", cmd); - if (ret) + cmd = cli_cmd_get_statusop(words[4]); + if (cmd == GF_CLI_STATUS_NONE) { + cli_err("%s is not a valid status option", words[4]); + ret = -1; goto out; + } + + ret = dict_set_str(dict, "volname", (char *)words[2]); + if (ret) + goto out; + + if (!strcmp(words[3], "nfs")) { + if (cmd == GF_CLI_STATUS_FD || cmd == GF_CLI_STATUS_DETAIL || + cmd == GF_CLI_STATUS_TASKS) { + cli_err( + "Detail/FD/Tasks status not available" + " for NFS Servers"); + ret = -1; + goto out; + } + cmd |= GF_CLI_STATUS_NFS; + } else if (!strcmp(words[3], "shd")) { + if (cmd == GF_CLI_STATUS_FD || cmd == GF_CLI_STATUS_CLIENTS || + cmd == GF_CLI_STATUS_DETAIL || cmd == GF_CLI_STATUS_TASKS) { + cli_err( + "Detail/FD/Clients/Tasks status not " + "available for Self-heal Daemons"); + ret = -1; + goto out; + } + cmd |= GF_CLI_STATUS_SHD; + } else if (!strcmp(words[3], "quotad")) { + if (cmd == GF_CLI_STATUS_FD || cmd == GF_CLI_STATUS_CLIENTS || + cmd == GF_CLI_STATUS_DETAIL || cmd == GF_CLI_STATUS_INODE) { + cli_err( + "Detail/FD/Clients/Inode status not " + "available for Quota Daemon"); + ret = -1; + goto out; + } + cmd |= GF_CLI_STATUS_QUOTAD; + } else if (!strcmp(words[3], "snapd")) { + if (cmd == GF_CLI_STATUS_FD || cmd == GF_CLI_STATUS_CLIENTS || + cmd == GF_CLI_STATUS_DETAIL || cmd == GF_CLI_STATUS_INODE) { + cli_err( + "Detail/FD/Clients/Inode status not " + "available for snap daemon"); + ret = -1; + goto out; + } + cmd |= GF_CLI_STATUS_SNAPD; + } else if (!strcmp(words[3], "tierd")) { + if (cmd == GF_CLI_STATUS_FD || cmd == GF_CLI_STATUS_CLIENTS || + cmd == GF_CLI_STATUS_DETAIL || cmd == GF_CLI_STATUS_INODE) { + cli_err( + "Detail/FD/Clients/Inode status not " + "available for tier daemon"); + ret = -1; + goto out; + } + cmd |= GF_CLI_STATUS_TIERD; + } else { + if (cmd == GF_CLI_STATUS_TASKS) { + cli_err( + "Tasks status not available for " + "bricks"); + ret = -1; + goto out; + } + cmd |= GF_CLI_STATUS_BRICK; + ret = dict_set_str(dict, "brick", (char *)words[3]); + } + break; - *options = dict; + default: + goto out; + } - out: - if (ret && dict) - dict_unref (dict); + if (ret) + goto out; - return ret; + ret = dict_set_int32(dict, "cmd", cmd); + if (ret) + goto out; + + *options = dict; + +out: + if (ret && dict) + dict_unref(dict); + + return ret; } gf_boolean_t -cli_cmd_validate_dumpoption (const char *arg, char **option) +cli_cmd_validate_dumpoption(const char *arg, char **option) { - char *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool", "priv", - "fd", "inode", "history", "inodectx", "fdctx", - "quotad", NULL}; - char *w = NULL; - - w = str_getunamb (arg, opwords); - if (!w) { - gf_log ("cli", GF_LOG_DEBUG, "Unknown statedump option %s", - arg); - return _gf_false; - } - *option = w; - return _gf_true; + char *opwords[] = {"all", "nfs", "mem", "iobuf", "callpool", + "priv", "fd", "inode", "history", "inodectx", + "fdctx", "quotad", NULL}; + char *w = NULL; + + w = str_getunamb(arg, opwords); + if (!w) { + gf_log("cli", GF_LOG_DEBUG, "Unknown statedump option %s", arg); + return _gf_false; + } + *option = w; + return _gf_true; } int -cli_cmd_volume_statedump_options_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_statedump_options_parse(const char **words, int wordcount, + dict_t **options) { - int ret = 0; - int i = 0; - dict_t *dict = NULL; - int option_cnt = 0; - char *option = NULL; - char *option_str = NULL; - char *tmp_str = NULL; - char *tmp = NULL; - char *ip_addr = NULL; - char *pid = NULL; - - if ((wordcount >= 5) && ((strcmp (words[3], "client")) == 0)) { - tmp = gf_strdup(words[4]); - if (!tmp) { - ret = -1; - goto out; - } - ip_addr = strtok(tmp, ":"); - pid = strtok(NULL, ":"); - if (valid_internet_address (ip_addr, _gf_true) - && pid && gf_valid_pid (pid, strlen(pid))) { - ret = gf_asprintf(&option_str, "%s %s %s", words[3], - ip_addr, pid); - if (ret < 0) { - goto out; - } - option_cnt = 3; - } else { - ret = -1; - goto out; - } + int ret = 0; + int i = 0; + dict_t *dict = NULL; + int option_cnt = 0; + char *option = NULL; + char *option_str = NULL; + char *tmp_str = NULL; + char *tmp = NULL; + char *ip_addr = NULL; + char *pid = NULL; + + if ((wordcount >= 5) && ((strcmp(words[3], "client")) == 0)) { + tmp = gf_strdup(words[4]); + if (!tmp) { + ret = -1; + goto out; + } + ip_addr = strtok(tmp, ":"); + pid = strtok(NULL, ":"); + if (valid_internet_address(ip_addr, _gf_true) && pid && + gf_valid_pid(pid, strlen(pid))) { + ret = gf_asprintf(&option_str, "%s %s %s", words[3], ip_addr, pid); + if (ret < 0) { + goto out; + } + option_cnt = 3; } else { - for (i = 3; i < wordcount; i++, option_cnt++) { - if (!cli_cmd_validate_dumpoption (words[i], &option)) { - ret = -1; - goto out; - } - tmp_str = option_str; - option_str = NULL; - ret = gf_asprintf(&option_str, "%s%s ", - tmp_str ? tmp_str : "", option); - GF_FREE(tmp_str); - if (ret < 0) { - goto out; - } - } - if (option_str && - (strstr (option_str, "nfs")) && - strstr (option_str, "quotad")) { - ret = -1; - goto out; - } + ret = -1; + goto out; } - - dict = dict_new (); - if (!dict) { + } else { + for (i = 3; i < wordcount; i++, option_cnt++) { + if (!cli_cmd_validate_dumpoption(words[i], &option)) { ret = -1; goto out; + } + tmp_str = option_str; + option_str = NULL; + ret = gf_asprintf(&option_str, "%s%s ", tmp_str ? tmp_str : "", + option); + GF_FREE(tmp_str); + if (ret < 0) { + goto out; + } } + if (option_str && (strstr(option_str, "nfs")) && + strstr(option_str, "quotad")) { + ret = -1; + goto out; + } + } - /* dynamic string in dict is freed up when dict is freed up, and hence - if option_str is NULL pass in an duplicate empty string to the same */ - ret = dict_set_dynstr (dict, "options", - (option_str ? option_str : gf_strdup(""))); - if (ret) - goto out; - option_str = NULL; + dict = dict_new(); + if (!dict) { + ret = -1; + goto out; + } - ret = dict_set_int32 (dict, "option_cnt", option_cnt); - if (ret) - goto out; + /* dynamic string in dict is freed up when dict is freed up, and hence + if option_str is NULL pass in an duplicate empty string to the same */ + ret = dict_set_dynstr(dict, "options", + (option_str ? option_str : gf_strdup(""))); + if (ret) + goto out; + option_str = NULL; - *options = dict; + ret = dict_set_int32(dict, "option_cnt", option_cnt); + if (ret) + goto out; + + *options = dict; out: - GF_FREE (tmp); - GF_FREE (option_str); - if (ret && dict) - dict_unref (dict); - if (ret) - gf_log ("cli", GF_LOG_ERROR, "Error parsing dumpoptions"); - return ret; + GF_FREE(tmp); + GF_FREE(option_str); + if (ret && dict) + dict_unref(dict); + if (ret) + gf_log("cli", GF_LOG_ERROR, "Error parsing dumpoptions"); + return ret; } int -cli_cmd_volume_clrlks_opts_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_clrlks_opts_parse(const char **words, int wordcount, + dict_t **options) { - int ret = -1; - int i = 0; - dict_t *dict = NULL; - char *kind_opts[4] = {"blocked", "granted", "all", NULL}; - char *types[4] = {"inode", "entry", "posix", NULL}; - char *free_ptr = NULL; - - dict = dict_new (); - if (!dict) - goto out; + int ret = -1; + int i = 0; + dict_t *dict = NULL; + char *kind_opts[4] = {"blocked", "granted", "all", NULL}; + char *types[4] = {"inode", "entry", "posix", NULL}; + char *free_ptr = NULL; + + dict = dict_new(); + if (!dict) + goto out; - if (strcmp (words[4], "kind")) - goto out; + if (strcmp(words[4], "kind")) + goto out; - for (i = 0; kind_opts[i]; i++) { - if (!strcmp (words[5], kind_opts[i])) { - free_ptr = gf_strdup (words[5]); - ret = dict_set_dynstr (dict, "kind", free_ptr); - if (ret) - goto out; - free_ptr = NULL; - break; - } - } - if (i == 3) + for (i = 0; kind_opts[i]; i++) { + if (!strcmp(words[5], kind_opts[i])) { + free_ptr = gf_strdup(words[5]); + ret = dict_set_dynstr(dict, "kind", free_ptr); + if (ret) goto out; + free_ptr = NULL; + break; + } + } + if (i == 3) + goto out; - ret = -1; - for (i = 0; types[i]; i++) { - if (!strcmp (words[6], types[i])) { - free_ptr = gf_strdup (words[6]); - ret = dict_set_dynstr (dict, "type", free_ptr); - if (ret) - goto out; - free_ptr = NULL; - break; - } - } - if (i == 3) + ret = -1; + for (i = 0; types[i]; i++) { + if (!strcmp(words[6], types[i])) { + free_ptr = gf_strdup(words[6]); + ret = dict_set_dynstr(dict, "type", free_ptr); + if (ret) goto out; - - if (wordcount == 8) { - free_ptr = gf_strdup (words[7]); - ret = dict_set_dynstr (dict, "opts", free_ptr); - if (ret) - goto out; - free_ptr = NULL; + free_ptr = NULL; + break; } + } + if (i == 3) + goto out; - ret = 0; - *options = dict; + if (wordcount == 8) { + free_ptr = gf_strdup(words[7]); + ret = dict_set_dynstr(dict, "opts", free_ptr); + if (ret) + goto out; + free_ptr = NULL; + } + + ret = 0; + *options = dict; out: - if (ret) { - GF_FREE (free_ptr); - dict_unref (dict); - } + if (ret) { + GF_FREE(free_ptr); + dict_unref(dict); + } - return ret; + return ret; } static int -extract_hostname_path_from_token (const char *tmp_words, char **hostname, - char **path) +extract_hostname_path_from_token(const char *tmp_words, char **hostname, + char **path) { - int ret = 0; - char *delimiter = NULL; - char *tmp_host = NULL; - char *host_name = NULL; - char *words = NULL; - int str_len = 0; - *hostname = NULL; - *path = NULL; - - str_len = strlen (tmp_words) + 1; - words = GF_MALLOC (str_len, gf_common_mt_char); - if (!words){ - ret = -1; - goto out; - } + int ret = 0; + char *delimiter = NULL; + char *tmp_host = NULL; + char *host_name = NULL; + char *words = NULL; + int str_len = 0; + *hostname = NULL; + *path = NULL; + + str_len = strlen(tmp_words) + 1; + words = GF_MALLOC(str_len, gf_common_mt_char); + if (!words) { + ret = -1; + goto out; + } - snprintf (words, str_len, "%s", tmp_words); + snprintf(words, str_len, "%s", tmp_words); - if (validate_brick_name (words)) { - cli_err ("Wrong brick type: %s, use :" - "", words); - ret = -1; - goto out; + if (validate_brick_name(words)) { + cli_err( + "Wrong brick type: %s, use :" + "", + words); + ret = -1; + goto out; + } else { + delimiter = strrchr(words, ':'); + ret = gf_canonicalize_path(delimiter + 1); + if (ret) { + goto out; } else { - delimiter = strrchr (words, ':'); - ret = gf_canonicalize_path (delimiter + 1); - if (ret) { - goto out; - } else { - str_len = strlen (delimiter + 1) + 1; - *path = GF_MALLOC (str_len, - gf_common_mt_char); - if (!*path) { - ret = -1; - goto out; - - } - snprintf (*path, str_len, "%s", delimiter +1); - } - } - - tmp_host = gf_strdup (words); - if (!tmp_host) { - gf_log ("cli", GF_LOG_ERROR, "Out of memory"); - ret = -1; - goto out; - } - get_host_name (tmp_host, &host_name); - if (!host_name) { - ret = -1; - gf_log("cli",GF_LOG_ERROR, "Unable to allocate " - "memory"); - goto out; - } - if (!(strcmp (host_name, "localhost") && - strcmp (host_name, "127.0.0.1") && - strncmp (host_name, "0.", 2))) { - cli_err ("Please provide a valid hostname/ip other " - "than localhost, 127.0.0.1 or loopback " - "address (0.0.0.0 to 0.255.255.255)."); - ret = -1; - goto out; - } - if (!valid_internet_address (host_name, _gf_false)) { - cli_err ("internet address '%s' does not conform to " - "standards", host_name); + str_len = strlen(delimiter + 1) + 1; + *path = GF_MALLOC(str_len, gf_common_mt_char); + if (!*path) { ret = -1; goto out; + } + snprintf(*path, str_len, "%s", delimiter + 1); } + } - str_len = strlen (host_name) + 1; - *hostname = GF_MALLOC (str_len, gf_common_mt_char); - if (!*hostname) { - ret = -1; - goto out; - } - snprintf (*hostname, str_len, "%s", host_name); - ret = 0; + tmp_host = gf_strdup(words); + if (!tmp_host) { + gf_log("cli", GF_LOG_ERROR, "Out of memory"); + ret = -1; + goto out; + } + get_host_name(tmp_host, &host_name); + if (!host_name) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, + "Unable to allocate " + "memory"); + goto out; + } + if (!(strcmp(host_name, "localhost") && strcmp(host_name, "127.0.0.1") && + strncmp(host_name, "0.", 2))) { + cli_err( + "Please provide a valid hostname/ip other " + "than localhost, 127.0.0.1 or loopback " + "address (0.0.0.0 to 0.255.255.255)."); + ret = -1; + goto out; + } + if (!valid_internet_address(host_name, _gf_false)) { + cli_err( + "internet address '%s' does not conform to " + "standards", + host_name); + ret = -1; + goto out; + } + + str_len = strlen(host_name) + 1; + *hostname = GF_MALLOC(str_len, gf_common_mt_char); + if (!*hostname) { + ret = -1; + goto out; + } + snprintf(*hostname, str_len, "%s", host_name); + ret = 0; out: - GF_FREE (words); - GF_FREE (tmp_host); - return ret; + GF_FREE(words); + GF_FREE(tmp_host); + return ret; } static int -set_hostname_path_in_dict (const char *token, dict_t *dict, int heal_op) +set_hostname_path_in_dict(const char *token, dict_t *dict, int heal_op) { - char *hostname = NULL; - char *path = NULL; - int ret = 0; + char *hostname = NULL; + char *path = NULL; + int ret = 0; - ret = extract_hostname_path_from_token (token, &hostname, &path); - if (ret) - goto out; + ret = extract_hostname_path_from_token(token, &hostname, &path); + if (ret) + goto out; - switch (heal_op) { + switch (heal_op) { case GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK: - ret = dict_set_dynstr (dict, "heal-source-hostname", - hostname); - if (ret) - goto out; - hostname = NULL; - ret = dict_set_dynstr (dict, "heal-source-brickpath", - path); - if (ret) { - goto out; - } - path = NULL; - break; + ret = dict_set_dynstr(dict, "heal-source-hostname", hostname); + if (ret) + goto out; + hostname = NULL; + ret = dict_set_dynstr(dict, "heal-source-brickpath", path); + if (ret) { + goto out; + } + path = NULL; + break; case GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA: - ret = dict_set_dynstr (dict, "per-replica-cmd-hostname", - hostname); - if (ret) - goto out; - hostname = NULL; - ret = dict_set_dynstr (dict, "per-replica-cmd-path", - path); - if (ret) { - goto out; - } - path = NULL; - break; + ret = dict_set_dynstr(dict, "per-replica-cmd-hostname", hostname); + if (ret) + goto out; + hostname = NULL; + ret = dict_set_dynstr(dict, "per-replica-cmd-path", path); + if (ret) { + goto out; + } + path = NULL; + break; default: - ret = -1; - break; - } + ret = -1; + break; + } out: - GF_FREE(hostname); - GF_FREE(path); - return ret; + GF_FREE(hostname); + GF_FREE(path); + return ret; } static int -heal_command_type_get (const char *command) +heal_command_type_get(const char *command) { - int i = 0; - /* subcommands are set as NULL */ - char *heal_cmds[GF_SHD_OP_HEAL_DISABLE + 1] = { - [GF_SHD_OP_INVALID] = NULL, - [GF_SHD_OP_HEAL_INDEX] = NULL, - [GF_SHD_OP_HEAL_FULL] = "full", - [GF_SHD_OP_INDEX_SUMMARY] = "info", - [GF_SHD_OP_HEALED_FILES] = NULL, - [GF_SHD_OP_HEAL_FAILED_FILES] = NULL, - [GF_SHD_OP_SPLIT_BRAIN_FILES] = NULL, - [GF_SHD_OP_STATISTICS] = "statistics", - [GF_SHD_OP_STATISTICS_HEAL_COUNT] = NULL, - [GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA] = NULL, - [GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE] = NULL, - [GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK] = NULL, - [GF_SHD_OP_HEAL_ENABLE] = "enable", - [GF_SHD_OP_HEAL_DISABLE] = "disable", - }; - - for (i = 0; i <= GF_SHD_OP_HEAL_DISABLE; i++) { - if (heal_cmds[i] && (strcmp (heal_cmds[i], command) == 0)) - return i; - } - - return GF_SHD_OP_INVALID; + int i = 0; + /* subcommands are set as NULL */ + char *heal_cmds[GF_SHD_OP_HEAL_DISABLE + 1] = { + [GF_SHD_OP_INVALID] = NULL, + [GF_SHD_OP_HEAL_INDEX] = NULL, + [GF_SHD_OP_HEAL_FULL] = "full", + [GF_SHD_OP_INDEX_SUMMARY] = "info", + [GF_SHD_OP_HEALED_FILES] = NULL, + [GF_SHD_OP_HEAL_FAILED_FILES] = NULL, + [GF_SHD_OP_SPLIT_BRAIN_FILES] = NULL, + [GF_SHD_OP_STATISTICS] = "statistics", + [GF_SHD_OP_STATISTICS_HEAL_COUNT] = NULL, + [GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA] = NULL, + [GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE] = NULL, + [GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK] = NULL, + [GF_SHD_OP_HEAL_ENABLE] = "enable", + [GF_SHD_OP_HEAL_DISABLE] = "disable", + }; + + for (i = 0; i <= GF_SHD_OP_HEAL_DISABLE; i++) { + if (heal_cmds[i] && (strcmp(heal_cmds[i], command) == 0)) + return i; + } + + return GF_SHD_OP_INVALID; } int -cli_cmd_volume_heal_options_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_heal_options_parse(const char **words, int wordcount, + dict_t **options) { - int ret = 0; - dict_t *dict = NULL; - gf_xl_afr_op_t op = GF_SHD_OP_INVALID; + int ret = 0; + dict_t *dict = NULL; + gf_xl_afr_op_t op = GF_SHD_OP_INVALID; - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - ret = dict_set_str (dict, "volname", (char *) words[2]); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to set volname"); - goto out; - } + ret = dict_set_str(dict, "volname", (char *)words[2]); + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "failed to set volname"); + goto out; + } - if (wordcount == 3) { - ret = dict_set_int32 (dict, "heal-op", GF_SHD_OP_HEAL_INDEX); - goto done; + if (wordcount == 3) { + ret = dict_set_int32(dict, "heal-op", GF_SHD_OP_HEAL_INDEX); + goto done; + } + + if (wordcount == 4) { + op = heal_command_type_get(words[3]); + if (op == GF_SHD_OP_INVALID) { + ret = -1; + goto out; } - if (wordcount == 4) { - op = heal_command_type_get (words[3]); - if (op == GF_SHD_OP_INVALID) { - ret = -1; - goto out; - } + ret = dict_set_int32(dict, "heal-op", op); + goto done; + } - ret = dict_set_int32 (dict, "heal-op", op); - goto done; + if (wordcount == 5) { + if (strcmp(words[3], "info") && strcmp(words[3], "statistics") && + strcmp(words[3], "granular-entry-heal")) { + ret = -1; + goto out; } - if (wordcount == 5) { - if (strcmp (words[3], "info") && - strcmp (words[3], "statistics") && - strcmp (words[3], "granular-entry-heal")) { - ret = -1; - goto out; - } - - if (!strcmp (words[3], "info")) { - if (!strcmp (words[4], "split-brain")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_SPLIT_BRAIN_FILES); - goto done; - } - if (!strcmp (words[4], "summary")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_HEAL_SUMMARY); - goto done; - } - } + if (!strcmp(words[3], "info")) { + if (!strcmp(words[4], "split-brain")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_SPLIT_BRAIN_FILES); + goto done; + } + if (!strcmp(words[4], "summary")) { + ret = dict_set_int32(dict, "heal-op", GF_SHD_OP_HEAL_SUMMARY); + goto done; + } + } - if (!strcmp (words[3], "statistics")) { - if (!strcmp (words[4], "heal-count")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_STATISTICS_HEAL_COUNT); - goto done; - } - } + if (!strcmp(words[3], "statistics")) { + if (!strcmp(words[4], "heal-count")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_STATISTICS_HEAL_COUNT); + goto done; + } + } - if (!strcmp (words[3], "granular-entry-heal")) { - if (!strcmp (words[4], "enable")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE); - goto done; - } else if (!strcmp (words[4], "disable")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_GRANULAR_ENTRY_HEAL_DISABLE); - goto done; - } - } + if (!strcmp(words[3], "granular-entry-heal")) { + if (!strcmp(words[4], "enable")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE); + goto done; + } else if (!strcmp(words[4], "disable")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_GRANULAR_ENTRY_HEAL_DISABLE); + goto done; + } + } - ret = -1; + ret = -1; + goto out; + } + if (wordcount == 6) { + if (strcmp(words[3], "split-brain")) { + ret = -1; + goto out; + } + if (!strcmp(words[4], "bigger-file")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE); + if (ret) goto out; + ret = dict_set_str(dict, "file", (char *)words[5]); + if (ret) + goto out; + goto done; } - if (wordcount == 6) { - if (strcmp (words[3], "split-brain")) { - ret = -1; - goto out; - } - if (!strcmp (words[4], "bigger-file")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_SBRAIN_HEAL_FROM_BIGGER_FILE); - if (ret) - goto out; - ret = dict_set_str (dict, "file", (char *)words[5]); - if (ret) - goto out; - goto done; - } - if (!strcmp (words[4], "latest-mtime")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME); - if (ret) - goto out; - ret = dict_set_str (dict, "file", (char *)words[5]); - if (ret) - goto out; - goto done; - } - if (!strcmp (words[4], "source-brick")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); - if (ret) - goto out; - ret = set_hostname_path_in_dict (words[5], dict, - GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); - if (ret) - goto out; - goto done; - } - ret = -1; + if (!strcmp(words[4], "latest-mtime")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_SBRAIN_HEAL_FROM_LATEST_MTIME); + if (ret) goto out; + ret = dict_set_str(dict, "file", (char *)words[5]); + if (ret) + goto out; + goto done; } - if (wordcount == 7) { - if (!strcmp (words[3], "statistics") - && !strcmp (words[4], "heal-count") - && !strcmp (words[5], "replica")) { - - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA); - if (ret) - goto out; - ret = set_hostname_path_in_dict (words[6], dict, - GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA); - if (ret) - goto out; - goto done; - - } - if (!strcmp (words[3], "split-brain") && - !strcmp (words[4], "source-brick")) { - ret = dict_set_int32 (dict, "heal-op", - GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); - ret = set_hostname_path_in_dict (words[5], dict, - GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); - if (ret) - goto out; - ret = dict_set_str (dict, "file", - (char *) words[6]); - if (ret) - goto out; - goto done; - } + if (!strcmp(words[4], "source-brick")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); + if (ret) + goto out; + ret = set_hostname_path_in_dict(words[5], dict, + GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); + if (ret) + goto out; + goto done; } ret = -1; goto out; + } + if (wordcount == 7) { + if (!strcmp(words[3], "statistics") && + !strcmp(words[4], "heal-count") && !strcmp(words[5], "replica")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA); + if (ret) + goto out; + ret = set_hostname_path_in_dict( + words[6], dict, GF_SHD_OP_STATISTICS_HEAL_COUNT_PER_REPLICA); + if (ret) + goto out; + goto done; + } + if (!strcmp(words[3], "split-brain") && + !strcmp(words[4], "source-brick")) { + ret = dict_set_int32(dict, "heal-op", + GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); + ret = set_hostname_path_in_dict(words[5], dict, + GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK); + if (ret) + goto out; + ret = dict_set_str(dict, "file", (char *)words[6]); + if (ret) + goto out; + goto done; + } + } + ret = -1; + goto out; done: - *options = dict; + *options = dict; out: - if (ret && dict) { - dict_unref (dict); - *options = NULL; - } + if (ret && dict) { + dict_unref(dict); + *options = NULL; + } - return ret; + return ret; } int -cli_cmd_volume_old_tier_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_old_tier_parse(const char **words, int wordcount, + dict_t **options) { - dict_t *dict = NULL; - int ret = -1; - char *volname = NULL; - gf_cli_defrag_type cmd = 0; + dict_t *dict = NULL; + int ret = -1; + char *volname = NULL; + gf_cli_defrag_type cmd = 0; - GF_ASSERT (words); - GF_ASSERT (options); + GF_ASSERT(words); + GF_ASSERT(options); - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - if (wordcount != 4) - goto out; + if (wordcount != 4) + goto out; - if ((strcmp (words[1], "tier") == 0) && - (strcmp (words[3], "start") == 0)) { - cmd = GF_DEFRAG_CMD_START_TIER; - } else - goto out; + if ((strcmp(words[1], "tier") == 0) && (strcmp(words[3], "start") == 0)) { + cmd = GF_DEFRAG_CMD_START_TIER; + } else + goto out; - volname = (char *) words[2]; + volname = (char *)words[2]; - ret = dict_set_str (dict, "volname", volname); + ret = dict_set_str(dict, "volname", volname); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict"); - goto out; - } + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "failed to set dict"); + goto out; + } - ret = dict_set_int32 (dict, "rebalance-command", (int32_t) cmd); + ret = dict_set_int32(dict, "rebalance-command", (int32_t)cmd); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict"); - goto out; - } + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "failed to set dict"); + goto out; + } - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } int -cli_cmd_volume_defrag_parse (const char **words, int wordcount, - dict_t **options) +cli_cmd_volume_defrag_parse(const char **words, int wordcount, dict_t **options) { - dict_t *dict = NULL; - int ret = -1; - char *option = NULL; - char *volname = NULL; - char *command = NULL; - gf_cli_defrag_type cmd = 0; - - GF_ASSERT (words); - GF_ASSERT (options); - - dict = dict_new (); - if (!dict) - goto out; - - if (!((wordcount == 4) || (wordcount == 5))) - goto out; - - if (wordcount == 4) { - if (strcmp (words[3], "start") && strcmp (words[3], "stop") && - strcmp (words[3], "status")) - goto out; - } else { - if (strcmp (words[3], "fix-layout") && - strcmp (words[3], "start")) - goto out; - } - - volname = (char *) words[2]; - - if (wordcount == 4) { - command = (char *) words[3]; - } - if (wordcount == 5) { - if ((strcmp (words[3], "fix-layout") || - strcmp (words[4], "start")) && - (strcmp (words[3], "start") || - strcmp (words[4], "force"))) { - ret = -1; - goto out; - } - command = (char *) words[3]; - option = (char *) words[4]; - } + dict_t *dict = NULL; + int ret = -1; + char *option = NULL; + char *volname = NULL; + char *command = NULL; + gf_cli_defrag_type cmd = 0; + + GF_ASSERT(words); + GF_ASSERT(options); + + dict = dict_new(); + if (!dict) + goto out; - if (strcmp (command, "start") == 0) { - cmd = GF_DEFRAG_CMD_START; - if (option && strcmp (option, "force") == 0) { - cmd = GF_DEFRAG_CMD_START_FORCE; - } - goto done; - } + if (!((wordcount == 4) || (wordcount == 5))) + goto out; - if (strcmp (command, "fix-layout") == 0) { - cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX; - goto done; - } - if (strcmp (command, "stop") == 0) { - cmd = GF_DEFRAG_CMD_STOP; - goto done; - } - if (strcmp (command, "status") == 0) { - cmd = GF_DEFRAG_CMD_STATUS; - } + if (wordcount == 4) { + if (strcmp(words[3], "start") && strcmp(words[3], "stop") && + strcmp(words[3], "status")) + goto out; + } else { + if (strcmp(words[3], "fix-layout") && strcmp(words[3], "start")) + goto out; + } + + volname = (char *)words[2]; + + if (wordcount == 4) { + command = (char *)words[3]; + } + if (wordcount == 5) { + if ((strcmp(words[3], "fix-layout") || strcmp(words[4], "start")) && + (strcmp(words[3], "start") || strcmp(words[4], "force"))) { + ret = -1; + goto out; + } + command = (char *)words[3]; + option = (char *)words[4]; + } + + if (strcmp(command, "start") == 0) { + cmd = GF_DEFRAG_CMD_START; + if (option && strcmp(option, "force") == 0) { + cmd = GF_DEFRAG_CMD_START_FORCE; + } + goto done; + } + + if (strcmp(command, "fix-layout") == 0) { + cmd = GF_DEFRAG_CMD_START_LAYOUT_FIX; + goto done; + } + if (strcmp(command, "stop") == 0) { + cmd = GF_DEFRAG_CMD_STOP; + goto done; + } + if (strcmp(command, "status") == 0) { + cmd = GF_DEFRAG_CMD_STATUS; + } done: - ret = dict_set_str (dict, "volname", volname); + ret = dict_set_str(dict, "volname", volname); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict"); - goto out; - } + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "failed to set dict"); + goto out; + } - ret = dict_set_int32 (dict, "rebalance-command", (int32_t) cmd); + ret = dict_set_int32(dict, "rebalance-command", (int32_t)cmd); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "failed to set dict"); - goto out; - } + if (ret) { + gf_log(THIS->name, GF_LOG_ERROR, "failed to set dict"); + goto out; + } - *options = dict; + *options = dict; out: - if (ret && dict) - dict_unref (dict); + if (ret && dict) + dict_unref(dict); - return ret; + return ret; } int32_t -cli_snap_create_desc_parse (dict_t *dict, const char **words, - size_t wordcount, int32_t desc_opt_loc) +cli_snap_create_desc_parse(dict_t *dict, const char **words, size_t wordcount, + int32_t desc_opt_loc) { - int32_t ret = -1; - char *desc = NULL; - int32_t desc_len = 0; - int len; - - desc = GF_MALLOC (MAX_SNAP_DESCRIPTION_LEN + 1, - gf_common_mt_char); - if (!desc) { - ret = -1; - goto out; - } - - - len = strlen (words[desc_opt_loc]); - if (len >= MAX_SNAP_DESCRIPTION_LEN) { - cli_out ("snapshot create: description truncated: " - "Description provided is longer than 1024 characters"); - desc_len = MAX_SNAP_DESCRIPTION_LEN; - } else { - desc_len = len; - } + int32_t ret = -1; + char *desc = NULL; + int32_t desc_len = 0; + int len; - snprintf (desc, desc_len + 1, "%s", words[desc_opt_loc]); - /* Calculating the size of the description as given by the user */ - - ret = dict_set_dynstr (dict, "description", desc); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save snap " - "description"); - goto out; - } + desc = GF_MALLOC(MAX_SNAP_DESCRIPTION_LEN + 1, gf_common_mt_char); + if (!desc) { + ret = -1; + goto out; + } + + len = strlen(words[desc_opt_loc]); + if (len >= MAX_SNAP_DESCRIPTION_LEN) { + cli_out( + "snapshot create: description truncated: " + "Description provided is longer than 1024 characters"); + desc_len = MAX_SNAP_DESCRIPTION_LEN; + } else { + desc_len = len; + } + + snprintf(desc, desc_len + 1, "%s", words[desc_opt_loc]); + /* Calculating the size of the description as given by the user */ + + ret = dict_set_dynstr(dict, "description", desc); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Unable to save snap " + "description"); + goto out; + } - ret = 0; + ret = 0; out: - if (ret && desc) - GF_FREE (desc); + if (ret && desc) + GF_FREE(desc); - return ret; + return ret; } /* Function to check whether the Volume name is repeated */ int -cli_check_if_volname_repeated (const char **words, unsigned int start_index, - uint64_t cur_index) { - uint64_t i = -1; - int ret = 0; +cli_check_if_volname_repeated(const char **words, unsigned int start_index, + uint64_t cur_index) +{ + uint64_t i = -1; + int ret = 0; - GF_ASSERT (words); + GF_ASSERT(words); - for (i = start_index ; i < cur_index ; i++) { - if (strcmp (words[i], words[cur_index]) == 0) { - ret = -1; - goto out; - } + for (i = start_index; i < cur_index; i++) { + if (strcmp(words[i], words[cur_index]) == 0) { + ret = -1; + goto out; } + } out: - return ret; + return ret; } /* snapshot clone @@ -4289,72 +4321,77 @@ out: * 0 on success */ int -cli_snap_clone_parse (dict_t *dict, const char **words, int wordcount) { - uint64_t i = 0; - int ret = -1; - char *clonename = NULL; - unsigned int cmdi = 2; - /* cmdi is command index, here cmdi is "2" (gluster snapshot clone)*/ - - GF_ASSERT (words); - GF_ASSERT (dict); - - if (wordcount == cmdi + 1) { - cli_err ("Invalid Syntax."); - gf_log ("cli", GF_LOG_ERROR, - "Invalid number of words for snap clone command"); - goto out; - } - - if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) { - cli_err ("snapshot clone: failed: clonename cannot exceed " - "255 characters."); - gf_log ("cli", GF_LOG_ERROR, "Clone name too long"); - - goto out; - } - - clonename = (char *) words[cmdi]; - for (i = 0 ; i < strlen (clonename); i++) { - /* Following volume name convention */ - if (!isalnum (clonename[i]) && (clonename[i] != '_' - && (clonename[i] != '-'))) { - /* TODO : Is this message enough?? */ - cli_err ("Clonename can contain only alphanumeric, " - "\"-\" and \"_\" characters"); - goto out; - } - } - - ret = dict_set_int32 (dict, "volcount", 1); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save volcount"); - goto out; - } - - ret = dict_set_str (dict, "clonename", (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save clone " - "name(%s)", (char *)words[cmdi]); - goto out; - } +cli_snap_clone_parse(dict_t *dict, const char **words, int wordcount) +{ + uint64_t i = 0; + int ret = -1; + char *clonename = NULL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot clone)*/ + + GF_ASSERT(words); + GF_ASSERT(dict); + + if (wordcount == cmdi + 1) { + cli_err("Invalid Syntax."); + gf_log("cli", GF_LOG_ERROR, + "Invalid number of words for snap clone command"); + goto out; + } - /* Filling snap name in the dictionary */ - ret = dict_set_str (dict, "snapname", (char *)words[cmdi+1]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not " - "save snap name(%s)", (char *)words[cmdi+1]); - goto out; - } + if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) { + cli_err( + "snapshot clone: failed: clonename cannot exceed " + "255 characters."); + gf_log("cli", GF_LOG_ERROR, "Clone name too long"); + goto out; + } + + clonename = (char *)words[cmdi]; + for (i = 0; i < strlen(clonename); i++) { + /* Following volume name convention */ + if (!isalnum(clonename[i]) && + (clonename[i] != '_' && (clonename[i] != '-'))) { + /* TODO : Is this message enough?? */ + cli_err( + "Clonename can contain only alphanumeric, " + "\"-\" and \"_\" characters"); + goto out; + } + } + + ret = dict_set_int32(dict, "volcount", 1); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Could not save volcount"); + goto out; + } + + ret = dict_set_str(dict, "clonename", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save clone " + "name(%s)", + (char *)words[cmdi]); + goto out; + } + + /* Filling snap name in the dictionary */ + ret = dict_set_str(dict, "snapname", (char *)words[cmdi + 1]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not " + "save snap name(%s)", + (char *)words[cmdi + 1]); + goto out; + } - ret = 0; + ret = 0; out: - return ret; + return ret; } - /* snapshot create [description ] * [force] * @arg-0, dict : Request Dictionary to be sent to server side. @@ -4365,172 +4402,181 @@ out: * 0 on success */ int -cli_snap_create_parse (dict_t *dict, const char **words, int wordcount) { - uint64_t i = 0; - int ret = -1; - uint64_t volcount = 0; - char key[PATH_MAX] = ""; - char *snapname = NULL; - unsigned int cmdi = 2; - int flags = 0; - /* cmdi is command index, here cmdi is "2" (gluster snapshot create)*/ - - GF_ASSERT (words); - GF_ASSERT (dict); - - if (wordcount <= cmdi + 1) { - cli_err ("Invalid Syntax."); - gf_log ("cli", GF_LOG_ERROR, - "Too less words for snap create command"); - goto out; - } +cli_snap_create_parse(dict_t *dict, const char **words, int wordcount) +{ + uint64_t i = 0; + int ret = -1; + uint64_t volcount = 0; + char key[PATH_MAX] = ""; + char *snapname = NULL; + unsigned int cmdi = 2; + int flags = 0; + /* cmdi is command index, here cmdi is "2" (gluster snapshot create)*/ + + GF_ASSERT(words); + GF_ASSERT(dict); + + if (wordcount <= cmdi + 1) { + cli_err("Invalid Syntax."); + gf_log("cli", GF_LOG_ERROR, "Too less words for snap create command"); + goto out; + } - if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) { - cli_err ("snapshot create: failed: snapname cannot exceed " - "255 characters."); - gf_log ("cli", GF_LOG_ERROR, "Snapname too long"); + if (strlen(words[cmdi]) >= GLUSTERD_MAX_SNAP_NAME) { + cli_err( + "snapshot create: failed: snapname cannot exceed " + "255 characters."); + gf_log("cli", GF_LOG_ERROR, "Snapname too long"); - goto out; + goto out; + } + + snapname = (char *)words[cmdi]; + for (i = 0; i < strlen(snapname); i++) { + /* Following volume name convention */ + if (!isalnum(snapname[i]) && + (snapname[i] != '_' && (snapname[i] != '-'))) { + /* TODO : Is this message enough?? */ + cli_err( + "Snapname can contain only alphanumeric, " + "\"-\" and \"_\" characters"); + goto out; + } + } + + ret = dict_set_str(dict, "snapname", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save snap " + "name(%s)", + (char *)words[cmdi]); + goto out; + } + + /* Filling volume name in the dictionary */ + for (i = cmdi + 1; + i < wordcount && (strcmp(words[i], "description")) != 0 && + (strcmp(words[i], "force") != 0) && + (strcmp(words[i], "no-timestamp") != 0); + i++) { + volcount++; + /* volume index starts from 1 */ + ret = snprintf(key, sizeof(key), "volname%" PRIu64, volcount); + if (ret < 0) { + goto out; } - snapname = (char *) words[cmdi]; - for (i = 0 ; i < strlen (snapname); i++) { - /* Following volume name convention */ - if (!isalnum (snapname[i]) && (snapname[i] != '_' - && (snapname[i] != '-'))) { - /* TODO : Is this message enough?? */ - cli_err ("Snapname can contain only alphanumeric, " - "\"-\" and \"_\" characters"); - goto out; - } + ret = dict_set_str(dict, key, (char *)words[i]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not " + "save volume name(%s)", + (char *)words[i]); + goto out; } - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save snap " - "name(%s)", (char *)words[cmdi]); - goto out; + if (i >= cmdi + 2) { + ret = -1; + cli_err( + "Creating multiple volume snapshot is not " + "supported as of now"); + goto out; } + /* TODO : remove this above condition check once + * multiple volume snapshot is supported */ + } - /* Filling volume name in the dictionary */ - for (i = cmdi + 1 ; i < wordcount - && (strcmp (words[i], "description")) != 0 - && (strcmp (words[i], "force") != 0) - && (strcmp (words[i], "no-timestamp") != 0); - i++) { - volcount++; - /* volume index starts from 1 */ - ret = snprintf (key, sizeof (key), "volname%"PRIu64, volcount); - if (ret < 0) { - goto out; - } + if (volcount == 0) { + ret = -1; + cli_err("Please provide the volume name"); + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = dict_set_str (dict, key, (char *)words[i]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not " - "save volume name(%s)", (char *)words[i]); - goto out; - } + ret = dict_set_int32(dict, "volcount", volcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Could not save volcount"); + goto out; + } + + /* Verify how we got out of "for" loop, + * if it is by reaching wordcount limit then goto "out", + * because we need not parse for "description","force" and + * "no-timestamp" after this. + */ + if (i == wordcount) { + goto out; + } - if (i >= cmdi + 2) { - ret = -1; - cli_err("Creating multiple volume snapshot is not " - "supported as of now"); - goto out; - } - /* TODO : remove this above condition check once - * multiple volume snapshot is supported */ + if (strcmp(words[i], "no-timestamp") == 0) { + ret = dict_set_str(dict, "no-timestamp", "true"); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save " + "time-stamp option"); } + if (i == (wordcount - 1)) + goto out; + i++; + } - if (volcount == 0) { - ret = -1; - cli_err ("Please provide the volume name"); - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; + if ((strcmp(words[i], "description")) == 0) { + ++i; + if (i > (wordcount - 1)) { + ret = -1; + cli_err("Please provide a description"); + gf_log("cli", GF_LOG_ERROR, "Description not provided"); + goto out; } - ret = dict_set_int32 (dict, "volcount", volcount); + ret = cli_snap_create_desc_parse(dict, words, wordcount, i); if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save volcount"); - goto out; - } - - /* Verify how we got out of "for" loop, - * if it is by reaching wordcount limit then goto "out", - * because we need not parse for "description","force" and - * "no-timestamp" after this. + gf_log("cli", GF_LOG_ERROR, + "Could not save snap " + "description"); + goto out; + } + + if (i == (wordcount - 1)) + goto out; + i++; + /* point the index to next word. + * As description might be follwed by force option. + * Before that, check if wordcount limit is reached */ - if (i == wordcount) { - goto out; - } - - if (strcmp (words[i], "no-timestamp") == 0) { - ret = dict_set_str (dict, "no-timestamp", "true"); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save " - "time-stamp option"); - } - if (i == (wordcount-1)) - goto out; - i++; - } - - if ((strcmp (words[i], "description")) == 0) { - ++i; - if (i > (wordcount - 1)) { - ret = -1; - cli_err ("Please provide a description"); - gf_log ("cli", GF_LOG_ERROR, - "Description not provided"); - goto out; - } - - ret = cli_snap_create_desc_parse(dict, words, wordcount, i); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save snap " - "description"); - goto out; - } - - if (i == (wordcount - 1)) - goto out; - i++; - /* point the index to next word. - * As description might be follwed by force option. - * Before that, check if wordcount limit is reached - */ - } + } - if (strcmp (words[i], "force") == 0) { - flags = GF_CLI_FLAG_OP_FORCE; + if (strcmp(words[i], "force") == 0) { + flags = GF_CLI_FLAG_OP_FORCE; - } else { - ret = -1; - cli_err ("Invalid Syntax."); - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + } else { + ret = -1; + cli_err("Invalid Syntax."); + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - /* Check if the command has anything after "force" keyword */ - if (++i < wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + /* Check if the command has anything after "force" keyword */ + if (++i < wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = 0; + ret = 0; out: - if(ret == 0) { - /*Adding force flag in either of the case i.e force set - * or unset*/ - ret = dict_set_int32 (dict, "flags", flags); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save " - "snap force option"); - } + if (ret == 0) { + /*Adding force flag in either of the case i.e force set + * or unset*/ + ret = dict_set_int32(dict, "flags", flags); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save " + "snap force option"); } - return ret; + } + return ret; } /* snapshot list [volname] @@ -4542,30 +4588,30 @@ out: * 0 on success */ int -cli_snap_list_parse (dict_t *dict, const char **words, int wordcount) { - int ret = -1; +cli_snap_list_parse(dict_t *dict, const char **words, int wordcount) +{ + int ret = -1; - GF_ASSERT (words); - GF_ASSERT (dict); + GF_ASSERT(words); + GF_ASSERT(dict); - if (wordcount < 2 || wordcount > 3) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + if (wordcount < 2 || wordcount > 3) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - if (wordcount == 2) { - ret = 0; - goto out; - } + if (wordcount == 2) { + ret = 0; + goto out; + } - ret = dict_set_str (dict, "volname", (char *)words[2]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, - "Failed to save volname in dictionary"); - goto out; - } + ret = dict_set_str(dict, "volname", (char *)words[2]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Failed to save volname in dictionary"); + goto out; + } out: - return ret; + return ret; } /* snapshot info [(snapname | volume )] @@ -4577,87 +4623,88 @@ out: * 0 on success */ int -cli_snap_info_parse (dict_t *dict, const char **words, int wordcount) +cli_snap_info_parse(dict_t *dict, const char **words, int wordcount) { + int ret = -1; + int32_t cmd = GF_SNAP_INFO_TYPE_ALL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot info)*/ - int ret = -1; - int32_t cmd = GF_SNAP_INFO_TYPE_ALL; - unsigned int cmdi = 2; - /* cmdi is command index, here cmdi is "2" (gluster snapshot info)*/ + GF_ASSERT(words); + GF_ASSERT(dict); - GF_ASSERT (words); - GF_ASSERT (dict); + if (wordcount > 4 || wordcount < cmdi) { + gf_log("cli", GF_LOG_ERROR, "Invalid syntax"); + goto out; + } - if (wordcount > 4 || wordcount < cmdi) { - gf_log ("cli", GF_LOG_ERROR, "Invalid syntax"); - goto out; - } + if (wordcount == cmdi) { + ret = 0; + goto out; + } - if (wordcount == cmdi) { - ret = 0; - goto out; + /* If 3rd word is not "volume", then it must + * be snapname. + */ + if (strcmp(words[cmdi], "volume") != 0) { + ret = dict_set_str(dict, "snapname", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Unable to save " + "snapname %s", + words[cmdi]); + goto out; } - /* If 3rd word is not "volume", then it must - * be snapname. + /* Once snap name is parsed, if we encounter any other + * word then fail it. Invalid Syntax. + * example : snapshot info word */ - if (strcmp (words[cmdi], "volume") != 0) { - ret = dict_set_str (dict, "snapname", - (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save " - "snapname %s", words[cmdi]); - goto out; - } - - /* Once snap name is parsed, if we encounter any other - * word then fail it. Invalid Syntax. - * example : snapshot info word - */ - if ((cmdi + 1) != wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - - cmd = GF_SNAP_INFO_TYPE_SNAP; - ret = 0; - goto out; - /* No need to continue the parsing once we - * get the snapname - */ + if ((cmdi + 1) != wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; } - /* If 3rd word is "volume", then check if next word - * is present. As, "snapshot info volume" is an - * invalid command. + cmd = GF_SNAP_INFO_TYPE_SNAP; + ret = 0; + goto out; + /* No need to continue the parsing once we + * get the snapname */ - if ((cmdi + 1) == wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + } - ret = dict_set_str (dict, "volname", (char *)words[wordcount - 1]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save " - "volume name %s", words[wordcount - 1]); - goto out; - } - cmd = GF_SNAP_INFO_TYPE_VOL; + /* If 3rd word is "volume", then check if next word + * is present. As, "snapshot info volume" is an + * invalid command. + */ + if ((cmdi + 1) == wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + ret = dict_set_str(dict, "volname", (char *)words[wordcount - 1]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save " + "volume name %s", + words[wordcount - 1]); + goto out; + } + cmd = GF_SNAP_INFO_TYPE_VOL; out: - if (ret == 0) { - ret = dict_set_int32 (dict, "sub-cmd", cmd); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save " - "type of snapshot info"); - } + if (ret == 0) { + ret = dict_set_int32(dict, "sub-cmd", cmd); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save " + "type of snapshot info"); } - return ret; + } + return ret; } - - /* snapshot restore * @arg-0, dict : Request Dictionary to be sent to server side. * @arg-1, words : Contains individual words of CLI command. @@ -4667,42 +4714,43 @@ out: * 0 on success */ int -cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount, - struct cli_state *state) +cli_snap_restore_parse(dict_t *dict, const char **words, int wordcount, + struct cli_state *state) { + int ret = -1; + const char *question = NULL; + gf_answer_t answer = GF_ANSWER_NO; - int ret = -1; - const char *question = NULL; - gf_answer_t answer = GF_ANSWER_NO; - - GF_ASSERT (words); - GF_ASSERT (dict); + GF_ASSERT(words); + GF_ASSERT(dict); - if (wordcount != 3) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - - ret = dict_set_str (dict, "snapname", (char *)words[2]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", - words[2]); - goto out; - } - - question = "Restore operation will replace the " - "original volume with the snapshotted volume. " - "Do you still want to continue?"; + if (wordcount != 3) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - ret = 1; - gf_log ("cli", GF_LOG_ERROR, "User cancelled a snapshot " - "restore operation for snap %s", (char *)words[2]); - goto out; - } + ret = dict_set_str(dict, "snapname", (char *)words[2]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to save snap-name %s", words[2]); + goto out; + } + + question = + "Restore operation will replace the " + "original volume with the snapshotted volume. " + "Do you still want to continue?"; + + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + ret = 1; + gf_log("cli", GF_LOG_ERROR, + "User cancelled a snapshot " + "restore operation for snap %s", + (char *)words[2]); + goto out; + } out: - return ret; + return ret; } /* snapshot activate [force] @@ -4714,43 +4762,41 @@ out: * 0 on success */ int -cli_snap_activate_parse (dict_t *dict, const char **words, int wordcount) +cli_snap_activate_parse(dict_t *dict, const char **words, int wordcount) { + int ret = -1; + int flags = 0; - int ret = -1; - int flags = 0; + GF_ASSERT(words); + GF_ASSERT(dict); - GF_ASSERT (words); - GF_ASSERT (dict); - - if ((wordcount < 3) || (wordcount > 4)) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + if ((wordcount < 3) || (wordcount > 4)) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = dict_set_str (dict, "snapname", (char *)words[2]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", - words[2]); - goto out; - } + ret = dict_set_str(dict, "snapname", (char *)words[2]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to save snap-name %s", words[2]); + goto out; + } - if (wordcount == 4) { - if (!strcmp("force", (char *)words[3])) { - flags = GF_CLI_FLAG_OP_FORCE; - } else { - gf_log ("cli", GF_LOG_ERROR, "Invalid option"); - ret = -1; - goto out; - } - } - ret = dict_set_int32 (dict, "flags", flags); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save force option"); - goto out; - } + if (wordcount == 4) { + if (!strcmp("force", (char *)words[3])) { + flags = GF_CLI_FLAG_OP_FORCE; + } else { + gf_log("cli", GF_LOG_ERROR, "Invalid option"); + ret = -1; + goto out; + } + } + ret = dict_set_int32(dict, "flags", flags); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to save force option"); + goto out; + } out: - return ret; + return ret; } /* snapshot deactivate @@ -4763,42 +4809,41 @@ out: * 1 if user cancelled the request */ int -cli_snap_deactivate_parse (dict_t *dict, const char **words, int wordcount, - struct cli_state *state) +cli_snap_deactivate_parse(dict_t *dict, const char **words, int wordcount, + struct cli_state *state) { + int ret = -1; + gf_answer_t answer = GF_ANSWER_NO; + const char *question = + "Deactivating snap will make its " + "data inaccessible. Do you want to " + "continue?"; + + GF_ASSERT(words); + GF_ASSERT(dict); + + if ((wordcount != 3)) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - int ret = -1; - gf_answer_t answer = GF_ANSWER_NO; - const char *question = "Deactivating snap will make its " - "data inaccessible. Do you want to " - "continue?"; - - - GF_ASSERT (words); - GF_ASSERT (dict); - - if ((wordcount != 3)) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - - ret = dict_set_str (dict, "snapname", (char *)words[2]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", - words[2]); - goto out; - } - - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - ret = 1; - gf_log ("cli", GF_LOG_DEBUG, "User cancelled " - "snapshot deactivate operation"); - goto out; - } + ret = dict_set_str(dict, "snapname", (char *)words[2]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to save snap-name %s", words[2]); + goto out; + } + + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + ret = 1; + gf_log("cli", GF_LOG_DEBUG, + "User cancelled " + "snapshot deactivate operation"); + goto out; + } out: - return ret; + return ret; } /* snapshot delete (all | snapname | volume ) @@ -4811,78 +4856,84 @@ out: * 1 if user cancel the operation */ int -cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, - struct cli_state *state) { - - int ret = -1; - const char *question = NULL; - int32_t cmd = -1; - unsigned int cmdi = 2; - gf_answer_t answer = GF_ANSWER_NO; - - GF_ASSERT (words); - GF_ASSERT (dict); +cli_snap_delete_parse(dict_t *dict, const char **words, int wordcount, + struct cli_state *state) +{ + int ret = -1; + const char *question = NULL; + int32_t cmd = -1; + unsigned int cmdi = 2; + gf_answer_t answer = GF_ANSWER_NO; - if (wordcount > 4 || wordcount <= cmdi) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + GF_ASSERT(words); + GF_ASSERT(dict); - question = "Deleting snap will erase all the information about " - "the snap. Do you still want to continue?"; + if (wordcount > 4 || wordcount <= cmdi) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - if (strcmp (words [cmdi], "all") == 0) { - ret = 0; - cmd = GF_SNAP_DELETE_TYPE_ALL; - } else if (strcmp (words [cmdi], "volume") == 0) { - if (++cmdi == wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + question = + "Deleting snap will erase all the information about " + "the snap. Do you still want to continue?"; - ret = dict_set_str (dict, "volname", - (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save " - "volume name %s", words[wordcount - 1]); - goto out; - } - cmd = GF_SNAP_DELETE_TYPE_VOL; - } else { - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to save " - "snapname %s", words[2]); - goto out; - } - cmd = GF_SNAP_DELETE_TYPE_SNAP; + if (strcmp(words[cmdi], "all") == 0) { + ret = 0; + cmd = GF_SNAP_DELETE_TYPE_ALL; + } else if (strcmp(words[cmdi], "volume") == 0) { + if (++cmdi == wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; } - if ((cmdi + 1) != wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; + ret = dict_set_str(dict, "volname", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save " + "volume name %s", + words[wordcount - 1]); + goto out; + } + cmd = GF_SNAP_DELETE_TYPE_VOL; + } else { + ret = dict_set_str(dict, "snapname", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Unable to save " + "snapname %s", + words[2]); + goto out; } + cmd = GF_SNAP_DELETE_TYPE_SNAP; + } - if (cmd == GF_SNAP_DELETE_TYPE_SNAP) { - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - ret = 1; - gf_log ("cli", GF_LOG_DEBUG, "User cancelled " - "snapshot delete operation for snap %s", - (char *)words[2]); - goto out; - } - } + if ((cmdi + 1) != wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = dict_set_int32 (dict, "sub-cmd", cmd); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save " - "type of snapshot delete"); - } + if (cmd == GF_SNAP_DELETE_TYPE_SNAP) { + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + ret = 1; + gf_log("cli", GF_LOG_DEBUG, + "User cancelled " + "snapshot delete operation for snap %s", + (char *)words[2]); + goto out; + } + } + + ret = dict_set_int32(dict, "sub-cmd", cmd); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save " + "type of snapshot delete"); + } out: - return ret; + return ret; } /* snapshot status [(snapname | volume )] @@ -4894,132 +4945,138 @@ out: * 0 on success */ int -cli_snap_status_parse (dict_t *dict, const char **words, int wordcount) +cli_snap_status_parse(dict_t *dict, const char **words, int wordcount) { + int ret = -1; + int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot status)*/ - int ret = -1; - int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; - unsigned int cmdi = 2; - /* cmdi is command index, here cmdi is "2" (gluster snapshot status)*/ + GF_ASSERT(words); + GF_ASSERT(dict); - GF_ASSERT (words); - GF_ASSERT (dict); + if (wordcount > 4 || wordcount < cmdi) { + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - if (wordcount > 4 || wordcount < cmdi) { - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + if (wordcount == cmdi) { + ret = 0; + goto out; + } - if (wordcount == cmdi) { - ret = 0; - goto out; + /* if 3rd word is not "volume", then it must be "snapname" + */ + if (strcmp(words[cmdi], "volume") != 0) { + ret = dict_set_str(dict, "snapname", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Count not save " + "snap name %s", + words[cmdi]); + goto out; } - /* if 3rd word is not "volume", then it must be "snapname" - */ - if (strcmp (words[cmdi], "volume") != 0) { - ret = dict_set_str (dict, "snapname", - (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Count not save " - "snap name %s", words[cmdi]); - goto out; - } - - if ((cmdi + 1) != wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - - ret = 0; - cmd = GF_SNAP_STATUS_TYPE_SNAP; - goto out; + if ((cmdi + 1) != wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; } - /* If 3rd word is "volume", then check if next word is present. - * As, "snapshot info volume" is an invalid command - */ - if ((cmdi + 1) == wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + ret = 0; + cmd = GF_SNAP_STATUS_TYPE_SNAP; + goto out; + } - ret = dict_set_str (dict, "volname", (char *)words [wordcount - 1]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Count not save " - "volume name %s", words[wordcount - 1]); - goto out; - } - cmd = GF_SNAP_STATUS_TYPE_VOL; + /* If 3rd word is "volume", then check if next word is present. + * As, "snapshot info volume" is an invalid command + */ + if ((cmdi + 1) == wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + ret = dict_set_str(dict, "volname", (char *)words[wordcount - 1]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Count not save " + "volume name %s", + words[wordcount - 1]); + goto out; + } + cmd = GF_SNAP_STATUS_TYPE_VOL; out: - if (ret == 0) { - ret = dict_set_int32 (dict, "sub-cmd", cmd); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not save cmd " - "of snapshot status"); - } + if (ret == 0) { + ret = dict_set_int32(dict, "sub-cmd", cmd); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not save cmd " + "of snapshot status"); } + } - return ret; + return ret; } - /* return value: * -1 in case of failure. * 0 in case of success. */ int32_t -cli_snap_config_limit_parse (const char **words, dict_t *dict, - unsigned int wordcount, unsigned int index, - char *key) +cli_snap_config_limit_parse(const char **words, dict_t *dict, + unsigned int wordcount, unsigned int index, + char *key) { - int ret = -1; - int limit = 0; - char *end_ptr = NULL; - - GF_ASSERT (words); - GF_ASSERT (dict); - GF_ASSERT (key); + int ret = -1; + int limit = 0; + char *end_ptr = NULL; - if (index >= wordcount) { - ret = -1; - cli_err ("Please provide a value for %s.", key); - gf_log ("cli", GF_LOG_ERROR, "Value not provided for %s", key); - goto out; - } + GF_ASSERT(words); + GF_ASSERT(dict); + GF_ASSERT(key); - limit = strtol (words[index], &end_ptr, 10); + if (index >= wordcount) { + ret = -1; + cli_err("Please provide a value for %s.", key); + gf_log("cli", GF_LOG_ERROR, "Value not provided for %s", key); + goto out; + } - if (limit <= 0 || strcmp (end_ptr, "") != 0) { - ret = -1; - cli_err("Please enter an integer value " - "greater than zero for %s", key); - goto out; - } + limit = strtol(words[index], &end_ptr, 10); - ret = dict_set_int32 (dict, key, limit); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not set " - "%s in dictionary", key); - goto out; - } + if (limit <= 0 || strcmp(end_ptr, "") != 0) { + ret = -1; + cli_err( + "Please enter an integer value " + "greater than zero for %s", + key); + goto out; + } + + ret = dict_set_int32(dict, key, limit); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Could not set " + "%s in dictionary", + key); + goto out; + } - ret = dict_set_dynstr_with_alloc (dict, "globalname", "All"); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not set global key"); - goto out; - } - ret = dict_set_int32 (dict, "hold_global_locks", _gf_true); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Could not set global locks"); - goto out; - } + ret = dict_set_dynstr_with_alloc(dict, "globalname", "All"); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Could not set global key"); + goto out; + } + ret = dict_set_int32(dict, "hold_global_locks", _gf_true); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Could not set global locks"); + goto out; + } out: - return ret; + return ret; } /* function cli_snap_config_parse @@ -5035,775 +5092,787 @@ out: NOTE : snap-max-soft-limit can only be set for system. */ int32_t -cli_snap_config_parse (const char **words, int wordcount, dict_t *dict, - struct cli_state *state) +cli_snap_config_parse(const char **words, int wordcount, dict_t *dict, + struct cli_state *state) { - int ret = -1; - gf_answer_t answer = GF_ANSWER_NO; - gf_boolean_t vol_presence = _gf_false; - struct snap_config_opt_vals_ *conf_vals = NULL; - int8_t hard_limit = 0; - int8_t soft_limit = 0; - int8_t config_type = -1; - const char *question = NULL; - unsigned int cmdi = 2; - /* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/ - - GF_ASSERT (words); - GF_ASSERT (dict); - GF_ASSERT (state); - - if ((wordcount < 2) || (wordcount > 7)) { - gf_log ("cli", GF_LOG_ERROR, - "Invalid wordcount(%d)", wordcount); - goto out; - } + int ret = -1; + gf_answer_t answer = GF_ANSWER_NO; + gf_boolean_t vol_presence = _gf_false; + struct snap_config_opt_vals_ *conf_vals = NULL; + int8_t hard_limit = 0; + int8_t soft_limit = 0; + int8_t config_type = -1; + const char *question = NULL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/ + + GF_ASSERT(words); + GF_ASSERT(dict); + GF_ASSERT(state); + + if ((wordcount < 2) || (wordcount > 7)) { + gf_log("cli", GF_LOG_ERROR, "Invalid wordcount(%d)", wordcount); + goto out; + } - if (wordcount == 2) { - config_type = GF_SNAP_CONFIG_DISPLAY; - ret = 0; - goto set; + if (wordcount == 2) { + config_type = GF_SNAP_CONFIG_DISPLAY; + ret = 0; + goto set; + } + + /* auto-delete cannot be a volume name */ + /* Check whether the 3rd word is volname */ + if (strcmp(words[cmdi], "snap-max-hard-limit") != 0 && + strcmp(words[cmdi], "snap-max-soft-limit") != 0 && + strcmp(words[cmdi], "auto-delete") != 0 && + strcmp(words[cmdi], "activate-on-create") != 0) { + ret = dict_set_str(dict, "volname", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Failed to set volname"); + goto out; } + cmdi++; + vol_presence = _gf_true; - /* auto-delete cannot be a volume name */ - /* Check whether the 3rd word is volname */ - if (strcmp (words[cmdi], "snap-max-hard-limit") != 0 - && strcmp (words[cmdi], "snap-max-soft-limit") != 0 - && strcmp (words[cmdi], "auto-delete") != 0 - && strcmp (words[cmdi], "activate-on-create") != 0) { - ret = dict_set_str (dict, "volname", (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set volname"); - goto out; - } - cmdi++; - vol_presence = _gf_true; - - if (cmdi == wordcount) { - config_type = GF_SNAP_CONFIG_DISPLAY; - ret = 0; - goto set; - } + if (cmdi == wordcount) { + config_type = GF_SNAP_CONFIG_DISPLAY; + ret = 0; + goto set; } + } - config_type = GF_SNAP_CONFIG_TYPE_SET; + config_type = GF_SNAP_CONFIG_TYPE_SET; - if (strcmp (words[cmdi], "snap-max-hard-limit") == 0) { - ret = cli_snap_config_limit_parse (words, dict, wordcount, - ++cmdi, "snap-max-hard-limit"); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse snap " - "config hard limit"); - goto out; - } - hard_limit = 1; - - if (++cmdi == wordcount) { - ret = 0; - goto set; - } + if (strcmp(words[cmdi], "snap-max-hard-limit") == 0) { + ret = cli_snap_config_limit_parse(words, dict, wordcount, ++cmdi, + "snap-max-hard-limit"); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse snap " + "config hard limit"); + goto out; } + hard_limit = 1; - if (strcmp (words[cmdi], "snap-max-soft-limit") == 0) { - if (vol_presence == 1) { - ret = -1; - cli_err ("Soft limit cannot be set to individual " - "volumes."); - gf_log ("cli", GF_LOG_ERROR, "Soft limit cannot be " - "set to volumes"); - goto out; - } - - ret = cli_snap_config_limit_parse (words, dict, wordcount, - ++cmdi, "snap-max-soft-limit"); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse snap " - "config soft limit"); - goto out; - } - - if (++cmdi != wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - soft_limit = 1; + if (++cmdi == wordcount) { + ret = 0; + goto set; } + } - if (hard_limit || soft_limit) - goto set; + if (strcmp(words[cmdi], "snap-max-soft-limit") == 0) { + if (vol_presence == 1) { + ret = -1; + cli_err( + "Soft limit cannot be set to individual " + "volumes."); + gf_log("cli", GF_LOG_ERROR, + "Soft limit cannot be " + "set to volumes"); + goto out; + } - if (strcmp(words[cmdi], "auto-delete") == 0) { - if (vol_presence == 1) { - ret = -1; - cli_err ("As of now, auto-delete option cannot be set " - "to volumes"); - gf_log ("cli", GF_LOG_ERROR, "auto-delete option " - "cannot be set to volumes"); - goto out; - } + ret = cli_snap_config_limit_parse(words, dict, wordcount, ++cmdi, + "snap-max-soft-limit"); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse snap " + "config soft limit"); + goto out; + } - if (++cmdi >= wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + if (++cmdi != wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + soft_limit = 1; + } - ret = dict_set_str (dict, "auto-delete", (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set " - "value of auto-delete in request " - "dictionary"); - goto out; - } + if (hard_limit || soft_limit) + goto set; - if (++cmdi != wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - } else if (strcmp(words[cmdi], "activate-on-create") == 0) { - if (vol_presence == 1) { - ret = -1; - cli_err ("As of now, activate-on-create option " - "cannot be set to volumes"); - gf_log ("cli", GF_LOG_ERROR, "activate-on-create " - "option cannot be set to volumes"); - goto out; - } + if (strcmp(words[cmdi], "auto-delete") == 0) { + if (vol_presence == 1) { + ret = -1; + cli_err( + "As of now, auto-delete option cannot be set " + "to volumes"); + gf_log("cli", GF_LOG_ERROR, + "auto-delete option " + "cannot be set to volumes"); + goto out; + } - if (++cmdi >= wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + if (++cmdi >= wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = dict_set_str (dict, "snap-activate-on-create", - (char *)words[cmdi]); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set value " - "of activate-on-create in request dictionary"); - goto out; - } + ret = dict_set_str(dict, "auto-delete", (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to set " + "value of auto-delete in request " + "dictionary"); + goto out; + } + + if (++cmdi != wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + } else if (strcmp(words[cmdi], "activate-on-create") == 0) { + if (vol_presence == 1) { + ret = -1; + cli_err( + "As of now, activate-on-create option " + "cannot be set to volumes"); + gf_log("cli", GF_LOG_ERROR, + "activate-on-create " + "option cannot be set to volumes"); + goto out; + } + + if (++cmdi >= wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + ret = dict_set_str(dict, "snap-activate-on-create", + (char *)words[cmdi]); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to set value " + "of activate-on-create in request dictionary"); + goto out; + } - if (++cmdi != wordcount) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - } else { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; + if (++cmdi != wordcount) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; } + } else { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = 0; /* Success */ + ret = 0; /* Success */ set: - ret = dict_set_int32 (dict, "config-command", config_type); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to set " - "config-command"); - goto out; - } + ret = dict_set_int32(dict, "config-command", config_type); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Unable to set " + "config-command"); + goto out; + } - if (config_type == GF_SNAP_CONFIG_TYPE_SET && - (hard_limit || soft_limit)) { - conf_vals = snap_confopt_vals; - if (hard_limit && soft_limit) { - question = conf_vals[GF_SNAP_CONFIG_SET_BOTH].question; - } else if (soft_limit) { - question = conf_vals[GF_SNAP_CONFIG_SET_SOFT].question; - } else if (hard_limit) { - question = conf_vals[GF_SNAP_CONFIG_SET_HARD].question; - } + if (config_type == GF_SNAP_CONFIG_TYPE_SET && (hard_limit || soft_limit)) { + conf_vals = snap_confopt_vals; + if (hard_limit && soft_limit) { + question = conf_vals[GF_SNAP_CONFIG_SET_BOTH].question; + } else if (soft_limit) { + question = conf_vals[GF_SNAP_CONFIG_SET_SOFT].question; + } else if (hard_limit) { + question = conf_vals[GF_SNAP_CONFIG_SET_HARD].question; + } - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - ret = 1; - gf_log ("cli", GF_LOG_DEBUG, "User cancelled " - "snapshot config operation"); - } + answer = cli_cmd_get_confirmation(state, question); + if (GF_ANSWER_NO == answer) { + ret = 1; + gf_log("cli", GF_LOG_DEBUG, + "User cancelled " + "snapshot config operation"); } + } out: - return ret; + return ret; } int -validate_op_name (const char *op, const char *opname, char **opwords) { - int ret = -1; - int i = 0; +validate_op_name(const char *op, const char *opname, char **opwords) +{ + int ret = -1; + int i = 0; - GF_ASSERT (opname); - GF_ASSERT (opwords); + GF_ASSERT(opname); + GF_ASSERT(opwords); - for (i = 0 ; opwords[i] != NULL; i++) { - if (strcmp (opwords[i], opname) == 0) { - cli_out ("\"%s\" cannot be a %s", opname, op); - goto out; - } + for (i = 0; opwords[i] != NULL; i++) { + if (strcmp(opwords[i], opname) == 0) { + cli_out("\"%s\" cannot be a %s", opname, op); + goto out; } - ret = 0; + } + ret = 0; out: - return ret; + return ret; } int32_t -cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, - struct cli_state *state) +cli_cmd_snapshot_parse(const char **words, int wordcount, dict_t **options, + struct cli_state *state) { - int32_t ret = -1; - dict_t *dict = NULL; - gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; - char *w = NULL; - char *opwords[] = {"create", "delete", "restore", - "activate", "deactivate", "list", - "status", "config", "info", "clone", - NULL}; - char *invalid_snapnames[] = {"description", "force", - "volume", "all", NULL}; - char *invalid_volnames[] = {"volume", "type", - "subvolumes", "option", - "end-volume", "all", - "volume_not_in_ring", - "description", "force", - "snap-max-hard-limit", - "snap-max-soft-limit", - "auto-delete", - "activate-on-create", NULL}; - - GF_ASSERT (words); - GF_ASSERT (options); - GF_ASSERT (state); - - dict = dict_new (); - if (!dict) - goto out; + int32_t ret = -1; + dict_t *dict = NULL; + gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; + char *w = NULL; + char *opwords[] = {"create", "delete", "restore", "activate", + "deactivate", "list", "status", "config", + "info", "clone", NULL}; + char *invalid_snapnames[] = {"description", "force", "volume", "all", NULL}; + char *invalid_volnames[] = {"volume", + "type", + "subvolumes", + "option", + "end-volume", + "all", + "volume_not_in_ring", + "description", + "force", + "snap-max-hard-limit", + "snap-max-soft-limit", + "auto-delete", + "activate-on-create", + NULL}; - /* Lowest wordcount possible */ - if (wordcount < 2) { - gf_log ("", GF_LOG_ERROR, - "Invalid command: Not enough arguments"); - goto out; - } + GF_ASSERT(words); + GF_ASSERT(options); + GF_ASSERT(state); - w = str_getunamb (words[1], opwords); - if (!w) { - /* Checks if the operation is a valid operation */ - gf_log ("", GF_LOG_ERROR, "Opword Mismatch"); - goto out; - } + dict = dict_new(); + if (!dict) + goto out; - if (!strcmp (w, "create")) { - type = GF_SNAP_OPTION_TYPE_CREATE; - } else if (!strcmp (w, "list")) { - type = GF_SNAP_OPTION_TYPE_LIST; - } else if (!strcmp (w, "info")) { - type = GF_SNAP_OPTION_TYPE_INFO; - } else if (!strcmp (w, "delete")) { - type = GF_SNAP_OPTION_TYPE_DELETE; - } else if (!strcmp (w, "config")) { - type = GF_SNAP_OPTION_TYPE_CONFIG; - } else if (!strcmp (w, "restore")) { - type = GF_SNAP_OPTION_TYPE_RESTORE; - } else if (!strcmp (w, "status")) { - type = GF_SNAP_OPTION_TYPE_STATUS; - } else if (!strcmp (w, "activate")) { - type = GF_SNAP_OPTION_TYPE_ACTIVATE; - } else if (!strcmp (w, "deactivate")) { - type = GF_SNAP_OPTION_TYPE_DEACTIVATE; - } else if (!strcmp(w, "clone")) { - type = GF_SNAP_OPTION_TYPE_CLONE; - } - - if (type != GF_SNAP_OPTION_TYPE_CONFIG && - type != GF_SNAP_OPTION_TYPE_STATUS) { - ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, - "Unable to set hold-snap-locks value " - "as _gf_true"); - goto out; - } - } + /* Lowest wordcount possible */ + if (wordcount < 2) { + gf_log("", GF_LOG_ERROR, "Invalid command: Not enough arguments"); + goto out; + } - /* Following commands does not require volume locks */ - if (type == GF_SNAP_OPTION_TYPE_STATUS || - type == GF_SNAP_OPTION_TYPE_ACTIVATE || - type == GF_SNAP_OPTION_TYPE_DEACTIVATE) { - ret = dict_set_int32 (dict, "hold_vol_locks", _gf_false); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Setting volume lock " - "flag failed"); - goto out; - } + w = str_getunamb(words[1], opwords); + if (!w) { + /* Checks if the operation is a valid operation */ + gf_log("", GF_LOG_ERROR, "Opword Mismatch"); + goto out; + } + + if (!strcmp(w, "create")) { + type = GF_SNAP_OPTION_TYPE_CREATE; + } else if (!strcmp(w, "list")) { + type = GF_SNAP_OPTION_TYPE_LIST; + } else if (!strcmp(w, "info")) { + type = GF_SNAP_OPTION_TYPE_INFO; + } else if (!strcmp(w, "delete")) { + type = GF_SNAP_OPTION_TYPE_DELETE; + } else if (!strcmp(w, "config")) { + type = GF_SNAP_OPTION_TYPE_CONFIG; + } else if (!strcmp(w, "restore")) { + type = GF_SNAP_OPTION_TYPE_RESTORE; + } else if (!strcmp(w, "status")) { + type = GF_SNAP_OPTION_TYPE_STATUS; + } else if (!strcmp(w, "activate")) { + type = GF_SNAP_OPTION_TYPE_ACTIVATE; + } else if (!strcmp(w, "deactivate")) { + type = GF_SNAP_OPTION_TYPE_DEACTIVATE; + } else if (!strcmp(w, "clone")) { + type = GF_SNAP_OPTION_TYPE_CLONE; + } + + if (type != GF_SNAP_OPTION_TYPE_CONFIG && + type != GF_SNAP_OPTION_TYPE_STATUS) { + ret = dict_set_int32(dict, "hold_snap_locks", _gf_true); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Unable to set hold-snap-locks value " + "as _gf_true"); + goto out; + } + } + + /* Following commands does not require volume locks */ + if (type == GF_SNAP_OPTION_TYPE_STATUS || + type == GF_SNAP_OPTION_TYPE_ACTIVATE || + type == GF_SNAP_OPTION_TYPE_DEACTIVATE) { + ret = dict_set_int32(dict, "hold_vol_locks", _gf_false); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Setting volume lock " + "flag failed"); + goto out; } + } - /* Check which op is intended */ - switch (type) { + /* Check which op is intended */ + switch (type) { case GF_SNAP_OPTION_TYPE_CREATE: - /* Syntax : - * gluster snapshot create - * [no-timestamp] - * [description ] - * [force] - */ - /* In cases where the snapname is not given then - * parsing fails & snapname cannot be "description", - * "force" and "volume", that check is made here - */ - if (wordcount == 2){ - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } + /* Syntax : + * gluster snapshot create + * [no-timestamp] + * [description ] + * [force] + */ + /* In cases where the snapname is not given then + * parsing fails & snapname cannot be "description", + * "force" and "volume", that check is made here + */ + if (wordcount == 2) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = validate_op_name ("snapname", words[2], - invalid_snapnames); - if (ret) { - goto out; - } + ret = validate_op_name("snapname", words[2], invalid_snapnames); + if (ret) { + goto out; + } - ret = cli_snap_create_parse (dict, words, wordcount); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, - "create command parsing failed."); - goto out; - } - break; + ret = cli_snap_create_parse(dict, words, wordcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "create command parsing failed."); + goto out; + } + break; case GF_SNAP_OPTION_TYPE_CLONE: - /* Syntax : - * gluster snapshot clone - */ - /* In cases where the clonename is not given then - * parsing fails & snapname cannot be "description", - * "force" and "volume", that check is made here - */ - if (wordcount == 2) { - ret = -1; - gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); - goto out; - } - - ret = validate_op_name ("clonename", words[2], - invalid_volnames); - if (ret) { - goto out; - } + /* Syntax : + * gluster snapshot clone + */ + /* In cases where the clonename is not given then + * parsing fails & snapname cannot be "description", + * "force" and "volume", that check is made here + */ + if (wordcount == 2) { + ret = -1; + gf_log("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } - ret = cli_snap_clone_parse (dict, words, wordcount); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, - "clone command parsing failed."); - goto out; - } - break; + ret = validate_op_name("clonename", words[2], invalid_volnames); + if (ret) { + goto out; + } + ret = cli_snap_clone_parse(dict, words, wordcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "clone command parsing failed."); + goto out; + } + break; case GF_SNAP_OPTION_TYPE_INFO: - /* Syntax : - * gluster snapshot info [(snapname] | [vol )] - */ - ret = cli_snap_info_parse (dict, words, wordcount); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse " - "snapshot info command"); - goto out; - } - break; + /* Syntax : + * gluster snapshot info [(snapname] | [vol )] + */ + ret = cli_snap_info_parse(dict, words, wordcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse " + "snapshot info command"); + goto out; + } + break; case GF_SNAP_OPTION_TYPE_LIST: - /* Syntax : - * gluster snaphsot list [volname] - */ + /* Syntax : + * gluster snaphsot list [volname] + */ - ret = cli_snap_list_parse (dict, words, wordcount); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse " - "snapshot list command"); - goto out; - } - break; + ret = cli_snap_list_parse(dict, words, wordcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse " + "snapshot list command"); + goto out; + } + break; case GF_SNAP_OPTION_TYPE_DELETE: - /* Syntax : - * snapshot delete (all | snapname | volume ) - */ - ret = cli_snap_delete_parse (dict, words, wordcount, state); - if (ret) { - /* A positive ret value means user cancelled - * the command */ - if (ret < 0) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse " - "snapshot delete command"); - } - goto out; + /* Syntax : + * snapshot delete (all | snapname | volume ) + */ + ret = cli_snap_delete_parse(dict, words, wordcount, state); + if (ret) { + /* A positive ret value means user cancelled + * the command */ + if (ret < 0) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse " + "snapshot delete command"); } - break; + goto out; + } + break; case GF_SNAP_OPTION_TYPE_CONFIG: - /* snapshot config [volname] [snap-max-hard-limit ] - * [snap-max-soft-limit ] */ - ret = cli_snap_config_parse (words, wordcount, dict, state); - if (ret) { - if (ret < 0) - gf_log ("cli", GF_LOG_ERROR, - "config command parsing failed."); - goto out; - } + /* snapshot config [volname] [snap-max-hard-limit ] + * [snap-max-soft-limit ] */ + ret = cli_snap_config_parse(words, wordcount, dict, state); + if (ret) { + if (ret < 0) + gf_log("cli", GF_LOG_ERROR, + "config command parsing failed."); + goto out; + } - ret = dict_set_int32 (dict, "type", GF_SNAP_OPTION_TYPE_CONFIG); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to set " - "config type"); - ret = -1; - goto out; - } - break; - - case GF_SNAP_OPTION_TYPE_STATUS: - { - /* Syntax : - * gluster snapshot status [(snapname | - * volume )] - */ - ret = cli_snap_status_parse (dict, words, wordcount); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse " - "snapshot status command"); - goto out; - } - break; - } + ret = dict_set_int32(dict, "type", GF_SNAP_OPTION_TYPE_CONFIG); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Unable to set " + "config type"); + ret = -1; + goto out; + } + break; + + case GF_SNAP_OPTION_TYPE_STATUS: { + /* Syntax : + * gluster snapshot status [(snapname | + * volume )] + */ + ret = cli_snap_status_parse(dict, words, wordcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse " + "snapshot status command"); + goto out; + } + break; + } case GF_SNAP_OPTION_TYPE_RESTORE: - /* Syntax: - * snapshot restore - */ - ret = cli_snap_restore_parse (dict, words, wordcount, state); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse " - "restore command"); - goto out; + /* Syntax: + * snapshot restore + */ + ret = cli_snap_restore_parse(dict, words, wordcount, state); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse " + "restore command"); + goto out; + } + break; + + case GF_SNAP_OPTION_TYPE_ACTIVATE: + /* Syntax: + * snapshot activate [force] + */ + ret = cli_snap_activate_parse(dict, words, wordcount); + if (ret) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse " + "start command"); + goto out; + } + break; + case GF_SNAP_OPTION_TYPE_DEACTIVATE: + /* Syntax: + * snapshot deactivate + */ + ret = cli_snap_deactivate_parse(dict, words, wordcount, state); + if (ret) { + /* A positive ret value means user cancelled + * the command */ + if (ret < 0) { + gf_log("cli", GF_LOG_ERROR, + "Failed to parse deactivate " + "command"); } - break; - - case GF_SNAP_OPTION_TYPE_ACTIVATE: - /* Syntax: - * snapshot activate [force] - */ - ret = cli_snap_activate_parse (dict, words, wordcount); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to parse " - "start command"); - goto out; - } - break; - case GF_SNAP_OPTION_TYPE_DEACTIVATE: - /* Syntax: - * snapshot deactivate - */ - ret = cli_snap_deactivate_parse (dict, words, wordcount, - state); - if (ret) { - /* A positive ret value means user cancelled - * the command */ - if (ret < 0) { - gf_log ("cli", GF_LOG_ERROR, - "Failed to parse deactivate " - "command"); - } - goto out; - } - break; + goto out; + } + break; default: - gf_log ("", GF_LOG_ERROR, "Opword Mismatch"); - goto out; - } + gf_log("", GF_LOG_ERROR, "Opword Mismatch"); + goto out; + } - ret = dict_set_int32 (dict, "type", type); - if (ret) { - gf_log ("", GF_LOG_ERROR, - "Failed to set type."); - goto out; - } - /* If you got so far, input is valid */ - ret = 0; + ret = dict_set_int32(dict, "type", type); + if (ret) { + gf_log("", GF_LOG_ERROR, "Failed to set type."); + goto out; + } + /* If you got so far, input is valid */ + ret = 0; out: - if (ret) { - if (dict) - dict_unref (dict); - } else - *options = dict; + if (ret) { + if (dict) + dict_unref(dict); + } else + *options = dict; - return ret; + return ret; } int -cli_cmd_validate_volume (char *volname) +cli_cmd_validate_volume(char *volname) { - int i = 0; - int ret = -1; - int volname_len; + int i = 0; + int ret = -1; + int volname_len; + if (volname[0] == '-') + return ret; - if (volname[0] == '-') - return ret; + if (!strcmp(volname, "all")) { + cli_err("\"all\" cannot be the name of a volume."); + return ret; + } - if (!strcmp (volname, "all")) { - cli_err ("\"all\" cannot be the name of a volume."); - return ret; - } + if (strchr(volname, '/')) { + cli_err("Volume name should not contain \"/\" character."); + return ret; + } - if (strchr (volname, '/')) { - cli_err ("Volume name should not contain \"/\" character."); - return ret; - } + volname_len = strlen(volname); + if (volname_len > GD_VOLUME_NAME_MAX) { + cli_err("Volname can not exceed %d characters.", GD_VOLUME_NAME_MAX); + return ret; + } - volname_len = strlen (volname); - if (volname_len > GD_VOLUME_NAME_MAX) { - cli_err ("Volname can not exceed %d characters.", - GD_VOLUME_NAME_MAX); - return ret; + for (i = 0; i < volname_len; i++) + if (!isalnum(volname[i]) && (volname[i] != '_') && + (volname[i] != '-')) { + cli_err( + "Volume name should not contain \"%c\"" + " character.\nVolume names can only" + "contain alphanumeric, '-' and '_' " + "characters.", + volname[i]); + return ret; } - for (i = 0; i < volname_len ; i++) - if (!isalnum (volname[i]) && (volname[i] != '_') && - (volname[i] != '-')) { - cli_err ("Volume name should not contain \"%c\"" - " character.\nVolume names can only" - "contain alphanumeric, '-' and '_' " - "characters.", volname[i]); - return ret; - } - - ret = 0; + ret = 0; - return ret; + return ret; } int32_t -cli_cmd_bitrot_parse (const char **words, int wordcount, dict_t **options) +cli_cmd_bitrot_parse(const char **words, int wordcount, dict_t **options) { - int32_t ret = -1; - char *w = NULL; - char *volname = NULL; - char *opwords[] = {"enable", "disable", - "scrub-throttle", - "scrub-frequency", "scrub", - "signing-time", NULL}; - char *scrub_throt_values[] = {"lazy", "normal", - "aggressive", NULL}; - char *scrub_freq_values[] = {"hourly", - "daily", "weekly", - "biweekly", "monthly", - "minute", NULL}; - char *scrub_values[] = {"pause", "resume", - "status", "ondemand", - NULL}; - dict_t *dict = NULL; - gf_bitrot_type type = GF_BITROT_OPTION_TYPE_NONE; - int32_t expiry_time = 0; - - GF_ASSERT (words); - GF_ASSERT (options); - - - /* Hack to print out bitrot help properly */ - if ((wordcount == 3) && !(strcmp (words[2], "help"))) { - ret = 1; - return ret; - } - - if (wordcount < 4 || wordcount > 5) { - gf_log ("cli", GF_LOG_ERROR, "Invalid syntax"); - goto out; - } + int32_t ret = -1; + char *w = NULL; + char *volname = NULL; + char *opwords[] = { + "enable", "disable", "scrub-throttle", "scrub-frequency", "scrub", + "signing-time", NULL}; + char *scrub_throt_values[] = {"lazy", "normal", "aggressive", NULL}; + char *scrub_freq_values[] = {"hourly", "daily", "weekly", "biweekly", + "monthly", "minute", NULL}; + char *scrub_values[] = {"pause", "resume", "status", "ondemand", NULL}; + dict_t *dict = NULL; + gf_bitrot_type type = GF_BITROT_OPTION_TYPE_NONE; + int32_t expiry_time = 0; + + GF_ASSERT(words); + GF_ASSERT(options); + + /* Hack to print out bitrot help properly */ + if ((wordcount == 3) && !(strcmp(words[2], "help"))) { + ret = 1; + return ret; + } - dict = dict_new (); - if (!dict) - goto out; + if (wordcount < 4 || wordcount > 5) { + gf_log("cli", GF_LOG_ERROR, "Invalid syntax"); + goto out; + } - volname = (char *)words[2]; - if (!volname) { - ret = -1; - goto out; - } + dict = dict_new(); + if (!dict) + goto out; - ret = cli_cmd_validate_volume (volname); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to validate volume name"); - goto out; - } + volname = (char *)words[2]; + if (!volname) { + ret = -1; + goto out; + } - ret = dict_set_str (dict, "volname", volname); - if (ret) { - cli_out ("Failed to set volume name in dictionary "); - goto out; - } + ret = cli_cmd_validate_volume(volname); + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Failed to validate volume name"); + goto out; + } - w = str_getunamb (words[3], opwords); - if (!w) { - cli_out ("Invalid bit rot option : %s", words[3]); - ret = -1; - goto out; - } + ret = dict_set_str(dict, "volname", volname); + if (ret) { + cli_out("Failed to set volume name in dictionary "); + goto out; + } - if (strcmp (w, "enable") == 0) { - if (wordcount == 4) { - type = GF_BITROT_OPTION_TYPE_ENABLE; - ret = 0; - goto set_type; - } else { - ret = -1; - goto out; - } - } + w = str_getunamb(words[3], opwords); + if (!w) { + cli_out("Invalid bit rot option : %s", words[3]); + ret = -1; + goto out; + } - if (strcmp (w, "disable") == 0) { - if (wordcount == 4) { - type = GF_BITROT_OPTION_TYPE_DISABLE; - ret = 0; - goto set_type; - } else { - ret = -1; - goto out; - } + if (strcmp(w, "enable") == 0) { + if (wordcount == 4) { + type = GF_BITROT_OPTION_TYPE_ENABLE; + ret = 0; + goto set_type; + } else { + ret = -1; + goto out; } + } - if (!strcmp (w, "scrub-throttle")) { - if (!words[4]) { - cli_err ("Missing scrub-throttle value for bitrot " - "option"); - ret = -1; - goto out; - } else { - w = str_getunamb (words[4], scrub_throt_values); - if (!w) { - cli_err ("Invalid scrub-throttle option for " - "bitrot"); - ret = -1; - goto out; - } else { - type = GF_BITROT_OPTION_TYPE_SCRUB_THROTTLE; - ret = dict_set_str (dict, - "scrub-throttle-value", - (char *) words[4]); - if (ret) { - cli_out ("Failed to set scrub-throttle " - "value in the dict"); - goto out; - } - goto set_type; - } + if (strcmp(w, "disable") == 0) { + if (wordcount == 4) { + type = GF_BITROT_OPTION_TYPE_DISABLE; + ret = 0; + goto set_type; + } else { + ret = -1; + goto out; + } + } + + if (!strcmp(w, "scrub-throttle")) { + if (!words[4]) { + cli_err( + "Missing scrub-throttle value for bitrot " + "option"); + ret = -1; + goto out; + } else { + w = str_getunamb(words[4], scrub_throt_values); + if (!w) { + cli_err( + "Invalid scrub-throttle option for " + "bitrot"); + ret = -1; + goto out; + } else { + type = GF_BITROT_OPTION_TYPE_SCRUB_THROTTLE; + ret = dict_set_str(dict, "scrub-throttle-value", + (char *)words[4]); + if (ret) { + cli_out( + "Failed to set scrub-throttle " + "value in the dict"); + goto out; } + goto set_type; + } } + } - if (!strcmp (words[3], "scrub-frequency")) { - if (!words[4]) { - cli_err ("Missing scrub-frequency value"); - ret = -1; - goto out; - } else { - w = str_getunamb (words[4], scrub_freq_values); - if (!w) { - cli_err ("Invalid frequency option for bitrot"); - ret = -1; - goto out; - } else { - type = GF_BITROT_OPTION_TYPE_SCRUB_FREQ; - ret = dict_set_str (dict, - "scrub-frequency-value", - (char *) words[4]); - if (ret) { - cli_out ("Failed to set dict for " - "bitrot"); - goto out; - } - goto set_type; - } + if (!strcmp(words[3], "scrub-frequency")) { + if (!words[4]) { + cli_err("Missing scrub-frequency value"); + ret = -1; + goto out; + } else { + w = str_getunamb(words[4], scrub_freq_values); + if (!w) { + cli_err("Invalid frequency option for bitrot"); + ret = -1; + goto out; + } else { + type = GF_BITROT_OPTION_TYPE_SCRUB_FREQ; + ret = dict_set_str(dict, "scrub-frequency-value", + (char *)words[4]); + if (ret) { + cli_out( + "Failed to set dict for " + "bitrot"); + goto out; } + goto set_type; + } } + } - if (!strcmp (words[3], "scrub")) { - if (!words[4]) { - cli_err ("Missing scrub value for bitrot option"); - ret = -1; - goto out; + if (!strcmp(words[3], "scrub")) { + if (!words[4]) { + cli_err("Missing scrub value for bitrot option"); + ret = -1; + goto out; + } else { + w = str_getunamb(words[4], scrub_values); + if (!w) { + cli_err("Invalid scrub option for bitrot"); + ret = -1; + goto out; + } else { + if (strcmp(words[4], "status") == 0) { + type = GF_BITROT_CMD_SCRUB_STATUS; + } else if (strcmp(words[4], "ondemand") == 0) { + type = GF_BITROT_CMD_SCRUB_ONDEMAND; } else { - w = str_getunamb (words[4], scrub_values); - if (!w) { - cli_err ("Invalid scrub option for bitrot"); - ret = -1; - goto out; - } else { - if (strcmp (words[4], "status") == 0) { - type = GF_BITROT_CMD_SCRUB_STATUS; - } else if (strcmp (words[4], "ondemand") == 0) { - type = GF_BITROT_CMD_SCRUB_ONDEMAND; - } else { - type = GF_BITROT_OPTION_TYPE_SCRUB; - } - ret = dict_set_str (dict, "scrub-value", - (char *) words[4]); - if (ret) { - cli_out ("Failed to set dict for " - "bitrot"); - goto out; - } - goto set_type; - } + type = GF_BITROT_OPTION_TYPE_SCRUB; } + ret = dict_set_str(dict, "scrub-value", (char *)words[4]); + if (ret) { + cli_out( + "Failed to set dict for " + "bitrot"); + goto out; + } + goto set_type; + } } + } - if (!strcmp (words[3], "signing-time")) { - if (!words[4]) { - cli_err ("Missing signing-time value for bitrot " - "option"); - ret = -1; - goto out; - } else { - type = GF_BITROT_OPTION_TYPE_EXPIRY_TIME; - - expiry_time = strtol (words[4], NULL, 0); - if (expiry_time < 1) { - cli_err ("Expiry time value should not be less" - " than 1"); - ret = -1; - goto out; - } - - ret = dict_set_uint32 (dict, "expiry-time", - (unsigned int) expiry_time); - if (ret) { - cli_out ("Failed to set dict for bitrot"); - goto out; - } - goto set_type; - } + if (!strcmp(words[3], "signing-time")) { + if (!words[4]) { + cli_err( + "Missing signing-time value for bitrot " + "option"); + ret = -1; + goto out; } else { - cli_err ("Invalid option %s for bitrot. Please enter valid " - "bitrot option", words[3]); + type = GF_BITROT_OPTION_TYPE_EXPIRY_TIME; + + expiry_time = strtol(words[4], NULL, 0); + if (expiry_time < 1) { + cli_err( + "Expiry time value should not be less" + " than 1"); ret = -1; goto out; + } + + ret = dict_set_uint32(dict, "expiry-time", + (unsigned int)expiry_time); + if (ret) { + cli_out("Failed to set dict for bitrot"); + goto out; + } + goto set_type; } + } else { + cli_err( + "Invalid option %s for bitrot. Please enter valid " + "bitrot option", + words[3]); + ret = -1; + goto out; + } set_type: - ret = dict_set_int32 (dict, "type", type); - if (ret < 0) - goto out; + ret = dict_set_int32(dict, "type", type); + if (ret < 0) + goto out; - *options = dict; + *options = dict; out: - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Unable to parse bitrot command"); - if (dict) - dict_unref (dict); - } + if (ret) { + gf_log("cli", GF_LOG_ERROR, "Unable to parse bitrot command"); + if (dict) + dict_unref(dict); + } - return ret; + return ret; } diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c index a50ea7c66b5..e0a38904a81 100644 --- a/cli/src/cli-cmd-peer.c +++ b/cli/src/cli-cmd-peer.c @@ -24,292 +24,282 @@ extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; -int cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, +int +cli_cmd_peer_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount); int -cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_peer_probe_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - dict_t *dict = NULL; - int sent = 0; - int parse_error = 0; - cli_local_t *local = NULL; - - if (!(wordcount == 3)) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROBE]; - - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_set_str (dict, "hostname", (char *)words[2]); - if (ret) - goto out; - - ret = valid_internet_address ((char *) words[2], _gf_false); - if (ret == 1) { - ret = 0; - } else { - cli_out ("%s is an invalid address", words[2]); - cli_usage_out (word->pattern); - parse_error = 1; - ret = -1; - goto out; - } -/* if (words[3]) { - ret = dict_set_str (dict, "port", (char *)words[3]); - if (ret) - goto out; - } -*/ - - CLI_LOCAL_INIT (local, words, frame, dict); - - if (proc->fn) { - ret = proc->fn (frame, THIS, dict); - } + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *dict = NULL; + int sent = 0; + int parse_error = 0; + cli_local_t *local = NULL; + + if (!(wordcount == 3)) { + cli_usage_out(word->pattern); + parse_error = 1; + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROBE]; + + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + + dict = dict_new(); + if (!dict) + goto out; + + ret = dict_set_str(dict, "hostname", (char *)words[2]); + if (ret) + goto out; + + ret = valid_internet_address((char *)words[2], _gf_false); + if (ret == 1) { + ret = 0; + } else { + cli_out("%s is an invalid address", words[2]); + cli_usage_out(word->pattern); + parse_error = 1; + ret = -1; + goto out; + } + /* if (words[3]) { + ret = dict_set_str (dict, "port", (char *)words[3]); + if (ret) + goto out; + } + */ + + CLI_LOCAL_INIT(local, words, frame, dict); + + if (proc->fn) { + ret = proc->fn(frame, THIS, dict); + } out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("Peer probe failed"); - } + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out("Peer probe failed"); + } - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - if (ret == 0) { - gf_event (EVENT_PEER_ATTACH, "host=%s", (char *)words[2]); - } + if (ret == 0) { + gf_event(EVENT_PEER_ATTACH, "host=%s", (char *)words[2]); + } - return ret; + return ret; } - int -cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_peer_deprobe_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - dict_t *dict = NULL; - int flags = 0; - int sent = 0; - int parse_error = 0; - cli_local_t *local = NULL; - - if ((wordcount < 3) || (wordcount > 4)) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *dict = NULL; + int flags = 0; + int sent = 0; + int parse_error = 0; + cli_local_t *local = NULL; + + if ((wordcount < 3) || (wordcount > 4)) { + cli_usage_out(word->pattern); + parse_error = 1; + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEPROBE]; + + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + + dict = dict_new(); + + ret = dict_set_str(dict, "hostname", (char *)words[2]); + if (ret) + goto out; + + /* if (words[3]) { + ret = dict_set_str (dict, "port", (char *)words[3]); + if (ret) + goto out; + } + */ + if (wordcount == 4) { + if (!strcmp("force", words[3])) + flags |= GF_CLI_FLAG_OP_FORCE; + else { + ret = -1; + cli_usage_out(word->pattern); + parse_error = 1; + goto out; } + } + ret = dict_set_int32(dict, "flags", flags); + if (ret) + goto out; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEPROBE]; + CLI_LOCAL_INIT(local, words, frame, dict); - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - - dict = dict_new (); - - ret = dict_set_str (dict, "hostname", (char *)words[2]); - if (ret) - goto out; - -/* if (words[3]) { - ret = dict_set_str (dict, "port", (char *)words[3]); - if (ret) - goto out; - } -*/ - if (wordcount == 4) { - if (!strcmp("force", words[3])) - flags |= GF_CLI_FLAG_OP_FORCE; - else { - ret = -1; - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - } - ret = dict_set_int32 (dict, "flags", flags); - if (ret) - goto out; - - CLI_LOCAL_INIT (local, words, frame, dict); - - if (proc->fn) { - ret = proc->fn (frame, THIS, dict); - } + if (proc->fn) { + ret = proc->fn(frame, THIS, dict); + } out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("Peer detach failed"); - } + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out("Peer detach failed"); + } - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - if (ret == 0) { - gf_event (EVENT_PEER_DETACH, "host=%s", (char *)words[2]); - } + if (ret == 0) { + gf_event(EVENT_PEER_DETACH, "host=%s", (char *)words[2]); + } - return ret; + return ret; } int -cli_cmd_peer_status_cbk (struct cli_state *state, struct cli_cmd_word *word, +cli_cmd_peer_status_cbk(struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - int sent = 0; - int parse_error = 0; - - if (wordcount != 2) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + int sent = 0; + int parse_error = 0; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_FRIENDS]; + if (wordcount != 2) { + cli_usage_out(word->pattern); + parse_error = 1; + goto out; + } - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_FRIENDS]; - if (proc->fn) { - ret = proc->fn (frame, THIS, (void *)GF_CLI_LIST_PEERS); - } + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + + if (proc->fn) { + ret = proc->fn(frame, THIS, (void *)GF_CLI_LIST_PEERS); + } out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("Peer status failed"); - } + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out("Peer status failed"); + } - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - return ret; + return ret; } int -cli_cmd_pool_list_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_pool_list_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - int sent = 0; - int parse_error = 0; - - if (wordcount != 2) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + int sent = 0; + int parse_error = 0; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_FRIENDS]; + if (wordcount != 2) { + cli_usage_out(word->pattern); + parse_error = 1; + goto out; + } - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LIST_FRIENDS]; - if (proc->fn) { - ret = proc->fn (frame, THIS, - (void *)GF_CLI_LIST_POOL_NODES); - } + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + + if (proc->fn) { + ret = proc->fn(frame, THIS, (void *)GF_CLI_LIST_POOL_NODES); + } out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_err ("pool list: command execution failed"); - } + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_err("pool list: command execution failed"); + } - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - return ret; + return ret; } struct cli_cmd cli_probe_cmds[] = { - { "peer probe { | }", - cli_cmd_peer_probe_cbk, - "probe peer specified by "}, + {"peer probe { | }", cli_cmd_peer_probe_cbk, + "probe peer specified by "}, - { "peer detach { | } [force]", - cli_cmd_peer_deprobe_cbk, - "detach peer specified by "}, + {"peer detach { | } [force]", + cli_cmd_peer_deprobe_cbk, "detach peer specified by "}, - { "peer status", - cli_cmd_peer_status_cbk, - "list status of peers"}, + {"peer status", cli_cmd_peer_status_cbk, "list status of peers"}, - { "peer help", - cli_cmd_peer_help_cbk, - "display help for peer commands"}, + {"peer help", cli_cmd_peer_help_cbk, "display help for peer commands"}, - { "pool list", - cli_cmd_pool_list_cbk, - "list all the nodes in the pool (including localhost)"}, + {"pool list", cli_cmd_pool_list_cbk, + "list all the nodes in the pool (including localhost)"}, - { NULL, NULL, NULL } -}; + {NULL, NULL, NULL}}; int -cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, +cli_cmd_peer_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, const char **words, int wordcount) { - struct cli_cmd *cmd = NULL; - struct cli_cmd *probe_cmd = NULL; - int count = 0; + struct cli_cmd *cmd = NULL; + struct cli_cmd *probe_cmd = NULL; + int count = 0; - cli_out ("\ngluster peer commands"); - cli_out ("======================\n"); + cli_out("\ngluster peer commands"); + cli_out("======================\n"); - cmd = GF_MALLOC (sizeof (cli_probe_cmds), cli_mt_cli_cmd); - memcpy (cmd, cli_probe_cmds, sizeof (cli_probe_cmds)); - count = (sizeof (cli_probe_cmds) / sizeof (struct cli_cmd)); - cli_cmd_sort (cmd, count); + cmd = GF_MALLOC(sizeof(cli_probe_cmds), cli_mt_cli_cmd); + memcpy(cmd, cli_probe_cmds, sizeof(cli_probe_cmds)); + count = (sizeof(cli_probe_cmds) / sizeof(struct cli_cmd)); + cli_cmd_sort(cmd, count); - for (probe_cmd = cmd; probe_cmd->pattern; probe_cmd++) - cli_out ("%s - %s", probe_cmd->pattern, probe_cmd->desc); + for (probe_cmd = cmd; probe_cmd->pattern; probe_cmd++) + cli_out("%s - %s", probe_cmd->pattern, probe_cmd->desc); - GF_FREE (cmd); + GF_FREE(cmd); - cli_out ("\n"); - return 0; + cli_out("\n"); + return 0; } int -cli_cmd_probe_register (struct cli_state *state) +cli_cmd_probe_register(struct cli_state *state) { - int ret = 0; - struct cli_cmd *cmd = NULL; - - for (cmd = cli_probe_cmds; cmd->pattern; cmd++) { + int ret = 0; + struct cli_cmd *cmd = NULL; - ret = cli_cmd_register (&state->tree, cmd); - if (ret) - goto out; - } + for (cmd = cli_probe_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register(&state->tree, cmd); + if (ret) + goto out; + } out: - return ret; + return ret; } diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index 64cbd42ce5a..814ab82f6eb 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -20,146 +20,118 @@ extern rpc_clnt_prog_t *cli_rpc_prog; int -cli_cmd_snapshot_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount); +cli_cmd_snapshot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); int -cli_cmd_snapshot_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_snapshot_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = 0; - int parse_err = 0; - dict_t *options = NULL; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - cli_local_t *local = NULL; - - proc = &cli_rpc_prog->proctable [GLUSTER_CLI_SNAP]; - - frame = create_frame (THIS, THIS->ctx->pool); - if (frame == NULL) { - ret = -1; - goto out; + int ret = 0; + int parse_err = 0; + dict_t *options = NULL; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + cli_local_t *local = NULL; + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SNAP]; + + frame = create_frame(THIS, THIS->ctx->pool); + if (frame == NULL) { + ret = -1; + goto out; + } + + /* Parses the command entered by the user */ + ret = cli_cmd_snapshot_parse(words, wordcount, &options, state); + if (ret) { + if (ret < 0) { + cli_usage_out(word->pattern); + parse_err = 1; + } else { + /* User might have cancelled the snapshot operation */ + ret = 0; } + goto out; + } - /* Parses the command entered by the user */ - ret = cli_cmd_snapshot_parse (words, wordcount, &options, state); - if (ret) { - if (ret < 0) { - cli_usage_out (word->pattern); - parse_err = 1; - } else { - /* User might have cancelled the snapshot operation */ - ret = 0; - } - goto out; - } - - CLI_LOCAL_INIT (local, words, frame, options); + CLI_LOCAL_INIT(local, words, frame, options); - if (proc->fn) - ret = proc->fn (frame, THIS, options); + if (proc->fn) + ret = proc->fn(frame, THIS, options); out: - if (ret && parse_err == 0) - cli_out ("Snapshot command failed"); + if (ret && parse_err == 0) + cli_out("Snapshot command failed"); - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - return ret; + return ret; } struct cli_cmd snapshot_cmds[] = { - { "snapshot help", - cli_cmd_snapshot_help_cbk, - "display help for snapshot commands" - }, - { "snapshot create [no-timestamp] " - "[description ] [force]", - cli_cmd_snapshot_cbk, - "Snapshot Create." - }, - { "snapshot clone ", - cli_cmd_snapshot_cbk, - "Snapshot Clone." - }, - { "snapshot restore ", - cli_cmd_snapshot_cbk, - "Snapshot Restore." - }, - { "snapshot status [(snapname | volume )]", - cli_cmd_snapshot_cbk, - "Snapshot Status." - }, - { "snapshot info [(snapname | volume )]", - cli_cmd_snapshot_cbk, - "Snapshot Info." - }, - { "snapshot list [volname]", - cli_cmd_snapshot_cbk, - "Snapshot List." - }, - {"snapshot config [volname] ([snap-max-hard-limit ] " - "[snap-max-soft-limit ]) " - "| ([auto-delete ])" - "| ([activate-on-create ])", - cli_cmd_snapshot_cbk, - "Snapshot Config." - }, - {"snapshot delete (all | snapname | volume )", - cli_cmd_snapshot_cbk, - "Snapshot Delete." - }, - {"snapshot activate [force]", - cli_cmd_snapshot_cbk, - "Activate snapshot volume." - }, - {"snapshot deactivate ", - cli_cmd_snapshot_cbk, - "Deactivate snapshot volume." - }, - { NULL, NULL, NULL } -}; + {"snapshot help", cli_cmd_snapshot_help_cbk, + "display help for snapshot commands"}, + {"snapshot create [no-timestamp] " + "[description ] [force]", + cli_cmd_snapshot_cbk, "Snapshot Create."}, + {"snapshot clone ", cli_cmd_snapshot_cbk, + "Snapshot Clone."}, + {"snapshot restore ", cli_cmd_snapshot_cbk, "Snapshot Restore."}, + {"snapshot status [(snapname | volume )]", cli_cmd_snapshot_cbk, + "Snapshot Status."}, + {"snapshot info [(snapname | volume )]", cli_cmd_snapshot_cbk, + "Snapshot Info."}, + {"snapshot list [volname]", cli_cmd_snapshot_cbk, "Snapshot List."}, + {"snapshot config [volname] ([snap-max-hard-limit ] " + "[snap-max-soft-limit ]) " + "| ([auto-delete ])" + "| ([activate-on-create ])", + cli_cmd_snapshot_cbk, "Snapshot Config."}, + {"snapshot delete (all | snapname | volume )", + cli_cmd_snapshot_cbk, "Snapshot Delete."}, + {"snapshot activate [force]", cli_cmd_snapshot_cbk, + "Activate snapshot volume."}, + {"snapshot deactivate ", cli_cmd_snapshot_cbk, + "Deactivate snapshot volume."}, + {NULL, NULL, NULL}}; int -cli_cmd_snapshot_help_cbk (struct cli_state *state, - struct cli_cmd_word *in_word, - const char **words, - int wordcount) +cli_cmd_snapshot_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount) { - struct cli_cmd *cmd = NULL; - struct cli_cmd *snap_cmd = NULL; - int count = 0; + struct cli_cmd *cmd = NULL; + struct cli_cmd *snap_cmd = NULL; + int count = 0; - cmd = GF_MALLOC (sizeof (snapshot_cmds), cli_mt_cli_cmd); - memcpy (cmd, snapshot_cmds, sizeof (snapshot_cmds)); - count = (sizeof (snapshot_cmds) / sizeof (struct cli_cmd)); - cli_cmd_sort (cmd, count); + cmd = GF_MALLOC(sizeof(snapshot_cmds), cli_mt_cli_cmd); + memcpy(cmd, snapshot_cmds, sizeof(snapshot_cmds)); + count = (sizeof(snapshot_cmds) / sizeof(struct cli_cmd)); + cli_cmd_sort(cmd, count); - cli_out ("\ngluster snapshot commands"); - cli_out ("=========================\n"); + cli_out("\ngluster snapshot commands"); + cli_out("=========================\n"); - for (snap_cmd = cmd; snap_cmd->pattern; snap_cmd++) - if (_gf_false == snap_cmd->disable) - cli_out ("%s - %s", snap_cmd->pattern, snap_cmd->desc); - cli_out ("\n"); + for (snap_cmd = cmd; snap_cmd->pattern; snap_cmd++) + if (_gf_false == snap_cmd->disable) + cli_out("%s - %s", snap_cmd->pattern, snap_cmd->desc); + cli_out("\n"); - GF_FREE (cmd); - return 0; + GF_FREE(cmd); + return 0; } int -cli_cmd_snapshot_register (struct cli_state *state) +cli_cmd_snapshot_register(struct cli_state *state) { - int ret = 0; - struct cli_cmd *cmd = NULL; - - for (cmd = snapshot_cmds; cmd->pattern; cmd++) { - - ret = cli_cmd_register (&state->tree, cmd); - if (ret) - goto out; - } + int ret = 0; + struct cli_cmd *cmd = NULL; + + for (cmd = snapshot_cmds; cmd->pattern; cmd++) { + ret = cli_cmd_register(&state->tree, cmd); + if (ret) + goto out; + } out: - return ret; + return ret; } diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c index 995e1b1ad5c..96b229582fb 100644 --- a/cli/src/cli-cmd-system.c +++ b/cli/src/cli-cmd-system.c @@ -18,604 +18,587 @@ #include "cli-mem-types.h" #include "protocol-common.h" - extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; -int cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount); +int +cli_cmd_system_help_cbk(struct cli_state *state, struct cli_cmd_word *in_word, + const char **words, int wordcount); -int cli_cmd_copy_file_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount); +int +cli_cmd_copy_file_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount); -int cli_cmd_sys_exec_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount); +int +cli_cmd_sys_exec_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount); int -cli_cmd_getspec_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_getspec_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - dict_t *dict = NULL; + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *dict = NULL; - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - if (wordcount != 3) { - cli_usage_out (word->pattern); - goto out; - } + if (wordcount != 3) { + cli_usage_out(word->pattern); + goto out; + } - ret = dict_set_str (dict, "volid", (char *)words[2]); - if (ret) - goto out; + ret = dict_set_str(dict, "volid", (char *)words[2]); + if (ret) + goto out; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETSPEC]; - if (proc->fn) { - ret = proc->fn (frame, THIS, dict); - } + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETSPEC]; + if (proc->fn) { + ret = proc->fn(frame, THIS, dict); + } out: - if (!proc && ret) { - if (dict) - dict_unref (dict); - if (wordcount > 1) - cli_out ("Fetching spec for volume %s failed", - (char *)words[2]); - } + if (!proc && ret) { + if (dict) + dict_unref(dict); + if (wordcount > 1) + cli_out("Fetching spec for volume %s failed", (char *)words[2]); + } - return ret; + return ret; } int -cli_cmd_pmap_b2p_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_pmap_b2p_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - dict_t *dict = NULL; + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *dict = NULL; - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; - dict = dict_new (); - if (!dict) - goto out; + dict = dict_new(); + if (!dict) + goto out; - if (wordcount != 4) { - cli_usage_out (word->pattern); - goto out; - } + if (wordcount != 4) { + cli_usage_out(word->pattern); + goto out; + } - ret = dict_set_str (dict, "brick", (char *)words[3]); - if (ret) - goto out; + ret = dict_set_str(dict, "brick", (char *)words[3]); + if (ret) + goto out; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PMAP_PORTBYBRICK]; - if (proc->fn) { - ret = proc->fn (frame, THIS, dict); - } + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PMAP_PORTBYBRICK]; + if (proc->fn) { + ret = proc->fn(frame, THIS, dict); + } out: - if (!proc && ret) { - if (dict) - dict_unref (dict); - if (wordcount > 1) - cli_out ("Fetching spec for volume %s failed", - (char *)words[3]); - } + if (!proc && ret) { + if (dict) + dict_unref(dict); + if (wordcount > 1) + cli_out("Fetching spec for volume %s failed", (char *)words[3]); + } - return ret; + return ret; } int -cli_cmd_fsm_log_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_fsm_log_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - char *name = ""; - - if ((wordcount != 4) && (wordcount != 3)) { - cli_usage_out (word->pattern); - goto out; - } - - if (wordcount == 4) - name = (char*)words[3]; - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_FSM_LOG]; - if (proc && proc->fn) { - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - ret = proc->fn (frame, THIS, (void*)name); - } + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + char *name = ""; + + if ((wordcount != 4) && (wordcount != 3)) { + cli_usage_out(word->pattern); + goto out; + } + + if (wordcount == 4) + name = (char *)words[3]; + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_FSM_LOG]; + if (proc && proc->fn) { + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + ret = proc->fn(frame, THIS, (void *)name); + } out: - return ret; + return ret; } int -cli_cmd_getwd_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_getwd_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - - if (wordcount != 2) { - cli_usage_out (word->pattern); - goto out; - } - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETWD]; - if (proc && proc->fn) { - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - ret = proc->fn (frame, THIS, NULL); - } + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + + if (wordcount != 2) { + cli_usage_out(word->pattern); + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_GETWD]; + if (proc && proc->fn) { + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + ret = proc->fn(frame, THIS, NULL); + } out: - return ret; + return ret; } static dict_t * -make_seq_dict (int argc, char **argv) +make_seq_dict(int argc, char **argv) { - char index[] = "4294967296"; // 1<<32 - int i = 0; - int ret = 0; - dict_t *dict = dict_new (); - - if (!dict) - return NULL; - - for (i = 0; i < argc; i++) { - snprintf(index, sizeof(index), "%d", i); - ret = dict_set_str (dict, index, argv[i]); - if (ret == -1) - break; - } - - if (ret) { - dict_unref (dict); - dict = NULL; - } - - return dict; + char index[] = "4294967296"; // 1<<32 + int i = 0; + int ret = 0; + dict_t *dict = dict_new(); + + if (!dict) + return NULL; + + for (i = 0; i < argc; i++) { + snprintf(index, sizeof(index), "%d", i); + ret = dict_set_str(dict, index, argv[i]); + if (ret == -1) + break; + } + + if (ret) { + dict_unref(dict); + dict = NULL; + } + + return dict; } int -cli_cmd_mount_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_mount_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - int ret = -1; - dict_t *dict = NULL; - void *dataa[] = {NULL, NULL}; - - if (wordcount < 4) { - cli_usage_out (word->pattern); - goto out; - } - - dict = make_seq_dict (wordcount - 3, (char **)words + 3); - if (!dict) - goto out; - - dataa[0] = (void *)words[2]; - dataa[1] = dict; - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_MOUNT]; - if (proc && proc->fn) { - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - ret = proc->fn (frame, THIS, dataa); - } + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + int ret = -1; + dict_t *dict = NULL; + void *dataa[] = {NULL, NULL}; + + if (wordcount < 4) { + cli_usage_out(word->pattern); + goto out; + } + + dict = make_seq_dict(wordcount - 3, (char **)words + 3); + if (!dict) + goto out; + + dataa[0] = (void *)words[2]; + dataa[1] = dict; + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_MOUNT]; + if (proc && proc->fn) { + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + ret = proc->fn(frame, THIS, dataa); + } - out: - if (dict) - dict_unref (dict); +out: + if (dict) + dict_unref(dict); - if (!proc && ret) - cli_out ("Mount command failed"); + if (!proc && ret) + cli_out("Mount command failed"); - return ret; + return ret; } int -cli_cmd_umount_cbk (struct cli_state *state, struct cli_cmd_word *word, +cli_cmd_umount_cbk(struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) { - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - int ret = -1; - dict_t *dict = NULL; - - if (!(wordcount == 3 || - (wordcount == 4 && strcmp (words[3], "lazy") == 0))) { - cli_usage_out (word->pattern); - goto out; - } - - dict = dict_new (); - if (!dict) - goto out; - - ret = dict_set_str (dict, "path", (char *)words[2]); - if (ret != 0) - goto out; - ret = dict_set_int32 (dict, "lazy", wordcount == 4); - if (ret != 0) - goto out; - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT]; - if (proc && proc->fn) { - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - ret = proc->fn (frame, THIS, dict); - } + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + int ret = -1; + dict_t *dict = NULL; + + if (!(wordcount == 3 || + (wordcount == 4 && strcmp(words[3], "lazy") == 0))) { + cli_usage_out(word->pattern); + goto out; + } + + dict = dict_new(); + if (!dict) + goto out; + + ret = dict_set_str(dict, "path", (char *)words[2]); + if (ret != 0) + goto out; + ret = dict_set_int32(dict, "lazy", wordcount == 4); + if (ret != 0) + goto out; + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT]; + if (proc && proc->fn) { + frame = create_frame(THIS, THIS->ctx->pool); + if (!frame) + goto out; + ret = proc->fn(frame, THIS, dict); + } - out: - if (dict) - dict_unref (dict); +out: + if (dict) + dict_unref(dict); - if (!proc && ret) - cli_out ("Umount command failed"); + if (!proc && ret) + cli_out("Umount command failed"); - return ret; + return ret; } int -cli_cmd_uuid_get_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_uuid_get_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - int sent = 0; - int parse_error = 0; - dict_t *dict = NULL; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - cli_local_t *local = NULL; - xlator_t *this = NULL; - - this = THIS; - if (wordcount != 3) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UUID_GET]; - frame = create_frame (this, this->ctx->pool); - if (!frame) - goto out; - - dict = dict_new (); - if (!dict) - goto out; - - CLI_LOCAL_INIT (local, words, frame, dict); - if (proc->fn) - ret = proc->fn (frame, this, dict); + int ret = -1; + int sent = 0; + int parse_error = 0; + dict_t *dict = NULL; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + cli_local_t *local = NULL; + xlator_t *this = NULL; + + this = THIS; + if (wordcount != 3) { + cli_usage_out(word->pattern); + parse_error = 1; + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UUID_GET]; + frame = create_frame(this, this->ctx->pool); + if (!frame) + goto out; + + dict = dict_new(); + if (!dict) + goto out; + + CLI_LOCAL_INIT(local, words, frame, dict); + if (proc->fn) + ret = proc->fn(frame, this, dict); out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("uuid get failed"); - } - - CLI_STACK_DESTROY (frame); - return ret; + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out("uuid get failed"); + } + + CLI_STACK_DESTROY(frame); + return ret; } int -cli_cmd_uuid_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, - const char **words, int wordcount) +cli_cmd_uuid_reset_cbk(struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) { - int ret = -1; - rpc_clnt_procedure_t *proc = NULL; - call_frame_t *frame = NULL; - int sent = 0; - int parse_error = 0; - gf_answer_t answer = GF_ANSWER_NO; - char *question = NULL; - cli_local_t *local = NULL; - dict_t *dict = NULL; - xlator_t *this = NULL; - - question = "Resetting uuid changes the uuid of local glusterd. " - "Do you want to continue?"; - - if (wordcount != 3) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UUID_RESET]; - - this = THIS; - frame = create_frame (this, this->ctx->pool); - if (!frame) - goto out; - - dict = dict_new (); - if (!dict) { - ret = -1; - goto out; - } - CLI_LOCAL_INIT (local, words, frame, dict); - answer = cli_cmd_get_confirmation (state, question); - - if (GF_ANSWER_NO == answer) { - ret = 0; - goto out; - } - - //send NULL as argument since no dictionary is sent to glusterd - if (proc->fn) { - ret = proc->fn (frame, this, dict); - } + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + int sent = 0; + int parse_error = 0; + gf_answer_t answer = GF_ANSWER_NO; + char *question = NULL; + cli_local_t *local = NULL; + dict_t *dict = NULL; + xlator_t *this = NULL; + + question = + "Resetting uuid changes the uuid of local glusterd. " + "Do you want to continue?"; + + if (wordcount != 3) { + cli_usage_out(word->pattern); + parse_error = 1; + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UUID_RESET]; + + this = THIS; + frame = create_frame(this, this->ctx->pool); + if (!frame) + goto out; + + dict = dict_new(); + if (!dict) { + ret = -1; + goto out; + } + CLI_LOCAL_INIT(local, words, frame, dict); + answer = cli_cmd_get_confirmation(state, question); + + if (GF_ANSWER_NO == answer) { + ret = 0; + goto out; + } + + // send NULL as argument since no dictionary is sent to glusterd + if (proc->fn) { + ret = proc->fn(frame, this, dict); + } out: - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("uuid reset failed"); - } + if (ret) { + cli_cmd_sent_status_get(&sent); + if ((sent == 0) && (parse_error == 0)) + cli_out("uuid reset failed"); + } - CLI_STACK_DESTROY (frame); + CLI_STACK_DESTROY(frame); - return ret; + return ret; } struct cli_cmd cli_system_cmds[] = { - { "system:: getspec ", - cli_cmd_getspec_cbk, - "fetch the volume file for the volume "}, + {"system:: getspec ", cli_cmd_getspec_cbk, + "fetch the volume file for the volume "}, - { "system:: portmap brick2port ", - cli_cmd_pmap_b2p_cbk, - "query which port listens on"}, + {"system:: portmap brick2port ", cli_cmd_pmap_b2p_cbk, + "query which port listens on"}, - { "system:: fsm log []", - cli_cmd_fsm_log_cbk, - "display fsm transitions"}, + {"system:: fsm log []", cli_cmd_fsm_log_cbk, + "display fsm transitions"}, - { "system:: getwd", - cli_cmd_getwd_cbk, - "query glusterd work directory"}, + {"system:: getwd", cli_cmd_getwd_cbk, "query glusterd work directory"}, - { "system:: mount