summaryrefslogtreecommitdiffstats
path: root/gluster-block.c
blob: 157d16ac11c491372e24dc2356496ad34febe27e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
/*
  Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
  This file is part of gluster-block.

  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.
*/


# define   _GNU_SOURCE         /* See feature_test_macros(7) */

# include  <string.h>
# include  <getopt.h>
# include  <uuid/uuid.h>

# include "utils.h"
# include "glfs-operations.h"
# include "ssh-common.h"

# define  UUID_BUF_SIZE    50
# define  CFG_STRING_SIZE  256

# define  LIST             "list"
# define  CREATE           "create"
# define  DELETE           "delete"
# define  INFO             "info"
# define  MODIFY           "modify"
# define  BLOCKHOST        "block-host"
# define  HELP             "help"

# define  GLFS_PATH        "/backstores/user:glfs"
# define  TARGETCLI_GLFS   "targetcli "GLFS_PATH
# define  TARGETCLI_ISCSI  "targetcli /iscsi"
# define  TARGETCLI_SAVE   "targetcli / saveconfig"
# define  ATTRIBUTES       "generate_node_acls=1 demo_mode_write_protect=0"
# define  BACKEND_CFGSTR   "ls | grep ' %s ' | cut -d'[' -f2 | cut -d']' -f1"
# define  LUNS_LIST        "ls | grep -v user:glfs | cut -d'-' -f2 | cut -d' ' -f2"

# define  IQN_PREFIX       "iqn.2016-12.org.gluster-block:"

# define MSERVER_DELIMITER ","



typedef struct blockServerDef {
  size_t nhosts;
  char   **hosts;
} blockServerDef;
typedef blockServerDef *blockServerDefPtr;


static void
glusterBlockHelp(void)
{
  MSG("%s",
      "gluster-block (Version 0.1) \n"
      " -c, --create      <name>          Create the gluster block\n"
      "     -v, --volume       <vol>            gluster volume name\n"
      "     -h, --host         <gluster-node>   node addr from gluster pool\n"
      "     -s, --size         <size>           block storage size in KiB|MiB|GiB|TiB..\n"
      "\n"
      " -l, --list                        List available gluster blocks\n"
      "\n"
      " -i, --info        <name>          Details about gluster block\n"
      "\n"
      " -m, --modify      <resize|auth>   Modify the metadata\n"
      "\n"
      " -d, --delete      <name>          Delete the gluster block\n"
      "\n"
      "     [-b, --block-host <IP1,IP2,IP3...>]  block servers, clubbed with any option\n");
}


void
blockServerDefFree(blockServerDefPtr blkServers)
{
  size_t i;

  if (!blkServers)
    return;

  for (i = 0; i < blkServers->nhosts; i++)
     GB_FREE(blkServers->hosts[i]);
   GB_FREE(blkServers->hosts);
   GB_FREE(blkServers);
}


static void
glusterBlockDefFree(glusterBlockDefPtr blk)
{
  if (!blk)
    return;

  GB_FREE(blk->volume);
  GB_FREE(blk->host);
  GB_FREE(blk->filename);
  GB_FREE(blk);
}


static blockServerDefPtr
blockServerParse(char *blkServers)
{
  blockServerDefPtr list;
  char *tmp = blkServers;
  size_t i = 0;

  if (!blkServers)
    return NULL;

  if (GB_ALLOC(list) < 0)
    return NULL;

  /* count number of servers */
  while (*tmp) {
    if (*tmp == ',')
      list->nhosts++;
    tmp++;
  }
  list->nhosts++;
  tmp = blkServers; /* reset addr */


  if (GB_ALLOC_N(list->hosts, list->nhosts) < 0)
    goto fail;

  for (i = 0; tmp != NULL; i++) {
    if (GB_STRDUP(list->hosts[i], strsep(&tmp, MSERVER_DELIMITER)) < 0)
      goto fail;
  }

  return list;

 fail:
   blockServerDefFree(list);
   return NULL;
}


