static int do_mount_one(struct nilfs_mount_info *mi, const struct mount_options *mo) { int res, errsv, mtab_ok; char *tmpexopts, *exopts; pp_opt_t prot_period; tmpexopts = change_opt(mo->extra_opts, pp_opt_fmt, &prot_period, ""); exopts = change_opt(tmpexopts, nogc_opt_fmt, NULL, ""); my_free(tmpexopts); res = mount(mi->device, mi->mntdir, fstype, mo->flags & ~MS_NOSYS, exopts); if (!res) goto out; errsv = errno; switch (errsv) { case ENODEV: error(_("%s: cannot find or load %s filesystem"), progname, fstype); break; default: error(_("%s: Error while mounting %s on %s: %s"), progname, mi->device, mi->mntdir, strerror(errsv)); break; } if (mi->type != RW2RO_REMOUNT && mi->type != RW2RW_REMOUNT) goto out; mtab_ok = check_mtab(); /* Cleaner daemon was stopped and it needs to run */ /* because filesystem is still mounted */ if (!mi->nogc && mtab_ok) { /* Restarting cleaner daemon */ if (nilfs_launch_cleanerd(mi->device, mi->mntdir, mi->protperiod, &mi->gcpid)) { if (verbose) printf(_("%s: restarted %s\n"), progname, NILFS_CLEANERD_NAME); update_gcpid_opt(&mi->optstr, mi->gcpid); update_mtab_entry(mi->device, mi->mntdir, fstype, mi->optstr, 0, 0, !mi->mounted); } else { error(_("%s: failed to restart %s"), progname, NILFS_CLEANERD_NAME); } } else printf(_("%s not restarted\n"), NILFS_CLEANERD_NAME); out: my_free(exopts); return res; }
int main(int argc, char *argv[]) { const char *src, *node, *opts; char *rsrc = NULL; char *popts = NULL; int flags = 0; int retval = 0; retval = parse_arguments(argc, argv, &src, &node, &opts); if (retval) { usage(argv[0]); exit((retval > 0) ? EXIT_SUCCESS : EXIT_FAILURE); } rsrc = mount_resolve_src(src); if (!rsrc) { printf("failed to resolve source\n"); exit(1); } modprobe(); popts = parse_options(opts, &flags); if (!popts) { printf("failed to parse ceph_options\n"); exit(1); } block_signals(SIG_BLOCK); if (mount(rsrc, node, "ceph", flags, popts)) { retval = errno; switch (errno) { case ENODEV: printf("mount error: ceph filesystem not supported by the system\n"); break; default: printf("mount error %d = %s\n",errno,strerror(errno)); } } else { if (!skip_mtab_flag) { update_mtab_entry(rsrc, node, "ceph", popts, flags, 0, 0); } } block_signals(SIG_UNBLOCK); free(popts); free(rsrc); exit(retval); }
static void update_mount_state(struct nilfs_mount_info *mi, const struct mount_options *mo) { pid_t pid = 0; pp_opt_t pp = ULONG_MAX; char *exopts; int rungc; rungc = (find_opt(mo->extra_opts, nogc_opt_fmt, NULL) < 0) && !(mo->flags & MS_RDONLY) && !(mo->flags & MS_BIND); if (!check_mtab()) { if (rungc) printf(_("%s not started\n"), NILFS_CLEANERD_NAME); return; } if (rungc) { if (find_opt(mo->extra_opts, pp_opt_fmt, &pp) < 0) pp = mi->protperiod; if (nilfs_launch_cleanerd(mi->device, mi->mntdir, pp, &pid) < 0) error(_("%s aborted"), NILFS_CLEANERD_NAME); else if (verbose) printf(_("%s: started %s\n"), progname, NILFS_CLEANERD_NAME); } my_free(mi->optstr); exopts = fix_extra_opts_string(mo->extra_opts, pid, pp); mi->optstr = fix_opts_string(((mo->flags & ~MS_NOMTAB) | MS_NETDEV), exopts, NULL); update_mtab_entry(mi->device, mi->mntdir, fstype, mi->optstr, 0, 0, !mi->mounted); my_free(exopts); }
int main(int argc, char *const argv[]) { struct mount_opts mop; char *options; int i, rc, flags; progname = strrchr(argv[0], '/'); progname = progname ? progname + 1 : argv[0]; set_defaults(&mop); rc = osd_init(); if (rc) return rc; rc = parse_opts(argc, argv, &mop); if (rc || version) return rc; if (verbose) { for (i = 0; i < argc; i++) printf("arg[%d] = %s\n", i, argv[i]); printf("source = %s (%s), target = %s\n", mop.mo_usource, mop.mo_source, mop.mo_target); printf("options = %s\n", mop.mo_orig_options); } options = malloc(MAXOPT); if (options == NULL) { fprintf(stderr, "can't allocate memory for options\n"); return -1; } strcpy(options, mop.mo_orig_options); rc = parse_options(&mop, options, &flags); if (rc) { fprintf(stderr, "%s: can't parse options: %s\n", progname, options); return(EINVAL); } if (!mop.mo_force) { rc = check_mtab_entry(mop.mo_usource, mop.mo_source, mop.mo_target, "lustre"); if (rc && !(flags & MS_REMOUNT)) { fprintf(stderr, "%s: according to %s %s is " "already mounted on %s\n", progname, MOUNTED, mop.mo_usource, mop.mo_target); return(EEXIST); } if (!rc && (flags & MS_REMOUNT)) { fprintf(stderr, "%s: according to %s %s is " "not already mounted on %s\n", progname, MOUNTED, mop.mo_usource, mop.mo_target); return(ENOENT); } } if (flags & MS_REMOUNT) mop.mo_nomtab++; rc = access(mop.mo_target, F_OK); if (rc) { rc = errno; fprintf(stderr, "%s: %s inaccessible: %s\n", progname, mop.mo_target, strerror(errno)); return rc; } if (!strstr(mop.mo_usource, ":/")) { rc = parse_ldd(mop.mo_source, &mop, options); if (rc) return rc; } /* In Linux 2.4, the target device doesn't get passed to any of our functions. So we'll stick it on the end of the options. */ append_option(options, "device="); strcat(options, mop.mo_source); if (verbose) printf("mounting device %s at %s, flags=%#x options=%s\n", mop.mo_source, mop.mo_target, flags, options); if (!strstr(mop.mo_usource, ":/") && osd_tune_lustre(mop.mo_source, &mop)) { if (verbose) fprintf(stderr, "%s: unable to set tunables for %s" " (may cause reduced IO performance)\n", argv[0], mop.mo_source); } if (!mop.mo_fake) { /* flags and target get to lustre_get_sb, but not lustre_fill_super. Lustre ignores the flags, but mount does not. */ for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) { rc = mount(mop.mo_source, mop.mo_target, "lustre", flags, (void *)options); if (rc == 0) { /* change label from <fsname>:<index> to * <fsname>-<index> to indicate the device has * been registered. only if the label is * supposed to be changed and target service * is supposed to start */ if (mop.mo_ldd.ldd_flags & (LDD_F_VIRGIN | LDD_F_WRITECONF)) { if (mop.mo_nosvc == 0) (void)osd_label_lustre(&mop); } } else { if (verbose) { fprintf(stderr, "%s: mount %s at %s " "failed: %s retries left: " "%d\n", basename(progname), mop.mo_usource, mop.mo_target, strerror(errno), mop.mo_retry - i); } if (mop.mo_retry) { sleep(1 << max((i/2), 5)); } else { rc = errno; } } } } if (rc) { char *cli; rc = errno; cli = strrchr(mop.mo_usource, ':'); if (cli && (strlen(cli) > 2)) cli += 2; else cli = NULL; fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname, mop.mo_usource, mop.mo_target, strerror(errno)); if (errno == EBUSY) fprintf(stderr, "Is the backend filesystem mounted?\n" "Check /etc/mtab and /proc/mounts\n"); if (errno == ENODEV) fprintf(stderr, "Are the lustre modules loaded?\n" "Check /etc/modprobe.conf and " "/proc/filesystems\n"); if (errno == ENOTBLK) fprintf(stderr, "Do you need -o loop?\n"); if (errno == ENOMEDIUM) fprintf(stderr, "This filesystem needs at least 1 OST\n"); if (errno == ENOENT) { fprintf(stderr, "Is the MGS specification correct?\n"); fprintf(stderr, "Is the filesystem name correct?\n"); fprintf(stderr, "If upgrading, is the copied client log" " valid? (see upgrade docs)\n"); } if (errno == EALREADY) fprintf(stderr, "The target service is already running." " (%s)\n", mop.mo_usource); if (errno == ENXIO) fprintf(stderr, "The target service failed to start " "(bad config log?) (%s). " "See /var/log/messages.\n", mop.mo_usource); if (errno == EIO) fprintf(stderr, "Is the MGS running?\n"); if (errno == EADDRINUSE) fprintf(stderr, "The target service's index is already " "in use. (%s)\n", mop.mo_usource); if (errno == EINVAL) { fprintf(stderr, "This may have multiple causes.\n"); if (cli) fprintf(stderr, "Is '%s' the correct filesystem" " name?\n", cli); fprintf(stderr, "Are the mount options correct?\n"); fprintf(stderr, "Check the syslog for more info.\n"); } /* May as well try to clean up loop devs */ if (strncmp(mop.mo_usource, "/dev/loop", 9) == 0) { char cmd[256]; int ret; sprintf(cmd, "/sbin/losetup -d %s", mop.mo_usource); if ((ret = system(cmd)) < 0) rc = errno; else if (ret > 0) rc = WEXITSTATUS(ret); } } else if (!mop.mo_nomtab) { rc = update_mtab_entry(mop.mo_usource, mop.mo_target, "lustre", mop.mo_orig_options, 0,0,0); } free(options); /* mo_usource should be freed, but we can rely on the kernel */ free(mop.mo_source); osd_fini(); return rc; }
int main(int argc, char **argv) { errcode_t ret = 0; struct mount_options mo; ocfs2_filesys *fs = NULL; struct o2cb_cluster_desc cluster; struct o2cb_region_desc desc; int clustered = 1; int group_join = 0; struct stat statbuf; const char *spec; char *opts_string = NULL; initialize_ocfs_error_table(); initialize_o2dl_error_table(); initialize_o2cb_error_table(); setbuf(stdout, NULL); setbuf(stderr, NULL); if (signal(SIGTERM, handle_signal) == SIG_ERR) { fprintf(stderr, "Could not set SIGTERM\n"); exit(1); } if (signal(SIGINT, handle_signal) == SIG_ERR) { fprintf(stderr, "Could not set SIGINT\n"); exit(1); } memset(&mo, 0, sizeof(mo)); read_options (argc, argv, &mo); ret = process_options(&mo); if (ret) goto bail; ret = ocfs2_open(mo.dev, OCFS2_FLAG_RO, 0, 0, &fs); //O_EXCL? if (ret) { com_err(progname, ret, "while opening device %s", mo.dev); goto bail; } clustered = (0 == ocfs2_mount_local(fs)); if (ocfs2_is_hard_readonly(fs) && (clustered || !(mo.flags & MS_RDONLY))) { ret = OCFS2_ET_IO; com_err(progname, ret, "while mounting read-only device in %s mode", (clustered ? "clustered" : "read-write")); goto bail; } if (verbose) printf("device=%s\n", mo.dev); ret = o2cb_setup_stack((char *)OCFS2_RAW_SB(fs->fs_super)->s_cluster_info.ci_stack); if (ret) { com_err(progname, ret, "while setting up stack\n"); goto bail; } if (clustered) { ret = o2cb_init(); if (ret) { com_err(progname, ret, "while trying initialize cluster"); goto bail; } ret = ocfs2_fill_cluster_desc(fs, &cluster); if (ret) { com_err(progname, ret, "while trying to determine cluster information"); goto bail; } ret = ocfs2_fill_heartbeat_desc(fs, &desc); if (ret) { com_err(progname, ret, "while trying to determine heartbeat information"); goto bail; } desc.r_persist = 1; desc.r_service = OCFS2_FS_NAME; } ret = add_mount_options(fs, &cluster, &mo.xtra_opts); if (ret) { com_err(progname, ret, "while adding mount options"); goto bail; } /* validate mount dir */ if (lstat(mo.dir, &statbuf)) { com_err(progname, 0, "mount directory %s does not exist", mo.dir); goto bail; } else if (stat(mo.dir, &statbuf)) { com_err(progname, 0, "mount directory %s is a broken symbolic " "link", mo.dir); goto bail; } else if (!S_ISDIR(statbuf.st_mode)) { com_err(progname, 0, "mount directory %s is not a directory", mo.dir); goto bail; } block_signals (SIG_BLOCK); if (clustered && !(mo.flags & MS_REMOUNT)) { ret = o2cb_begin_group_join(&cluster, &desc); if (ret) { block_signals (SIG_UNBLOCK); com_err(progname, ret, "while trying to join the group"); goto bail; } group_join = 1; } spec = canonicalize(mo.dev); ret = mount(spec, mo.dir, OCFS2_FS_NAME, mo.flags & ~MS_NOSYS, mo.xtra_opts); if (ret) { ret = errno; if (group_join) { /* We ignore the return code because the mount * failure is the important error. * complete_group_join() will handle cleaning up */ o2cb_complete_group_join(&cluster, &desc, errno); } block_signals (SIG_UNBLOCK); if (ret == -EROFS) com_err(progname, OCFS2_ET_RO_FILESYS, "while mounting %s " "on %s, please try fixing this by fsck.ocfs2 and then " "retry mounting", mo.dev, mo.dir); else com_err(progname, OCFS2_ET_INTERNAL_FAILURE, "while mounting %s on %s. Check 'dmesg' for more " "information on this error %d.", mo.dev, mo.dir, (int)ret); goto bail; } if (group_join) { ret = o2cb_complete_group_join(&cluster, &desc, 0); if (ret) { com_err(progname, ret, "while completing group join (WARNING)"); /* * XXX: GFS2 allows the mount to continue, so we * will do the same. I don't know how clean that * is, but I don't have a better solution. */ ret = 0; } } change_local_hb_io_priority(fs, mo.dev); opts_string = fix_opts_string(((mo.flags & ~MS_NOMTAB) | (clustered ? MS_NETDEV : 0)), mo.xtra_opts, NULL); update_mtab_entry(mo.dev, mo.dir, OCFS2_FS_NAME, opts_string, mo.flags, 0, 0); block_signals (SIG_UNBLOCK); bail: if (fs) ocfs2_close(fs); if (mo.dev) free(mo.dev); if (mo.dir) free(mo.dir); if (mo.opts) free(mo.opts); if (mo.xtra_opts) free(mo.xtra_opts); if (mo.type) free(mo.type); if (opts_string) free(opts_string); return ret ? 1 : 0; }
int main(int argc, char *const argv[]) { char default_options[] = ""; char *options = default_options; char *origin_source = NULL; char *source = NULL; char *target = NULL; char *ptr = NULL; int opt = 0; int i = 0; int rc = 0; int flags = 0; int optlen = 0; char *optcopy = NULL; static struct option long_opt[] = { {"fake", 0, 0, 'f'}, {"force", 0, 0, 1}, {"help", 0, 0, 'h'}, {"nomtab", 0, 0, 'n'}, {"options", 1, 0, 'o'}, {"verbose", 0, 0, 'v'}, {0, 0, 0, 0} }; progname = strrchr(argv[0], '/'); progname = progname ? progname + 1 : argv[0]; while ((opt = getopt_long(argc, argv, "fhno:v", long_opt, NULL)) != EOF){ switch (opt) { case 1: ++force; printf("force: %d\n", force); break; case 'f': ++fake; printf("fake: %d\n", fake); break; case 'h': usage(stdout); break; case 'n': ++nomtab; printf("nomtab: %d\n", nomtab); break; case 'o': options = optarg; break; case 'v': ++verbose; break; default: fprintf(stderr, "%s: unknown option '%c'\n", progname, opt); usage(stderr); break; } } if (optind + 2 > argc) { fprintf(stderr, "%s: too few arguments\n", progname); usage(stderr); rc = EINVAL; goto out; } origin_source = argv[optind]; if (origin_source == NULL) { usage(stderr); goto out; } target = argv[optind + 1]; ptr = target + strlen(target) - 1; while ((ptr > target) && (*ptr == '/')) { *ptr = 0; ptr--; } if (verbose) { for (i = 0; i < argc; i++) { printf("arg[%d] = %s\n", i, argv[i]); } printf("source = %s, target = %s\n", origin_source, target); printf("options = %s\n", options); } rc = parse_options(options, &flags); if (rc) { fprintf(stderr, "%s: can't parse options: %s\n", progname, options); rc = EINVAL; goto out; } source = reslove_source_path(origin_source); if (source == NULL) { fprintf(stderr, "%s: can't reslove device option %s\n", progname, origin_source); rc = EINVAL; goto out; } if (verbose) { printf("resolved source = %s\n", source); } if (!force) { /* * TODO: need stricter check, not enough * e.g. dir1:dir2, dir2:dir1 */ rc = check_mtab_entry(source, target, "mtfs"); if (rc && !(flags & MS_REMOUNT)) { fprintf(stderr, "%s: according to %s %s is " "already mounted on %s\n", progname, MOUNTED, source, target); rc = EEXIST; goto free_source; } if (!rc && (flags & MS_REMOUNT)) { fprintf(stderr, "%s: according to %s %s is " "not already mounted on %s\n", progname, MOUNTED, source, target); rc = ENOENT; goto free_source; } } if (flags & MS_REMOUNT) { nomtab++; } rc = access(target, F_OK); if (rc) { rc = errno; fprintf(stderr, "%s: %s inaccessible: %s\n", progname, target, strerror(errno)); goto free_source; } /* * In Linux 2.4, the target device doesn't get passed to any of our * functions. So we'll stick it on the end of the options. */ optlen = strlen(options) + strlen(",device=") + strlen(source) + 1; optcopy = malloc(optlen); if (optcopy == NULL) { fprintf(stderr, "can't allocate memory to optcopy\n"); rc = ENOMEM; goto free_source; } strcpy(optcopy, options); if (*optcopy) { strcat(optcopy, ","); } strcat(optcopy, "device="); strcat(optcopy, source); if (verbose) { printf("mounting device %s at %s, flags=%#x options=%s\n", source, target, flags, optcopy); } if (!fake) { for (i = 0, rc = -EAGAIN; i <= retry && rc != 0; i++) { rc = mount(source, target, "mtfs", flags, (void *)optcopy); if (rc) { if (verbose) { fprintf(stderr, "%s: mount %s at %s " "failed: %s retries left: " "%d\n", basename(progname), source, target, strerror(errno), retry-i); } if (retry) { sleep(1 << max((i/2), 5)); } else { rc = errno; } } } } if (rc) { rc = errno; fprintf(stderr, "%s: mount %s at %s failed: %s\n", progname, source, target, strerror(errno)); switch (errno) { case ENODEV: fprintf(stderr, "Are the mtfs modules loaded?\n"); break; case ENOTBLK: fprintf(stderr, "Do you need -o loop?\n"); break; case EINVAL: fprintf(stderr, "Are the mount options correct?\n"); break; case ENOENT: fprintf(stderr, "Are the source directorys exist?\n"); break; default: break; } goto free_optcopy; } if (!nomtab) { if (verbose) { printf("Adding to mtab\n"); } rc = update_mtab_entry(source, target, "mtfs", options, 0, 0, 0); if (rc) { fprintf(stderr, "Failed to update mtabl\n"); } } goto free_optcopy; free_optcopy: free(optcopy); free_source: free(source); out: return rc; }