示例#1
0
int32_t
cli_cmd_volume_profile_parse (const char **words, int wordcount,
                              dict_t **options)
{
        dict_t    *dict       = NULL;
        char      *volname    = NULL;
        int       ret         = -1;
        gf1_cli_stats_op op = GF_CLI_STATS_NONE;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "profile")) == 0);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount != 4)
                goto out;

        volname = (char *)words[2];

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        if (strcmp (words[3], "start") == 0) {
                op = GF_CLI_STATS_START;
        } else if (strcmp (words[3], "stop") == 0) {
                op = GF_CLI_STATS_STOP;
        } else if (strcmp (words[3], "info") == 0) {
                op = GF_CLI_STATS_INFO;
        } else {
                ret = -1;
                goto out;
        }
        ret = dict_set_int32 (dict, "op", (int32_t)op);
        *options = dict;
out:
        if (ret && dict)
                dict_destroy (dict);
        return ret;
}
示例#2
0
int
cli_cmd_umount_cbk (struct cli_state *state, struct cli_cmd_word *word,
                   const char **words, int wordcount)
{
        rpc_clnt_procedure_t *proc = NULL;
        call_frame_t *frame        = NULL;
        int ret                    = -1;
        dict_t *dict               = NULL;

        if (!(wordcount == 3 ||
              (wordcount == 4 && strcmp (words[3], "lazy") == 0))) {
                cli_usage_out (word->pattern);
                goto out;
        }

        dict = dict_new ();
        if (!dict)
                goto out;

        ret = dict_set_str (dict, "path", (char *)words[2]);
        if (ret != 0)
                goto out;
        ret = dict_set_int32 (dict, "lazy", wordcount == 4);
        if (ret != 0)
                goto out;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT];
        if (proc && proc->fn) {
                frame = create_frame (THIS, THIS->ctx->pool);
                if (!frame)
                        goto out;
                ret = proc->fn (frame, THIS, dict);
        }

 out:
        if (dict)
                dict_unref (dict);

        if (!proc && ret)
                cli_out ("Umount command failed");

        return ret;
}
示例#3
0
int
cli_cmd_peer_deprobe_cbk (struct cli_state *state, struct cli_cmd_word *word,
                          const char **words, int wordcount)
{
        int                   ret   = -1;
        rpc_clnt_procedure_t *proc  = NULL;
        call_frame_t         *frame = NULL;
        dict_t               *dict  = NULL;
        int                  flags = 0;
        int                  sent = 0;
        int                  parse_error = 0;

        if ((wordcount < 3) || (wordcount > 4)) {
                cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_DEPROBE];

        frame = create_frame (THIS, THIS->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();

        ret = dict_set_str (dict, "hostname", (char *)words[2]);
        if (ret)
                goto out;

/*        if (words[3]) {
                ret = dict_set_str (dict, "port", (char *)words[3]);
                if (ret)
                        goto out;
        }
*/
        if (wordcount == 4) {
                if (!strcmp("force", words[3]))
                        flags |= GF_CLI_FLAG_OP_FORCE;
                else {
                        ret = -1;
                        cli_usage_out (word->pattern);
                        parse_error = 1;
                        goto out;
                }
        }
        ret = dict_set_int32 (dict, "flags", flags);
        if (ret)
                goto out;

        if (proc->fn) {
                ret = proc->fn (frame, THIS, dict);
        }

out:
        if (ret) {
                cli_cmd_sent_status_get (&sent);
                if ((sent == 0) && (parse_error == 0))
                        cli_out ("Peer detach failed");
        }

        return ret;
}
示例#4
0
int
cli_cmd_sys_exec_cbk (struct cli_state *state, struct cli_cmd_word *word,
                      const char **words, int wordcount)
{
        char                   cmd_arg_name[PATH_MAX] = "";
        char                  *command                = NULL;
        char                  *saveptr                = NULL;
        char                  *tmp                    = NULL;
        int                    ret                    = -1;
        int                    i                      = -1;
        int                    cmd_args_count         = 0;
        int                    in_cmd_args_count      = 0;
        rpc_clnt_procedure_t  *proc                   = NULL;
        call_frame_t          *frame                  = NULL;
        dict_t                *dict                   = NULL;
        cli_local_t           *local                  = NULL;

        if (wordcount < 3) {
                cli_usage_out (word->pattern);
                goto out;
        }

        dict = dict_new ();
        if (!dict)
                goto out;

        command = strtok_r ((char *)words[2], " ", &saveptr);
        do {
                tmp = strtok_r (NULL, " ", &saveptr);
                if (tmp) {
                        in_cmd_args_count++;
                        memset (cmd_arg_name, '\0', sizeof(cmd_arg_name));
                        snprintf (cmd_arg_name, sizeof(cmd_arg_name),
                                  "cmd_arg_%d", in_cmd_args_count);
                        ret = dict_set_str (dict, cmd_arg_name, tmp);
                        if (ret) {
                                gf_log ("", GF_LOG_ERROR, "Unable to set "
                                        "%s in dict", cmd_arg_name);
                                goto out;
                        }
                }
        } while (tmp);

        cmd_args_count = wordcount - 3;

        ret = dict_set_str (dict, "command", command);
        if (ret) {
                gf_log ("", GF_LOG_ERROR, "Unable to set command in dict");
                goto out;
        }

        for (i=1; i <= cmd_args_count; i++) {
                in_cmd_args_count++;
                memset (cmd_arg_name, '\0', sizeof(cmd_arg_name));
                snprintf (cmd_arg_name, sizeof(cmd_arg_name),
                          "cmd_arg_%d", in_cmd_args_count);
                ret = dict_set_str (dict, cmd_arg_name,
                                    (char *)words[2+i]);
                if (ret) {
                        gf_log ("", GF_LOG_ERROR, "Unable to set %s in dict",
                               cmd_arg_name);
                        goto out;
                }
        }

        ret = dict_set_int32 (dict, "cmd_args_count", in_cmd_args_count);
        if (ret) {
                gf_log ("", GF_LOG_ERROR,
                        "Unable to set cmd_args_count in dict");
                goto out;
        }

        ret = dict_set_str (dict, "volname", "N/A");
        if (ret) {
                gf_log ("", GF_LOG_ERROR, "Unable to set volname in dict");
                goto out;
        }

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYS_EXEC];
        if (proc && proc->fn) {
                frame = create_frame (THIS, THIS->ctx->pool);
                if (!frame)
                        goto out;
                CLI_LOCAL_INIT (local, words, frame, dict);
                ret = proc->fn (frame, THIS, (void*)dict);
        }
out:
        return ret;
}
示例#5
0
文件: vtb.c 项目: Ezio-PS/movian
static int
video_vtb_codec_create(media_codec_t *mc, const media_codec_params_t *mcp,
		       media_pipe_t *mp)
{
  OSStatus status;

  if(!video_settings.video_accel)
    return 1;

  switch(mc->codec_id) {
  case AV_CODEC_ID_H264:
    break;
  default:
    return 1;
  }


  if(mcp == NULL || mcp->extradata == NULL || mcp->extradata_size == 0 ||
     ((const uint8_t *)mcp->extradata)[0] != 1)
    return h264_annexb_to_avc(mc, mp, &video_vtb_codec_create);

  CFMutableDictionaryRef config_dict =
    CFDictionaryCreateMutable(kCFAllocatorDefault,
                              2,
                              &kCFTypeDictionaryKeyCallBacks,
                              &kCFTypeDictionaryValueCallBacks);

  CFDictionarySetValue(config_dict,
                       kCVImageBufferChromaLocationBottomFieldKey,
                       kCVImageBufferChromaLocation_Left);

  CFDictionarySetValue(config_dict,
                       kCVImageBufferChromaLocationTopFieldKey,
                       kCVImageBufferChromaLocation_Left);

  // Setup extradata
  CFMutableDictionaryRef extradata_dict =
    CFDictionaryCreateMutable(kCFAllocatorDefault,
                              1,
                              &kCFTypeDictionaryKeyCallBacks,
                              &kCFTypeDictionaryValueCallBacks);


  CFDataRef extradata = CFDataCreate(kCFAllocatorDefault, mcp->extradata,
                                     mcp->extradata_size);
  CFDictionarySetValue(extradata_dict, CFSTR("avcC"), extradata);
  CFRelease(extradata);
  CFDictionarySetValue(config_dict,
                       kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms,
                       extradata_dict);
  CFRelease(extradata_dict);

#if !TARGET_OS_IPHONE
  // Enable and force HW accelration
  CFDictionarySetValue(config_dict,
                       kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder,
                       kCFBooleanTrue);

  CFDictionarySetValue(config_dict,
                       kVTVideoDecoderSpecification_RequireHardwareAcceleratedVideoDecoder,
                       kCFBooleanTrue);
#endif

  CMVideoFormatDescriptionRef fmt;

  status = CMVideoFormatDescriptionCreate(kCFAllocatorDefault,
                                          kCMVideoCodecType_H264,
                                          mcp->width,
                                          mcp->height,
                                          config_dict,
                                          &fmt);
  if(status) {
    TRACE(TRACE_DEBUG, "VTB", "Unable to create description %d", status);
    return 1;
  }


  CFMutableDictionaryRef surface_dict =
    CFDictionaryCreateMutable(kCFAllocatorDefault,
                              2,
                              &kCFTypeDictionaryKeyCallBacks,
                              &kCFTypeDictionaryValueCallBacks);

  CFDictionarySetValue(surface_dict,
#if !TARGET_OS_IPHONE
                       kCVPixelBufferOpenGLCompatibilityKey,
#else
                       kCVPixelBufferOpenGLESCompatibilityKey,
#endif
                       kCFBooleanTrue);

  vtb_decoder_t *vtbd = calloc(1, sizeof(vtb_decoder_t));

  dict_set_int32(surface_dict, kCVPixelBufferWidthKey, mcp->width);
  dict_set_int32(surface_dict, kCVPixelBufferHeightKey, mcp->height);

#if TARGET_OS_IPHONE
    vtbd->vtbd_pixel_format = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
#else
    vtbd->vtbd_pixel_format = kCVPixelFormatType_420YpCbCr8Planar;
#endif

  dict_set_int32(surface_dict, kCVPixelBufferPixelFormatTypeKey,
                 vtbd->vtbd_pixel_format);

  int linewidth = mcp->width;

  switch(vtbd->vtbd_pixel_format) {
    case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
    case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
      linewidth *= 2;
      break;
  }

  dict_set_int32(surface_dict, kCVPixelBufferBytesPerRowAlignmentKey, linewidth);

  VTDecompressionOutputCallbackRecord cb = {
    .decompressionOutputCallback = picture_out,
    .decompressionOutputRefCon = vtbd
  };

  /* create decompression session */
  status = VTDecompressionSessionCreate(kCFAllocatorDefault,
                                        fmt,
                                        config_dict,
                                        surface_dict,
                                        &cb,
                                        &vtbd->vtbd_session);

  CFRelease(config_dict);
  CFRelease(surface_dict);

  if(status) {
    TRACE(TRACE_DEBUG, "VTB", "Failed to open -- %d", status);
    CFRelease(fmt);
    return 1;

  }
  vtbd->vtbd_fmt = fmt;
  vtbd->vtbd_max_ts   = PTS_UNSET;
  vtbd->vtbd_flush_to = PTS_UNSET;
  vtbd->vtbd_last_pts = PTS_UNSET;

  mc->opaque = vtbd;
  mc->decode = vtb_decode;
  mc->close = vtb_close;
  mc->flush = vtb_flush;

  TRACE(TRACE_DEBUG, "VTB", "Opened decoder");
  return 0;
}
示例#6
0
int32_t
cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
                                   dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        char    *op = NULL;
        int     op_index = 0;
        char    *delimiter = NULL;
        gf1_cli_replace_op replace_op = GF_REPLACE_OP_NONE;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "replace-brick")) == 0);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }

        delimiter = strchr ((char *)words[3], ':');
        if (!delimiter || delimiter == words[3]
            || *(delimiter+1) != '/') {
                cli_out ("wrong brick type: %s, use "
                        "<HOSTNAME>:<export-dir-abs-path>", words[3]);
                ret = -1;
                goto out;
        } else {
                cli_path_strip_trailing_slashes (delimiter + 1);
        }
        ret = dict_set_str (dict, "src-brick", (char *)words[3]);

        if (ret)
                goto out;

        if (wordcount < 5) {
                ret = -1;
                goto out;
        }

        delimiter = strchr ((char *)words[4], ':');
        if (!delimiter || delimiter == words[4]
            || *(delimiter+1) != '/') {
                cli_out ("wrong brick type: %s, use "
                        "<HOSTNAME>:<export-dir-abs-path>", words[4]);
                ret = -1;
                goto out;
        } else {
                cli_path_strip_trailing_slashes (delimiter + 1);
        }


        ret = dict_set_str (dict, "dst-brick", (char *)words[4]);

        if (ret)
                goto out;

        op_index = 5;
        if ((wordcount < (op_index + 1))) {
                ret = -1;
                goto out;
        }

        op = (char *) words[op_index];

        if (!strcasecmp ("start", op)) {
                replace_op = GF_REPLACE_OP_START;
        } else if (!strcasecmp ("commit", op)) {
                replace_op = GF_REPLACE_OP_COMMIT;
        } else if (!strcasecmp ("pause", op)) {
                replace_op = GF_REPLACE_OP_PAUSE;
        } else if (!strcasecmp ("abort", op)) {
                replace_op = GF_REPLACE_OP_ABORT;
        } else if (!strcasecmp ("status", op)) {
                replace_op = GF_REPLACE_OP_STATUS;
        }

        /* commit force option */
        op_index = 6;

        if (wordcount > (op_index + 1)) {
                ret = -1;
                goto out;
        }

        if (wordcount == (op_index + 1)) {
                op = (char *) words[op_index];
                if (!strcasecmp ("force", op)) {
                        replace_op = GF_REPLACE_OP_COMMIT_FORCE;
                }
        }

        if (replace_op == GF_REPLACE_OP_NONE) {
                ret = -1;
                goto out;
        }

        ret = dict_set_int32 (dict, "operation", (int32_t) replace_op);

        if (ret)
                goto out;




        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI");
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}
示例#7
0
int32_t
cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
                                   dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        char    *delimiter = NULL;
        int     ret = -1;
        char    key[50];
        int     brick_count = 0, brick_index = 0;
        int32_t tmp_index = 0;
        int32_t j = 0;
        char    *tmp_brick = NULL;
        char    *tmp_brick1 = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "remove-brick")) == 0);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }

        brick_index = 3;

        if (ret)
                goto out;

        tmp_index = brick_index;
        tmp_brick = GF_MALLOC(2048 * sizeof(*tmp_brick), gf_common_mt_char);

        if (!tmp_brick) {
                gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "
                        "Unable to get memory");
                ret = -1;
                goto out;
        }
 
        tmp_brick1 = GF_MALLOC(2048 * sizeof(*tmp_brick1), gf_common_mt_char);

        if (!tmp_brick1) {
                gf_log ("",GF_LOG_ERROR,"cli_cmd_volume_remove_brick_parse: "
                        "Unable to get memory");
                ret = -1;
                goto out;
        }

        while (brick_index < wordcount) {
                delimiter = strchr(words[brick_index], ':');
                if (!delimiter || delimiter == words[brick_index]
                    || *(delimiter+1) != '/') {
                        cli_out ("wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[brick_index]);
                        ret = -1;
                        goto out;
                } else {
                        cli_path_strip_trailing_slashes (delimiter + 1);
                }

                j = tmp_index;
                strcpy(tmp_brick, words[brick_index]);
                while ( j < brick_index) {
                        strcpy(tmp_brick1, words[j]);
                        if (!(strcmp (tmp_brick, tmp_brick1))) {
                                gf_log("",GF_LOG_ERROR, "Duplicate bricks"
                                       " found %s", words[brick_index]);
                                cli_out("Duplicate bricks found %s",
                                        words[brick_index]);
                                ret = -1;
                                goto out;
                        }
                        j++;
                }
                snprintf (key, 50, "brick%d", ++brick_count);
                ret = dict_set_str (dict, key, (char *)words[brick_index++]);

                if (ret)
                        goto out;
        }

        ret = dict_set_int32 (dict, "count", brick_count);

        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse remove-brick CLI");
                if (dict)
                        dict_destroy (dict);
        }

        if (tmp_brick)
                GF_FREE (tmp_brick);
        if (tmp_brick1)
                GF_FREE (tmp_brick1);

        return ret;
}
示例#8
0
int32_t
cli_cmd_volume_add_brick_parse (const char **words, int wordcount,
                                dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        int     brick_count = 0, brick_index = 0;
        char    *bricks = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "add-brick")) == 0);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }

        brick_index = 3;
        ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks,
                                    &brick_count);
        if (ret)
                goto out;

        ret = dict_set_dynstr (dict, "bricks", bricks);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "count", brick_count);

        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse add-brick CLI");
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}
示例#9
0
int32_t
cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        int     count = 0;
        char    *key = NULL;
        char    *value = NULL;
        int     i = 0;
        char    str[50] = {0,};

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "set")) == 0);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 4)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;


        for (i = 3; i < wordcount; i+=2) {

		key = (char *) words[i];
		value = (char *) words[i+1];

		if ( !key || !value) {
			ret = -1;
			goto out;
        	}

                count++;

                sprintf (str, "key%d", count);
                ret = dict_set_str (dict, str, key);
                if (ret)
                        goto out;

                sprintf (str, "value%d", count);
                ret = dict_set_str (dict, str, value);

                if (ret)
                        goto out;
        }

        ret = dict_set_int32 (dict, "count", wordcount-3);

        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}
