* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*/
/*
int fake = 0;
int force = 0;
int retry = 0;
-int md_stripe_cache_size = 2048;
+int md_stripe_cache_size = 16384;
char *progname = NULL;
void usage(FILE *out)
return 0;
}
+static void append_option(char *options, const char *one)
+{
+ if (*options)
+ strcat(options, ",");
+ strcat(options, one);
+}
+
/* Replace options with subset of Lustre-specific options, and
fill in mount flags */
int parse_options(char *orig_options, int *flagp)
* manner */
arg = opt;
val = strchr(opt, '=');
- if (val != NULL) {
- if (strncmp(arg, "md_stripe_cache_size", 20) == 0) {
- md_stripe_cache_size = atoi(val + 1);
- } else if (strncmp(arg, "retry", 5) == 0) {
- retry = atoi(val + 1);
- if (retry > MAX_RETRIES)
- retry = MAX_RETRIES;
- else if (retry < 0)
- retry = 0;
- }
+ /* please note that some ldiskfs mount options are also in the form
+ * of param=value. We should pay attention not to remove those
+ * mount options, see bug 22097. */
+ if (val && strncmp(arg, "md_stripe_cache_size", 20) == 0) {
+ md_stripe_cache_size = atoi(val + 1);
+ } else if (val && strncmp(arg, "retry", 5) == 0) {
+ retry = atoi(val + 1);
+ if (retry > MAX_RETRIES)
+ retry = MAX_RETRIES;
+ else if (retry < 0)
+ retry = 0;
+ } else if (val && strncmp(arg, "mgssec", 6) == 0) {
+ append_option(options, opt);
} else if (strncmp(opt, "force", 5) == 0) {
//XXX special check for 'force' option
++force;
printf("force: %d\n", force);
} else if (parse_one_option(opt, flagp) == 0) {
/* pass this on as an option */
- if (*options)
- strcat(options, ",");
- strcat(options, opt);
+ append_option(options, opt);
}
}
strcpy(orig_options, options);
if (fd == NULL)
return errno;
- fgets(buf, size, fd);
+ /* should not ignore fgets(3)'s return value */
+ if (!fgets(buf, size, fd)) {
+ fprintf(stderr, "reading from %s: %s", path, strerror(errno));
+ fclose(fd);
+ return 1;
+ }
fclose(fd);
return 0;
}
int main(int argc, char *const argv[])
{
char default_options[] = "";
- char *usource, *source, *target, *ptr;
+ char *usource, *source;
+ char target[PATH_MAX] = {'\0'};
char *options, *optcopy, *orig_options = default_options;
int i, nargs = 3, opt, rc, flags, optlen;
static struct option long_opt[] = {
usage(stderr);
}
- target = argv[optind + 1];
- ptr = target + strlen(target) - 1;
- while ((ptr > target) && (*ptr == '/')) {
- *ptr = 0;
- ptr--;
+ if (realpath(argv[optind + 1], target) == NULL) {
+ rc = errno;
+ fprintf(stderr, "warning: %s: cannot resolve: %s\n",
+ argv[optind + 1], strerror(errno));
+ return rc;
}
if (verbose) {
/* May as well try to clean up loop devs */
if (strncmp(usource, "/dev/loop", 9) == 0) {
char cmd[256];
+ int ret;
sprintf(cmd, "/sbin/losetup -d %s", usource);
- system(cmd);
+ if ((ret = system(cmd)) < 0)
+ rc = errno;
+ else if (ret > 0)
+ rc = WEXITSTATUS(ret);
}
} else if (!nomtab) {