static size_t
glusterBlockCreateParseSize(char *value)
{
  char *postfix;
  char *tmp;
  size_t sizef;

  if (!value)
    return -1;

  sizef = strtod(value, &postfix);
  if (sizef < 0) {
    ERROR("%s", "size cannot be negative number\n");
    return -1;
  }

  tmp = postfix;
  if (*postfix == ' ')
    tmp = tmp + 1;

  switch (*tmp) {
  case 'Y':
    sizef *= 1024;
    /* fall through */
  case 'Z':
    sizef *= 1024;
    /* fall through */
  case 'E':
    sizef *= 1024;
    /* fall through */
  case 'P':
    sizef *= 1024;
    /* fall through */
  case 'T':
    sizef *= 1024;
    /* fall through */
  case 'G':
    sizef *= 1024;
    /* fall through */
  case 'M':
    sizef *= 1024;
    /* fall through */
  case 'K':
  case 'k':
    sizef *= 1024;
    /* fall through */
  case 'b':
  case '\0':
    return sizef;
    break;
  default:
    ERROR("%s", "You may use k/K, M, G or T suffixes for "
                "kilobytes, megabytes, gigabytes and terabytes.");
    return -1;
  }
}


static char *
glusterBlockListGetHumanReadableSize(size_t bytes)
{
  char *size;
  char *types[] = {"Byte(s)", "KiB", "MiB", "GiB",
                   "TiB", "PiB", "EiB", "ZiB", "YiB"};
  size_t i;

  if (bytes < 1024) {
    asprintf(&size, "%zu %s", bytes, *(types));
    return size;
  }

  for (i = 1; i < 8; i++) {
    bytes /= 1024;
    if (bytes < 1024) {
      asprintf(&size, "%zu %s    ", bytes, *(types + i));
      return size;
    }
  }

  return NULL;
}


static int
glusterBlockCreate(int count, char **options, char *name)
{
  int c;
  int ret = 0;
  char *cmd = NULL;
  char *exec = NULL;
  char *iqn = NULL;
  char *blkServers = NULL;
  blockServerDefPtr list;
  uuid_t out;
  glusterBlockDefPtr blk;
  char *sshout;
  size_t i;

  if (GB_ALLOC(blk) < 0)
    return -1;

  blk->filename = CALLOC(UUID_BUF_SIZE);

  uuid_generate(out);
  uuid_unparse(out, blk->filename);

  if (!name) {
    ERROR("%s", "Insufficient arguments supplied for"
                "'gluster-block create'");
    ret = -1;
    goto out;
  }

  while (1) {
    static const struct option long_options[] = {
      {"volume",     required_argument, 0, 'v'},
      {"host",       required_argument, 0, 'h'},
      {"size",       required_argument, 0, 's'},
      {"block-host", required_argument, 0, 'b'},
      {0, 0, 0, 0}
    };

    /* getopt_long stores the option index here. */
    int option_index = 0;

    c = getopt_long(count, options, "b:v:h:s:",
                    long_options, &option_index);

    if (c == -1)
      break;

    switch (c) {
    case 'b':
      blkServers = optarg;
      break;

    case 'v':
      GB_STRDUP(blk->volume, optarg);
      ret++;
      break;

    case 'h':
      GB_STRDUP(blk->host, optarg);
      ret++;
      break;

    case 's':
      blk->size = glusterBlockCreateParseSize(optarg);
      if (blk->size < 0) {
        ERROR("%s", "failed while parsing size");
        ret = -1;
        goto out;
      }
      ret++;
      break;

    case '?':
      MSG("unrecognized option '%s'", options[optind-1]);
      MSG("%s", "Hint: gluster-block --help");
      goto out;

    default:
      break;
    }
  }

  if (blkServers) {
    list = blockServerParse(blkServers);
  } else {
    list = blockServerParse("localhost");
  }

  /* Print any remaining command line arguments (not options). */
  if (optind < count) {
    ERROR("%s", "non-option ARGV-elements: ");
    while (optind < count)
      printf("%s ", options[optind++]);
    putchar('\n');

    ret = -1;
    goto out;
  }

  if (ret != 3) {
    ERROR("%s", "Insufficient arguments supplied for"
                "'gluster-block create'\n");
    ret = -1;
    goto out;
  }

  ret = glusterBlockCreateEntry(blk);
  if (ret) {
    ERROR("%s volume: %s host: %s",
          FAILED_CREATING_FILE, blk->volume, blk->host);
    goto out;
  }

  if (asprintf(&cmd, "%s %s %s %zu %s@%s/%s", TARGETCLI_GLFS,
               CREATE, name, blk->size, blk->volume, blk->host,
               blk->filename) < 0)
    goto out;

  /* Created user-backed storage object LUN size 2147483648. */
  for (i = 0; i < list->nhosts; i++) {
    MSG("[OnHost: %s]", list->hosts[i]);
    sshout = glusterBlockSSHRun(list->hosts[i], cmd, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_CREATING_BACKEND, list->hosts[i]);
      ret = -1;
      goto out;
    }

    asprintf(&iqn, "%s%s-%s",
             IQN_PREFIX, list->hosts[i], blk->filename);
    asprintf(&exec, "%s %s %s", TARGETCLI_ISCSI, CREATE, iqn);
    sshout = glusterBlockSSHRun(list->hosts[i], exec, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_CREATING_IQN, list->hosts[i]);
      ret = -1;
      goto out;
    }
    GB_FREE(exec);

    asprintf(&exec, "%s/%s/tpg1/luns %s %s/%s",
             TARGETCLI_ISCSI, iqn, CREATE, GLFS_PATH, name);
    sshout = glusterBlockSSHRun(list->hosts[i], exec, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_CREATING_LUN, list->hosts[i]);
      ret = -1;
      goto out;
    }
    GB_FREE(exec);

    asprintf(&exec, "%s/%s/tpg1 set attribute %s",
             TARGETCLI_ISCSI, iqn, ATTRIBUTES);
    sshout = glusterBlockSSHRun(list->hosts[i], exec, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_SETTING_ATTRIBUTES, list->hosts[i]);
      ret = -1;
      goto out;
    }
    GB_FREE(exec);
    GB_FREE(iqn);

    sshout = glusterBlockSSHRun(list->hosts[i], TARGETCLI_SAVE, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_SAVEING_CONFIG, list->hosts[i]);
      ret = -1;
      goto out;
    }
    putchar('\n');
  }

 out:
  GB_FREE(cmd);
  GB_FREE(exec);
  GB_FREE(iqn);
  glusterBlockDefFree(blk);
  blockServerDefFree(list);

  return ret;
}