示例#10
0
int32_t
cli_cmd_quota_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t          *dict    = NULL;
        char            *volname = NULL;
        int              ret     = -1;
        int              i       = 0;
        char             key[20] = {0, };
        gf_quota_type    type    = GF_QUOTA_OPTION_TYPE_NONE;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "quota")) == 0);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 4)
                goto out;

        volname = (char *)words[2];

        if (!volname) {
                ret = -1;
                goto out;
        }

        /* Validate the volume name here itself */
        {
                if (volname[0] == '-')
                        goto out;

                if (!strcmp (volname, "all")) {
                        cli_out ("\"all\" cannot be the name of a volume.");
                        goto out;
                }

                if (strchr (volname, '/'))
                        goto out;

                if (strlen (volname) > 512)
                        goto out;

                for (i = 0; i < strlen (volname); i++)
                        if (!isalnum (volname[i]) && (volname[i] != '_') && (volname[i] != '-'))
                                goto out;
        }

        ret = dict_set_str (dict, "volname", volname);

        if (ret)
                goto out;


        if ((strcasecmp (words[3], "enable")) == 0) {
                type = GF_QUOTA_OPTION_TYPE_ENABLE;
                goto set_type;
        }

        if (strcasecmp (words[3], "disable") == 0) {
                type = GF_QUOTA_OPTION_TYPE_DISABLE;
                goto set_type;
        }

        if (strcasecmp (words[3], "limit-usage") == 0) {
                if (wordcount != 6) {
                        ret = -1;
                        goto out;
                }

                type = GF_QUOTA_OPTION_TYPE_LIMIT_USAGE;

                if (words[4][0] != '/') {
                        cli_out ("Please enter absolute path");

                        return -2;
                }
                ret = dict_set_str (dict, "path", (char *) words[4]);

                if (ret)
                        goto out;

                if (!words[5]) {
                        gf_log ("cli", GF_LOG_ERROR, "Please enter the limit value "
                                            "to be set");

                        return -2;
                }

                ret = dict_set_str (dict, "limit", (char *) words[5]);
                if (ret)
                        goto out;

                goto set_type;
        }
        if (strcasecmp (words[3], "remove") == 0) {
                if (wordcount != 5) {
                        ret = -1;
                        goto out;
                }

                type = GF_QUOTA_OPTION_TYPE_REMOVE;

                if (words[4][0] != '/') {
                        cli_out ("Please enter absolute path");

                        return -2;
                }

                ret = dict_set_str (dict, "path", (char *) words[4]);
                if (ret)
                        goto out;
                goto set_type;
        }

        if (strcasecmp (words[3], "list") == 0) {
                        if (wordcount < 4) {
                                ret = -1;
                                goto out;
                        }

                        type = GF_QUOTA_OPTION_TYPE_LIST;

                        i = 4;
                        while (i < wordcount) {
                                snprintf (key, 20, "path%d", i-4);

                                ret = dict_set_str (dict, key, (char *) words [i++]);
                                if (ret < 0)
                                        goto out;
                        }

                        ret = dict_set_int32 (dict, "count", i - 4);
                        if (ret < 0)
                                goto out;

                        goto set_type;
        }

        if (strcasecmp (words[3], "version") == 0) {
                type = GF_QUOTA_OPTION_TYPE_VERSION;

        } else {
                ret = -1;
                goto out;
        }

