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 **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; }