static int
glusterBlockParseCfgStringToDef(char* cfgstring,
                                glusterBlockDefPtr blk)
{
  int ret = 0;
  char *p, *sep;

  /* part before '@' is the volume name */
  p = cfgstring;
  sep = strchr(p, '@');
  if (!sep) {
    ret = -1;
    goto fail;
  }

  *sep = '\0';
  if (GB_STRDUP(blk->volume, p) < 0) {
    ret = -1;
    goto fail;
  }

  /* part between '@' and '/' is the server name */
  p = sep + 1;
  sep = strchr(p, '/');
  if (!sep) {
    ret = -1;
    goto fail;
  }

  *sep = '\0';
  if (GB_STRDUP(blk->host, p) < 0) {
    ret = -1;
    goto fail;
  }

  /* part between '/' and '(' is the filename */
  p = sep + 1;
  sep = strchr(p, '(');
  if (!sep) {
    ret = -1;
    goto fail;
  }

  *(sep - 1) = '\0';  /* discard extra space at end of filename */
  if (GB_STRDUP(blk->filename, p) < 0) {
    ret = -1;
    goto fail;
  }

  /* part between '(' and ')' is the size */
  p = sep + 1;
  sep = strchr(p, ')');
  if (!sep) {
    ret = -1;
    goto fail;
  }

  *sep = '\0';
  blk->size = glusterBlockCreateParseSize(p);
  if (blk->size < 0) {
    ERROR("%s", "failed while parsing size");
    ret = -1;
    goto fail;
  }


  /* part between ')' and '\n' is the status */
  p = sep + 1;
  sep = strchr(p, '\n');
  if (!sep) {
    ret = -1;
    goto fail;
  }

  *sep = '\0';
  if (!strcmp(p, " activated"))
    blk->status = true;

  return 0;

 fail:
  glusterBlockDefFree(blk);

  return ret;
}