set_type:
        ret = dict_set_int32 (dict, "type", type);

        if (ret)
                goto out;
        *options = dict;
out:
        if (ret) {
                if (dict)
                        dict_destroy (dict);
        }

        return ret;
}
示例#11
0
int32_t
cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        int     ret = -1;
        gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
        int     count = 1;
        int     brick_index = 0;
        int     i = 0;
        char    *trans_type = NULL;
        int32_t index = 0;
        char    *bricks = NULL;
        int32_t brick_count = 0;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "create")) == 0);

        dict = dict_new ();

        if (!dict)
                goto out;

        if (wordcount < 3)
                goto out;

        volname = (char *)words[2];

        GF_ASSERT (volname);

        /* Validate the volume name here itself */
        {
                if (volname[0] == '-')
                        goto out;

                if (!strcmp (volname, "all")) {
                        cli_out ("\"all\" cannot be the name of a volume.");
                        goto out;
                }

                if (strchr (volname, '/'))
                        goto out;

                if (strlen (volname) > 512)
                        goto out;

                for (i = 0; i < strlen (volname); i++)
                        if (!isalnum (volname[i]) && (volname[i] != '_') && (volname[i] != '-'))
                                goto out;
        }


        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        if (wordcount < 4) {
                ret = -1;
                goto out;
        }
        if ((strcasecmp (words[3], "replica")) == 0) {
                type = GF_CLUSTER_TYPE_REPLICATE;
                if (wordcount < 5) {
                        ret = -1;
                        goto out;
                }
                count = strtol (words[4], NULL, 0);
                if (!count || (count < 2)) {
                        cli_out ("replica count should be greater than 1");
                        ret = -1;
                        goto out;
                }
                ret = dict_set_int32 (dict, "replica-count", count);
                if (ret)
                        goto out;
                brick_index = 5;
        } else if ((strcasecmp (words[3], "stripe")) == 0) {
                type = GF_CLUSTER_TYPE_STRIPE;
                if (wordcount < 5) {
                        ret = -1;
                        goto out;
                }
                count = strtol (words[4], NULL, 0);
                if (!count || (count < 2)) {
                        cli_out ("stripe count should be greater than 1");
                        ret = -1;
                        goto out;
                }
                ret = dict_set_int32 (dict, "stripe-count", count);
                if (ret)
                        goto out;
                brick_index = 5;
        } else {
                type = GF_CLUSTER_TYPE_NONE;
                brick_index = 3;
        }

        ret = dict_set_int32 (dict, "type", type);
        if (ret)
                goto out;

        if (type)
                index = 5;
        else
                index = 3;

        if (wordcount < (index + 1)) {
                ret = -1;
                goto out;
        }

        if (strcasecmp(words[index], "transport") == 0) {
                brick_index = index+2;
                if (wordcount < (index + 2)) {
                        ret = -1;
                        goto out;
                }

                if ((strcasecmp (words[index+1], "tcp") == 0)) {
                        trans_type = gf_strdup ("tcp");
                } else if ((strcasecmp (words[index+1], "rdma") == 0)) {
                        trans_type = gf_strdup ("rdma");
                } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) ||
                           (strcasecmp (words[index+1], "rdma,tcp") == 0)) {
                        trans_type = gf_strdup ("tcp,rdma");
                } else {
                        gf_log ("", GF_LOG_ERROR, "incorrect transport"
                                       " protocol specified");
                        ret = -1;
                        goto out;
                }
        } else {
                trans_type = gf_strdup ("tcp");
        }

        ret = dict_set_dynstr (dict, "transport", trans_type);
        if (ret)
                goto out;

        ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks,
                                    &brick_count);
        if (ret)
                goto out;

        /* If brick-count is not valid when replica or stripe is
           given, exit here */
        if (!brick_count) {
                cli_out ("No bricks specified");
                ret = -1;
                goto out;
        }

        if (brick_count % count) {
                if (type == GF_CLUSTER_TYPE_STRIPE)
                        cli_out ("number of bricks is not a multiple of "
                                 "stripe count");
                else if (type == GF_CLUSTER_TYPE_REPLICATE)
                        cli_out ("number of bricks is not a multiple of "
                                 "replica count");
                ret = -1;
                goto out;
        }

        ret = dict_set_dynstr (dict, "bricks", bricks);
        if (ret)
                goto out;

        ret = dict_set_int32 (dict, "count", brick_count);
        if (ret)
                goto out;

        *options = dict;

