diff options
author | M. Mohan Kumar <mohan@in.ibm.com> | 2013-11-13 22:44:42 +0530 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2013-11-13 11:38:28 -0800 |
commit | 15a8ecd9b3eedf80881bd3dba81f16b7d2cb7c97 (patch) | |
tree | 856377a3f077ac4ea5cb9db2950210c8d9f30fb1 | |
parent | c1109ed6c6c7bff0df22c304158e9f392f83cf59 (diff) |
bd_map: Remove bd_map xlator
Remove bd_map xlator and CLI related changes.
Change-Id: If7086205df1907127c1a1fa4ba603f1c48421d09
BUG: 1028672
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Reviewed-on: http://review.gluster.org/5747
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
35 files changed, 20 insertions, 4602 deletions
diff --git a/cli/src/Makefile.am b/cli/src/Makefile.am index ae52310264d..d5189da5e8c 100644 --- a/cli/src/Makefile.am +++ b/cli/src/Makefile.am @@ -3,9 +3,6 @@ sbin_PROGRAMS = gluster gluster_SOURCES = cli.c registry.c input.c cli-cmd.c cli-rl.c \ cli-cmd-volume.c cli-cmd-peer.c cli-rpc-ops.c cli-cmd-parser.c\ cli-cmd-system.c cli-cmd-misc.c cli-xml-output.c -if ENABLE_BD_XLATOR -gluster_SOURCES += cli-cmd-volume-bdevice.c -endif gluster_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(GF_LDADD)\ $(RLLIBS) $(top_builddir)/rpc/xdr/src/libgfxdr.la \ diff --git a/cli/src/cli-cmd-misc.c b/cli/src/cli-cmd-misc.c index 5f3a77ca67f..4aec8dd35b4 100644 --- a/cli/src/cli-cmd-misc.c +++ b/cli/src/cli-cmd-misc.c @@ -47,9 +47,6 @@ cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word, { struct cli_cmd *cmd[] = {volume_cmds, cli_probe_cmds, cli_misc_cmds, -#ifdef HAVE_BD_XLATOR - cli_bd_cmds, -#endif NULL}; struct cli_cmd *cmd_ind = NULL; int i = 0; diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 5278a3ebfcb..cd0370acc78 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -159,11 +159,7 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options int32_t index = 0; char *bricks = NULL; int32_t brick_count = 0; - char *opwords[] = { "replica", "stripe", "transport", -#ifdef HAVE_BD_XLATOR - "device", -#endif - NULL }; + char *opwords[] = { "replica", "stripe", "transport", NULL }; char *invalid_volnames[] = {"volume", "type", "subvolumes", "option", "end-volume", "all", "volume_not_in_ring", @@ -172,9 +168,6 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options int op_count = 0; int32_t replica_count = 1; int32_t stripe_count = 1; -#ifdef HAVE_BD_XLATOR - char *dev_type = NULL; -#endif gf_boolean_t is_force = _gf_false; int wc = wordcount; @@ -311,26 +304,7 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options goto out; } index += 2; - } -#ifdef HAVE_BD_XLATOR - else if ((strcmp (w, "device")) == 0) { - if (dev_type) { - cli_err ("'device' option given more" - " than one time"); - goto out; - } - if ((strcasecmp (words[index+1], "vg") == 0)) { - dev_type = gf_strdup ("vg"); - } else { - gf_log ("", GF_LOG_ERROR, "incorrect" - " device type specified"); - ret = -1; - goto out; - } - index += 2; - } -#endif - else { + } else { GF_ASSERT (!"opword mismatch"); ret = -1; goto out; @@ -371,19 +345,6 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options goto out; } - /* BD xlator does not support multiple bricks */ -#ifdef HAVE_BD_XLATOR - if (brick_count > 1 && dev_type) { - cli_err ("Block Device backend volume does not support multiple" - " bricks"); - gf_log ("", GF_LOG_ERROR, - "Block Device backend volume does not support multiple" - " bricks"); - ret = -1; - goto out; - } -#endif - if (brick_count % sub_count) { if (type == GF_CLUSTER_TYPE_STRIPE) cli_err ("number of bricks is not a multiple of " @@ -417,14 +378,6 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options if (ret) goto out; -#ifdef HAVE_BD_XLATOR - if (dev_type) { - ret = dict_set_dynstr (dict, "device", dev_type); - if (ret) - goto out; - } -#endif - ret = dict_set_int32 (dict, "count", brick_count); if (ret) goto out; diff --git a/cli/src/cli-cmd-volume-bdevice.c b/cli/src/cli-cmd-volume-bdevice.c deleted file mode 100644 index 19325754fb9..00000000000 --- a/cli/src/cli-cmd-volume-bdevice.c +++ /dev/null @@ -1,270 +0,0 @@ -/* - CLI for BD translator - - Copyright IBM, Corp. 2012 - - This file is part of GlusterFS. - - Author: - M. Mohan Kumar <mohan@in.ibm.com> - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "cli.h" -#include "cli-cmd.h" -#include <string.h> - -extern rpc_clnt_prog_t *cli_rpc_prog; - -int -cli_cmd_bd_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount); - -int32_t -cli_cmd_bd_parse (dict_t *dict, const char **words) -{ - char *volname = NULL; - char *buff = NULL; - char *buffp = NULL; - int ret = -1; - char *save = NULL; - char *path = NULL; - char *size = NULL; - char *eptr = NULL; - gf_xl_bd_op_t bd_op = GF_BD_OP_INVALID; - char *dest_lv = NULL; - - - /* volname:/path */ - if (!strchr (words[2], ':') || !strchr (words[2], '/')) { - cli_out ("invalid parameter %s, needs <volname:/path>", - words[2]); - return -1; - } - buff = buffp = gf_strdup (words[2]); - volname = strtok_r (buff, ":", &save); - path = strtok_r (NULL, ":", &save); - - ret = dict_set_dynstr (dict, "volname", gf_strdup (volname)); - if (ret) - goto out; - - ret = dict_set_dynstr (dict, "path", gf_strdup (path)); - if (ret) - goto out; - - if (!strcasecmp (words[1], "create")) - bd_op = GF_BD_OP_NEW_BD; - else if (!strcasecmp (words[1], "delete")) - bd_op = GF_BD_OP_DELETE_BD; - else if (!strcasecmp (words[1], "clone")) - bd_op = GF_BD_OP_CLONE_BD; - else if (!strcasecmp (words[1], "snapshot")) - bd_op = GF_BD_OP_SNAPSHOT_BD; - else - return -1; - - ret = dict_set_int32 (dict, "bd-op", bd_op); - if (ret) - goto out; - - if (bd_op == GF_BD_OP_NEW_BD) { - /* If no suffix given we will treat it as MB */ - strtoull (words[3], &eptr, 0); - /* no suffix */ - if (!eptr[0]) - gf_asprintf (&size, "%sMB", words[3]); - else - size = gf_strdup (words[3]); - - ret = dict_set_dynstr (dict, "size", size); - if (ret) - goto out; - } else if (bd_op == GF_BD_OP_SNAPSHOT_BD || - bd_op == GF_BD_OP_CLONE_BD) { - /* - * dest_lv should be just dest_lv, we don't support - * cloning/snapshotting to a different volume or vg - */ - if (strchr (words[3], ':') || strchr (words[3], '/')) { - cli_err ("invalid parameter %s, volname/vg not needed", - words[3]); - ret = -1; - goto out; - } - dest_lv = gf_strdup (words[3]); - ret = dict_set_dynstr (dict, "dest_lv", dest_lv); - if (ret) - goto out; - - /* clone needs size as parameter */ - if (bd_op == GF_BD_OP_SNAPSHOT_BD) { - ret = dict_set_dynstr (dict, "size", - gf_strdup (words[4])); - if (ret) - goto out; - } - } - - ret = 0; -out: - GF_FREE (buffp); - return ret; -} - -/* - * bd create <volname>:/path <size> - * bd delete <volname>:/path - * bd clone <volname>:/path <newbd> - * bd snapshot <volname>:/<path> <newbd> <size> - */ -int32_t -cli_cmd_bd_validate (const char **words, int wordcount, dict_t **options) -{ - dict_t *dict = NULL; - int ret = -1; - char *op[] = { "create", "delete", "clone", "snapshot", NULL }; - int index = 0; - - for (index = 0; op[index]; index++) - if (!strcasecmp (words[1], op[index])) - break; - - if (!op[index]) - return -1; - - dict = dict_new (); - if (!dict) - goto out; - - if (!strcasecmp (words[1], "create")) { - if (wordcount != 4) - goto out; - } else if (!strcasecmp (words[1], "delete")) { - if (wordcount != 3) - goto out; - } else if (!strcasecmp (words[1], "clone")) { - if (wordcount != 4) - goto out; - } else if (!strcasecmp (words[1], "snapshot")) { - if (wordcount != 5) - goto out; - } else { - ret = -1; - goto out; - } - - ret = cli_cmd_bd_parse (dict, words); - if (ret < 0) - goto out; - - *options = dict; - ret = 0; -out: - if (ret) - dict_unref (dict); - return ret; -} - -int -cli_cmd_bd_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; - dict_t *options = NULL; - cli_local_t *local = NULL; - - proc = &cli_rpc_prog->proctable[GLUSTER_CLI_BD_OP]; - - frame = create_frame (THIS, THIS->ctx->pool); - if (!frame) - goto out; - - ret = cli_cmd_bd_validate (words, wordcount, &options); - if (ret) { - cli_usage_out (word->pattern); - parse_error = 1; - goto out; - } - - CLI_LOCAL_INIT (local, words, frame, options); - if (proc->fn) { - ret = proc->fn (frame, THIS, options); - } - -out: - if (options) - dict_unref (options); - - if (ret) { - cli_cmd_sent_status_get (&sent); - if ((sent == 0) && (parse_error == 0)) - cli_out ("BD op failed!"); - } - - CLI_STACK_DESTROY (frame); - - return ret; -} - -struct cli_cmd cli_bd_cmds[] = { - { "bd help", - cli_cmd_bd_help_cbk, - "display help for bd command"}, - { "bd create <volname>:<bd> <size>", - cli_cmd_bd_cbk, - "\n\tcreate a block device where size can be " - "suffixed with KB, MB etc. Default size is in MB"}, - { "bd delete <volname>:<bd>", - cli_cmd_bd_cbk, - "Delete a block device"}, - { "bd clone <volname>:<bd> <newbd>", - cli_cmd_bd_cbk, - "clone device"}, - { "bd snapshot <volname>:<bd> <newbd> <size>", - cli_cmd_bd_cbk, - "\n\tsnapshot device where size can be " - "suffixed with KB, MB etc. Default size is in MB"}, - { NULL, NULL, NULL } -}; - -int -cli_cmd_bd_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word, - const char **words, int wordcount) -{ - struct cli_cmd *cmd = NULL; - - for (cmd = cli_bd_cmds; cmd->pattern; cmd++) - if (_gf_false == cmd->disable) - cli_out ("%s - %s", cmd->pattern, cmd->desc); - - return 0; -} - -int -cli_cmd_bd_register (struct cli_state *state) -{ - int ret = 0; - struct cli_cmd *cmd = NULL; - - for (cmd = cli_bd_cmds; cmd->pattern; cmd++) { - ret = cli_cmd_register (&state->tree, cmd); - if (ret) - goto out; - } -out: - return ret; -} diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 4b4bd02d286..dcb317f54fc 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1829,9 +1829,6 @@ struct cli_cmd volume_cmds[] = { "list information of all volumes"}, { "volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT>] " -#ifdef HAVE_BD_XLATOR - "[device vg] " -#endif "[transport <tcp|rdma|tcp,rdma>] <NEW-BRICK> ... [force]", cli_cmd_volume_create_cbk, "create a new volume of specified type with mentioned bricks"}, diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c index aa7600350c1..1045f34f0f5 100644 --- a/cli/src/cli-cmd.c +++ b/cli/src/cli-cmd.c @@ -231,11 +231,6 @@ cli_cmds_register (struct cli_state *state) if (ret) goto out; -#ifdef HAVE_BD_XLATOR - ret = cli_cmd_bd_register (state); - if (ret) - goto out; -#endif out: return ret; } diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h index 0ad37d49843..06a1ed32aac 100644 --- a/cli/src/cli-cmd.h +++ b/cli/src/cli-cmd.h @@ -119,7 +119,4 @@ gf_answer_t cli_cmd_get_confirmation (struct cli_state *state, const char *question); int cli_cmd_sent_status_get (int *status); -#ifdef HAVE_BD_XLATOR -int cli_cmd_bd_register (struct cli_state *state); -#endif #endif /* __CLI_CMD_H__ */ diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 6ecb423385d..0ff997dc55e 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -58,10 +58,6 @@ char *cli_vol_status_str[] = {"Created", "Stopped", }; -char *cli_volume_backend[] = {"", - "Volume Group", -}; - char *cli_vol_task_status_str[] = {"not started", "in progress", "stopped", @@ -500,7 +496,6 @@ gf_cli_get_volume_cbk (struct rpc_req *req, struct iovec *iov, char key[1024] = {0}; char err_str[2048] = {0}; gf_cli_rsp rsp = {0}; - int32_t backend = 0; if (-1 == req->rpc_status) goto out; @@ -652,9 +647,6 @@ xml_output: if (ret) goto out; - snprintf (key, 256, "volume%d.backend", i); - ret = dict_get_int32 (dict, key, &backend); - vol_type = type; // Distributed (stripe/replicate/stripe-replica) setups @@ -666,9 +658,6 @@ xml_output: cli_out ("Volume ID: %s", volume_id_str); cli_out ("Status: %s", cli_vol_status_str[status]); - if (backend) - goto next; - if (type == GF_CLUSTER_TYPE_STRIPE_REPLICATE) { cli_out ("Number of Bricks: %d x %d x %d = %d", (brick_count / dist_count), @@ -689,12 +678,6 @@ xml_output: ((transport == 0)?"tcp": (transport == 1)?"rdma": "tcp,rdma")); - -next: - if (backend) { - cli_out ("Backend Type: Block, %s", - cli_volume_backend[backend]); - } j = 1; GF_FREE (local->get_vol.volname); @@ -2932,142 +2915,6 @@ out: return ret; } -#ifdef HAVE_BD_XLATOR -int -gf_cli_bd_op_cbk (struct rpc_req *req, struct iovec *iov, - int count, void *myframe) -{ - gf_cli_rsp rsp = {0,}; - int ret = -1; - cli_local_t *local = NULL; - dict_t *dict = NULL; - dict_t *input_dict = NULL; - gf_xl_bd_op_t bd_op = GF_BD_OP_INVALID; - char *operation = NULL; - call_frame_t *frame = NULL; - - if (-1 == req->rpc_status) - goto out; - - frame = myframe; - - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_cli_rsp); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_ERROR, - "Failed to decode xdr response"); - goto out; - } - - dict = dict_new (); - if (!dict) { - ret = -1; - goto out; - } - - if (frame) - local = frame->local; - - if (local) { - input_dict = local->dict; - ret = dict_get_int32 (input_dict, "bd-op", - (int32_t *)&bd_op); - } - - switch (bd_op) { - case GF_BD_OP_NEW_BD: - operation = gf_strdup ("create"); - break; - case GF_BD_OP_DELETE_BD: - operation = gf_strdup ("delete"); - break; - case GF_BD_OP_CLONE_BD: - operation = gf_strdup ("clone"); - break; - case GF_BD_OP_SNAPSHOT_BD: - operation = gf_strdup ("snapshot"); - break; - default: - break; - } - - ret = dict_unserialize (rsp.dict.dict_val, rsp.dict.dict_len, &dict); - if (ret) - goto out; - - gf_log ("cli", GF_LOG_INFO, "Received resp to %s bd op", operation); - - if (global_state->mode & GLUSTER_MODE_XML) { - ret = cli_xml_output_dict ("BdOp", dict, rsp.op_ret, - rsp.op_errno, rsp.op_errstr); - if (ret) - gf_log ("cli", GF_LOG_ERROR, - "Error outputting to xml"); - goto out; - } - - if (rsp.op_ret && strcmp (rsp.op_errstr, "")) - cli_err ("%s", rsp.op_errstr); - else - cli_out ("BD %s has been %s", operation, - (rsp.op_ret) ? "unsuccessful": - "successful."); - ret = rsp.op_ret; - -out: - cli_cmd_broadcast_response (ret); - - if (dict) - dict_unref (dict); - - if (operation) - GF_FREE (operation); - - if (rsp.dict.dict_val) - free (rsp.dict.dict_val); - if (rsp.op_errstr) - free (rsp.op_errstr); - return ret; -} - -int32_t -gf_cli_bd_op (call_frame_t *frame, xlator_t *this, - void *data) -{ - gf_cli_req req = { {0,} }; - int ret = 0; - dict_t *dict = NULL; - - if (!frame || !this || !data) { - ret = -1; - goto out; - } - - dict = dict_ref ((dict_t *)data); - if (!dict) - goto out; - - ret = dict_allocate_and_serialize (dict, - &req.dict.dict_val, - &req.dict.dict_len); - - - ret = cli_to_glusterd (&req, frame, gf_cli_bd_op_cbk, - (xdrproc_t)xdr_gf_cli_req, dict, - GLUSTER_CLI_BD_OP, this, cli_rpc_prog, - NULL); - -out: - if (dict) - dict_unref (dict); - - if (req.dict.dict_val) - GF_FREE (req.dict.dict_val); - - gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); - return ret; -} -#endif - int32_t gf_cli_create_volume (call_frame_t *frame, xlator_t *this, void *data) @@ -7740,9 +7587,6 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { [GLUSTER_CLI_CLRLOCKS_VOLUME] = {"CLEARLOCKS_VOLUME", gf_cli_clearlocks_volume}, [GLUSTER_CLI_COPY_FILE] = {"COPY_FILE", gf_cli_copy_file}, [GLUSTER_CLI_SYS_EXEC] = {"SYS_EXEC", gf_cli_sys_exec}, -#ifdef HAVE_BD_XLATOR - [GLUSTER_CLI_BD_OP] = {"BD_OP", gf_cli_bd_op}, -#endif }; struct rpc_clnt_program cli_prog = { diff --git a/cli/src/cli.h b/cli/src/cli.h index d7b64cfbf4d..bc71ee2b4f0 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -37,19 +37,6 @@ #define CLI_TAB_LENGTH 8 #define CLI_BRICK_STATUS_LINE_LEN 78 -#define CLI_LOCAL_INIT(local, words, frame, dictionary) \ - do { \ - local = cli_local_get (); \ - \ - if (local) { \ - local->words = words; \ - if (dictionary) \ - local->dict = dictionary; \ - if (frame) \ - frame->local = local; \ - } \ - } while (0) - enum argp_option_keys { ARGP_DEBUG_KEY = 133, ARGP_PORT_KEY = 'p', diff --git a/configure.ac b/configure.ac index cf301b2901a..9d676cd15a9 100644 --- a/configure.ac +++ b/configure.ac @@ -53,8 +53,6 @@ AC_CONFIG_FILES([Makefile xlators/storage/Makefile xlators/storage/posix/Makefile xlators/storage/posix/src/Makefile - xlators/storage/bd_map/Makefile - xlators/storage/bd_map/src/Makefile xlators/cluster/Makefile xlators/cluster/afr/Makefile xlators/cluster/afr/src/Makefile @@ -303,44 +301,6 @@ if test "x$enable_fuse_client" != "xno"; then BUILD_FUSE_CLIENT="yes" fi -AC_ARG_ENABLE([bd-xlator], - AC_HELP_STRING([--enable-bd-xlator], - [Build BD xlator])) - -if test "x$enable_bd_xlator" != "xno"; then - AC_CHECK_LIB([lvm2app], - [lvm_init,lvm_lv_from_name], - [HAVE_BD_LIB="yes"], - [HAVE_BD_LIB="no"]) - - if test "x$HAVE_BD_LIB" = "xyes"; then - # lvm_lv_from_name() has been made public with lvm2-2.02.79 - AC_CHECK_DECLS( - [lvm_lv_from_name], - [NEED_LVM_LV_FROM_NAME_DECL="no"], - [NEED_LVM_LV_FROM_NAME_DECL="yes"], - [[#include <lvm2app.h>]]) - fi -fi - -if test "x$enable_bd_xlator" = "xyes" -a "x$HAVE_BD_LIB" = "xno"; then - echo "BD xlator requested but required lvm2 development library not found." - exit 1 -fi - -BUILD_BD_XLATOR=no -if test "x${enable_bd_xlator}" != "xno" -a "x${HAVE_BD_LIB}" = "xyes"; then - BUILD_BD_XLATOR=yes - AC_DEFINE(HAVE_BD_XLATOR, 1, [define if lvm2app library found and bd - xlator enabled]) - if test "x$NEED_LVM_LV_FROM_NAME_DECL" = "xyes"; then - AC_DEFINE(NEED_LVM_LV_FROM_NAME_DECL, 1, [defined if lvm_lv_from_name() - was not found in the lvm2app.h header, but can be linked]) - fi -fi - -AM_CONDITIONAL([ENABLE_BD_XLATOR], [test x$BUILD_BD_XLATOR = xyes]) - AC_SUBST(FUSE_CLIENT_SUBDIR) # end FUSE section @@ -861,7 +821,6 @@ echo "georeplication : $BUILD_SYNCDAEMON" echo "Linux-AIO : $BUILD_LIBAIO" echo "Enable Debug : $BUILD_DEBUG" echo "systemtap : $BUILD_SYSTEMTAP" -echo "Block Device backend : $BUILD_BD_XLATOR" echo "glupy : $BUILD_GLUPY" echo "Use syslog : $USE_SYSLOG" echo "XML output : $BUILD_XML_OUTPUT" diff --git a/doc/features/bd.txt b/doc/features/bd.txt deleted file mode 100644 index c1ba006ef8c..00000000000 --- a/doc/features/bd.txt +++ /dev/null @@ -1,130 +0,0 @@ -Sections -1. Introduction -2. Advantages -3. Creating BD backend volume -4. BD volume file -5. Using BD backend gluster volume -6. Limitations -7. TODO - -1. Introduction -=============== -Block Device translator(BD xlator) represented as storage/bd_map in -volume file adds a new backend 'block' to GlusterFS. It enables -GlusterFS to export block devices as regular files to the client. -Currently BD xlator supports exporting of 'Volume Group(VG)' as -directory and Logical Volumes(LV) within that VG as regular files to the -client. - -The eventual goal of this work is to support thin provisioning, -snapshot, copy etc of VM images seamlessly in GlusterFS storage -environment - -The immediate goal of this translator is to use LVs to store -VM images and expose them as files to QEMU/KVM. Given VG is represented -as directory and its logical volumes as files. - -BD xlator uses lvm2-devel APIs for getting the list of VGs and LVs in -the system and lvm binaries (such as lvcreate, lvresize etc) to perform -the required LV operations. - -2. Advantages -============= -By exporting LVs as regular files, it becomes possible to: -* Associate each VM to a LV so that there is no file system overhead. -* Use file system commands like cp to take copy of VM images -* Create linked clones of VM by doing LV snapshot at server -side -* Implement thin provisioning by developing a qcow2 translator - -3. Creating BD backend volume -============================= -New parameter "device vg" in volume create command is used to create BD -backend gluster volumes. - -For example - $ gluster volume create my-volume device vg hostname:/my-vg - -creates gluster volume 'my-volume' with BD backend which uses the VG -'my-vg' to store data. VG 'my-vg' should exist before creating this -gluster volume. - -4. BD volume file -================= -BD backend volume file specifies which VG to export to the client. The -section in the volume file that describes BD xlator looks like this. - -volume my-volume-bd_map -type storage/bd_map -option device vg -option export volume-group -end-volume - -option device=vg specifies that it should use VG as block backend. option -export=volume-group specifies that it should export VG "volume-group" -to the client. - -5. Using BD backend gluster volume -================================== -Mount ------ - $ mount -t glusterfs hostname:/my-volume /media/bd - $ cd /media/bd - -From the mount point: --------------------- -* Creating a new file (ie LV) involves two steps - $ touch lv1 - $ truncate -s <size> lv1 - or - $ qemu-img create -f <format> gluster:/hostname/my-volume/path-to-image <size> - -* Cloning an LV - $ ln lv1 lv2 - -* Snapshotting an LV - $ ln -s lv1 lv1-ss - -* Passing it to QEMU as one of the drives - $ qemu -drive file=<mount>/<file>,if=<if-type> - -* GlusterFS is one of the supported QEMU block drivers, the URI format - is - gluster[+transport]://[server[:port]]/my-volume/image[?socket=...] - ie - $ qemu -drive file=gluster:/hostname/my-volume/path-to-image,if=<if-type> - -Using Gluster CLI: ------------------ -* To create a new image of required size - $ gluster bd create my-volume:/path-to-image <size> - -* To delete an existing image - $ gluster bd delete my-volume:/path-to-image - -* To clone (full clone) an image - $ gluster bd clone my-volume:/path-to-image new-image - -* To take a snapshot of an image - $ gluster bd snapshot my-volume:/path-to-image snapshot-image <size> - -All gluster BD commands need size to specified in terms of KB, MB, etc. - -6. Limitations -============== -* No support to create multiple bricks -* Image creation should be used with truncate to get proper size or use - qemu-img create -* cp command can't be used to copy images, instead use ln command or - gluster bd clone command -* ln -s command throws an error even if snapshot is successful -* When ln command used on BD volumes, target file's inode is different - from target's -* Creation/deletion of directories, xattr operations, mknod and readlink - operations are not supported. - -7. TODO -======= -Add support for exporting LUNs also as a regular files. -Add support for xattr and multi brick support -Include support for device mapper thin targets diff --git a/doc/gluster.8 b/doc/gluster.8 index b23e2c8917c..3c78fb8b19a 100644 --- a/doc/gluster.8 +++ b/doc/gluster.8 @@ -8,7 +8,7 @@ .\" cases as published by the Free Software Foundation. .\" .\" -.TH Gluster 8 "Gluster command line utility" "22 November 2012" "Gluster Inc." +.TH Gluster 8 "Gluster command line utility" "07 March 2011" "Gluster Inc." .SH NAME gluster - Gluster Console Manager (command line utility) .SH SYNOPSIS @@ -36,11 +36,9 @@ The Gluster Console Manager is a command line utility for elastic volume managem \fB\ volume info [all|<VOLNAME>] \fR Display information about all volumes, or the specified volume. .TP -\fB\ volume create <NEW-VOLNAME> [device vg] [stripe <COUNT>] [replica <COUNT>] [transport <tcp|rdma|tcp,rdma>] <NEW-BRICK> ... \fR +\fB\ volume create <NEW-VOLNAME> [stripe <COUNT>] [replica <COUNT>] [transport <tcp|rdma|tcp,rdma>] <NEW-BRICK> ... \fR Create a new volume of the specified type using the specified bricks and transport type (the default transport type is tcp). To create a volume with both transports (tcp and rdma), give 'transport tcp,rdma' as an option. -device vg parameter specifies volume should use block backend instead of regular posix backend. In this case NEW-BRICK should specify an existing Volume Group and there can be only one brick for Block backend volumes. \fR -Refer Block backend section for more details .TP \fB\ volume delete <VOLNAME> \fR Delete the specified volume. @@ -59,9 +57,6 @@ Set the volume options. .TP \fB\ volume help \fR Display help for the volume command. -.SS "Block backend" -.TP -By specifying "device vg" in volume create, a volume capable of exporting block devices(ie Volume Groups (VG)) is created. As of now exporting only VG is supported. While creating block backend volume the "VG" (mentioned in NEW-BRICK) must exist (ie created with vgcreate). VG is exported as a directory and all LVs under that VG will be exported as files. Please refer BD commands section for Block backend related commands .SS "Brick Commands" .PP .TP @@ -110,20 +105,6 @@ Display the status of peers. .TP \fB\ peer help \fR Display help for the peer command. -.SS "BD commands" -.TP -\fB\ bd create <VOLNAME:/path-to-image> <size> \fR -Creates a new image of given size in the volume. Size can be suffixed with MB, GB etc, if nothing specified MB is taken as default. -.TP -\fB\ bd delete <VOLNAME:/path-to-image> \fR -Deletes a image in the volume -.TP -\fB\ bd clone <VOLNAME:/path-to-image> <new-image> \fR -Clones an existing image (full clone) -.TP -\fB\ bd snapshot <VOLNAME:/path-to-image> <new-image> <size> \fR -Creates a linked clone of an existing image with given size. Size can be suffixed with MB, GB etc, if nothing specified MB is taken as default. - .SS "Other Commands" .TP \fB\ help \fR diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index 071066bdbaa..f4445acf6dd 100644 --- a/glusterfsd/src/glusterfsd-mgmt.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -1124,75 +1124,6 @@ out: } int -glusterfs_handle_bd_op (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gd1_mgmt_brick_op_req xlator_req = {0,}; - dict_t *input = NULL; - xlator_t *xlator = NULL; - xlator_t *any = NULL; - dict_t *output = NULL; - char *xname = NULL; - glusterfs_ctx_t *ctx = NULL; - glusterfs_graph_t *active = NULL; - xlator_t *this = NULL; - char *error = NULL; - - GF_ASSERT (req); - this = THIS; - GF_ASSERT (this); - - ret = xdr_to_generic (req->msg[0], &xlator_req, - (xdrproc_t)xdr_gd1_mgmt_brick_op_req); - if (ret < 0) { - /* failed to decode msg */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - ctx = glusterfsd_ctx; - active = ctx->active; - any = active->first; - input = dict_new (); - ret = dict_unserialize (xlator_req.input.input_val, - xlator_req.input.input_len, - &input); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "failed to " - "unserialize req-buffer to dictionary"); - goto out; - } else { - input->extra_stdfree = xlator_req.input.input_val; - } - - /* FIXME, hardcoded */ - xlator = xlator_search_by_xl_type (any, "storage/bd_map"); - if (!xlator) { - gf_log (this->name, GF_LOG_ERROR, "xlator %s is not " - "loaded", xname); - goto out; - } - output = dict_new (); - XLATOR_NOTIFY (xlator, GF_EVENT_TRANSLATOR_OP, input, output); -out: - if (ret < 0) { - int retval; - retval = dict_get_str (output, "error", &error); - } - glusterfs_xlator_op_response_send (req, ret, error, output); - if (input) - dict_unref (input); - if (output) - dict_unref (output); - if (xlator_req.name) - /* malloced by xdr */ - free (xlator_req.name); - - return 0; -} - -int glusterfs_handle_rpc_msg (rpcsvc_request_t *req) { int ret = -1; @@ -1256,9 +1187,6 @@ rpcsvc_actor_t glusterfs_actors[] = { [GLUSTERD_BRICK_XLATOR_DEFRAG] = {"TRANSLATOR DEFRAG", GLUSTERD_BRICK_XLATOR_DEFRAG, glusterfs_handle_defrag, NULL, 0, DRC_NA}, [GLUSTERD_NODE_PROFILE] = {"NFS PROFILE", GLUSTERD_NODE_PROFILE, glusterfs_handle_nfs_profile, NULL, 0, DRC_NA}, [GLUSTERD_NODE_STATUS] = {"NFS STATUS", GLUSTERD_NODE_STATUS, glusterfs_handle_node_status, NULL, 0, DRC_NA}, -#ifdef HAVE_BD_XLATOR - [GLUSTERD_BRICK_BD_OP] = {"BD OP", GLUSTERD_BRICK_BD_OP, glusterfs_handle_bd_op, NULL, 0, DRC_NA} -#endif }; struct rpcsvc_program glusterfs_mop_prog = { diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 483c588a9f1..a277c58a8f5 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -362,29 +362,6 @@ out: return search; } -xlator_t * -xlator_search_by_xl_type (xlator_t *any, const char *type) -{ - xlator_t *search = NULL; - - GF_VALIDATE_OR_GOTO ("xlator", any, out); - GF_VALIDATE_OR_GOTO ("xlator", type, out); - - search = any; - - while (search->prev) - search = search->prev; - - while (search) { - if (!strcmp (search->type, type)) - break; - search = search->next; - } - -out: - return search; -} - static int __xlator_init(xlator_t *xl) { diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 2f938c384fc..b57e5873e3d 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -933,7 +933,6 @@ void xlator_foreach_depth_first (xlator_t *this, void *data); xlator_t *xlator_search_by_name (xlator_t *any, const char *name); -xlator_t *xlator_search_by_xl_type (xlator_t *any, const char *type); void inode_destroy_notify (inode_t *inode, const char *xlname); diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index adec7b63849..4bca0f55822 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -157,7 +157,6 @@ enum gluster_cli_procnum { GLUSTER_CLI_LIST_VOLUME, GLUSTER_CLI_CLRLOCKS_VOLUME, GLUSTER_CLI_UUID_RESET, - GLUSTER_CLI_BD_OP, GLUSTER_CLI_UUID_GET, GLUSTER_CLI_COPY_FILE, GLUSTER_CLI_SYS_EXEC, @@ -192,7 +191,6 @@ enum glusterd_brick_procnum { GLUSTERD_BRICK_XLATOR_DEFRAG, GLUSTERD_NODE_PROFILE, GLUSTERD_NODE_STATUS, - GLUSTERD_BRICK_BD_OP, GLUSTERD_BRICK_MAXVALUE, }; @@ -216,14 +214,6 @@ typedef enum { GF_AFR_OP_STATISTICS_HEAL_COUNT_PER_REPLICA, } gf_xl_afr_op_t ; -typedef enum { - GF_BD_OP_INVALID, - GF_BD_OP_NEW_BD, - GF_BD_OP_DELETE_BD, - GF_BD_OP_CLONE_BD, - GF_BD_OP_SNAPSHOT_BD, -} gf_xl_bd_op_t ; - #define GLUSTER_HNDSK_PROGRAM 14398633 /* Completely random */ #define GLUSTER_HNDSK_VERSION 2 /* 0.0.2 */ diff --git a/tests/basic/bd.t b/tests/basic/bd.t deleted file mode 100755 index 3201b7460a0..00000000000 --- a/tests/basic/bd.t +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -. $(dirname $0)/../include.rc - -cleanup; - - -function execute() -{ - cmd=$1 - shift - ${cmd} $@ >/dev/null 2>&1 -} - -function bd_cleanup() -{ - execute vgremove -f ${VG} - execute pvremove ${ld} - execute losetup -d ${ld} - execute rm ${BD_DISK} - execute $CLI volume delete ${V0} - cleanup -} - -function check() -{ - if [ $? -ne 0 ]; then - echo prerequsite $@ failed - bd_cleanup - exit - fi -} - -VG=__bd_vg -SIZE=256 #in MB - -## Configure environment needed for BD backend volumes -## Create a file with configured size and -## set it as a temporary loop device to create -## physical volume & VG. These are basic things needed -## for testing BD xlator if anyone of these steps fail, -## test script exits -function configure() -{ - GLDIR=`$CLI system:: getwd` - BD_DISK=${GLDIR}/bd_disk - - execute truncate -s${SIZE}M ${BD_DISK} - check ${BD_DISK} creation - - execute losetup -f - check losetup - ld=`losetup -f` - - execute losetup ${ld} ${BD_DISK} - check losetup ${BD_DISK} - execute pvcreate -f ${ld} - check pvcreate ${ld} - execute vgcreate ${VG} ${ld} - check vgcreate ${VG} -} - -function volinfo_field() -{ - local vol=$1; - local field=$2; - - $CLI volume info $vol | grep "^$field: " | sed 's/.*: //'; -} - -TEST glusterd -TEST pidof glusterd -configure - -TEST $CLI volume create $V0 device vg ${H0}:/${VG} -EXPECT "$V0" volinfo_field $V0 'Volume Name'; -EXPECT 'Created' volinfo_field $V0 'Status'; - -## Start volume and verify -TEST $CLI volume start $V0; -EXPECT 'Started' volinfo_field $V0 'Status' - -TEST glusterfs --volfile-server=$H0 --volfile-id=$V0 $M0 - -## Create file (LV) -TEST touch $M0/$VG/lv1 -TEST stat /dev/$VG/lv1 - -TEST rm $M0/$VG/lv1; -TEST ! stat $M0/$VG/lv1; - -TEST touch $M0/$VG/lv1 -TEST truncate -s64M $M0/$VG/lv1 - -TEST ln $M0/$VG/lv1 $M0/$VG/lv2 -TEST stat /dev/$VG/lv2 - -rm $M0/$VG/lv1 -rm $M0/$VG/lv2 - -TEST $CLI bd create $V0:/$VG/lv1 4MB -TEST stat /dev/$VG/lv1 - -TEST $CLI bd clone $V0:/$VG/lv1 lv2 -TEST stat /dev/$VG/lv2 -TEST $CLI bd delete $V0:/$VG/lv2 - -TEST $CLI bd snapshot $V0:/$VG/lv1 lv2 1 -TEST stat /dev/$VG/lv2 -rm $M0/$VG/lv2 -rm $M0/$VG/lv1 - -TEST umount $M0 -TEST $CLI volume stop ${V0} -TEST $CLI volume delete ${V0} - -bd_cleanup diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am index a6f49ae01b1..17767d7ca92 100644 --- a/xlators/mgmt/glusterd/src/Makefile.am +++ b/xlators/mgmt/glusterd/src/Makefile.am @@ -2,9 +2,6 @@ xlator_LTLIBRARIES = glusterd.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/mgmt glusterd_la_CPPFLAGS = $(AM_CPPFLAGS) "-DFILTERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/filter\"" glusterd_la_LDFLAGS = -module -avoid-version -if ENABLE_BD_XLATOR -glusterd_la_LDFLAGS += -llvm2app -endif glusterd_la_SOURCES = glusterd.c glusterd-handler.c glusterd-sm.c \ glusterd-op-sm.c glusterd-utils.c glusterd-rpc-ops.c \ glusterd-store.c glusterd-handshake.c glusterd-pmap.c \ diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index 5b9471fa7a3..e24edb2d594 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -1244,15 +1244,6 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr) goto out; } - if (volinfo->backend == GD_VOL_BK_BD) { - snprintf (msg, sizeof (msg), "Add brick is not supported for " - "Block backend volume %s.", volname); - gf_log (THIS->name, GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - ret = -1; - goto out; - } - ret = glusterd_validate_volume_id (dict, volinfo); if (ret) goto out; diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index a80d8689c6c..e545fc2120d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -50,10 +50,6 @@ #include "globals.h" #include "glusterd-syncop.h" -#ifdef HAVE_BD_XLATOR -#include <lvm2app.h> -#endif - int glusterd_big_locked_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, void *data, rpc_clnt_notify_t notify_fn) @@ -399,13 +395,6 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo, if (ret) goto out; -#ifdef HAVE_BD_XLATOR - snprintf (key, 256, "volume%d.backend", count); - ret = dict_set_int32 (volumes, key, volinfo->backend); - if (ret) - goto out; -#endif - list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { char brick[1024] = {0,}; char brick_uuid[64] = {0,}; @@ -1108,79 +1097,6 @@ glusterd_handle_cli_get_volume (rpcsvc_request_t *req) __glusterd_handle_cli_get_volume); } -#ifdef HAVE_BD_XLATOR -int -__glusterd_handle_cli_bd_op (rpcsvc_request_t *req) -{ - int32_t ret = -1; - gf_cli_req cli_req = { {0,} }; - dict_t *dict = NULL; - char *volname = NULL; - char op_errstr[2048] = {0,}; - glusterd_op_t cli_op = GD_OP_BD_OP; - - GF_ASSERT (req); - - ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); - if (ret < 0) { - /* failed to decode msg */ - req->rpc_err = GARBAGE_ARGS; - goto out; - } - - gf_log ("glusterd", GF_LOG_DEBUG, "Received bd op req"); - - if (cli_req.dict.dict_len) { - /* Unserialize the dictionary */ - dict = dict_new (); - - ret = dict_unserialize (cli_req.dict.dict_val, - cli_req.dict.dict_len, - &dict); - if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, - "failed to " - "unserialize req-buffer to dictionary"); - goto out; - } else { - dict->extra_stdfree = cli_req.dict.dict_val; - } - } - - ret = dict_get_str (dict, "volname", &volname); - if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, - "failed to get volname"); - goto out; - } - - ret = glusterd_op_begin (req, GD_OP_BD_OP, dict, op_errstr, - sizeof (op_errstr)); -out: - if (ret && dict) - dict_unref (dict); - - glusterd_friend_sm (); - glusterd_op_sm (); - - if (ret) { - if (op_errstr[0] == '\0') - snprintf (op_errstr, sizeof (op_errstr), - "Operation failed"); - ret = glusterd_op_send_cli_response (cli_op, ret, 0, - req, NULL, op_errstr); - } - - return ret; -} - -int -glusterd_handle_cli_bd_op (rpcsvc_request_t *req) -{ - return glusterd_big_locked_handler (req, __glusterd_handle_cli_bd_op); -} -#endif - int __glusterd_handle_cli_uuid_reset (rpcsvc_request_t *req) { @@ -3938,9 +3854,6 @@ rpcsvc_actor_t gd_svc_cli_actors[] = { [GLUSTER_CLI_STATEDUMP_VOLUME] = {"STATEDUMP_VOLUME", GLUSTER_CLI_STATEDUMP_VOLUME, glusterd_handle_cli_statedump_volume, NULL, 0, DRC_NA}, [GLUSTER_CLI_LIST_VOLUME] = {"LIST_VOLUME", GLUSTER_CLI_LIST_VOLUME, glusterd_handle_cli_list_volume, NULL, 0, DRC_NA}, [GLUSTER_CLI_CLRLOCKS_VOLUME] = {"CLEARLOCKS_VOLUME", GLUSTER_CLI_CLRLOCKS_VOLUME, glusterd_handle_cli_clearlocks_volume, NULL, 0, DRC_NA}, -#ifdef HAVE_BD_XLATOR - [GLUSTER_CLI_BD_OP] = {"BD_OP", GLUSTER_CLI_BD_OP, glusterd_handle_cli_bd_op, NULL, 0, DRC_NA}, -#endif [GLUSTER_CLI_COPY_FILE] = {"COPY_FILE", GLUSTER_CLI_COPY_FILE, glusterd_handle_copy_file, NULL, 0, DRC_NA}, [GLUSTER_CLI_SYS_EXEC] = {"SYS_EXEC", GLUSTER_CLI_SYS_EXEC, glusterd_handle_sys_exec, NULL, 0, DRC_NA}, }; diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index cd14e36121a..b7b71adb213 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -236,19 +236,6 @@ glusterd_brick_op_build_payload (glusterd_op_t op, glusterd_brickinfo_t *brickin break; -#ifdef HAVE_BD_XLATOR - case GD_OP_BD_OP: - { - brick_req = GF_CALLOC (1, sizeof (*brick_req), - gf_gld_mt_mop_brick_req_t); - if (!brick_req) - goto out; - - brick_req->op = GLUSTERD_BRICK_BD_OP; - brick_req->name = ""; - } - break; -#endif default: goto out; break; @@ -2761,9 +2748,6 @@ glusterd_op_build_payload (dict_t **req, char **op_errstr, dict_t *op_ctx) case GD_OP_STATEDUMP_VOLUME: case GD_OP_CLEARLOCKS_VOLUME: case GD_OP_DEFRAG_BRICK_VOLUME: -#ifdef HAVE_BD_XLATOR - case GD_OP_BD_OP: -#endif { ret = dict_get_str (dict, "volname", &volname); if (ret) { @@ -4083,11 +4067,6 @@ glusterd_op_stage_validate (glusterd_op_t op, dict_t *dict, char **op_errstr, ret = glusterd_op_stage_clearlocks_volume (dict, op_errstr); break; -#ifdef HAVE_BD_XLATOR - case GD_OP_BD_OP: - ret = glusterd_op_stage_bd (dict, op_errstr); - break; -#endif case GD_OP_COPY_FILE: ret = glusterd_op_stage_copy_file (dict, op_errstr); @@ -4199,11 +4178,6 @@ glusterd_op_commit_perform (glusterd_op_t op, dict_t *dict, char **op_errstr, ret = glusterd_op_clearlocks_volume (dict, op_errstr, rsp_dict); break; -#ifdef HAVE_BD_XLATOR - case GD_OP_BD_OP: - ret = 0; - break; -#endif case GD_OP_COPY_FILE: ret = glusterd_op_copy_file (dict, op_errstr); @@ -4688,61 +4662,6 @@ _select_rxlators_for_full_self_heal (xlator_t *this, return rxlator_count; } -#ifdef HAVE_BD_XLATOR -static int -glusterd_bricks_select_bd (dict_t *dict, char **op_errstr) -{ - int ret = -1; - glusterd_conf_t *priv = NULL; - xlator_t *this = NULL; - glusterd_pending_node_t *pending_node = NULL; - glusterd_volinfo_t *volinfo = NULL; - char *volname = NULL; - glusterd_brickinfo_t *brickinfo = NULL; - int brick_index = -1; - - this = THIS; - GF_ASSERT (this); - priv = this->private; - GF_ASSERT (priv); - - ret = dict_get_str (dict, "volname", &volname); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Unable to get volname"); - goto out; - } - ret = glusterd_volinfo_find (volname, &volinfo); - if (ret) - goto out; - - pending_node = GF_CALLOC (1, sizeof (*pending_node), - gf_gld_mt_pending_node_t); - if (!pending_node) { - ret = -1; - goto out; - } - - list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) { - brick_index++; - if (uuid_compare (brickinfo->uuid, MY_UUID) || - !glusterd_is_brick_started (brickinfo)) { - continue; - } - pending_node->node = brickinfo; - pending_node->type = GD_NODE_BRICK; - pending_node->index = brick_index; - list_add_tail (&pending_node->list, - &opinfo.pending_bricks); - pending_node = NULL; - } - - ret = 0; - -out: - gf_log (THIS->name, GF_LOG_DEBUG, "Returning ret %d", ret); - return ret; -} -#endif static int fill_shd_status_for_local_bricks (dict_t *dict, glusterd_volinfo_t *volinfo, @@ -5296,11 +5215,7 @@ glusterd_op_bricks_select (glusterd_op_t op, dict_t *dict, char **op_errstr, ret = glusterd_bricks_select_rebalance_volume (dict, op_errstr, selected); break; -#ifdef HAVE_BD_XLATOR - case GD_OP_BD_OP: - ret = glusterd_bricks_select_bd (dict, op_errstr); - break; -#endif + default: break; } @@ -5873,9 +5788,6 @@ glusterd_op_free_ctx (glusterd_op_t op, void *ctx) case GD_OP_STATEDUMP_VOLUME: case GD_OP_CLEARLOCKS_VOLUME: case GD_OP_DEFRAG_BRICK_VOLUME: -#ifdef HAVE_BD_XLATOR - case GD_OP_BD_OP: -#endif dict_unref (ctx); break; default: diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index 5c879b64c3a..29f6a0e0f7c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -268,13 +268,6 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr, goto out; } - if (volinfo->backend == GD_VOL_BK_BD) { - snprintf (msg, sizeof (msg), "replace brick not supported " - "for Block backend volume"); - *op_errstr = gf_strdup (msg); - goto out; - } - if (GLUSTERD_STATUS_STARTED != volinfo->status) { ret = -1; snprintf (msg, sizeof (msg), "volume: %s is not started", diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index 2d8d381bf26..38714a5ebf9 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -142,7 +142,6 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, case GD_OP_LIST_VOLUME: case GD_OP_CLEARLOCKS_VOLUME: case GD_OP_HEAL_VOLUME: - case GD_OP_BD_OP: { /*nothing specific to be done*/ break; diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 36e7d6508ef..8b658ae3037 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -571,14 +571,6 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo) goto out; } - if (volinfo->backend == GD_VOL_BK_BD) { - snprintf (buf, sizeof (buf), "%d", volinfo->backend); - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_BACKEND, - buf); - if (ret) - goto out; - } - snprintf (buf, sizeof (buf), "%d", volinfo->op_version); ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_OP_VERSION, buf); if (ret) @@ -1858,9 +1850,6 @@ glusterd_store_retrieve_volume (char *volname) gf_log ("", GF_LOG_DEBUG, "Parsed as "GEOREP" " " slave:key=%s,value:%s", key, value); - } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_BACKEND, - strlen (GLUSTERD_STORE_KEY_VOL_BACKEND))) { - volinfo->backend = atoi (value); } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_OP_VERSION, strlen (GLUSTERD_STORE_KEY_VOL_OP_VERSION))) { volinfo->op_version = atoi (value); diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h index 9882225ab2b..facb964fa72 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.h +++ b/xlators/mgmt/glusterd/src/glusterd-store.h @@ -68,7 +68,7 @@ typedef enum glusterd_store_ver_ac_{ #define GLUSTERD_STORE_KEY_PEER_UUID "uuid" #define GLUSTERD_STORE_KEY_PEER_HOSTNAME "hostname" #define GLUSTERD_STORE_KEY_PEER_STATE "state" -#define GLUSTERD_STORE_KEY_VOL_BACKEND "backend" + #define glusterd_for_each_entry(entry, dir) \ do {\ diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 33147105a80..6bf14bc3daa 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -1419,8 +1419,6 @@ server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, char *password = NULL; char index_basepath[PATH_MAX] = {0}; char key[1024] = {0}; - char *vgname = NULL; - char *vg = NULL; glusterd_brickinfo_t *brickinfo = NULL; char changelog_basepath[PATH_MAX] = {0,}; @@ -1441,47 +1439,24 @@ server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, } } - if (volinfo->backend == GD_VOL_BK_BD) { - xl = volgen_graph_add (graph, "storage/bd_map", volname); - if (!xl) - return -1; - - ret = xlator_set_option (xl, "device", "vg"); - if (ret) - return -1; - - vg = gf_strdup (path); - vgname = strrchr (vg, '/'); - if (strchr(vg, '/') != vgname) { - gf_log ("glusterd", GF_LOG_ERROR, - "invalid vg specified %s", path); - GF_FREE (vg); - goto out; - } - vgname++; - ret = xlator_set_option (xl, "export", vgname); - GF_FREE (vg); - if (ret) - return -1; - } else { - xl = volgen_graph_add (graph, "storage/posix", volname); - if (!xl) - return -1; + xl = volgen_graph_add (graph, "storage/posix", volname); + if (!xl) + return -1; - ret = xlator_set_option (xl, "directory", path); - if (ret) - return -1; + ret = xlator_set_option (xl, "directory", path); + if (ret) + return -1; - ret = xlator_set_option (xl, "volume-id", + ret = xlator_set_option (xl, "volume-id", uuid_utoa (volinfo->volume_id)); - if (ret) - return -1; + if (ret) + return -1; + + ret = check_and_add_debug_xl (graph, set_dict, volname, + "posix"); + if (ret) + return -1; - ret = check_and_add_debug_xl (graph, set_dict, volname, - "posix"); - if (ret) - return -1; - } xl = volgen_graph_add (graph, "features/changelog", volname); if (!xl) diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index d47951f734d..034004dbd9e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -12,10 +12,6 @@ #include "config.h" #endif -#ifdef HAVE_BD_XLATOR -#include <lvm2app.h> -#endif - #include "common-utils.h" #include "syscall.h" #include "cli1-xdr.h" @@ -603,36 +599,6 @@ glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) __glusterd_handle_cli_statedump_volume); } -#ifdef HAVE_BD_XLATOR -int -glusterd_is_valid_vg (const char *name) -{ - lvm_t handle = NULL; - vg_t vg = NULL; - char *vg_name = NULL; - int retval = -1; - - handle = lvm_init (NULL); - if (!handle) { - gf_log ("", GF_LOG_ERROR, "lvm_init failed"); - return -1; - } - vg_name = gf_strdup (name); - vg = lvm_vg_open (handle, basename (vg_name), "r", 0); - if (!vg) { - gf_log ("", GF_LOG_ERROR, "no such vg: %s", vg_name); - goto out; - } - retval = 0; -out: - if (vg) - lvm_vg_close (vg); - lvm_quit (handle); - GF_FREE (vg_name); - return retval; -} -#endif - /* op-sm */ int glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr) @@ -653,9 +619,6 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr) char msg[2048] = {0}; uuid_t volume_uuid; char *volume_uuid_str; -#ifdef HAVE_BD_XLATOR - char *dev_type = NULL; -#endif gf_boolean_t is_force = _gf_false; this = THIS; @@ -700,10 +663,6 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr) goto out; } -#ifdef HAVE_BD_XLATOR - ret = dict_get_str (dict, "device", &dev_type); -#endif - ret = dict_get_str (dict, "bricks", &bricks); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to get bricks for " @@ -752,18 +711,6 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr) goto out; } -#ifdef HAVE_BD_XLATOR - if (dev_type) { - ret = glusterd_is_valid_vg (brick_info->path); - if (ret) { - snprintf (msg, sizeof(msg), "invalid vg %s", - brick_info->path); - goto out; - } - - break; - } else -#endif if (!uuid_compare (brick_info->uuid, MY_UUID)) { ret = glusterd_validate_and_create_brickpath (brick_info, volume_uuid, op_errstr, @@ -911,9 +858,6 @@ glusterd_op_stage_start_volume (dict_t *dict, char **op_errstr) if (uuid_compare (brickinfo->uuid, MY_UUID)) continue; - if (volinfo->backend == GD_VOL_BK_BD) - continue; - ret = gf_lstat_dir (brickinfo->path, NULL); if (ret && (flags & GF_CLI_FLAG_OP_FORCE)) { continue; @@ -1350,109 +1294,6 @@ out: return ret; } -#ifdef HAVE_BD_XLATOR -int -glusterd_op_stage_bd (dict_t *dict, char **op_errstr) -{ - int ret = -1; - char *volname = NULL; - char *path = NULL; - char *size = NULL; - glusterd_volinfo_t *volinfo = NULL; - char msg[2048] = {0,}; - gf_xl_bd_op_t bd_op = GF_BD_OP_INVALID; - uint64_t bytes = 0; - - ret = dict_get_str (dict, "volname", &volname); - if (ret) { - snprintf (msg, sizeof(msg), "Failed to get volume name"); - gf_log (THIS->name, GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - - ret = dict_get_int32 (dict, "bd-op", (int32_t *)&bd_op); - if (ret) { - snprintf (msg, sizeof(msg), "Failed to get bd-op"); - gf_log (THIS->name, GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - - ret = dict_get_str (dict, "path", &path); - if (ret) { - snprintf (msg, sizeof(msg), "Failed to get path"); - gf_log (THIS->name, GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - - if (bd_op == GF_BD_OP_NEW_BD) { - ret = dict_get_str (dict, "size", &size); - if (ret) { - snprintf (msg, sizeof(msg), "Failed to get size"); - gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - if (gf_string2bytesize (size, &bytes) < 0) { - snprintf (msg, sizeof(msg), - "Invalid size %s, suffix with KB, MB etc", - size); - gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - ret = -1; - goto out; - } - } else if (bd_op == GF_BD_OP_SNAPSHOT_BD) { - ret = dict_get_str (dict, "size", &size); - if (ret) { - snprintf (msg, sizeof(msg), "Failed to get size"); - gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - - if (gf_string2bytesize (size, &bytes) < 0) { - ret = -1; - snprintf (msg, sizeof(msg), - "Invalid size %s, suffix with KB, MB etc", - size); - gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - } - - ret = glusterd_volinfo_find (volname, &volinfo); - if (ret) { - snprintf (msg, sizeof(msg), "Volume %s does not exist", - volname); - gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - goto out; - } - - ret = glusterd_validate_volume_id (dict, volinfo); - if (ret) - goto out; - - if (!glusterd_is_volume_started (volinfo)) { - snprintf (msg, sizeof(msg), "Volume %s is not started", - volname); - gf_log ("", GF_LOG_ERROR, "%s", msg); - *op_errstr = gf_strdup (msg); - ret = -1; - goto out; - } - - ret = 0; -out: - gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); - return ret; -} -#endif - int glusterd_op_create_volume (dict_t *dict, char **op_errstr) { @@ -1474,9 +1315,6 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) char *str = NULL; char *username = NULL; char *password = NULL; -#ifdef HAVE_BD_XLATOR - char *device = NULL; -#endif this = THIS; GF_ASSERT (this); @@ -1531,12 +1369,6 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) goto out; } -#ifdef HAVE_BD_XLATOR - ret = dict_get_str (dict, "device", &device); - if (!ret) - volinfo->backend = GD_VOL_BK_BD; -#endif - /* replica-count 1 means, no replication, file is in one brick only */ volinfo->replica_count = 1; /* stripe-count 1 means, no striping, file is present as a whole */ diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index ff9ca41f918..8d8f8d4e07e 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -98,7 +98,6 @@ typedef enum glusterd_op_ { GD_OP_LIST_VOLUME, GD_OP_CLEARLOCKS_VOLUME, GD_OP_DEFRAG_BRICK_VOLUME, - GD_OP_BD_OP, GD_OP_COPY_FILE, GD_OP_SYS_EXEC, GD_OP_GSYNC_CREATE, @@ -232,11 +231,6 @@ struct _auth { typedef struct _auth auth_t; -typedef enum glusterd_vol_backend_ { - GD_VOL_BK_DEFAULT = 0, /* POSIX */ - GD_VOL_BK_BD = 1, -} glusterd_vol_backend_t; - struct glusterd_rebalance_ { gf_defrag_status_t defrag_status; uint64_t rebalance_files; @@ -306,7 +300,6 @@ struct glusterd_volinfo_ { xlator_t *xl; gf_boolean_t memory_accounting; - glusterd_vol_backend_t backend; int op_version; int client_op_version; @@ -746,7 +739,6 @@ int glusterd_op_statedump_volume (dict_t *dict, char **op_errstr); int glusterd_op_stage_clearlocks_volume (dict_t *dict, char **op_errstr); int glusterd_op_clearlocks_volume (dict_t *dict, char **op_errstr, dict_t *rsp_dict); -int glusterd_op_stage_bd (dict_t *dict, char **op_errstr); /* misc */ void glusterd_do_replace_brick (void *data); diff --git a/xlators/storage/Makefile.am b/xlators/storage/Makefile.am index e1316a12702..5e3ed0eb93b 100644 --- a/xlators/storage/Makefile.am +++ b/xlators/storage/Makefile.am @@ -1,6 +1,3 @@ SUBDIRS = posix -if ENABLE_BD_XLATOR -SUBDIRS += bd_map -endif CLEANFILES = diff --git a/xlators/storage/bd_map/Makefile.am b/xlators/storage/bd_map/Makefile.am deleted file mode 100644 index a985f42a877..00000000000 --- a/xlators/storage/bd_map/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES = diff --git a/xlators/storage/bd_map/src/Makefile.am b/xlators/storage/bd_map/src/Makefile.am deleted file mode 100644 index 91412e91d9a..00000000000 --- a/xlators/storage/bd_map/src/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ - -if ENABLE_BD_XLATOR -xlator_LTLIBRARIES = bd_map.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/storage - -bd_map_la_LDFLAGS = -module -avoid-version -LIBBD = -llvm2app -lrt -bd_map_la_SOURCES = bd_map.c bd_map_help.c -bd_map_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(LIBBD) - -noinst_HEADERS = bd_map.h bd_map_help.h - -AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \ - -I$(top_srcdir)/rpc/xdr/src \ - -I$(top_srcdir)/rpc/rpc-lib/src - -AM_CFLAGS = -fno-strict-aliasing -Wall $(GF_CFLAGS) - -CLEANFILES = - -endif diff --git a/xlators/storage/bd_map/src/bd_map.c b/xlators/storage/bd_map/src/bd_map.c deleted file mode 100644 index 9c8f69c6488..00000000000 --- a/xlators/storage/bd_map/src/bd_map.c +++ /dev/null @@ -1,2580 +0,0 @@ -/* - BD translator - Exports Block devices on server side as regular - files to client - - Now only exporting Logical volumes supported. - - Copyright IBM, Corp. 2012 - - This file is part of GlusterFS. - - Author: - M. Mohan Kumar <mohan@in.ibm.com> - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <time.h> -#include <lvm2app.h> -#include <openssl/md5.h> - -#include "bd_map.h" -#include "bd_map_help.h" -#include "defaults.h" -#include "glusterfs3-xdr.h" -#include "run.h" -#include "protocol-common.h" - -/* Regular fops */ - -int -bd_access (call_frame_t *frame, xlator_t *this, - loc_t *loc, int32_t mask, dict_t *xdict) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - char path[PATH_MAX] = {0, }; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - - sprintf (path, "/dev/mapper/%s", loc->path); - op_ret = access (path, mask & 07); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, "access failed on %s: %s", - loc->path, strerror (op_errno)); - goto out; - } - op_ret = 0; -out: - STACK_UNWIND_STRICT (access, frame, op_ret, op_errno, NULL); - - return 0; -} - -#define LV_RENAME "/sbin/lvrename" - -int bd_rename (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc, dict_t *xdict) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - char *new_path = NULL; - char *np = NULL; - struct iatt stbuf = {0, }; - struct iatt preoldparent = {0, }; - struct iatt postoldparent = {0, }; - struct iatt prenewparent = {0, }; - struct iatt postnewparent = {0, }; - bd_priv_t *priv = NULL; - bd_entry_t *lventry = NULL; - bd_entry_t *newp_entry = NULL; - char *path = NULL; - struct stat v_stat = {0, }; - runner_t runner = {0, }; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (oldloc, out); - VALIDATE_OR_GOTO (newloc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - BD_ENTRY (priv, lventry, oldloc->path); - if (lventry->refcnt > 1) { - op_errno = EBUSY; - goto out; - } - - memcpy (&preoldparent, lventry->parent->attr, sizeof(preoldparent)); - - new_path = np = gf_strdup (newloc->path); - if (!new_path) - goto out; - new_path = strrchr (np, '/'); - if (!new_path) { - op_errno = EINVAL; - goto out; - } - - *new_path = '\0'; - BD_ENTRY (priv, newp_entry, np); - - memcpy (&prenewparent, newp_entry->parent->attr, sizeof(preoldparent)); - - runinit (&runner); - - runner_add_args (&runner, LV_RENAME, NULL); - runner_add_args (&runner, lventry->parent->name, NULL); - runner_add_args (&runner, oldloc->name, NULL); - runner_add_args (&runner, newloc->name, NULL); - - runner_start (&runner); - runner_end (&runner); - - /* verify */ - gf_asprintf (&path, "/dev/%s", newloc->path); - if (stat (path, &v_stat) < 0) { - op_errno = EIO; - goto out; - } - BD_ENTRY_UPDATE_MTIME (lventry); - BD_ENTRY_UPDATE_MTIME (newp_entry); - memcpy (&postoldparent, lventry->parent->attr, sizeof(postoldparent)); - memcpy (&postnewparent, newp_entry->parent->attr, - sizeof(postoldparent)); - BD_WR_LOCK (&priv->lock); - strncpy (lventry->name, newloc->name, sizeof(lventry->name)); - memcpy (&stbuf, lventry->attr, sizeof(stbuf)); - BD_UNLOCK (&priv->lock); - op_ret = 0; -out: - if (lventry) - BD_PUT_ENTRY (priv, lventry); - if (newp_entry) - BD_PUT_ENTRY (priv, newp_entry); - if (np) - GF_FREE (np); - if (path) - GF_FREE (path); - - STACK_UNWIND_STRICT (rename, frame, op_ret, op_errno, &stbuf, - &preoldparent, &postoldparent, &prenewparent, - &postnewparent, NULL); - return 0; -} - -int32_t -bd_delete_lv (bd_priv_t *priv, bd_entry_t *p_entry, bd_entry_t *lventry, - const char *path, int *op_errno) -{ - vg_t vg = NULL; - lv_t lv = NULL; - int op_ret = -1; - - *op_errno = 0; - BD_WR_LOCK (&priv->lock); - vg = lvm_vg_open (priv->handle, p_entry->name, "w", 0); - if (!vg) { - *op_errno = ENOENT; - BD_UNLOCK (&priv->lock); - goto out; - } - - lv = lvm_lv_from_name (vg, lventry->name); - if (!lv) { - lvm_vg_close (vg); - *op_errno = ENOENT; - BD_UNLOCK (&priv->lock); - goto out; - } - op_ret = lvm_vg_remove_lv (lv); - if (op_ret < 0) { - *op_errno = errno; - lvm_vg_close (vg); - BD_UNLOCK (&priv->lock); - goto out; - } - lvm_vg_close (vg); - - op_ret = bd_entry_rm (path); - if (op_ret < 0) { - *op_errno = EIO; - BD_UNLOCK (&priv->lock); - goto out; - } - BD_ENTRY_UPDATE_MTIME (p_entry); - - op_ret = 0; - op_errno = 0; - - BD_UNLOCK (&priv->lock); - op_ret = 0; -out: - return op_ret; -} - -int32_t -bd_unlink (call_frame_t *frame, xlator_t *this, - loc_t *loc, int xflag, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t op_errno = ENOENT; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - bd_priv_t *priv = NULL; - bd_entry_t *lventry = NULL; - bd_entry_t *p_entry = NULL; - char *vg_name = NULL; - char *volume = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - volume = vg_name = gf_strdup (loc->path); - if (!volume) - goto out; - volume = strrchr (volume, '/'); - if (!volume) { - op_errno = EINVAL; - goto out; - } - /* creating under non VG directory not permited */ - if (vg_name == volume) { - op_errno = EOPNOTSUPP; - goto out; - } - *volume = '\0'; - - BD_ENTRY (priv, p_entry, vg_name); - BD_ENTRY (priv, lventry, loc->path); - if (!p_entry || !lventry) - goto out; - - memcpy (&preparent, p_entry->attr, sizeof(preparent)); - op_ret = bd_delete_lv (priv, p_entry, lventry, loc->path, &op_errno); - memcpy (&postparent, p_entry->attr, sizeof(postparent)); -out: - if (p_entry) - BD_PUT_ENTRY (priv, p_entry); - if (lventry) - BD_PUT_ENTRY (priv, lventry); - if (vg_name) - GF_FREE (vg_name); - STACK_UNWIND_STRICT (unlink, frame, op_ret, op_errno, - &preparent, &postparent, NULL); - - return 0; -} - -#define LVM_CREATE "/sbin/lvcreate" - -#define IOV_NR 4 -#define IOV_SIZE (4 * 1024) - -int bd_clone_lv (bd_priv_t *priv, bd_entry_t *p_entry, dict_t *output, - const char *vg_name, const char *lv_name, - const char *dest_lv_name, struct iatt *stbuf) -{ - int32_t ret = -1; - vg_t vg = NULL; - lv_t lv = NULL; - ssize_t size = 0; - uint64_t extent = 0; - int fd1 = -1; - int fd2 = -1; - struct iatt iattr = {0, }; - bd_entry_t *lventry = NULL; - char path[512] = {0, }; - struct iovec *vec = NULL; - int i = 0; - ssize_t bytes = 0; - int nr_iov = 0; - - vec = GF_CALLOC (IOV_NR, sizeof(struct iovec), gf_common_mt_iovec); - if (!vec) - goto out; - - for (i = 0; i < IOV_NR; i++) { - vec[i].iov_base = GF_MALLOC (IOV_SIZE, gf_common_mt_char); - if (!vec[i].iov_base) - goto out; - vec[i].iov_len = IOV_SIZE; - } - - vg = lvm_vg_open (priv->handle, vg_name, "w", 0); - if (!vg) { - gf_log (THIS->name, GF_LOG_ERROR, - "lvm_vg_open %s failed", vg_name); - ret = -1; - goto out; - } - lv = lvm_lv_from_name (vg, lv_name); - if (!lv) { - gf_log (THIS->name, GF_LOG_ERROR, "lvm_lv_from_name failed"); - ret = -1; - goto out; - } - - size = lvm_lv_get_size (lv); - extent = size / lvm_vg_get_extent_size (vg); - - if (lvm_vg_create_lv_linear (vg, dest_lv_name, size) == NULL) { - gf_log (THIS->name, GF_LOG_ERROR, "lv_create:%s", - lvm_errmsg(priv->handle)); - ret = -1; - goto out; - } - sprintf (path, "/dev/%s/%s", vg_name, lv_name); - fd1 = open (path, O_RDONLY); - if (fd1 < 0) { - gf_log (THIS->name, GF_LOG_ERROR, "opening %s failed", path); - goto out; - } - sprintf (path, "/dev/%s/%s", vg_name, dest_lv_name); - fd2 = open (path, O_WRONLY); - if (fd2 < 0) { - gf_log (THIS->name, GF_LOG_ERROR, "opening %s failed", path); - goto out; - } - - bd_entry_istat (path, &iattr, IA_IFREG); - iattr.ia_size = size; - - bytes = size; - while (bytes) { - size = readv(fd1, vec, IOV_NR); - if (size < 0) { - gf_log (THIS->name, GF_LOG_DEBUG, - "read failed:%s", strerror(errno)); - goto out; - } - if (size < IOV_NR * IOV_SIZE) { - vec[size / IOV_SIZE].iov_len = size % IOV_SIZE; - nr_iov = (size / IOV_SIZE) + 1; - } else - nr_iov = IOV_NR; - bytes -= size; - size = writev (fd2, vec, nr_iov); - if (size < 0) { - gf_log (THIS->name, GF_LOG_DEBUG, - "write failed:%s", strerror(errno)); - goto out; - } - } - - lventry = bd_entry_add (p_entry, dest_lv_name, &iattr, IA_IFREG); - if (!lventry) { - ret = EAGAIN; - goto out; - } - - if (stbuf) - memcpy (stbuf, &iattr, sizeof(iattr)); - - ret = 0; - gf_log (THIS->name, GF_LOG_INFO, "Clone completed"); -out: - if (vg) - lvm_vg_close (vg); - if (fd1 != -1) - close (fd1); - if (fd2 != -1) - close (fd2); - if (vec) - iov_free (vec, IOV_NR); - return ret; -} - -int bd_snapshot_lv (bd_priv_t *priv, bd_entry_t *p_entry, dict_t *output, - const char *lv_name, const char *dest_lv, char *size, - struct iatt *stbuf) -{ - int32_t ret = -1; - struct iatt iattr = {0, }; - struct stat stat = {0, }; - bd_entry_t *lventry = NULL; - char *error = NULL; - int retval = -1; - runner_t runner = {0, }; - char *path = NULL; - vg_t vg = NULL; - lv_t lv = NULL; - - runinit (&runner); - - runner_add_args (&runner, LVM_CREATE, NULL); - runner_add_args (&runner, "--snapshot", NULL); - runner_argprintf (&runner, "/dev/%s/%s", p_entry->name, lv_name); - runner_add_args (&runner, "--name", NULL); - runner_argprintf (&runner, "%s", dest_lv); - runner_argprintf (&runner, "-L%s", size); - - runner_start (&runner); - runner_end (&runner); - - gf_asprintf (&path, "/dev/%s/%s", p_entry->name, dest_lv); - if (!path) { - ret = -ENOMEM; - goto out; - } - if (lstat (path, &stat) < 0) { - ret = -EAGAIN; - if (output) - gf_asprintf (&error, "try again"); - goto out; - } - - vg = lvm_vg_open (priv->handle, p_entry->name, "r", 0); - if (!vg) { - ret = -EIO; - if (output) - gf_asprintf (&error, "can't open vg %s", p_entry->name); - goto out; - } - lv = lvm_lv_from_name (vg, lv_name); - if (!lv) { - ret = -EIO; - if (output) - gf_asprintf (&error, "can't open lv %s", lv_name); - goto out; - } - bd_entry_istat (path, &iattr, IA_IFREG); - iattr.ia_size = lvm_lv_get_size (lv); - lventry = bd_entry_add (p_entry, dest_lv, &iattr, IA_IFREG); - if (!lventry) { - if (output) - gf_asprintf (&error, "try again"); - ret = -EAGAIN; - goto out; - } - if (stbuf) - memcpy (stbuf, &iattr, sizeof(iattr)); - ret = 0; -out: - if (vg) - lvm_vg_close (vg); - if (error && output) - retval = dict_set_str (output, "error", error); - GF_FREE (path); - return ret; -} - -/* - * Creates a snapshot of given LV - */ -int -bd_symlink (call_frame_t *frame, xlator_t *this, - const char *linkname, loc_t *loc, mode_t umask, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - bd_priv_t *priv = NULL; - struct iatt stbuf = {0, }; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - bd_entry_t *lventry = NULL; - char *name = NULL; - char *np = NULL; - char *volume = NULL; - char *vg_name = NULL; - char *path = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - if (strchr (loc->path, '/')) { - vg_name = gf_strdup (loc->path); - volume = strrchr (vg_name, '/'); - if (!volume) { - op_errno = EINVAL; - goto out; - } - /* creating under non VG directory not permited */ - if (vg_name == volume) { - op_errno = EOPNOTSUPP; - goto out; - } - GF_FREE (vg_name); - vg_name = NULL; - } - - /* - * symlink creation for BD xlator is different - * source (LV) has to exist for creation of symbolic link (snapshot) - */ - if (strchr (linkname, '/')) { - op_errno = EOPNOTSUPP; - goto out; - } - gf_asprintf (&path, "%s/%s", priv->vg, linkname); - if (!path) { - op_errno = -ENOMEM; - goto out; - } - BD_ENTRY (priv, lventry, path); - if (!lventry) { - op_errno = ENOENT; - goto out; - } - - name = np = gf_strdup (loc->path); - if (!name) - goto out; - - /* Get LV name from loc->path */ - name = strrchr (loc->path, '/'); - if (name != loc->path) - name++; - - memcpy (&preparent, lventry->parent->attr, sizeof(preparent)); - if (bd_snapshot_lv (priv, lventry->parent, NULL, lventry->name, - name, "1", &stbuf) < 0) { - op_errno = EAGAIN; - goto out; - } - BD_ENTRY_UPDATE_MTIME (lventry->parent); - memcpy (&postparent, lventry->parent->attr, sizeof (postparent)); - op_ret = 0; -out: - if (lventry) - BD_PUT_ENTRY (priv, lventry); - if (np) - GF_FREE (np); - if (vg_name) - GF_FREE (vg_name); - if (path) - GF_FREE (path); - - STACK_UNWIND_STRICT (symlink, frame, op_ret, op_errno, - (loc)?loc->inode:NULL, &stbuf, &preparent, - &postparent, NULL); - return 0; -} - -/* - * bd_link: Does full clone of given logical volume - * A new logical volume with source logical volume's size created - * and entire content copied - */ -int -bd_link (call_frame_t *frame, xlator_t *this, - loc_t *oldloc, loc_t *newloc, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - bd_priv_t *priv = NULL; - struct iatt stbuf = {0, }; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - bd_entry_t *lventry = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - VALIDATE_OR_GOTO (oldloc, out); - VALIDATE_OR_GOTO (newloc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - BD_ENTRY (priv, lventry, oldloc->path); - if (!lventry) { - op_errno = ENOENT; - goto out; - } - memcpy (&postparent, lventry->parent->attr, sizeof (postparent)); - if (bd_clone_lv (priv, lventry->parent, NULL, lventry->parent->name, - lventry->name, newloc->name, &stbuf) < 0) { - op_errno = EAGAIN; - goto out; - } - BD_ENTRY_UPDATE_MTIME (lventry->parent); - memcpy (&preparent, lventry->parent->attr, sizeof (preparent)); - op_ret = 0; -out: - if (lventry) - BD_PUT_ENTRY (priv, lventry); - - - STACK_UNWIND_STRICT (link, frame, op_ret, op_errno, - (oldloc)?oldloc->inode:NULL, &stbuf, &preparent, - &postparent, NULL); - return 0; -} - -int32_t -bd_open (call_frame_t *frame, xlator_t *this, - loc_t *loc, int32_t flags, fd_t *fd, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - int32_t _fd = -1; - bd_fd_t *bd_fd = NULL; - bd_entry_t *lventry = NULL; - bd_priv_t *priv = NULL; - char *devpath = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - VALIDATE_OR_GOTO (loc, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - BD_ENTRY (priv, lventry, loc->path); - if (!lventry) { - op_errno = ENOENT; - goto out; - } - - gf_asprintf (&devpath, "/dev/%s/%s", lventry->parent->name, - lventry->name); - _fd = open (devpath, flags, 0); - if (_fd == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "open on %s: %s", devpath, strerror (op_errno)); - goto out; - } - - bd_fd = GF_CALLOC (1, sizeof(*bd_fd), gf_bd_fd); - if (!bd_fd) { - op_errno = errno; - goto out; - } - bd_fd->entry = lventry; - bd_fd->fd = _fd; - - op_ret = fd_ctx_set (fd, this, (uint64_t)(long)bd_fd); - if (op_ret) { - gf_log (this->name, GF_LOG_WARNING, - "failed to set the fd context path=%s fd=%p", - loc->name, fd); - goto out; - } - - op_ret = 0; -out: - if (op_ret == -1) { - if (_fd != -1) - close (_fd); - /* FIXME: Should we call fd_ctx_set with NULL? */ - if (bd_fd) - GF_FREE (bd_fd); - if (lventry) - BD_PUT_ENTRY (priv, lventry); - } - if (devpath) - GF_FREE (devpath); - - STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, NULL); - - return 0; -} - -int -bd_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset, uint32_t flags, dict_t *xdata) -{ - uint64_t tmp_bd_fd = 0; - int32_t op_ret = -1; - int32_t op_errno = 0; - int _fd = -1; - bd_priv_t *priv = NULL; - struct iobuf *iobuf = NULL; - struct iobref *iobref = NULL; - struct iovec vec = {0, }; - bd_fd_t *bd_fd = NULL; - int ret = -1; - struct iatt stbuf = {0, }; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - VALIDATE_OR_GOTO (this->private, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - op_errno = -EINVAL; - gf_log (this->name, GF_LOG_WARNING, - "bd_fd is NULL from fd=%p", fd); - goto out; - } - bd_fd = (bd_fd_t *)(long)tmp_bd_fd; - if (!size) { - op_errno = EINVAL; - gf_log (this->name, GF_LOG_WARNING, "size=%"GF_PRI_SIZET, size); - goto out; - } - iobuf = iobuf_get2 (this->ctx->iobuf_pool, size); - if (!iobuf) { - op_errno = ENOMEM; - goto out; - } - _fd = bd_fd->fd; - op_ret = pread (_fd, iobuf->ptr, size, offset); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "read failed on fd=%p: %s", fd, - strerror (op_errno)); - goto out; - } - - vec.iov_base = iobuf->ptr; - vec.iov_len = op_ret; - - iobref = iobref_new (); - iobref_add (iobref, iobuf); - BD_ENTRY_UPDATE_ATIME (bd_fd->entry); - - memcpy (&stbuf, bd_fd->entry->attr, sizeof(stbuf)); - - /* Hack to notify higher layers of EOF. */ - if (bd_fd->entry->size == 0) - op_errno = ENOENT; - else if ((offset + vec.iov_len) >= bd_fd->entry->size) - op_errno = ENOENT; - op_ret = vec.iov_len; -out: - STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, - &vec, 1, &stbuf, iobref, NULL); - - if (iobref) - iobref_unref (iobref); - if (iobuf) - iobuf_unref (iobuf); - return 0; -} - -#define LVM_RESIZE "/sbin/lvresize" - -int32_t -bd_resize (bd_priv_t *priv, bd_entry_t *lventry, off_t *size) -{ - bd_entry_t *vgentry = NULL; - uint64_t extent = 0; - int32_t op_ret = -1; - vg_t vg = NULL; - uint32_t nr_ex = 0; - lv_t lv = NULL; - uint64_t new_size = 0; - runner_t runner = {0, }; - - BD_ENTRY (priv, vgentry, lventry->parent->name); - if (!vgentry) { - op_ret = ENOENT; - goto out; - } - - BD_WR_LOCK (&priv->lock); - vg = lvm_vg_open (priv->handle, vgentry->name, "w", 0); - if (!vg) { - op_ret = lvm_errno (priv->handle); - BD_UNLOCK (&priv->lock); - goto out; - } - - extent = lvm_vg_get_extent_size (vg); - lvm_vg_close (vg); - BD_UNLOCK (&priv->lock); - - nr_ex = *size / extent; - if (*size % extent) - nr_ex++; - *size = extent * nr_ex; - - runinit (&runner); - - runner_add_args (&runner, LVM_RESIZE, NULL); - runner_argprintf (&runner, "/dev/%s/%s", lventry->parent->name, - lventry->name); - runner_argprintf (&runner, "-l%ld", nr_ex); - runner_add_args (&runner, "-f", NULL); - - runner_start (&runner); - runner_end (&runner); - - BD_WR_LOCK (&priv->lock); - vg = lvm_vg_open (priv->handle, vgentry->name, "w", 0); - if (!vg) { - op_ret = lvm_errno (priv->handle); - BD_UNLOCK (&priv->lock); - goto out; - } - - lv = lvm_lv_from_name (vg, lventry->name); - if (!lv) { - op_ret = lvm_errno (priv->handle); - lvm_vg_close (vg); - BD_UNLOCK (&priv->lock); - goto out; - } - new_size = lvm_lv_get_size (lv); - lvm_vg_close (vg); - if (new_size != *size) { - op_ret = EIO; - BD_UNLOCK (&priv->lock); - goto out; - } - - BD_UNLOCK (&priv->lock); - op_ret = 0; - -out: - if (vgentry) - BD_PUT_ENTRY (priv, vgentry); - - return op_ret; -} - - int32_t -bd_ftruncate (call_frame_t *frame, xlator_t *this, - fd_t *fd, off_t offset, dict_t *xdict) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - struct iatt preop = {0, }; - struct iatt postop = {0, }; - bd_fd_t *bd_fd = NULL; - int ret = -1; - uint64_t tmp_bd_fd = 0; - bd_priv_t *priv = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "bd_fd is NULL, fd=%p", fd); - op_errno = -ret; - goto out; - } - bd_fd = (bd_fd_t *)(long)tmp_bd_fd; - - memcpy (&preop, bd_fd->entry->attr, sizeof(preop)); - if (offset > bd_fd->entry->size) { - op_errno = bd_resize (priv, bd_fd->entry, &offset); - if (op_errno) - goto out; - if (offset > bd_fd->entry->size) { - bd_fd->entry->attr->ia_size = offset; - bd_fd->entry->size = offset; - } - } - /* If the requested size is less then current size - * we will not update that in bd_fd->entry->attr - * because it will result in showing size of this file less - * instead we will return 0 for less size truncation - */ - BD_ENTRY_UPDATE_MTIME (bd_fd->entry); - memcpy (&postop, bd_fd->entry->attr, sizeof(postop)); - - op_ret = 0; -out: - STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, &preop, - &postop, NULL); - return 0; -} - -int32_t -bd_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, - off_t offset, dict_t *xdict) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - struct iatt prebuf = {0, }; - struct iatt postbuf = {0, }; - bd_entry_t *lventry = NULL; - bd_priv_t *priv = NULL; - off_t size = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - BD_ENTRY (priv, lventry, loc->path); - if (!lventry) { - op_errno = ENOENT; - gf_log (this->name, GF_LOG_ERROR, - "pre-operation lstat on %s failed: %s", - loc->path, strerror (op_errno)); - goto out; - } - memcpy (&prebuf, lventry->attr, sizeof(prebuf)); - if (offset > lventry->size) { - op_errno = bd_resize (priv, lventry, &size); - if (op_errno) - goto out; - if (lventry->size < offset) { - lventry->attr->ia_size = offset; - lventry->size = size; - } - } - BD_ENTRY_UPDATE_MTIME (lventry); - memcpy (&postbuf, lventry->attr, sizeof(postbuf)); - BD_PUT_ENTRY (priv, lventry); - op_ret = 0; -out: - if (lventry) - BD_PUT_ENTRY (priv, lventry); - STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, - &prebuf, &postbuf, NULL); - return 0; -} - -int32_t -__bd_pwritev (int fd, struct iovec *vector, int count, off_t offset, - uint64_t bd_size) -{ - int32_t op_ret = 0; - int index = 0; - int retval = 0; - off_t internal_offset = 0; - int no_space = 0; - - if (!vector) - return -EFAULT; - - internal_offset = offset; - for (index = 0; index < count; index++) { - if (internal_offset >= bd_size) { - op_ret = -ENOSPC; - goto err; - } - if (internal_offset + vector[index].iov_len >= bd_size) { - vector[index].iov_len = bd_size - internal_offset; - no_space = 1; - } - - retval = pwrite (fd, vector[index].iov_base, - vector[index].iov_len, internal_offset); - if (retval == -1) { - gf_log (THIS->name, GF_LOG_WARNING, - "base %p, length %ld, offset %ld, message %s", - vector[index].iov_base, vector[index].iov_len, - internal_offset, strerror (errno)); - op_ret = -errno; - goto err; - } - op_ret += retval; - internal_offset += retval; - if (no_space) - break; - } -err: - return op_ret; -} - -int bd_create_lv (bd_priv_t *priv, bd_entry_t *p_entry, const char *vg_name, - const char *lv_name, char *size, mode_t mode) -{ - vg_t vg = NULL; - int ret = -1; - char *path = NULL; - struct iatt iattr = {0, }; - bd_entry_t *lventry = NULL; - uint64_t extent = 0; - - BD_WR_LOCK (&priv->lock); - vg = lvm_vg_open (priv->handle, vg_name, "w", 0); - if (!vg) { - ret = -1; - goto out; - } - extent = lvm_vg_get_extent_size (vg); - if (size) - gf_string2bytesize (size, &extent); - - if (lvm_vg_create_lv_linear (vg, lv_name, extent) == NULL) { - ret = -EAGAIN; - lvm_vg_close (vg); - goto out; - } - lvm_vg_close (vg); - - gf_asprintf (&path, "/dev/%s/%s", vg_name, lv_name); - if (!path) { - ret = -ENOMEM; - lvm_vg_close (vg); - goto out; - } - bd_entry_istat (path, &iattr, IA_IFREG); - iattr.ia_size = extent; - if (!mode) - mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; - - iattr.ia_type = ia_type_from_st_mode (mode); - iattr.ia_prot = ia_prot_from_st_mode (mode); - lventry = bd_entry_add (p_entry, lv_name, &iattr, IA_IFREG); - if (!lventry) { - ret = -EAGAIN; - goto out; - } - ret = 0; -out: - BD_UNLOCK (&priv->lock); - if (path) - GF_FREE (path); - return ret; -} - -int bd_create (call_frame_t *frame, xlator_t *this, - loc_t *loc, int32_t flags, mode_t mode, - mode_t umask, fd_t *fd, dict_t *params) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - int32_t _fd = -1; - bd_priv_t *priv = NULL; - struct iatt stbuf = {0, }; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - bd_entry_t *p_entry = NULL; - bd_entry_t *lventry = NULL; - bd_fd_t *pfd = NULL; - char *vg_name = NULL; - char *volume = NULL; - char *path = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - VALIDATE_OR_GOTO (loc, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - volume = vg_name = gf_strdup (loc->path); - if (!volume) - goto out; - volume = strrchr (volume, '/'); - if (!volume) { - op_errno = EINVAL; - goto out; - } - /* creating under non VG directory not permited */ - if (vg_name == volume) { - op_errno = EOPNOTSUPP; - goto out; - } - *volume = '\0'; - - BD_ENTRY (priv, p_entry, vg_name); - if (!p_entry) { - op_errno = ENOENT; - goto out; - } - - memcpy (&preparent, p_entry->attr, sizeof(preparent)); - - op_errno = bd_create_lv (priv, p_entry, p_entry->name, loc->name, 0, - mode); - if (op_errno) - goto out; - - BD_ENTRY (priv, lventry, loc->path); - if (!lventry) { - gf_log (this->name, GF_LOG_WARNING, - "newly created LV not available %s", loc->path); - op_errno = EAGAIN; - goto out; - } - - /* Mask O_CREATE since we created LV */ - flags &= ~(O_CREAT | O_EXCL); - - gf_asprintf (&path, "/dev/%s/%s", p_entry->name, loc->name); - if (!path) { - op_errno = ENOMEM; - goto out; - } - _fd = open (path, flags, 0); - if (_fd == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "open on %s: %s", path, strerror (op_errno)); - goto out; - } - - memcpy (&stbuf, lventry->attr, sizeof(stbuf)); - - pfd = GF_CALLOC (1, sizeof(*pfd), gf_bd_fd); - if (!pfd) { - op_errno = errno; - goto out; - } - pfd->flag = flags; - pfd->fd = _fd; - pfd->entry = lventry; - - if (fd_ctx_set (fd, this, (uint64_t)(long)pfd)) { - gf_log (this->name, GF_LOG_WARNING, - "failed to set the fd context path=%s fd=%p", - loc->name, fd); - goto out; - } - - op_ret = 0; - - memcpy (&postparent, p_entry->attr, sizeof(postparent)); -out: - if (p_entry) - BD_PUT_ENTRY (priv, p_entry); - if (path) - GF_FREE (path); - if (op_ret < 0 && lventry) - BD_PUT_ENTRY (priv, lventry); - if (vg_name) - GF_FREE (vg_name); - - STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, - (loc)?loc->inode:NULL, &stbuf, &preparent, - &postparent, NULL); - return 0; -} - -/* - * We don't do actual setattr on devices on the host side, we just update - * the entries in server process & they are not persistent - */ -int bd_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid, dict_t *xdata) -{ - struct iatt statpre = {0, }; - struct iatt statpost = {0, }; - int32_t op_ret = -1; - int32_t op_errno = 0; - bd_priv_t *priv = NULL; - bd_fd_t *pfd = NULL; - int ret = 0; - uint64_t tmp_pfd = 0; - int _fd = -1; - - priv = this->private; - - ret = fd_ctx_get (fd, this, &tmp_pfd); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "pfd is NULL, fd=%p", fd); - op_errno = -ret; - goto out; - } - pfd = (bd_fd_t *)(long)tmp_pfd; - - _fd = pfd->fd; - memcpy (&statpre, pfd->entry->attr, sizeof(statpre)); - op_ret = 0; - - if (valid & GF_SET_ATTR_MODE) - pfd->entry->attr->ia_prot = stbuf->ia_prot; - if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { - if (valid & GF_SET_ATTR_UID) - pfd->entry->attr->ia_uid = stbuf->ia_uid; - if (valid & GF_SET_ATTR_GID) - pfd->entry->attr->ia_gid = stbuf->ia_gid; - } - if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { - pfd->entry->attr->ia_atime = stbuf->ia_atime; - pfd->entry->attr->ia_atime_nsec = stbuf->ia_atime_nsec; - pfd->entry->attr->ia_mtime = stbuf->ia_mtime; - pfd->entry->attr->ia_mtime_nsec = stbuf->ia_mtime_nsec; - } - memcpy (&statpost, pfd->entry->attr, sizeof(statpost)); - op_errno = 0; -out: - STACK_UNWIND_STRICT (setattr, frame, 0, 0, &statpre, &statpost, NULL); - return 0; -} - -int bd_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid, dict_t *xdata) -{ - struct iatt statpre = {0, }; - struct iatt statpost = {0, }; - bd_entry_t *lventry = NULL; - int32_t op_ret = -1; - int32_t op_errno = 0; - bd_priv_t *priv = NULL; - char path[PATH_MAX] = {0, }; - - priv = this->private; - - /* - * We don't allow to do setattr on / on host side - * ie /dev - */ - if (!strcmp (loc->path, "/")) { - op_ret = 0; - goto out; - } - - BD_ENTRY (priv, lventry, loc->path); - if (!lventry) { - op_errno = ENOENT; - goto out; - } - sprintf (path, "/dev/%s/%s", lventry->parent->name, lventry->name); - - memcpy (&statpre, lventry->attr, sizeof(statpre)); - if (valid & GF_SET_ATTR_MODE) - lventry->attr->ia_prot = stbuf->ia_prot; - if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) { - if (valid & GF_SET_ATTR_UID) - lventry->attr->ia_uid = stbuf->ia_uid; - if (valid & GF_SET_ATTR_GID) - lventry->attr->ia_gid = stbuf->ia_gid; - } - if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { - lventry->attr->ia_atime = stbuf->ia_atime; - lventry->attr->ia_atime_nsec = stbuf->ia_atime_nsec; - lventry->attr->ia_mtime = stbuf->ia_mtime; - lventry->attr->ia_mtime_nsec = stbuf->ia_mtime_nsec; - } - memcpy (&statpost, lventry->attr, sizeof(statpost)); - op_errno = 0; -out: - if (lventry) - BD_PUT_ENTRY (priv, lventry); - STACK_UNWIND_STRICT (setattr, frame, 0, 0, &statpre, &statpost, NULL); - return 0; -} - -int -bd_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iovec *vector, int32_t count, off_t offset, - uint32_t flags, struct iobref *iobref, dict_t *xdict) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - int _fd = -1; - bd_priv_t *priv = NULL; - bd_fd_t *bd_fd = NULL; - int ret = -1; - struct iatt preop = {0, }; - struct iatt postop = {0, }; - uint64_t tmp_bd_fd = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - VALIDATE_OR_GOTO (vector, out); - VALIDATE_OR_GOTO (this->private, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - op_errno = -ret; - gf_log (this->name, GF_LOG_WARNING, - "bd_fd is NULL from fd=%p", fd); - goto out; - } - bd_fd = (bd_fd_t *)(long)tmp_bd_fd; - _fd = bd_fd->fd; - - memcpy (&preop, bd_fd->entry->attr, sizeof(preop)); - op_ret = __bd_pwritev (_fd, vector, count, offset, bd_fd->entry->size); - if (op_ret < 0) { - op_errno = -op_ret; - op_ret = -1; - gf_log (this->name, GF_LOG_ERROR, "write failed: offset %"PRIu64 - ", %s", offset, strerror (op_errno)); - goto out; - } - BD_ENTRY_UPDATE_MTIME (bd_fd->entry); - memcpy (&postop, bd_fd->entry->attr, sizeof(postop)); - -out: - STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, &preop, - &postop, NULL); - - return 0; -} - -int32_t -bd_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req) -{ - struct iatt buf = {0, }; - int32_t op_ret = -1; - int32_t entry_ret = 0; - int32_t op_errno = 0; - char *pathdup = NULL; - bd_entry_t *bdentry = NULL; - struct iatt postparent = {0, }; - bd_priv_t *priv = NULL; - char *p = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - VALIDATE_OR_GOTO (loc->path, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - BD_ENTRY (priv, bdentry, loc->path); - if (!bdentry) { - op_errno = ENOENT; - entry_ret = -1; - goto parent; - } - memcpy (&buf, bdentry->attr, sizeof(buf)); - BD_PUT_ENTRY (priv, bdentry); - -parent: - if (loc->parent) { - pathdup = p = gf_strdup (loc->path); - if (!pathdup) { - op_errno = ENOMEM; - entry_ret = -1; - goto out; - } - p = strrchr (pathdup, '/'); - if (p == pathdup) - *(p+1) = '\0'; - else - *p = '\0'; - BD_ENTRY (priv, bdentry, pathdup); - if (!bdentry) { - op_errno = ENOENT; - gf_log (this->name, GF_LOG_ERROR, - "post-operation lookup on parent of %s " - "failed: %s", - loc->path, strerror (op_errno)); - goto out; - } - memcpy (&postparent, bdentry->attr, sizeof(postparent)); - BD_PUT_ENTRY (priv, bdentry); - } - - op_ret = entry_ret; -out: - if (pathdup) - GF_FREE (pathdup); - - STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, - (loc)?loc->inode:NULL, &buf, NULL, &postparent); - - return 0; -} - -int32_t -bd_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) -{ - struct iatt buf = {0,}; - int32_t op_ret = -1; - int32_t op_errno = 0; - bd_entry_t *bdentry = NULL; - bd_priv_t *priv = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - BD_ENTRY (priv, bdentry, loc->path); - if (!bdentry) { - op_errno = ENOENT; - gf_log (this->name, GF_LOG_ERROR, "stat on %s failed: %s", - loc->path, strerror (op_errno)); - goto out; - } - memcpy (&buf, bdentry->attr, sizeof(buf)); - BD_PUT_ENTRY (priv, bdentry); - op_ret = 0; - -out: - STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, &buf, NULL); - - return 0; -} - -int32_t -bd_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) -{ - int ret = -1; - int32_t op_ret = -1; - int32_t op_errno = 0; - uint64_t tmp_bd_fd = 0; - struct iatt buf = {0, }; - bd_fd_t *bd_fd = NULL; - int _fd = -1; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "bd_fd is NULL, fd=%p", fd); - op_errno = -EINVAL; - goto out; - } - bd_fd = (bd_fd_t *)(long)tmp_bd_fd; - _fd = bd_fd->fd; - - memcpy (&buf, bd_fd->entry->attr, sizeof(buf)); - op_ret = 0; - -out: - STACK_UNWIND_STRICT (stat, frame, op_ret, op_errno, &buf, NULL); - return 0; -} - -int32_t -bd_opendir (call_frame_t *frame, xlator_t *this, - loc_t *loc, fd_t *fd, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t op_errno = EINVAL; - bd_fd_t *bd_fd = NULL; - bd_entry_t *bdentry = NULL; - bd_priv_t *priv = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (loc, out); - VALIDATE_OR_GOTO (loc->path, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - BD_ENTRY (priv, bdentry, loc->path); - if (!bdentry) { - op_errno = ENOENT; - gf_log (this->name, GF_LOG_ERROR, "opendir failed on %s: %s", - loc->path, strerror (op_errno)); - goto out; - } - bd_fd = GF_CALLOC (1, sizeof(*bd_fd), gf_bd_fd); - if (!bd_fd) { - op_errno = errno; - BD_PUT_ENTRY (priv, bdentry); - goto out; - } - - bd_fd->p_entry = bdentry; - - bdentry = list_entry ((&bdentry->child)->next, typeof(*bdentry), child); - if (!bdentry) { - op_errno = EINVAL; - gf_log (this->name, GF_LOG_ERROR, "bd_entry NULL"); - goto out; - } - bdentry = list_entry ((&bdentry->sibling), typeof(*bdentry), sibling); - if (!bdentry) { - op_errno = EINVAL; - gf_log (this->name, GF_LOG_ERROR, "bd_entry NULL"); - goto out; - } - - bd_fd->entry = bdentry; - - op_ret = fd_ctx_set (fd, this, (uint64_t) (long)bd_fd); - if (op_ret) { - gf_log (this->name, GF_LOG_ERROR, - "failed to set the fd context path=%s fd=%p", - loc->path, fd); - goto out; - } - - op_ret = 0; -out: - if (op_ret == -1) { - BD_PUT_ENTRY (priv, bd_fd->p_entry); - if (bd_fd) - GF_FREE (bd_fd); - } - - STACK_UNWIND_STRICT (opendir, frame, op_ret, op_errno, fd, NULL); - return 0; -} - -int32_t -bd_releasedir (xlator_t *this, fd_t *fd) -{ - bd_fd_t *bd_fd = NULL; - uint64_t tmp_bd_fd = 0; - int ret = 0; - bd_priv_t *priv = NULL; - - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = fd_ctx_del (fd, this, &tmp_bd_fd); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, "bd_fd from fd=%p is NULL", - fd); - goto out; - } - bd_fd = (bd_fd_t *) (long)tmp_bd_fd; - BD_PUT_ENTRY (priv, bd_fd->p_entry); - - bd_fd = (bd_fd_t *) (long)tmp_bd_fd; - GF_FREE (bd_fd); -out: - return 0; -} - -/* - * bd_statfs: Mimics statfs by returning used/free extents in the VG - * TODO: IF more than one VG allowed per volume, this functions needs some - * change - */ -int32_t -bd_statfs (call_frame_t *frame, xlator_t *this, - loc_t *loc, dict_t *xdata) -{ - int32_t op_ret = -1; - int32_t ret = -1; - int32_t op_errno = 0; - bd_priv_t *priv = NULL; - struct statvfs buf = {0, }; - vg_t vg = NULL; - char *vg_name = NULL; - uint64_t size = 0; - uint64_t fr_size = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (this->private, out); - VALIDATE_OR_GOTO (loc, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = dict_get_str (this->options, "export", &vg_name); - if (ret) { - gf_log (this->name, GF_LOG_CRITICAL, - "FATAL: storage/bd does not specify volume groups"); - op_errno = EINVAL; - goto out; - } - - BD_RD_LOCK (&priv->lock); - - vg = lvm_vg_open (priv->handle, vg_name, "r", 0); - size += lvm_vg_get_size (vg); - fr_size += lvm_vg_get_free_size (vg); - lvm_vg_close (vg); - - BD_UNLOCK (&priv->lock); - - if (statvfs ("/", &buf) < 0) { - op_errno = errno; - goto out; - } - op_ret = 0; - buf.f_blocks = size / buf.f_frsize; - buf.f_bfree = fr_size / buf.f_frsize; - buf.f_bavail = fr_size / buf.f_frsize; -out: - STACK_UNWIND_STRICT (statfs, frame, op_ret, op_errno, &buf, NULL); - return 0; -} - -int32_t -bd_release (xlator_t *this, fd_t *fd) -{ - bd_fd_t *bd_fd = NULL; - int ret = -1; - uint64_t tmp_bd_fd = 0; - bd_priv_t *priv = NULL; - - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "bd_fd is NULL from fd=%p", - fd); - goto out; - } - bd_fd = (bd_fd_t *) (long)tmp_bd_fd; - close (bd_fd->fd); - BD_PUT_ENTRY (priv, bd_fd->entry); - - GF_FREE (bd_fd); -out: - return 0; -} - -int32_t -bd_fsync (call_frame_t *frame, xlator_t *this, - fd_t *fd, int32_t datasync, dict_t *xdata) -{ - int _fd = -1; - int ret = -1; - int32_t op_ret = -1; - int32_t op_errno = 0; - uint64_t tmp_bd_fd = 0; - bd_fd_t *bd_fd = NULL; - struct iatt preop = {0, }; - struct iatt postop = {0, }; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "bd_fd is NULL, fd=%p", fd); - op_errno = -ret; - goto out; - } - bd_fd = (bd_fd_t *)(long)tmp_bd_fd; - - _fd = bd_fd->fd; - memcpy (&preop, &bd_fd->entry->attr, sizeof(preop)); - if (datasync) { - ; -#ifdef HAVE_FDATASYNC - op_ret = fdatasync (_fd); - if (op_ret == -1) { - gf_log (this->name, GF_LOG_ERROR, - "fdatasync on fd=%p failed: %s", - fd, strerror (errno)); - } -#endif - } else { - op_ret = fsync (_fd); - if (op_ret == -1) { - op_errno = errno; - gf_log (this->name, GF_LOG_ERROR, - "fsync on fd=%p failed: %s", - fd, strerror (op_errno)); - goto out; - } - } - - memcpy (&postop, bd_fd->entry->attr, sizeof(postop)); - op_ret = 0; - -out: - STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, &preop, - &postop, NULL); - - return 0; -} - -int32_t -bd_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdict) -{ - int32_t op_ret = -1; - int32_t op_errno = 0; - int ret = -1; - uint64_t tmp_bd_fd = 0; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - op_errno = -EINVAL; - gf_log (this->name, GF_LOG_WARNING, - "bd_fd is NULL on fd=%p", fd); - goto out; - } - op_ret = 0; -out: - STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno, NULL); - - return 0; -} - -int -__bd_fill_readdir (pthread_rwlock_t *bd_lock, bd_fd_t *bd_fd, off_t off, - size_t size, gf_dirent_t *entries) -{ - size_t filled = 0; - int count = 0; - struct dirent entry = {0, }; - int32_t this_size = -1; - gf_dirent_t *this_entry = NULL; - bd_entry_t *bdentry = NULL; - bd_entry_t *cur_entry = NULL; - bd_entry_t *n_entry = NULL; - - BD_RD_LOCK (bd_lock); - - bdentry = list_entry ((&bd_fd->p_entry->child)->next, typeof(*n_entry), - child); - - if (off) { - int i = 0; - list_for_each_entry (n_entry, &bd_fd->entry->sibling, sibling) { - if (i == off && strcmp (n_entry->name, "")) { - bd_fd->entry = n_entry; - break; - } - } - } else - bd_fd->entry = list_entry ((&bdentry->sibling), - typeof(*n_entry), sibling); - - while (filled <= size) { - cur_entry = bd_fd->entry; - - n_entry = list_entry ((&bd_fd->entry->sibling)->next, - typeof (*cur_entry), sibling); - if (&n_entry->sibling == (&bdentry->sibling)) - break; - - strcpy (entry.d_name, n_entry->name); - entry.d_ino = n_entry->attr->ia_ino; - entry.d_off = off; - if (n_entry->attr->ia_type == IA_IFDIR) - entry.d_type = DT_DIR; - else - entry.d_type = DT_REG; - - this_size = max (sizeof(gf_dirent_t), - sizeof (gfs3_dirplist)) - + strlen (entry.d_name) + 1; - - if (this_size + filled > size) - break; - - bd_fd->entry = n_entry; - - this_entry = gf_dirent_for_name (entry.d_name); - if (!this_entry) { - gf_log (THIS->name, GF_LOG_ERROR, - "could not create gf_dirent for entry %s", - entry.d_name); - goto out; - } - this_entry->d_off = off; - this_entry->d_ino = entry.d_ino; - this_entry->d_type = entry.d_type; - off++; - - list_add_tail (&this_entry->list, &entries->list); - - filled += this_size; - count++; - } -out: - BD_UNLOCK (bd_lock); - return count; -} - -int32_t -bd_do_readdir (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t off, int whichop) -{ - uint64_t tmp_bd_fd = 0; - bd_fd_t *bd_fd = NULL; - int ret = -1; - int count = 0; - int32_t op_ret = -1; - int32_t op_errno = 0; - gf_dirent_t entries; - gf_dirent_t *tmp_entry = NULL; - bd_entry_t *bdentry = NULL; - bd_priv_t *priv = NULL; - char *devpath = NULL; - - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (this, out); - VALIDATE_OR_GOTO (fd, out); - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - INIT_LIST_HEAD (&entries.list); - - ret = fd_ctx_get (fd, this, &tmp_bd_fd); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, "bd_fd is NULL, fd=%p", fd); - op_errno = -EINVAL; - goto out; - } - bd_fd = (bd_fd_t *) (long)tmp_bd_fd; - LOCK (&fd->lock); - { - count = __bd_fill_readdir (&priv->lock, bd_fd, off, - size, &entries); - } - UNLOCK (&fd->lock); - - /* pick ENOENT to indicate EOF */ - op_errno = errno; - op_ret = count; - - if (whichop != GF_FOP_READDIRP) - goto out; - - BD_RD_LOCK (&priv->lock); - list_for_each_entry (tmp_entry, &entries.list, list) { - char path[PATH_MAX]; - sprintf (path, "%s/%s", bd_fd->p_entry->name, - tmp_entry->d_name); - bdentry = bd_entry_get (path); - if (!bdentry) { - gf_log (this->name, GF_LOG_WARNING, - "entry failed %s\n", tmp_entry->d_name); - continue; - } - if (bdentry->attr->ia_ino) - tmp_entry->d_ino = bdentry->attr->ia_ino; - memcpy (&tmp_entry->d_stat, - bdentry->attr, sizeof (tmp_entry->d_stat)); - bd_entry_put (bdentry); - GF_FREE (devpath); - } - BD_UNLOCK (&priv->lock); - -out: - STACK_UNWIND_STRICT (readdir, frame, op_ret, op_errno, &entries, NULL); - - gf_dirent_free (&entries); - - return 0; -} - -int32_t -bd_readdir (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t off, dict_t *dict) -{ - bd_do_readdir (frame, this, fd, size, off, GF_FOP_READDIR); - return 0; -} - - -int32_t -bd_readdirp (call_frame_t *frame, xlator_t *this, - fd_t *fd, size_t size, off_t off, dict_t *dict) -{ - bd_do_readdir (frame, this, fd, size, off, GF_FOP_READDIRP); - return 0; -} - -int32_t -bd_priv (xlator_t *this) -{ - return 0; -} - -int32_t -bd_inode (xlator_t *this) -{ - return 0; -} - -/* unsupported interfaces */ -int32_t -bd_readlink (call_frame_t *frame, xlator_t *this, - loc_t *loc, size_t size, dict_t *xdata) -{ - struct iatt stbuf = {0, }; - char *dest = NULL; - - dest = alloca (size + 1); - STACK_UNWIND_STRICT (readlink, frame, -1, ENOSYS, dest, &stbuf, NULL); - return 0; -} - -int -bd_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dev_t dev, mode_t umask, dict_t *xdata) -{ - struct iatt stbuf = {0, }; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - - STACK_UNWIND_STRICT (mknod, frame, -1, ENOSYS, - (loc)?loc->inode:NULL, &stbuf, &preparent, - &postparent, NULL); - return 0; -} - -int -bd_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - mode_t umask, dict_t *xdata) -{ - struct iatt stbuf = {0, }; - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - - STACK_UNWIND_STRICT (mkdir, frame, -1, ENOSYS, - (loc)?loc->inode:NULL, &stbuf, &preparent, - &postparent, NULL); - return 0; -} - -int -bd_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, - dict_t *xdata) -{ - struct iatt preparent = {0, }; - struct iatt postparent = {0, }; - - STACK_UNWIND_STRICT (rmdir, frame, -1, ENOSYS, - &preparent, &postparent, NULL); - return 0; -} - -int32_t -bd_setxattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, dict_t *dict, int flags, dict_t *xdata) -{ - STACK_UNWIND_STRICT (setxattr, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_fsetxattr (call_frame_t *frame, xlator_t *this, - fd_t *fd, dict_t *dict, int flags, dict_t *xdata) -{ - STACK_UNWIND_STRICT (setxattr, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_getxattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name, dict_t *xdata) -{ - STACK_UNWIND_STRICT (getxattr, frame, -1, ENOSYS, NULL, NULL); - return 0; -} - -int32_t -bd_fgetxattr (call_frame_t *frame, xlator_t *this, - fd_t *fd, const char *name, dict_t *xdata) -{ - STACK_UNWIND_STRICT (fgetxattr, frame, -1, ENOSYS, NULL, NULL); - - return 0; -} - -int32_t -bd_removexattr (call_frame_t *frame, xlator_t *this, - loc_t *loc, const char *name, dict_t *xdata) -{ - STACK_UNWIND_STRICT (removexattr, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_fremovexattr (call_frame_t *frame, xlator_t *this, - fd_t *fd, const char *name, dict_t *xdata) -{ - STACK_UNWIND_STRICT (fremovexattr, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_fsyncdir (call_frame_t *frame, xlator_t *this, - fd_t *fd, int datasync, dict_t *xdata) -{ - STACK_UNWIND_STRICT (fsyncdir, frame, -1, ENOSYS, NULL); - return 0; -} - -static int gf_bd_lk_log; -int32_t -bd_lk (call_frame_t *frame, xlator_t *this, - fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata) -{ - struct gf_flock nullock = {0, }; - - GF_LOG_OCCASIONALLY (gf_bd_lk_log, this->name, GF_LOG_CRITICAL, - "\"features/locks\" translator is " - "not loaded. You need to use it for proper " - "functioning of your application."); - - STACK_UNWIND_STRICT (lk, frame, -1, ENOSYS, &nullock, NULL); - return 0; -} - -int32_t -bd_inodelk (call_frame_t *frame, xlator_t *this, - const char *volume, loc_t *loc, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) -{ - GF_LOG_OCCASIONALLY (gf_bd_lk_log, this->name, GF_LOG_CRITICAL, - "\"features/locks\" translator is " - "not loaded. You need to use it for proper " - "functioning of your application."); - - STACK_UNWIND_STRICT (inodelk, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_finodelk (call_frame_t *frame, xlator_t *this, - const char *volume, fd_t *fd, int32_t cmd, - struct gf_flock *lock, dict_t *xdata) -{ - GF_LOG_OCCASIONALLY (gf_bd_lk_log, this->name, GF_LOG_CRITICAL, - "\"features/locks\" translator is " - "not loaded. You need to use it for proper " - "functioning of your application."); - - STACK_UNWIND_STRICT (finodelk, frame, -1, ENOSYS, NULL); - return 0; -} - - -int32_t -bd_entrylk (call_frame_t *frame, xlator_t *this, - const char *volume, loc_t *loc, const char *basename, - entrylk_cmd cmd, entrylk_type type, dict_t *xdata) -{ - GF_LOG_OCCASIONALLY (gf_bd_lk_log, this->name, GF_LOG_CRITICAL, - "\"features/locks\" translator is " - "not loaded. You need to use it for proper " - "functioning of your application."); - - STACK_UNWIND_STRICT (entrylk, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_fentrylk (call_frame_t *frame, xlator_t *this, - const char *volume, fd_t *fd, const char *basename, - entrylk_cmd cmd, entrylk_type type, dict_t *xdata) -{ - GF_LOG_OCCASIONALLY (gf_bd_lk_log, this->name, GF_LOG_CRITICAL, - "\"features/locks\" translator is " - "not loaded. You need to use it for proper " - "functioning of your application."); - - STACK_UNWIND_STRICT (fentrylk, frame, -1, ENOSYS, NULL); - return 0; -} - -int32_t -bd_rchecksum (call_frame_t *frame, xlator_t *this, - fd_t *fd, off_t offset, int32_t len, dict_t *xdata) -{ - int32_t weak_checksum = 0; - unsigned char strong_checksum[MD5_DIGEST_LENGTH]; - - STACK_UNWIND_STRICT (rchecksum, frame, -1, ENOSYS, - weak_checksum, strong_checksum, NULL); - return 0; -} - -int -bd_xattrop (call_frame_t *frame, xlator_t *this, - loc_t *loc, gf_xattrop_flags_t optype, dict_t *xattr, - dict_t *xdata) -{ - STACK_UNWIND_STRICT (xattrop, frame, -1, ENOSYS, xattr, NULL); - return 0; -} - - -int -bd_fxattrop (call_frame_t *frame, xlator_t *this, - fd_t *fd, gf_xattrop_flags_t optype, dict_t *xattr, - dict_t *xdata) -{ - STACK_UNWIND_STRICT (xattrop, frame, -1, ENOSYS, xattr, NULL); - return 0; -} - -int bd_xl_op_create (bd_priv_t *priv, dict_t *input, dict_t *output) -{ - char *vg = NULL; - char *lv = NULL; - char *path = NULL; - bd_entry_t *p_entry = NULL; - bd_entry_t *lventry = NULL; - char *size = 0; - int ret = -1; - char *error = NULL; - int retval = -1; - char *buff = NULL; - char *buffp = NULL; - char *save = NULL; - - ret = dict_get_str (input, "size", &size); - if (ret) { - gf_asprintf (&error, "no size specified"); - goto out; - } - ret = dict_get_str (input, "path", &path); - if (ret) { - gf_asprintf (&error, "no path specified"); - goto out; - } - - buff = buffp = gf_strdup (path); - - vg = strtok_r (buff, "/", &save); - lv = strtok_r (NULL, "/", &save); - - if (!vg || !lv) { - gf_asprintf (&error, "invalid path %s", path); - ret = -1; - goto out; - } - - BD_ENTRY (priv, p_entry, vg); - if (!p_entry) { - ret = -ENOENT; - goto out; - } - BD_ENTRY (priv, lventry, path); - if (lventry) { - ret = -EEXIST; - gf_asprintf (&error, "%s already exists", lv); - BD_PUT_ENTRY (priv, lventry); - goto out; - } - - ret = bd_create_lv (priv, p_entry, vg, lv, size, 0); - if (ret < 0) { - gf_asprintf (&error, "bd_create_lv error %d", -ret); - goto out; - } - ret = 0; -out: - if (p_entry) - BD_PUT_ENTRY (priv, p_entry); - - if (buffp) - GF_FREE (buffp); - - if (error) - retval = dict_set_dynstr (output, "error", error); - return ret; -} - -int bd_xl_op_delete (bd_priv_t *priv, dict_t *input, dict_t *output) -{ - char *vg = NULL; - char *path = NULL; - bd_entry_t *p_entry = NULL; - bd_entry_t *lventry = NULL; - int ret = -1; - char *error = NULL; - int retval = -1; - char *buff = NULL; - char *buffp = NULL; - char *save = NULL; - int op_errno = 0; - - ret = dict_get_str (input, "path", &path); - if (ret) { - gf_asprintf (&error, "no path specified"); - goto out; - } - - buff = buffp = gf_strdup (path); - - vg = strtok_r (buff, "/", &save); - if (!vg) { - gf_asprintf (&error, "invalid path %s", path); - op_errno = EINVAL; - ret = -1; - goto out; - } - - BD_ENTRY (priv, p_entry, vg); - BD_ENTRY (priv, lventry, path); - if (!p_entry || !lventry) { - op_errno = -ENOENT; - gf_asprintf (&error, "%s not found", path); - ret = -1; - goto out; - } - ret = bd_delete_lv (priv, p_entry, lventry, path, &op_errno); - if (ret < 0) { - gf_asprintf (&error, "bd_delete_lv error, error:%d", op_errno); - goto out; - } - ret = 0; -out: - if (p_entry) - BD_PUT_ENTRY (priv, p_entry); - if (lventry) - BD_PUT_ENTRY (priv, lventry); - if (buffp) - GF_FREE (buffp); - if (error) - retval = dict_set_dynstr (output, "error", error); - return ret; -} - -int bd_xl_op_clone(bd_priv_t *priv, int subop, dict_t *input, dict_t *output) -{ - bd_entry_t *p_entry = NULL; - bd_entry_t *lventry = NULL; - int ret = -1; - char *error = NULL; - int retval = -1; - char *vg = NULL; - char *lv = NULL; - char *dest_lv = NULL; - char *size = NULL; - char *buff = NULL; - char *buffp = NULL; - char *path = NULL; - char *save = NULL; - char *npath = NULL; - - ret = dict_get_str (input, "path", &path); - ret = dict_get_str (input, "dest_lv", &dest_lv); - ret = dict_get_str (input, "size", &size); - - if (!path || !dest_lv) { - gf_asprintf (&error, "invalid arguments"); - ret = -1; - goto out; - } - - buff = buffp = gf_strdup (path); - - vg = strtok_r (buff, "/", &save); - lv = strtok_r (NULL, "/", &save); - if (!lv) { - gf_asprintf (&error, "lv not given %s", path); - ret = -1; - goto out; - } - - BD_ENTRY (priv, p_entry, vg); - if (!p_entry) { - gf_asprintf (&error, "%s does not exist", vg); - retval = dict_set_str (output, "error", error); - goto out; - } - - BD_ENTRY (priv, lventry, path); - if (!lventry) { - gf_asprintf (&error, "%s does not exist", path); - ret = -1; - goto out; - } - BD_PUT_ENTRY (priv, lventry); - lventry = NULL; - gf_asprintf (&npath, "/%s/%s", vg, dest_lv); - BD_ENTRY (priv, lventry, npath); - if (lventry) { - gf_asprintf (&error, "%s already exists", dest_lv); - BD_PUT_ENTRY (priv, lventry); - ret = -1; - goto out; - } - - if (subop == GF_BD_OP_SNAPSHOT_BD) { - if (!size) { - gf_asprintf (&error, "size not given"); - ret = -1; - goto out; - } - ret = bd_snapshot_lv (priv, p_entry, output, lv, dest_lv, - size, NULL); - } else - ret = bd_clone_lv (priv, p_entry, output, vg, lv, dest_lv, - NULL); - - if (ret) - goto out; - ret = 0; -out: - if (error) - retval = dict_set_dynstr (output, "error", error); - if (p_entry) - BD_PUT_ENTRY (priv, p_entry); - if (npath) - GF_FREE (npath); - if (buffp) - GF_FREE (buffp); - return ret; -} - -int32_t -bd_notify (xlator_t *this, dict_t *input, dict_t *output) -{ - int ret = -1; - int retval = -1; - int32_t bdop = -1; - bd_priv_t *priv = NULL; - char *error = NULL; - - priv = this->private; - VALIDATE_OR_GOTO (priv, out); - - ret = dict_get_int32 (input, "bd-op", (int32_t *)&bdop); - if (ret) { - gf_asprintf (&error, "no sub-op specified"); - goto out; - } - - switch (bdop) - { - case GF_BD_OP_NEW_BD: - ret = bd_xl_op_create (priv, input, output); - break; - case GF_BD_OP_DELETE_BD: - ret = bd_xl_op_delete (priv, input, output); - break; - case GF_BD_OP_CLONE_BD: - case GF_BD_OP_SNAPSHOT_BD: - ret = bd_xl_op_clone (priv, bdop, input, output); - break; - default: - gf_asprintf (&error, "invalid bd-op %d specified", bdop); - retval = dict_set_dynstr (output, "error", error); - goto out; - } - -out: - return ret; -} - -/** - * notify - when parent sends PARENT_UP, send CHILD_UP event from here - */ -int32_t -notify (xlator_t *this, - int32_t event, - void *data, - ...) -{ - va_list ap; - int ret = 0; - void *data2 = NULL; - dict_t *input = NULL; - dict_t *output = NULL; - - va_start (ap, data); - data2 = va_arg (ap, dict_t *); - va_end (ap); - - switch (event) - { - case GF_EVENT_PARENT_UP: - { - /* Tell the parent that bd xlator is up */ - default_notify (this, GF_EVENT_CHILD_UP, data); - } - break; - case GF_EVENT_TRANSLATOR_OP: - input = data; - output = data2; - if (!output) - output = dict_new (); - ret = bd_notify (this, input, output); - break; - - default: - break; - } - return ret; -} - -int32_t -mem_acct_init (xlator_t *this) -{ - int ret = -1; - - if (!this) - return ret; - - ret = xlator_mem_acct_init (this, gf_bd_mt_end + 1); - - if (ret != 0) { - gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" - "failed"); - return ret; - } - - return ret; -} - - -/** - * init - Constructs lists of LVs in the given VG - */ -int -init (xlator_t *this) -{ - bd_priv_t *_private = NULL; - int ret = 0; - char *vg = NULL; - char *device = NULL; - - LOCK_INIT (&inode_lk); - - bd_rootp = bd_entry_add_root (); - if (!bd_rootp) { - gf_log (this->name, GF_LOG_CRITICAL, - "FATAL: adding root entry failed"); - return -1; - } - - if (this->children) { - gf_log (this->name, GF_LOG_CRITICAL, - "FATAL: storage/bd cannot have subvolumes"); - ret = -1; - goto out; - } - - if (!this->parents) { - gf_log (this->name, GF_LOG_WARNING, - "Volume is dangling. Please check the volume file."); - } - - ret = dict_get_str (this->options, "device", &device); - if (ret) { - gf_log (this->name, GF_LOG_CRITICAL, - "FATAL: storage/bd does not specify backend"); - return -1; - } - - /* Now we support only LV device */ - if (strcasecmp (device, BACKEND_VG)) { - gf_log (this->name, GF_LOG_CRITICAL, - "FATAL: unknown %s backend %s", BD_XLATOR, device); - return -1; - } - - ret = dict_get_str (this->options, "export", &vg); - if (ret) { - gf_log (this->name, GF_LOG_CRITICAL, - "FATAL: storage/bd does not specify volume groups"); - return -1; - } - - ret = 0; - _private = GF_CALLOC (1, sizeof(*_private), gf_bd_private); - if (!_private) - goto error; - - pthread_rwlock_init (&_private->lock, NULL); - this->private = (void *)_private; - _private->handle = NULL; - _private->vg = gf_strdup (vg); - if (!_private->vg) { - goto error; - } - - if (bd_build_lv_list (this->private, vg) < 0) - goto error; - -out: - return 0; -error: - BD_WR_LOCK (&_private->lock); - bd_entry_cleanup (); - lvm_quit (_private->handle); - if (_private->vg) - GF_FREE (_private->vg); - GF_FREE (_private); - return -1; -} - -void -fini (xlator_t *this) -{ - bd_priv_t *priv = this->private; - if (!priv) - return; - lvm_quit (priv->handle); - BD_WR_LOCK (&priv->lock); - bd_entry_cleanup (); - BD_UNLOCK (&priv->lock); - GF_FREE (priv->vg); - this->private = NULL; - GF_FREE (priv); - return; -} - -struct xlator_dumpops dumpops = { - .priv = bd_priv, - .inode = bd_inode, -}; - -struct xlator_fops fops = { - /* Not supported */ - .readlink = bd_readlink, - .mknod = bd_mknod, - .mkdir = bd_mkdir, - .rmdir = bd_rmdir, - .setxattr = bd_setxattr, - .fsetxattr = bd_fsetxattr, - .getxattr = bd_getxattr, - .fgetxattr = bd_fgetxattr, - .removexattr = bd_removexattr, - .fremovexattr= bd_fremovexattr, - .fsyncdir = bd_fsyncdir, - .lk = bd_lk, - .inodelk = bd_inodelk, - .finodelk = bd_finodelk, - .entrylk = bd_entrylk, - .fentrylk = bd_fentrylk, - .rchecksum = bd_rchecksum, - .xattrop = bd_xattrop, - - /* Supported */ - .lookup = bd_lookup, - .opendir = bd_opendir, - .readdir = bd_readdir, - .readdirp = bd_readdirp, - .stat = bd_stat, - .statfs = bd_statfs, - .open = bd_open, - .access = bd_access, - .flush = bd_flush, - .readv = bd_readv, - .fstat = bd_fstat, - .truncate = bd_truncate, - .ftruncate = bd_ftruncate, - .fsync = bd_fsync, - .writev = bd_writev, - .fstat = bd_fstat, - .create = bd_create, - .setattr = bd_setattr, - .fsetattr = bd_fsetattr, - .unlink = bd_unlink, - .link = bd_link, - .symlink = bd_symlink, - .rename = bd_rename, -}; - -struct xlator_cbks cbks = { - .releasedir = bd_releasedir, - .release = bd_release, -}; - -struct volume_options options[] = { - { .key = {"export"}, - .type = GF_OPTION_TYPE_STR}, - { .key = {"device"}, - .type = GF_OPTION_TYPE_STR}, - { .key = {NULL} } -}; diff --git a/xlators/storage/bd_map/src/bd_map.h b/xlators/storage/bd_map/src/bd_map.h deleted file mode 100644 index fa10e97a947..00000000000 --- a/xlators/storage/bd_map/src/bd_map.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - BD translator - Exports Block devices on server side as regular - files to client - - Copyright IBM, Corp. 2012 - - This file is part of GlusterFS. - - Author: - M. Mohan Kumar <mohan@in.ibm.com> - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _BD_MAP_H -#define _BD_MAP_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "xlator.h" -#include "mem-types.h" - -#define BD_XLATOR "block device mapper xlator" - -#define BACKEND_VG "vg" - -/* lvm2-2.02.79 added this in lvm2app.h, but it is available for linking in - * older versions already */ -#if NEED_LVM_LV_FROM_NAME_DECL -lv_t lvm_lv_from_name(vg_t vg, const char *name); -#endif - -enum gf_bd_mem_types_ { - gf_bd_fd = gf_common_mt_end + 1, - gf_bd_private, - gf_bd_entry, - gf_bd_attr, - gf_bd_mt_end -}; - -/* - * Each BD/LV is represented by this data structure - * Usually root entry will have only children and there is no sibling for that - * All other entries may have children and/or sibling entries - * If an entry is a Volume Group it will have child (. & .. and Logical - * Volumes) and also other Volume groups will be a sibling for this - */ -typedef struct bd_entry { - struct list_head child; /* List to child */ - struct list_head sibling; /* List of siblings */ - struct bd_entry *parent;/* Parent of this node */ - struct bd_entry *link; /* Link to actual entry, if its . or .. */ - char name[NAME_MAX]; - struct iatt *attr; - int refcnt; - uint64_t size; - pthread_rwlock_t lock; -} bd_entry_t; - -/** - * bd_fd - internal structure common to file and directory fd's - */ -typedef struct bd_fd { - bd_entry_t *entry; - bd_entry_t *p_entry; /* Parent entry */ - int fd; - int32_t flag; -} bd_fd_t; - -typedef struct bd_priv { - lvm_t handle; - pthread_rwlock_t lock; - char *vg; -} bd_priv_t; - -#endif diff --git a/xlators/storage/bd_map/src/bd_map_help.c b/xlators/storage/bd_map/src/bd_map_help.c deleted file mode 100644 index 0613aa383ff..00000000000 --- a/xlators/storage/bd_map/src/bd_map_help.c +++ /dev/null @@ -1,501 +0,0 @@ -/* - BD translator - Exports Block devices on server side as regular - files to client - - Copyright IBM, Corp. 2012 - - This file is part of GlusterFS. - - Author: - M. Mohan Kumar <mohan@in.ibm.com> - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#define __XOPEN_SOURCE 500 - -#include <libgen.h> -#include <time.h> -#include <lvm2app.h> - -#include "bd_map.h" -#include "bd_map_help.h" -#include "defaults.h" -#include "glusterfs3-xdr.h" - -#define CHILD_ENTRY(node) list_entry ((&node->child)->next, typeof(*node), \ - child) - -bd_entry_t *bd_rootp; -gf_lock_t inode_lk; -static uint64_t bd_entry_ino = 5000; /* Starting inode */ - -static void bd_entry_get_ino (uint64_t *inode) -{ - LOCK (&inode_lk); - { - *inode = bd_entry_ino++; - } - UNLOCK (&inode_lk); -} - -void bd_update_time (bd_entry_t *entry, int type) -{ - struct timespec ts; - - clock_gettime (CLOCK_REALTIME, &ts); - if (type == 0) { - entry->attr->ia_mtime = ts.tv_sec; - entry->attr->ia_mtime_nsec = ts.tv_nsec; - entry->attr->ia_atime = ts.tv_sec; - entry->attr->ia_atime_nsec = ts.tv_nsec; - } else if (type == 1) { - entry->attr->ia_mtime = ts.tv_sec; - entry->attr->ia_mtime_nsec = ts.tv_nsec; - } else { - entry->attr->ia_atime = ts.tv_sec; - entry->attr->ia_atime_nsec = ts.tv_nsec; - } -} - -static bd_entry_t *bd_entry_init (const char *name) -{ - bd_entry_t *bdentry; - - bdentry = GF_MALLOC (sizeof(bd_entry_t), gf_bd_entry); - if (!bdentry) - return NULL; - - bdentry->attr = GF_MALLOC (sizeof(struct iatt), gf_bd_attr); - if (!bdentry->attr) { - GF_FREE (bdentry); - return NULL; - } - - strcpy (bdentry->name, name); - INIT_LIST_HEAD (&bdentry->sibling); - INIT_LIST_HEAD (&bdentry->child); - bdentry->link = NULL; - bdentry->refcnt = 0; - return bdentry; -} - -static bd_entry_t *bd_entry_clone (bd_entry_t *orig, char *name) -{ - bd_entry_t *bdentry; - - bdentry = GF_MALLOC (sizeof(bd_entry_t), gf_bd_entry); - if (!bdentry) - return NULL; - - bdentry->attr = orig->attr; - - strcpy (bdentry->name, name); - INIT_LIST_HEAD (&bdentry->sibling); - INIT_LIST_HEAD (&bdentry->child); - bdentry->link = orig; - bdentry->refcnt = 0; - return bdentry; -} - -static void bd_entry_init_iattr (struct iatt *attr, int type) -{ - struct timespec ts = {0, }; - - clock_gettime (CLOCK_REALTIME, &ts); - attr->ia_dev = ia_makedev (0, 0); /* FIXME: */ - attr->ia_type = type; - attr->ia_prot = ia_prot_from_st_mode (0750); - attr->ia_nlink = 2; - attr->ia_uid = 0; - attr->ia_gid = 0; - attr->ia_rdev = ia_makedev (0, 0); - - attr->ia_size = 4096; /* FIXME */ - attr->ia_blksize = 4096; - attr->ia_blocks = 0; - - attr->ia_atime = ts.tv_sec; - attr->ia_atime_nsec = ts.tv_nsec; - attr->ia_mtime = ts.tv_sec; - attr->ia_mtime_nsec = ts.tv_nsec; - attr->ia_ctime = ts.tv_sec; - attr->ia_ctime_nsec = ts.tv_nsec; -} - -/* - * bd_entry_istat: Initialize iatt strucutre for a given path on success - */ -void bd_entry_istat (const char *path, struct iatt *attr, int type) -{ - struct stat stbuf = {0, }; - - if (stat (path, &stbuf) < 0) - bd_entry_init_iattr (attr, type); - else - iatt_from_stat (attr, &stbuf); - sprintf ((char *)attr->ia_gfid, "%lx", stbuf.st_ino); -} - -/* - * Adds the root entry and required entries - * ie header entry followed by . and .. entries - */ -bd_entry_t *bd_entry_add_root (void) -{ - bd_entry_t *bdentry = NULL; - bd_entry_t *h_entry = NULL; - bd_entry_t *d_entry = NULL; - bd_entry_t *dd_entry = NULL; - - bdentry = bd_entry_init ("/"); - if (!bdentry) - return NULL; - - bdentry->parent = bdentry; - - bd_entry_get_ino (&bdentry->attr->ia_ino); - sprintf ((char *)bdentry->attr->ia_gfid, "%ld", - bdentry->attr->ia_ino << 2); - bd_entry_init_iattr (bdentry->attr, IA_IFDIR); - - h_entry = bd_entry_clone (bdentry, ""); - bdentry->child.next = &h_entry->child; - bdentry->child.prev = &h_entry->child; - - d_entry = bd_entry_clone (bdentry, "."); - dd_entry = bd_entry_clone (bdentry, ".."); - - list_add_tail (&d_entry->sibling, &h_entry->sibling); - list_add_tail (&dd_entry->sibling, &h_entry->sibling); - return bdentry; -} - -bd_entry_t *bd_entry_add (bd_entry_t *parent, const char *name, - struct iatt *iattr, ia_type_t type) -{ - bd_entry_t *bdentry = NULL; - bd_entry_t *h_entry = NULL; - bd_entry_t *d_entry = NULL; - bd_entry_t *dd_entry = NULL; - bd_entry_t *sentry = NULL; - struct timespec ts = { 0, }; - - if (!parent) - parent = bd_rootp; - - if (type != IA_IFREG && type != IA_IFDIR) - return NULL; - - bdentry = bd_entry_init (name); - if (!bdentry) - return NULL; - - bdentry->parent = parent; - - iattr->ia_type = type; - - bd_entry_get_ino (&iattr->ia_ino); - if (IA_ISDIR(type)) { - h_entry = bd_entry_clone (bdentry, ""); - parent->attr->ia_nlink++; - bdentry->child.next = &h_entry->child; - bdentry->child.prev = &h_entry->child; - - d_entry = bd_entry_clone (bdentry, "."); - dd_entry = bd_entry_clone (bdentry, ".."); - - list_add_tail (&d_entry->sibling, &h_entry->sibling); - list_add_tail (&dd_entry->sibling, &h_entry->sibling); - } - memcpy (bdentry->attr, iattr, sizeof(*iattr)); - - clock_gettime (CLOCK_REALTIME, &ts); - parent->attr->ia_mtime = ts.tv_sec; - parent->attr->ia_mtime_nsec = ts.tv_nsec; - bdentry->size = iattr->ia_size; - - sentry = CHILD_ENTRY (parent); - list_add_tail (&bdentry->sibling, &sentry->sibling); - return bdentry; -} - -bd_entry_t *bd_entry_get_list (const char *name, bd_entry_t *parent) -{ - bd_entry_t *centry = NULL; - bd_entry_t *bdentry = NULL; - - if (!parent) - parent = bd_rootp; - - if (parent->child.next == &parent->child) - return NULL; - - centry = CHILD_ENTRY (parent); - if (!strcmp (centry->name, name)) - return centry; - - list_for_each_entry (bdentry, ¢ry->sibling, sibling) { - if (!strcmp (bdentry->name, name)) - return bdentry; - } - return NULL; -} - -/* FIXME: Do we need hashing here? */ -bd_entry_t *bd_entry_find_by_gfid (const char *path) -{ - bd_entry_t *h = NULL; - bd_entry_t *tmp = NULL; - bd_entry_t *tmp2 = NULL; - bd_entry_t *node = NULL; - bd_entry_t *cnode = NULL; - bd_entry_t *leaf = NULL; - char *gfid = NULL; - char *cp = NULL; - char *bgfid = NULL; - bd_entry_t *entry = NULL; - - gfid = GF_MALLOC (strlen(path) + 1, gf_common_mt_char); - sscanf (path, "<gfid:%s", gfid); - if (!gfid) - return NULL; - - cp = strchr(gfid, '>'); - *cp = '\0'; - - node = CHILD_ENTRY (bd_rootp); - - bgfid = GF_MALLOC (GF_UUID_BUF_SIZE, gf_common_mt_char); - if (!bgfid) - return NULL; - - list_for_each_entry_safe (h, tmp, &node->sibling, sibling) { - uuid_utoa_r (h->attr->ia_gfid, bgfid); - if (!h->link && !strcmp (gfid, bgfid)) { - entry = h; - goto out; - } - - /* if we have children for this node */ - if (h->child.next != &h->child) { - cnode = CHILD_ENTRY (h); - uuid_utoa_r (cnode->attr->ia_gfid, bgfid); - if (!cnode->link && !strcmp (gfid, bgfid)) { - entry = cnode; - goto out; - } - - list_for_each_entry_safe (leaf, tmp2, (&cnode->sibling), - sibling) { - uuid_utoa_r (leaf->attr->ia_gfid, bgfid); - if (!leaf->link && !strcmp (gfid, bgfid)) { - entry = leaf; - goto out; - } - - } - } - } -out: - if (bgfid) - GF_FREE (bgfid); - - return entry; -} - -/* Called with priv->bd_lock held */ -bd_entry_t *bd_entry_get (const char *name) -{ - bd_entry_t *pentry = NULL; - char *path = NULL; - char *comp = NULL; - char *save = NULL; - - if (!strncmp (name, "<gfid:", 5)) { - pentry = bd_entry_find_by_gfid (name); - if (pentry) - pentry->refcnt++; - return pentry; - } - - if (!strcmp (name, "/")) { - bd_rootp->refcnt++; - return bd_rootp; - } - - path = gf_strdup (name); - comp = strtok_r (path, "/", &save); - pentry = bd_entry_get_list (comp, NULL); - if (!pentry) - goto out; - while (comp) { - comp = strtok_r (NULL, "/", &save); - if (!comp) - break; - pentry = bd_entry_get_list (comp, pentry); - if (!pentry) - goto out; - } - - pentry->refcnt++; -out: - GF_FREE (path); - return pentry; -} - -int bd_entry_rm (const char *path) -{ - bd_entry_t *bdentry = NULL; - int ret = -1; - - bdentry = bd_entry_get (path); - if (!bdentry) - goto out; - - list_del_init (&bdentry->sibling); - list_del_init (&bdentry->child); - GF_FREE (bdentry); - - ret = 0; -out: - return ret; -} - - - -/* Called with priv->bd_lock held */ -void bd_entry_put (bd_entry_t *entry) -{ - entry->refcnt--; -} - -int bd_build_lv_list (bd_priv_t *priv, char *vg_name) -{ - struct dm_list *lv_dm_list = NULL; - struct lvm_lv_list *lv_list = NULL; - struct iatt iattr = {0, }; - char path[PATH_MAX] = {0, }; - vg_t vg = NULL; - bd_entry_t *vg_map = NULL; - bd_entry_t *bd = NULL; - int ret = -1; - const char *lv_name = NULL; - - priv->handle = lvm_init (NULL); - if (!priv->handle) { - gf_log (THIS->name, GF_LOG_CRITICAL, "FATAL: bd_init failed"); - return -1; - } - - BD_WR_LOCK (&priv->lock); - - vg = lvm_vg_open (priv->handle, vg_name, "r", 0); - if (!vg) { - gf_log (THIS->name, GF_LOG_CRITICAL, - "opening vg %s failed", vg_name); - goto out; - } - /* get list of LVs associated with this VG */ - lv_dm_list = lvm_vg_list_lvs (vg); - sprintf (path, "/dev/%s", vg_name); - bd_entry_istat (path, &iattr, IA_IFDIR); - vg_map = bd_entry_add (bd_rootp, vg_name, &iattr, - IA_IFDIR); - if (!vg_map) { - gf_log (THIS->name, GF_LOG_CRITICAL, - "bd_add_entry failed"); - goto out; - } - ret = 0; - if (!lv_dm_list) /* no lvs for this VG */ - goto out; - - dm_list_iterate_items (lv_list, lv_dm_list) { - if (!lv_list) - continue; - lv_name = lvm_lv_get_name (lv_list->lv); - /* snapshot%d is reserved name */ - if (!strncmp (lv_name, "snapshot", 8)) - continue; - /* get symbolic path for this LV */ - sprintf (path, "/dev/%s/%s", vg_name, lv_name); - bd_entry_istat (path, &iattr, IA_IFREG); - /* Make the file size equivalant to BD size */ - iattr.ia_size = lvm_lv_get_size (lv_list->lv); - /* got LV, add it to our tree */ - bd = bd_entry_add (vg_map, - lvm_lv_get_name (lv_list->lv), - &iattr, IA_IFREG); - if (bd == NULL) { - gf_log (THIS->name, GF_LOG_ERROR, - "bd_add_entry failed"); - goto out; - } - } -out: - if (vg) - lvm_vg_close (vg); - - BD_UNLOCK (&priv->lock); - return ret; -} - -/* - * Called with bd_lock held to cleanup entire list. If there was a - * reference to any one of the entry, nothing cleared. - * Return 0 on success -1 in case if there is a reference to the entry - */ -int bd_entry_cleanup (void) -{ - bd_entry_t *node = NULL; - bd_entry_t *tmp = NULL; - bd_entry_t *tmp2 = NULL; - bd_entry_t *cnode = NULL; - bd_entry_t *h = NULL; - bd_entry_t *leaf = NULL; - - if (!bd_rootp) - return 0; - - node = CHILD_ENTRY (bd_rootp); - if (node->refcnt) { - gf_log (THIS->name, GF_LOG_WARNING, - "entry %s is inuse\n", node->name); - return -1; - } - list_for_each_entry_safe (h, tmp, &node->sibling, sibling) { - /* if we have children for this node */ - if (h->child.next != &h->child) { - cnode = CHILD_ENTRY (h); - list_for_each_entry_safe (leaf, tmp2, (&cnode->sibling), - sibling) { - list_del_init (&leaf->sibling); - list_del_init (&leaf->child); - if (!leaf->link) - GF_FREE (leaf->attr); - GF_FREE (leaf); - } - list_del_init (&cnode->sibling); - list_del_init (&cnode->child); - if (!cnode->link) - GF_FREE (cnode->attr); - GF_FREE (cnode); - } - if (!h->link) - GF_FREE (h->attr); - GF_FREE (h); - } - GF_FREE (h); - GF_FREE (bd_rootp->attr); - GF_FREE (bd_rootp); - return 0; -} diff --git a/xlators/storage/bd_map/src/bd_map_help.h b/xlators/storage/bd_map/src/bd_map_help.h deleted file mode 100644 index 9fafa2d137e..00000000000 --- a/xlators/storage/bd_map/src/bd_map_help.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - BD translator - Exports Block devices on server side as regular - files to client. - - Copyright IBM, Corp. 2012 - - This file is part of GlusterFS. - - Author: - M. Mohan Kumar <mohan@in.ibm.com> - - This file is licensed to you under your choice of the GNU Lesser - General Public License, version 3 or any later version (LGPLv3 or - later), or the GNU General Public License, version 2 (GPLv2), in all - cases as published by the Free Software Foundation. -*/ -#ifndef _BD_MAP_HELP_H -#define _BD_MAP_HELP_H - -#define BD_RD_LOCK(lock) \ - pthread_rwlock_rdlock (lock); - -#define BD_WR_LOCK(lock) \ - pthread_rwlock_wrlock (lock); - -#define BD_UNLOCK(lock) \ - pthread_rwlock_unlock (lock); - -#define BD_WR_ENTRY(priv, bdentry, path) \ - do { \ - BD_WR_LOCK (&priv->lock); \ - bdentry = bd_entry_get (path); \ - BD_UNLOCK (&priv->lock); \ - } while (0) - -#define BD_ENTRY(priv, bdentry, path) \ - do { \ - BD_RD_LOCK (&priv->lock); \ - bdentry = bd_entry_get (path); \ - BD_UNLOCK (&priv->lock); \ - } while (0) - -#define BD_PUT_ENTRY(priv, bdentry) \ - do { \ - BD_RD_LOCK (&priv->lock); \ - bd_entry_put (bdentry); \ - BD_UNLOCK (&priv->lock); \ - } while (0) - -#define BD_ENTRY_UPDATE_TIME(bdentry) bd_update_time (bdentry, 0) -#define BD_ENTRY_UPDATE_ATIME(bdentry) bd_update_time (bdentry, 2) -#define BD_ENTRY_UPDATE_MTIME(bdentry) bd_update_time (bdentry, 1) - -extern bd_entry_t *bd_rootp; -extern gf_lock_t inode_lk; - -void bd_entry_istat (const char *path, struct iatt *attr, int type); -bd_entry_t *bd_entry_add_root (void); -bd_entry_t *bd_entry_add (bd_entry_t *parent, const char *name, - struct iatt *iattr, ia_type_t type); -bd_entry_t *bd_entry_get_list (const char *name, bd_entry_t *parent); -bd_entry_t *bd_entry_get (const char *name); -void bd_entry_put (bd_entry_t *entry); -int bd_build_lv_list (bd_priv_t *priv, char *vg); -int bd_entry_cleanup (void); -void bd_update_time (bd_entry_t *entry, int type); -int bd_entry_rm (const char *path); - -#endif |