static char *
getCfgstring(char* name, char *blkServer)
{
  FILE *fd;
  char *cmd;
  char *exec;
  char *sshout;
  char *buf = CALLOC(CFG_STRING_SIZE);

  asprintf(&cmd, "%s %s", TARGETCLI_GLFS, BACKEND_CFGSTR);
  asprintf(&exec, cmd, name);

  sshout = glusterBlockSSHRun(blkServer, exec, false);
  if (!sshout) {
    ERROR("%s on host: %s",
          FAILED_GATHERING_CFGSTR, blkServer);
    GB_FREE(buf);
    buf = NULL;
    goto fail;
  }

  fd = fopen(sshout, "r");
  if (!fgets(buf, CFG_STRING_SIZE, fd)) {
    GB_FREE(buf);
    buf = NULL;
  }

 fail:
  fclose(fd);
  remove(sshout);
  GB_FREE(sshout);
  GB_FREE(cmd);
  GB_FREE(exec);

  return buf;
}


/* TODO: need to implement sessions [ list | detail ] [sid] */
static int
glusterBlockList(blockServerDefPtr blkServers)
{
  size_t i;
  int ret;
  char *cmd;
  char *pos;
  char *sshout;
  char *cfgstring = NULL;
  char buf[CFG_STRING_SIZE];
  FILE *fd = NULL;
  glusterBlockDefPtr blk = NULL;

  MSG("%s", "BlockName      Volname      Host      Size      Status");

  asprintf(&cmd, "%s %s", TARGETCLI_GLFS, LUNS_LIST);

  for (i = 0; i < blkServers->nhosts; i++) {
    MSG("[OnHost: %s]", blkServers->hosts[i]);
    sshout = glusterBlockSSHRun(blkServers->hosts[i], cmd, false);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_LIST_BACKEND, blkServers->hosts[i]);
      ret = -1;
      goto fail;
    }

    fd = fopen(sshout, "r");
    while (fgets(buf, sizeof(buf), fd)) {
      pos = strtok(buf, "\n");

      cfgstring = getCfgstring(pos, blkServers->hosts[i]);
      if (!cfgstring) {
        ERROR("%s", "failed while gathering CfgString");
        ret = -1;
        goto fail;
      }

      if (GB_ALLOC(blk) < 0)
        goto fail;

      ret = glusterBlockParseCfgStringToDef(cfgstring, blk);
      if (ret) {
        ERROR("%s", "failed while parsing CfgString to glusterBlockDef");
        goto fail;
      }

      fprintf(stdout, " %s   %s   %s   %s   %s\n",
              pos, blk->volume, blk->host,
              glusterBlockListGetHumanReadableSize(blk->size),
              blk->status ? "Online" : "Offline");

      GB_FREE(cfgstring);
      glusterBlockDefFree(blk);
    }

    fclose(fd);
    remove(sshout);
    GB_FREE(sshout);
  }

  GB_FREE(cmd);
  return 0;

 fail:
  fclose(fd);
  remove(sshout);
  glusterBlockDefFree(blk);
  GB_FREE(cfgstring);

  GB_FREE(sshout);
  GB_FREE(cmd);

  return -1;
}


static int
glusterBlockDelete(char* name, blockServerDefPtr blkServers)
{
  size_t i;
  int ret;
  char *cmd;
  char *exec = NULL;
  char *sshout;
  char *cfgstring = NULL;
  char *iqn = NULL;
  glusterBlockDefPtr blk = NULL;

  asprintf(&cmd, "%s %s %s", TARGETCLI_GLFS, DELETE, name);

  for (i = 0; i < blkServers->nhosts; i++) {
    MSG("[OnHost: %s]", blkServers->hosts[i]);
    if (cfgstring)
      GB_FREE(cfgstring);
    cfgstring = getCfgstring(name, blkServers->hosts[i]);
    if (!cfgstring) {
      ERROR("%s", "failed while gathering CfgString");
      ret = -1;
      goto fail;
    }

    sshout = glusterBlockSSHRun(blkServers->hosts[i], cmd, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_DELETING_BACKEND, blkServers->hosts[i]);
      ret = -1;
      goto fail;
    }

    /* cfgstring is constant across all tcmu nodes */
    if (!blk) {
      if (GB_ALLOC(blk) < 0)
        goto fail;

      ret = glusterBlockParseCfgStringToDef(cfgstring, blk);
      if (ret) {
        ERROR("%s", "failed while parsing CfgString to glusterBlockDef");
        goto fail;
      }
    }

    asprintf(&iqn, "%s%s-%s",
             IQN_PREFIX, blkServers->hosts[i], blk->filename);
    asprintf(&exec, "%s %s %s", TARGETCLI_ISCSI, DELETE, iqn);
    sshout = glusterBlockSSHRun(blkServers->hosts[i], exec, true);
    if (!sshout) {
      ERROR("%s on host: %s",
            FAILED_DELETING_IQN, blkServers->hosts[i]);
      ret = -1;
      goto fail;
    }
    GB_FREE(exec);
    GB_FREE(iqn);
  }

  ret = glusterBlockDeleteEntry(blk);
  if (ret) {
    ERROR("%s volume: %s host: %s",
          FAILED_DELETING_FILE, blk->volume, blk->host);
  }

 fail:
  glusterBlockDefFree(blk);
  GB_FREE(cfgstring);
  GB_FREE(iqn);
  GB_FREE(exec);
  GB_FREE(cmd);

  return ret;
}