out:
        if (ret) {
                gf_log ("cli", GF_LOG_ERROR, "Unable to parse create volume CLI");
                if (dict)
                        dict_destroy (dict);
        }
        return ret;
}
示例#12
0
int32_t
cli_cmd_volume_top_parse (const char **words, int wordcount,
                              dict_t **options)
{
        dict_t  *dict           = NULL;
        char    *volname        = NULL;
        char    *value          = NULL;
        char    *key            = NULL;
        int      ret            = -1;
        gf1_cli_stats_op op = GF_CLI_STATS_NONE;
        gf1_cli_top_op    top_op = GF_CLI_TOP_NONE;
        int32_t  list_cnt       = -1;
        int      index          = 0;
        int      perf           = 0;
        int32_t  blk_size       = 0;
        int32_t  count          = 0;
        char    *delimiter      = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "top")) == 0);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount < 4)
                goto out;

        volname = (char *)words[2];

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        op = GF_CLI_STATS_TOP;
        ret = dict_set_int32 (dict, "op", (int32_t)op);
        if (ret)
                goto out;

        if (strcmp (words[3], "open") == 0) {
                top_op = GF_CLI_TOP_OPEN;
        } else if (strcmp (words[3], "read") == 0) {
                top_op = GF_CLI_TOP_READ;
        } else if (strcmp (words[3], "write") == 0) {
                top_op = GF_CLI_TOP_WRITE;
        } else if (strcmp (words[3], "opendir") == 0) {
                top_op = GF_CLI_TOP_OPENDIR;
        } else if (strcmp (words[3], "readdir") == 0) {
                top_op = GF_CLI_TOP_READDIR;
        } else if (strcmp (words[3], "read-perf") == 0) {
                top_op = GF_CLI_TOP_READ_PERF;
                perf = 1;
        } else if (strcmp (words[3], "write-perf") == 0) {
                top_op = GF_CLI_TOP_WRITE_PERF;
                perf = 1;
        } else {
                ret = -1;
                goto out;
        } 
        ret = dict_set_int32 (dict, "top-op", (int32_t)top_op);
        if (ret)
                goto out;

        for (index = 4; index < wordcount; index+=2) {

                key = (char *) words[index];
                value = (char *) words[index+1];

                if ( key && !value ) {
                        ret = -1;
                        goto out;
                }
                if (!strcmp (key, "brick")) {
                        delimiter = strchr (value, ':');
                        if (!delimiter || delimiter == value 
                            || *(delimiter+1) != '/') {
                                cli_out ("wrong brick type: %s, use <HOSTNAME>:"
                                         "<export-dir-abs-path>", value);
                                ret = -1;
                                goto out;
                        } else {
                                cli_path_strip_trailing_slashes (delimiter + 1);
                        }
                        ret = dict_set_str (dict, "brick", value);

                } else if (!strcmp (key, "list-cnt")) {
                        ret = gf_is_str_int (value);
                        if (!ret)
                                list_cnt = atoi (value);
                        if (ret || (list_cnt < 0) || (list_cnt > 100)) {
                                cli_out ("list-cnt should be between 0 to 100");
                                ret = -1;
                                goto out;
                        }
                } else if (perf && !strcmp (key, "bs")) {
                        ret = gf_is_str_int (value);
                        if (!ret)
                                blk_size = atoi (value);
                        if (ret || (blk_size < 0)) {
                                cli_out ("block size should be an integer "
                                         "greater than zero");
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_int32 (dict, "blk-size", blk_size);
                } else if (perf && !strcmp (key, "count")) {
                        ret = gf_is_str_int (value);
                        if (!ret)
                                count = atoi(value);
                        if (ret || (count < 0)) {
                                cli_out ("count should be an integer greater "
                                         "zero");
                                ret = -1;
                                goto out;
                        }
                        ret = dict_set_int32 (dict, "blk-cnt", count);
                } else {
                        ret = -1;
                        goto out;
                }
                if (ret) {
                        gf_log ("", GF_LOG_WARNING, "Dict set failed for "
                                "key %s", key);
                        goto out;
                }
        }
        if (list_cnt == -1)
                list_cnt = 100;
        ret = dict_set_int32 (dict, "list-cnt", list_cnt);
        if (ret) {
                gf_log ("", GF_LOG_WARNING, "Dict set failed for list_cnt");
                goto out;
        }

        *options = dict;
out:
        if (ret && dict)
                dict_destroy (dict);
        return ret;
}
示例#13
0
int32_t
cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)
{
        int32_t            ret     = 0;
        int32_t            config_type = 0;
        dict_t            *dict   = NULL;
        gf1_cli_gsync_set type    = GF_GSYNC_OPTION_TYPE_NONE;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "gsync")) == 0);

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount < 5)
                goto out;

        ret = dict_set_str (dict, "master", (char *)words[3]);
        if (ret < 0)
                goto out;

        ret = dict_set_str (dict, "slave", (char *)words[4]);
        if (ret < 0)
                goto out;

        if ((strcmp (words[2], "start")) == 0) {
                type = GF_GSYNC_OPTION_TYPE_START;

                goto set_type;
        }

        if ((strcmp (words[2], "stop")) == 0) {
                type = GF_GSYNC_OPTION_TYPE_STOP;

                goto set_type;
        }

        if ((strcmp (words[2], "configure")) == 0) {
                type = GF_GSYNC_OPTION_TYPE_CONFIGURE;

                if (strcmp (words [5], "config-set") == 0) {
                        config_type = GF_GSYNC_OPTION_TYPE_CONFIG_SET;

                        ret = dict_set_str (dict, "op_name", (char *)words[6]);
                        if (ret < 0)
                                goto out;

                        ret = dict_set_str (dict, "op_value", (char *)words[7]);
                        if (ret < 0)
                                goto out;
                }

                if ((strcmp (words [5], "config-del")) == 0) {
                        config_type = GF_GSYNC_OPTION_TYPE_CONFIG_DEL;

                        ret = dict_set_str (dict, "op_name", (char *)words[6]);
                        if (ret < 0)
                                goto out;
                }

                if ((strcmp (words [5], "config-get")) == 0) {
                        config_type = GF_GSYNC_OPTION_TYPE_CONFIG_GET;

                        ret = dict_set_str (dict, "op_name", (char *)words[6]);
                        if (ret < 0)
                                goto out;
                }

                if ((strcmp (words [5], "config-get-all")) == 0) {
                        config_type = GF_GSYNC_OPTION_TYPE_CONFIG_GET_ALL;
                }

                ret = dict_set_int32 (dict, "config_type", config_type);
                if (ret < 0)
                        goto out;
        }

