diff options
| -rw-r--r-- | glusterfsd/src/glusterfsd.c | 63 | ||||
| -rw-r--r-- | glusterfsd/src/glusterfsd.h | 2 | ||||
| -rw-r--r-- | libglusterfs/src/glusterfs.h | 1 | 
3 files changed, 66 insertions, 0 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 072422fe46e..aa90f351314 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -144,6 +144,8 @@ static struct argp_option gf_options[] = {           "in VOLFILE]"},          {"xlator-option", ARGP_XLATOR_OPTION_KEY,"VOLUME-NAME.OPTION=VALUE", 0,           "Add/override a translator option for a volume with specified value"}, +        {"read-only", ARGP_READ_ONLY_KEY, 0, 0, +         "Mount the filesystem in 'read-only' mode"},          {0, 0, 0, 0, "Fuse options:"},          {"disable-direct-io-mode", ARGP_DISABLE_DIRECT_IO_MODE_KEY, 0, 0, @@ -363,6 +365,43 @@ _add_fuse_mount (xlator_t *graph)          return top;  } +static xlator_t * +_add_ro_volume (xlator_t *graph) +{ +        cmd_args_t      *cmd_args = NULL; +        xlator_t        *top = NULL; +        glusterfs_ctx_t *ctx = NULL; +        xlator_list_t   *xlchild = NULL; + +        ctx = graph->ctx; +        cmd_args = &ctx->cmd_args; + +        xlchild = CALLOC (sizeof (*xlchild), 1); +        if (!xlchild) { +                return NULL; +        } +        xlchild->xlator = graph; + +        top = CALLOC (1, sizeof (*top)); +        top->name = strdup ("read-only"); +        if (xlator_set_type (top, ZR_XLATOR_READ_ONLY) == -1) { +                fprintf (stderr, +                         "read-only volume initialization failed"); +                gf_log ("glusterfs", GF_LOG_ERROR, +                        "read-only initialization failed"); +                return NULL; +        } +        top->children = xlchild; +        top->ctx      = graph->ctx; +        top->next     = gf_get_first_xlator (graph); +        top->options  = get_new_dict (); + +        graph->parents = CALLOC (1, sizeof (xlator_list_t)); +        graph->parents->xlator = top; + +        return top; +} +  static FILE *  _get_specfp (glusterfs_ctx_t *ctx) @@ -786,6 +825,10 @@ parse_opts (int key, char *arg, struct argp_state *state)                                "Invalid limit on connect attempts %s", arg);                  break; +        case ARGP_READ_ONLY_KEY: +                cmd_args->read_only = 1; +                break; +          case ARGP_VOLUME_FILE_KEY:                  cmd_args->volume_file = strdup (arg);                  break; @@ -1287,7 +1330,27 @@ main (int argc, char *argv[])          ctx->xl_count = xl_count + 1; +        if (cmd_args->read_only && !fuse_volume_found && +            (cmd_args->mount_point == NULL)) { +                gf_log ("glusterfs", GF_LOG_ERROR, +                        "'--read-only' option is valid only on client side"); +                fprintf (stderr, "'--read-only' option is valid only " +                         "on client side, exiting\n"); +                return -1; +        }          if (!fuse_volume_found && (cmd_args->mount_point != NULL)) { +                /* Check for read-only option and add a read-only translator */ +                if (cmd_args->read_only) { +                        if ((graph = _add_ro_volume (graph)) == NULL) { +                                /* _add_fuse_mount() prints necessary +                                 * error message +                                 */ +                                fprintf (stderr, +                                         "failed to load 'ro' option. exiting\n"); +                                gf_log ("glusterfs", GF_LOG_ERROR, "exiting"); +                                return -1; +                        } +                }                  if ((graph = _add_fuse_mount (graph)) == NULL) {                          /* _add_fuse_mount() prints necessary                           * error message diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h index 8198f6f5238..77028c70664 100644 --- a/glusterfsd/src/glusterfsd.h +++ b/glusterfsd/src/glusterfsd.h @@ -43,6 +43,7 @@  #define ENABLE_NO_DAEMON_MODE     1  #define ENABLE_DEBUG_MODE         1 +#define ZR_XLATOR_READ_ONLY     "features/read-only"  #define ZR_XLATOR_FUSE          "mount/fuse"  #define ZR_MOUNTPOINT_OPT       "mountpoint"  #define ZR_ATTR_TIMEOUT_OPT     "attribute-timeout" @@ -74,6 +75,7 @@ enum argp_option_keys {          ARGP_VOLFILE_MAX_FETCH_ATTEMPTS = 145,          ARGP_LOG_SERVER_KEY = 146,          ARGP_LOG_SERVER_PORT_KEY = 147, +        ARGP_READ_ONLY_KEY = 148,  };  /* Moved here from fetch-spec.h */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 42084ba3ab9..464c4302570 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -232,6 +232,7 @@ struct _cmd_args {  	int              no_daemon_mode;  	char            *run_id;  	int              debug_mode; +        int              read_only;  	struct list_head xlator_options;  /* list of xlator_option_t */  	/* fuse options */  | 