static int
glusterBlockInfo(char* name, blockServerDefPtr blkServers)
{
  size_t i;
  int ret = 0;
  char *cmd;
  char *sshout;

  asprintf(&cmd, "%s/%s %s", TARGETCLI_GLFS, name, INFO);

  for (i = 0; i < blkServers->nhosts; i++) {
    MSG("[OnHost: %s]", blkServers->hosts[i]);
    sshout = glusterBlockSSHRun(blkServers->hosts[i], cmd, true);
    if (!sshout) {
      ret = -1;
      ERROR("%s on host: %s",
            FAILED_GATHERING_INFO, blkServers->hosts[i]);
      goto fail;
    }
    putchar('\n');
  }

 fail:
  GB_FREE(cmd);

  return ret;
}


static int
glusterBlockParseArgs(int count, char **options)
{
  int c;
  int ret = 0;
  int optFlag = 0;
  char *block = NULL;
  char *blkServers = NULL;
  blockServerDefPtr list = NULL;

  while (1) {
    static const struct option long_options[] = {
      {HELP,      no_argument,       0, 'h'},
      {CREATE,    required_argument, 0, 'c'},
      {DELETE,    required_argument, 0, 'd'},
      {LIST,      no_argument,       0, 'l'},
      {INFO,      required_argument, 0, 'i'},
      {MODIFY,    required_argument, 0, 'm'},
      {BLOCKHOST, required_argument, 0, 'b'},
      {0, 0, 0, 0}
    };

    /* getopt_long stores the option index here. */
    int option_index = 0;

    c = getopt_long(count, options, "hc:b:d:lim:",
                    long_options, &option_index);

    /* Detect the end of the options. */
    if (c == -1)
      break;

    switch (c) {
    case 'b':
      blkServers = optarg;
      if (optFlag)
        goto opt;
      break;

    case 'c':
      ret = glusterBlockCreate(count, options, optarg);
      if (ret) {
        ERROR("%s", FAILED_CREATE);
        goto out;
      }
      break;

    case 'l':
    case 'd':
    case 'i':
      if (optFlag) /* more than one main opterations ?*/
        goto out;
      optFlag = c;
      block = optarg;
      if (blkServers)
        goto opt;
      break;

    case 'm':
      MSG("option --modify yet TODO '%s'", optarg);
      break;

    case 'h':
      glusterBlockHelp();
      break;

    case '?':
      /* getopt_long already printed an error message. */
      break;
    }
  }

 opt:
  if (blkServers) {
    list = blockServerParse(blkServers);
  } else {
    list = blockServerParse("localhost");
  }

  switch (optFlag) {
  case 'l':
    ret = glusterBlockList(list);
    if (ret)
        ERROR("%s", FAILED_LIST);
    break;
  case 'i':
    ret = glusterBlockInfo(block, list);
    if (ret)
        ERROR("%s", FAILED_INFO);
    break;
  case 'd':
    ret = glusterBlockDelete(block, list);
    if (ret)
        ERROR("%s", FAILED_DELETE);
    break;
  }

 out:
  if (ret == 0 && optind < count) {
    ERROR("%s", "Unable to parse elements: ");
    while (optind < count)
      printf("%s ", options[optind++]);
    putchar('\n');
    MSG("Hint: %s --help", options[0]);
  }

  blockServerDefFree(list);
  return ret;
}


int
main(int argc, char *argv[])
{
  int ret;
  if (argc <= 1)
    glusterBlockHelp();

  ret = glusterBlockParseArgs(argc, argv);

  return ret;
}