set_type:
        ret = dict_set_int32 (dict, "type", type);
        if (ret < 0)
                goto out;

        *options = dict;
out:
        if (ret)
                if (dict)
                        dict_destroy (dict);

        return ret;
}
int
quotad_aggregator_getlimit (rpcsvc_request_t *req)
{
        call_frame_t              *frame = NULL;
        gf_cli_req                 cli_req = {{0}, };
        gf_cli_rsp                 cli_rsp = {0};
        gfs3_lookup_req            args  = {{0,},};
        gfs3_lookup_rsp            rsp   = {0,};
        quotad_aggregator_state_t *state = NULL;
        xlator_t                  *this  = NULL;
        dict_t                    *dict  = NULL;
        int                        ret   = -1, op_errno = 0;
        char                      *gfid_str = NULL;
        uuid_t                     gfid = {0};

        GF_VALIDATE_OR_GOTO ("quotad-aggregator", req, err);

        this = THIS;

        ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req);
        if (ret < 0)  {
                //failed to decode msg;
                gf_log ("", GF_LOG_ERROR, "xdr decoding error");
                req->rpc_err = GARBAGE_ARGS;
                goto err;
        }

        if (cli_req.dict.dict_len) {
                dict = dict_new ();
                ret = dict_unserialize (cli_req.dict.dict_val,
                                        cli_req.dict.dict_len, &dict);
                if (ret < 0) {
                        gf_log (this->name, GF_LOG_ERROR, "Failed to "
                                "unserialize req-buffer to dictionary");
                        goto err;
                }
        }

        ret = dict_get_str (dict, "gfid", &gfid_str);
        if (ret) {
                goto err;
        }

        uuid_parse ((const char*)gfid_str, gfid);

        frame = quotad_aggregator_get_frame_from_req (req);
        if (frame == NULL) {
                rsp.op_errno = ENOMEM;
                goto err;
        }
        state = frame->root->state;
        state->xdata = dict;
        ret = dict_set_int32 (state->xdata, QUOTA_LIMIT_KEY, 42);
        if (ret)
                goto err;

        ret = dict_set_int32 (state->xdata, QUOTA_SIZE_KEY, 42);
        if (ret)
                goto err;

        ret = dict_set_int32 (state->xdata, GET_ANCESTRY_PATH_KEY,42);
        if (ret)
                goto err;

        memcpy (&args.gfid, &gfid, 16);

        args.bname           = alloca (req->msg[0].iov_len);
        args.xdata.xdata_val = alloca (req->msg[0].iov_len);

        ret = qd_nameless_lookup (this, frame, &args, state->xdata,
                                  quotad_aggregator_getlimit_cbk);
        if (ret) {
                rsp.op_errno = ret;
                goto err;
        }

        return ret;

