#include <lustre_ver.h>
#include <sys/stat.h>
#include <sys/utsname.h>
+#include <linux/loop.h>
extern char *progname;
extern int verbose;
int add_param(char *buf, char *key, char *val)
{
- char *sub_val = NULL;
- int buflen = strlen(buf);
- int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
- int start = 0;
- int keylen = 0;
+ int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
+ int start = strlen(buf);
+ int keylen = 0;
- if (key != NULL)
+ if (key)
keylen = strlen(key);
-
- start = buflen;
- while ((sub_val = strsep(&val, ",")) != NULL) {
- if (*sub_val == 0)
- continue;
-
- if (start + 1 + keylen + strlen(sub_val) >= end) {
- fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
- progname, buf, key != NULL ? key : "", sub_val);
- buf[buflen] = '\0';
- return 1;
- }
-
- sprintf(buf + start, " %s%s", key != NULL ? key : "", sub_val);
- start = strlen(buf);
+ if (start + 1 + keylen + strlen(val) >= end) {
+ fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
+ progname, buf, key ? key : "", val);
+ return 1;
}
+ sprintf(buf + start, " %s%s", key ? key : "", val);
return 0;
}
int i, ret = 0;
/* Figure out the loop device names */
- if (!access("/dev/loop0", F_OK | R_OK)) {
+ if (!access("/dev/loop0", F_OK | R_OK) ||
+ !access("/dev/loop-control", F_OK | R_OK)) {
strcpy(loop_base, "/dev/loop\0");
} else if (!access("/dev/loop/0", F_OK | R_OK)) {
strcpy(loop_base, "/dev/loop/\0");
char cmd[PATH_MAX];
int cmdsz = sizeof(cmd);
+#ifdef LOOP_CTL_GET_FREE
+ ret = open("/dev/loop-control", O_RDWR);
+ if (ret < 0) {
+ fprintf(stderr, "%s: can't access loop control\n", progname);
+ return EACCES;
+ }
+ /* find or allocate a free loop device to use */
+ i = ioctl(ret, LOOP_CTL_GET_FREE);
+ if (i < 0) {
+ fprintf(stderr, "%s: access loop control error\n", progname);
+ return EACCES;
+ }
+ sprintf(l_device, "%s%d", loop_base, i);
+#else
sprintf(l_device, "%s%d", loop_base, i);
if (access(l_device, F_OK | R_OK))
break;
+#endif
snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
ret = system(cmd);
{
int fd;
- if (mop->mo_device_sz == 0) {
+ if (mop->mo_device_kb == 0) {
fatal();
fprintf(stderr, "loop device requires a --device-size= "
"param\n");
return errno;
}
- if (ftruncate(fd, mop->mo_device_sz * 1024) != 0) {
+ if (ftruncate(fd, mop->mo_device_kb * 1024) != 0) {
close(fd);
fatal();
fprintf(stderr, "%s: Unable to truncate backing store: %s\n",