bcacheadm: register bcache ioctl already takes an argv, no need to parse it

Change-Id: I0295ebde998c038feb40332ea303935035b8e2bd
Signed-off-by: Jacob Malevich <jam@daterainc.com>
This commit is contained in:
Jacob Malevich 2014-11-13 12:30:26 -08:00
parent 34f54790d5
commit 7d34cf342e
2 changed files with 3 additions and 29 deletions

View File

@ -934,39 +934,19 @@ int list_cachesets(char *cset_dir)
return 0;
}
char *parse_array_to_list(char *const *args)
{
int i, len = 0;
char *space = " ";
for(i=0; args[i] != NULL; i++) {
len+=strlen(args[i]) + 1;
}
char *arg_list = (char*)malloc(sizeof(char)*len);
strcpy(arg_list, args[0]);
strcat(arg_list, space);
for(i=1; args[i] != NULL; i++) {
strcat(arg_list, args[i]);
strcat(arg_list, space);
}
return arg_list;
}
int register_bcache(char *devs)
{
int ret, bcachefd;
bcachefd = open("/dev/bcache", O_RDWR);
if (bcachefd < 0) {
perror("Can't open bcache device");
perror("Can't open bcache device\n");
exit(EXIT_FAILURE);
}
ret = ioctl(bcachefd, BCH_IOCTL_REGISTER, devs);
if (ret < 0) {
fprintf(stderr, "ioctl register error: %s", strerror(ret));
fprintf(stderr, "ioctl register error: %s\n", strerror(ret));
exit(EXIT_FAILURE);
}
return 0;

View File

@ -345,13 +345,7 @@ int probe_bcache (NihCommand *command, char *const *args)
int bcache_register (NihCommand *command, char *const *args)
{
int ret;
char *arg_list = parse_array_to_list(args);
if(arg_list) {
ret = register_bcache(arg_list);
free(arg_list);
}
int ret = register_bcache(args);
return ret;
}