err:
        cli_rsp.op_ret = -1;
        cli_rsp.op_errno = op_errno;
        cli_rsp.op_errstr = "";

        quotad_aggregator_getlimit_cbk (this, frame, &cli_rsp);
        dict_unref (dict);

        return ret;
}
示例#15
0
int
create_fuse_mount (glusterfs_ctx_t *ctx)
{
    int              ret = 0;
    cmd_args_t      *cmd_args = NULL;
    xlator_t        *master = NULL;

    cmd_args = &ctx->cmd_args;

    if (!cmd_args->mount_point)
        return 0;

    master = GF_CALLOC (1, sizeof (*master),
                        gfd_mt_xlator_t);
    if (!master)
        goto err;

    master->name = gf_strdup ("fuse");
    if (!master->name)
        goto err;

    if (xlator_set_type (master, "mount/fuse") == -1) {
        gf_log ("glusterfsd", GF_LOG_ERROR,
                "MOUNT-POINT %s initialization failed",
                cmd_args->mount_point);
        goto err;
    }

    master->ctx      = ctx;
    master->options  = get_new_dict ();

    ret = dict_set_static_ptr (master->options, ZR_MOUNTPOINT_OPT,
                               cmd_args->mount_point);
    if (ret < 0) {
        gf_log ("glusterfsd", GF_LOG_ERROR,
                "failed to set mount-point to options dictionary");
        goto err;
    }

    if (cmd_args->fuse_attribute_timeout >= 0) {
        ret = dict_set_double (master->options, ZR_ATTR_TIMEOUT_OPT,
                               cmd_args->fuse_attribute_timeout);

        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
    }

    if (cmd_args->fuse_entry_timeout >= 0) {
        ret = dict_set_double (master->options, ZR_ENTRY_TIMEOUT_OPT,
                               cmd_args->fuse_entry_timeout);
        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
    }

    if (cmd_args->client_pid_set) {
        ret = dict_set_int32 (master->options, "client-pid",
                              cmd_args->client_pid);
        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
    }

    if (cmd_args->volfile_check) {
        ret = dict_set_int32 (master->options, ZR_STRICT_VOLFILE_CHECK,
                              cmd_args->volfile_check);
        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
    }

    if (cmd_args->dump_fuse) {
        ret = dict_set_static_ptr (master->options, ZR_DUMP_FUSE,
                                   cmd_args->dump_fuse);
        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
    }

    switch (cmd_args->fuse_direct_io_mode) {
    case GF_OPTION_DISABLE: /* disable */
        ret = dict_set_static_ptr (master->options, ZR_DIRECT_IO_OPT,
                                   "disable");
        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
        break;
    case GF_OPTION_ENABLE: /* enable */
        ret = dict_set_static_ptr (master->options, ZR_DIRECT_IO_OPT,
                                   "enable");
        if (ret < 0) {
            gf_log ("glusterfsd", GF_LOG_ERROR,
                    "failed to set dict value.");
            goto err;
        }
        break;
    case GF_OPTION_DEFERRED: /* default */
    default:
        break;
    }

    ret = xlator_init (master);
    if (ret)
        goto err;

    ctx->master = master;

    return 0;

err:
    if (master) {
        xlator_destroy (master);
    }

    return -1;
}