From bcbef643358f163f856961a01b503d5902985380 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 22 Feb 2009 19:32:43 +0000 Subject: [PATCH] - very preliminary prototype for "early osd" - OSD is setup by mountconf (both ldiskfs and dmu are tried) - mountconf uses OSD to access mountdata file - mountconf can request registration w/o mountdata file (to be reimplemented within MGS) - MDT and OFD re-use that OSD --- lustre/include/lu_object.h | 4 +- lustre/include/lustre_disk.h | 14 +- lustre/include/obd.h | 3 + lustre/include/obd_class.h | 1 + lustre/mds/handler.c | 9 +- lustre/mdt/mdt_handler.c | 31 +- lustre/mgc/mgc_request.c | 27 +- lustre/mgs/mgs_fs.c | 6 + lustre/mgs/mgs_handler.c | 12 +- lustre/obdclass/obd_mount.c | 655 ++++++++++++++++++++++++++++++++++--------- lustre/ofd/ofd_dev.c | 17 +- lustre/ofd/ofd_fs.c | 3 - lustre/ofd/ofd_internal.h | 2 + lustre/ofd/ofd_obd.c | 3 +- lustre/ofd/ofd_objects.c | 2 +- lustre/osd/osd_handler.c | 77 ++--- lustre/osd/osd_internal.h | 3 +- lustre/osd/osd_lproc.c | 8 +- lustre/osd/osd_oi.c | 2 +- 19 files changed, 664 insertions(+), 215 deletions(-) diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index 73fe7af..d635908 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -292,7 +292,9 @@ enum lu_device_tag { /** this is data device */ LU_DEVICE_DT = (1 << 1), /** data device in the client stack */ - LU_DEVICE_CL = (1 << 2) + LU_DEVICE_CL = (1 << 2), + /** mountconf device (used for bootstrapping only */ + LU_DEVICE_MC = (1 << 3) }; /** diff --git a/lustre/include/lustre_disk.h b/lustre/include/lustre_disk.h index 4914390..3aed8776 100644 --- a/lustre/include/lustre_disk.h +++ b/lustre/include/lustre_disk.h @@ -89,6 +89,7 @@ enum ldd_mount_type { LDD_MT_SMFS, LDD_MT_REISERFS, LDD_MT_LDISKFS2, + LDD_MT_DMU, LDD_MT_LAST }; @@ -99,7 +100,8 @@ static inline char *mt_str(enum ldd_mount_type mt) "ldiskfs", "smfs", "reiserfs", - "ldiskfs2" + "ldiskfs2", + "dmu" }; return mount_type_string[mt]; } @@ -177,6 +179,8 @@ struct lustre_mount_data { char *lmd_opts; /* lustre mount options (as opposed to _device_ mount options) */ __u32 *lmd_exclude; /* array of OSTs to ignore */ + char *lmd_mgs; /* MGS nid */ + char *lmd_fsname; /* fs name for first mount */ }; #define LMD_FLG_SERVER 0x0001 /* Mounting a server */ @@ -284,7 +288,7 @@ struct lustre_sb_info { struct lustre_mount_data *lsi_lmd; /* mount command info */ struct lustre_disk_data *lsi_ldd; /* mount info on-disk */ struct ll_sb_info *lsi_llsbi; /* add'l client sbi info */ - struct vfsmount *lsi_srv_mnt; /* the one server mount */ + struct dt_device *lsi_dt_dev; /* dt device to access disk fs*/ atomic_t lsi_mounts; /* references to the srv_mnt */ }; @@ -304,7 +308,7 @@ struct lustre_sb_info { struct lustre_mount_info { char *lmi_name; struct super_block *lmi_sb; - struct vfsmount *lmi_mnt; + struct dt_device *lmi_dt; struct list_head lmi_list_chain; }; @@ -325,8 +329,8 @@ int lustre_end_log(struct super_block *sb, char *logname, struct config_llog_instance *cfg); struct lustre_mount_info *server_get_mount(const char *name); struct lustre_mount_info *server_get_mount_2(const char *name); -int server_put_mount(const char *name, struct vfsmount *mnt); -int server_put_mount_2(const char *name, struct vfsmount *mnt); +int server_put_mount(const char *name, struct dt_device *dt); +int server_put_mount_2(const char *name, struct dt_device *dt); int server_register_target(struct super_block *sb); struct mgs_target_info; int server_mti_print(char *title, struct mgs_target_info *mti); diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 0728503..cc078f0 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -454,6 +454,7 @@ struct client_obd { /* mgc datastruct */ struct semaphore cl_mgc_sem; struct vfsmount *cl_mgc_vfsmnt; + struct dt_device *cl_mgc_dt_dev; struct dentry *cl_mgc_configs_dir; atomic_t cl_mgc_refcount; struct obd_export *cl_mgc_mgsexp; @@ -765,6 +766,7 @@ struct niobuf_local { #define LUSTRE_LMV_NAME "lmv" #define LUSTRE_CMM_MDC_NAME "cmm-mdc" #define LUSTRE_SLP_NAME "slp" +#define LUSTRE_DMU_NAME "dmu" /* obd device type names */ /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */ @@ -777,6 +779,7 @@ struct niobuf_local { #define LUSTRE_LOV_NAME "lov" #define LUSTRE_MGS_NAME "mgs" #define LUSTRE_MGC_NAME "mgc" +#define LUSTRE_MCF_NAME "mountconf" #define LUSTRE_CACHEOBD_NAME "cobd" #define LUSTRE_ECHO_NAME "obdecho" diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index b47d60b..3883da0 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -199,6 +199,7 @@ struct obd_import *class_new_import(struct obd_device *obd); void class_destroy_import(struct obd_import *exp); struct obd_type *class_search_type(const char *name); +struct obd_type *class_get_type_by_tag(const int tag, const char *name); struct obd_type *class_get_type(const char *name); void class_put_type(struct obd_type *type); int class_connect(struct lustre_handle *conn, struct obd_device *obd, diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 00527cb..38f5733 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -338,6 +338,7 @@ static int mds_cmd_setup(struct obd_device *obd, struct lustre_cfg *lcfg) struct vfsmount *mnt; struct lustre_sb_info *lsi; struct lustre_mount_info *lmi; + struct dt_device_param dt_param; struct dentry *dentry; int rc = 0; ENTRY; @@ -355,13 +356,17 @@ static int mds_cmd_setup(struct obd_device *obd, struct lustre_cfg *lcfg) LASSERT(lmi != NULL); lsi = s2lsi(lmi->lmi_sb); - mnt = lmi->lmi_mnt; + lmi->lmi_dt->dd_ops->dt_conf_get(NULL, lmi->lmi_dt, &dt_param); + mnt = dt_param.ddp_mnt; + LASSERT(mnt); + /* FIXME: MDD LOV initialize objects. * we need only lmi here but not get mount * OSD did mount already, so put mount back */ atomic_dec(&lsi->lsi_mounts); - mntput(mnt); + /* XXX: fix mntput/mntget */ + //mntput(mnt); init_rwsem(&mds->mds_notify_lock); obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd)); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index d164c65..58935fe 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -4072,11 +4072,10 @@ static int mdt_stack_init(struct lu_env *env, int rc; ENTRY; - /* init the stack */ - tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg); - if (IS_ERR(tmp)) { - RETURN(PTR_ERR(tmp)); - } + LASSERT(lmi->lmi_dt); + tmp = &lmi->lmi_dt->dd_lu_dev; + tmp->ld_site = d->ld_site; + m->mdt_bottom = lu2dt_dev(tmp); d = tmp; tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg); @@ -4125,25 +4124,31 @@ out: * this may need to be rewrite as part of llog rewrite for lu-api. */ static int mdt_obd_llog_setup(struct obd_device *obd, + struct lustre_mount_info *lmi, struct lustre_sb_info *lsi) { - int rc; + struct dt_device_param dt_param; + struct vfsmount *mnt; + int rc; LASSERT(obd->obd_fsops == NULL); + lmi->lmi_dt->dd_ops->dt_conf_get(NULL, lmi->lmi_dt, &dt_param); + mnt = dt_param.ddp_mnt; + LASSERT(mnt); obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd)); if (IS_ERR(obd->obd_fsops)) return PTR_ERR(obd->obd_fsops); - rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb); + rc = fsfilt_setup(obd, mnt->mnt_sb); if (rc) { fsfilt_put_ops(obd->obd_fsops); return rc; } OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); - obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt; - obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root; + obd->obd_lvfs_ctxt.pwdmnt = mnt; + obd->obd_lvfs_ctxt.pwd = mnt->mnt_root; obd->obd_lvfs_ctxt.fs = get_ds(); rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd, @@ -4520,7 +4525,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, if (rc) GOTO(err_capa, rc); - rc = mdt_obd_llog_setup(obd, lsi); + rc = mdt_obd_llog_setup(obd, lmi, lsi); if (rc) GOTO(err_fs_cleanup, rc); @@ -4528,12 +4533,12 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, #ifdef HAVE_QUOTA_SUPPORT next = m->mdt_child; - rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt); + rc = next->md_ops->mdo_quota.mqo_setup(env, next, NULL); if (rc) GOTO(err_llog_cleanup, rc); #endif - server_put_mount_2(dev, lmi->lmi_mnt); + server_put_mount_2(dev, lmi->lmi_dt); lmi = NULL; target_recovery_init(obd, mdt_recovery_handle); @@ -4601,7 +4606,7 @@ err_free_site: OBD_FREE_PTR(mite); err_lmi: if (lmi) - server_put_mount_2(dev, lmi->lmi_mnt); + server_put_mount_2(dev, lmi->lmi_dt); return (rc); } diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 270de52..dc8d8d2 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -528,18 +528,25 @@ static int mgc_requeue_add(struct config_llog_data *cld, int later) /********************** class fns **********************/ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb, - struct vfsmount *mnt) + struct dt_device *dt) { struct lvfs_run_ctxt saved; struct lustre_sb_info *lsi = s2lsi(sb); struct client_obd *cli = &obd->u.cli; + struct vfsmount *mnt; struct dentry *dentry; char *label; int err = 0; ENTRY; LASSERT(lsi); - LASSERT(lsi->lsi_srv_mnt == mnt); + + cli->cl_mgc_dt_dev = NULL; + RETURN(0); + + /* XXX: retrieve mnt via osd here */ + mnt = NULL; + cli->cl_mgc_dt_dev = dt; /* The mgc fs exclusion sem. Only one fs can be setup at a time. */ down(&cli->cl_mgc_sem); @@ -558,9 +565,9 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb, fsfilt_setup(obd, mnt->mnt_sb); OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); - obd->obd_lvfs_ctxt.pwdmnt = mnt; + /*obd->obd_lvfs_ctxt.pwdmnt = mnt; obd->obd_lvfs_ctxt.pwd = mnt->mnt_root; - obd->obd_lvfs_ctxt.fs = get_ds(); + obd->obd_lvfs_ctxt.fs = get_ds();*/ push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); dentry = lookup_one_len(MOUNT_CONFIGS_DIR, current->fs->pwd, @@ -578,7 +585,9 @@ static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb, without calling mgc_fs_cleanup first. */ class_incref(obd, "mgc_fs", obd); - label = fsfilt_get_label(obd, mnt->mnt_sb); + /* XXX: retrieve real label here */ + //label = fsfilt_get_label(obd, mnt->mnt_sb); + label = "haha"; if (label) CDEBUG(D_MGC, "MGC using disk labelled=%s\n", label); @@ -599,7 +608,8 @@ static int mgc_fs_cleanup(struct obd_device *obd) int rc = 0; ENTRY; - LASSERT(cli->cl_mgc_vfsmnt != NULL); + if (cli->cl_mgc_vfsmnt == NULL) + RETURN(0); if (cli->cl_mgc_configs_dir != NULL) { struct lvfs_run_ctxt saved; @@ -1004,7 +1014,7 @@ int mgc_set_info_async(struct obd_export *exp, obd_count keylen, if (vallen != sizeof(struct super_block)) RETURN(-EINVAL); lsi = s2lsi(sb); - rc = mgc_fs_setup(exp->exp_obd, sb, lsi->lsi_srv_mnt); + rc = mgc_fs_setup(exp->exp_obd, sb, NULL); if (rc) { CERROR("set_fs got %d\n", rc); } @@ -1345,8 +1355,9 @@ int mgc_process_log(struct obd_device *mgc, /* Copy the setup log locally if we can. Don't mess around if we're running an MGS though (logs are already local). */ + /* XXX: disable local copy for a while -bzzz */ if (lctxt && lsi && (lsi->lsi_flags & LSI_SERVER) && - (lsi->lsi_srv_mnt == cli->cl_mgc_vfsmnt) && + (lsi->lsi_dt_dev == cli->cl_mgc_dt_dev) && !IS_MGS(lsi->lsi_ldd)) { push_ctxt(&saved, &mgc->obd_lvfs_ctxt, NULL); must_pop++; diff --git a/lustre/mgs/mgs_fs.c b/lustre/mgs/mgs_fs.c index 2812f84..61627e5 100644 --- a/lustre/mgs/mgs_fs.c +++ b/lustre/mgs/mgs_fs.c @@ -185,6 +185,7 @@ int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt) RETURN(rc); mgs->mgs_vfsmnt = mnt; + mntget(mnt); mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb; fsfilt_setup(obd, mgs->mgs_sb); @@ -224,6 +225,8 @@ int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt) } err_pop: + if (rc) + mntput(mnt); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); return rc; err_fid: @@ -257,5 +260,8 @@ int mgs_fs_cleanup(struct obd_device *obd) pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + if (mgs->mgs_vfsmnt) + mntput(mgs->mgs_vfsmnt); + return rc; } diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 97878c8..a1cfa49 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -195,6 +195,7 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg) struct mgs_obd *mgs = &obd->u.mgs; struct lustre_mount_info *lmi; struct lustre_sb_info *lsi; + struct dt_device_param dt_param; struct vfsmount *mnt; int rc = 0; ENTRY; @@ -206,7 +207,10 @@ static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg) if (!lmi) RETURN(rc = -EINVAL); - mnt = lmi->lmi_mnt; + lmi->lmi_dt->dd_ops->dt_conf_get(NULL, lmi->lmi_dt, &dt_param); + mnt = dt_param.ddp_mnt; + LASSERT(mnt); + lsi = s2lsi(lmi->lmi_sb); obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd)); if (IS_ERR(obd->obd_fsops)) @@ -290,7 +294,8 @@ err_ns: err_ops: fsfilt_put_ops(obd->obd_fsops); err_put: - server_put_mount(obd->obd_name, mnt); + //server_put_mount(obd->obd_name, mnt); + CERROR("put mount here\n"); mgs->mgs_sb = 0; return rc; } @@ -328,7 +333,8 @@ static int mgs_cleanup(struct obd_device *obd) lproc_mgs_cleanup(obd); mgs_fs_cleanup(obd); - server_put_mount(obd->obd_name, mgs->mgs_vfsmnt); + CERROR("real put mount here\n"); + //server_put_mount(obd->obd_name, mgs->mgs_vfsmnt); mgs->mgs_sb = NULL; ldlm_namespace_free(obd->obd_namespace, NULL, 1); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index fbd047a..f2cfa2b 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -59,6 +59,30 @@ static int (*client_fill_super)(struct super_block *sb) = NULL; static void (*kill_super_cb)(struct super_block *sb) = NULL; +struct mconf_device { + struct lu_device mcf_lu_dev; + struct lu_device *mcf_bottom; +}; + +struct mconf_object { + struct lu_object_header mco_header; + struct lu_object mco_obj; +}; + +static inline struct mconf_device *mconf_dev(struct lu_device *d) +{ + return container_of0(d, struct mconf_device, mcf_lu_dev); +} + +static struct mconf_object *mconf_obj(struct lu_object *o) +{ + return container_of0(o, struct mconf_object, mco_obj); +} + +static char *mconf_get_label(struct dt_device *dt); +static int mconf_set_label(struct dt_device *dt, char *label); + + /*********** mount lookup *********/ DECLARE_MUTEX(lustre_mount_info_lock); @@ -82,13 +106,13 @@ static struct lustre_mount_info *server_find_mount(const char *name) *_setup will call lustre_get_mount to get the mnt struct by obd_name, since we can't pass the pointer to setup. */ static int server_register_mount(const char *name, struct super_block *sb, - struct vfsmount *mnt) + struct dt_device *dt) { struct lustre_mount_info *lmi; char *name_cp; ENTRY; - LASSERT(mnt); + LASSERT(dt); LASSERT(sb); OBD_ALLOC(lmi, sizeof(*lmi)); @@ -112,13 +136,12 @@ static int server_register_mount(const char *name, struct super_block *sb, } lmi->lmi_name = name_cp; lmi->lmi_sb = sb; - lmi->lmi_mnt = mnt; + lmi->lmi_dt = dt; list_add(&lmi->lmi_list_chain, &server_mount_info_list); up(&lustre_mount_info_lock); - CDEBUG(D_MOUNT, "reg_mnt %p from %s, vfscount=%d\n", - lmi->lmi_mnt, name, atomic_read(&lmi->lmi_mnt->mnt_count)); + CDEBUG(D_MOUNT, "reg_dt %p from %s\n", lmi->lmi_dt, name); RETURN(0); } @@ -137,8 +160,7 @@ static int server_deregister_mount(const char *name) RETURN(-ENOENT); } - CDEBUG(D_MOUNT, "dereg_mnt %p from %s, vfscount=%d\n", - lmi->lmi_mnt, name, atomic_read(&lmi->lmi_mnt->mnt_count)); + CDEBUG(D_MOUNT, "dereg_dt %p from %s\n", lmi->lmi_dt, name); OBD_FREE(lmi->lmi_name, strlen(lmi->lmi_name) + 1); list_del(&lmi->lmi_list_chain); @@ -165,12 +187,11 @@ struct lustre_mount_info *server_get_mount(const char *name) RETURN(NULL); } lsi = s2lsi(lmi->lmi_sb); - mntget(lmi->lmi_mnt); + //mntget(lmi->lmi_mnt); atomic_inc(&lsi->lsi_mounts); - CDEBUG(D_MOUNT, "get_mnt %p from %s, refs=%d, vfscount=%d\n", - lmi->lmi_mnt, name, atomic_read(&lsi->lsi_mounts), - atomic_read(&lmi->lmi_mnt->mnt_count)); + CDEBUG(D_MOUNT, "get_dt %p from %s, refs=%d\n", + lmi->lmi_dt, name, atomic_read(&lsi->lsi_mounts)); RETURN(lmi); } @@ -208,8 +229,10 @@ static void unlock_mntput(struct vfsmount *mnt) static int lustre_put_lsi(struct super_block *sb); /* to be called from obd_cleanup methods */ -int server_put_mount(const char *name, struct vfsmount *mnt) +//int server_put_mount(const char *name, struct vfsmount *mnt) +int server_put_mount(const char *name, struct dt_device *dt) { +#if 0 struct lustre_mount_info *lmi; struct lustre_sb_info *lsi; int count = atomic_read(&mnt->mnt_count) - 1; @@ -241,12 +264,12 @@ int server_put_mount(const char *name, struct vfsmount *mnt) /* this obd should never need the mount again */ server_deregister_mount(name); - +#endif RETURN(0); } /* Corresponding to server_get_mount_2 */ -int server_put_mount_2(const char *name, struct vfsmount *mnt) +int server_put_mount_2(const char *name, struct dt_device *dt) { ENTRY; RETURN(0); @@ -271,106 +294,46 @@ static void ldd_print(struct lustre_disk_data *ldd) } #endif -static int ldd_parse(struct lvfs_run_ctxt *mount_ctxt, - struct lustre_disk_data *ldd) +static int ldd_write(struct dt_device *dt, struct lustre_disk_data *ldd) { - struct lvfs_run_ctxt saved; - struct file *file; - loff_t off = 0; - unsigned long len; - int rc; - ENTRY; - - push_ctxt(&saved, mount_ctxt, NULL); - - file = filp_open(MOUNT_DATA_FILE, O_RDONLY, 0644); - if (IS_ERR(file)) { - rc = PTR_ERR(file); - CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc); - GOTO(out, rc); - } - - len = i_size_read(file->f_dentry->d_inode); - CDEBUG(D_MOUNT, "Have %s, size %lu\n", MOUNT_DATA_FILE, len); - if (len != sizeof(*ldd)) { - CERROR("disk data size does not match: see %lu expect "LPSZ"\n", - len, sizeof(*ldd)); - GOTO(out_close, rc = -EINVAL); - } - - rc = lustre_fread(file, ldd, len, &off); - if (rc != len) { - CERROR("error reading %s: read %d of %lu\n", - MOUNT_DATA_FILE, rc, len); - GOTO(out_close, rc = -EINVAL); - } - rc = 0; - - if (ldd->ldd_magic != LDD_MAGIC) { - /* FIXME add swabbing support */ - CERROR("Bad magic in %s: %x!=%x\n", MOUNT_DATA_FILE, - ldd->ldd_magic, LDD_MAGIC); - GOTO(out_close, rc = -EINVAL); - } + struct lu_env env; + int rc; + struct dt_object *file; + struct lu_fid fid; + struct lu_buf buf; + loff_t pos; + struct thandle *th; - if (ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP) { - CERROR("%s: unsupported incompat filesystem feature(s) %x\n", - ldd->ldd_svname, - ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP); - GOTO(out_close, rc = -EINVAL); + if (dt->dd_lu_dev.ld_site == NULL) { + /* no configuration file */ + return 0; } - if (ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP) { - CERROR("%s: unsupported read-only filesystem feature(s) %x\n", - ldd->ldd_svname, - ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP); - /* Do something like remount filesystem read-only */ - GOTO(out_close, rc = -EINVAL); - } - -out_close: - filp_close(file, 0); -out: - pop_ctxt(&saved, mount_ctxt, NULL); - RETURN(rc); -} - -static int ldd_write(struct lvfs_run_ctxt *mount_ctxt, - struct lustre_disk_data *ldd) -{ - struct lvfs_run_ctxt saved; - struct file *file; - loff_t off = 0; - unsigned long len = sizeof(struct lustre_disk_data); - int rc = 0; - ENTRY; - LASSERT(ldd->ldd_magic == LDD_MAGIC); + rc = lu_env_init(&env, dt->dd_lu_dev.ld_type->ldt_ctx_tags); + LASSERT(rc == 0); - ldd->ldd_config_ver++; + file = dt_store_open(&env, dt, MOUNT_CONFIGS_DIR, CONFIGS_FILE, &fid); + LASSERT(!IS_ERR(file)); - push_ctxt(&saved, mount_ctxt, NULL); + buf.lb_buf = ldd; + buf.lb_len = sizeof(*ldd); + pos = 0; - file = filp_open(MOUNT_DATA_FILE, O_RDWR, 0644); - if (IS_ERR(file)) { - rc = PTR_ERR(file); - CERROR("cannot open %s: rc = %d\n", MOUNT_DATA_FILE, rc); - GOTO(out, rc); - } + th = dt->dd_ops->dt_trans_create(&env, dt); + LASSERT(!IS_ERR(th)); + rc = file->do_body_ops->dbo_declare_write(&env, file, buf.lb_len, pos, + th, BYPASS_CAPA); + LASSERT(rc == 0); + rc = dt->dd_ops->dt_trans_start(&env, dt, th); + LASSERT(rc == 0); - rc = lustre_fwrite(file, ldd, len, &off); - if (rc != len) { - CERROR("error writing %s: read %d of %lu\n", - MOUNT_DATA_FILE, rc, len); - GOTO(out_close, rc = -EINVAL); - } + rc = file->do_body_ops->dbo_write(&env, file, &buf, &pos, th, 1); - rc = 0; + dt->dd_ops->dt_trans_stop(&env, th); -out_close: - filp_close(file, 0); -out: - pop_ctxt(&saved, mount_ctxt, NULL); - RETURN(rc); + lu_object_put(&env, &file->do_lu); + lu_env_fini(&env); + RETURN(0); } @@ -500,11 +463,10 @@ static int lustre_start_simple(char *obdname, char *type, char *uuid, static int server_start_mgs(struct super_block *sb) { struct lustre_sb_info *lsi = s2lsi(sb); - struct vfsmount *mnt = lsi->lsi_srv_mnt; struct lustre_mount_info *lmi; int rc = 0; ENTRY; - LASSERT(mnt); + LASSERT(lsi->lsi_dt_dev); /* It is impossible to have more than 1 MGS per node, since MGC wouldn't know which to connect to */ @@ -519,7 +481,7 @@ static int server_start_mgs(struct super_block *sb) CDEBUG(D_CONFIG, "Start MGS service %s\n", LUSTRE_MGS_OBDNAME); - rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb, mnt); + rc = server_register_mount(LUSTRE_MGS_OBDNAME, sb, lsi->lsi_dt_dev); if (!rc) { rc = lustre_start_simple(LUSTRE_MGS_OBDNAME, LUSTRE_MGS_NAME, @@ -589,6 +551,9 @@ static int lustre_start_mgc(struct super_block *sb) if ((class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0) && (class_parse_nid(ptr, &nid, &ptr) == 0)) { i++; + } else if (lsi->lsi_lmd->lmd_mgs && + (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, NULL) == 0)) { + i++; } else if (IS_MGS(lsi->lsi_ldd)) { lnet_process_id_t id; while ((rc = LNetGetId(i++, &id)) != -ENOENT) { @@ -945,6 +910,49 @@ int server_mti_print(char *title, struct mgs_target_info *mti) return(0); } +static int server_label2mti(struct super_block *sb, struct mgs_target_info *mti) +{ + struct dt_device_param dt_param; + struct lustre_sb_info *lsi = s2lsi(sb); + unsigned newsv_flags; + char *label; + + LASSERT(lsi); + LASSERT(lsi->lsi_dt_dev); + + /* first, retrieve label */ + label = mconf_get_label(lsi->lsi_dt_dev); + + lsi->lsi_dt_dev->dd_ops->dt_conf_get(NULL, lsi->lsi_dt_dev, &dt_param); + lsi->lsi_ldd->ldd_mount_type = dt_param.ddp_mount_type; + + /* parse label: NEW:OST */ + newsv_flags = LDD_F_VIRGIN | LDD_F_UPDATE | LDD_F_NEED_INDEX; + if (!strcmp(label, "NEW:OST")) { + mti->mti_flags |= newsv_flags | LDD_F_SV_TYPE_OST; + } else if (!strcmp(label, "NEW:MDS")) { + mti->mti_flags |= newsv_flags | LDD_F_SV_TYPE_MDT; + } else if (strstr(label, "OST")) { + /* registered before service */ + mti->mti_flags |= LDD_F_SV_TYPE_OST; + strcpy(mti->mti_svname, label); + strcpy(lsi->lsi_ldd->ldd_svname, label); + } else if (strstr(label, "MDT")) { + /* registered before service */ + mti->mti_flags |= LDD_F_SV_TYPE_MDT; + strcpy(mti->mti_svname, label); + strcpy(lsi->lsi_ldd->ldd_svname, label); + } else { + LBUG(); + } + + if (lsi->lsi_lmd->lmd_fsname) + strncpy(mti->mti_fsname, lsi->lsi_lmd->lmd_fsname, + sizeof(mti->mti_fsname)); + + return 0; +} + static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti) { struct lustre_sb_info *lsi = s2lsi(sb); @@ -956,11 +964,6 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti) if (!(lsi->lsi_flags & LSI_SERVER)) RETURN(-EINVAL); - strncpy(mti->mti_fsname, ldd->ldd_fsname, - sizeof(mti->mti_fsname)); - strncpy(mti->mti_svname, ldd->ldd_svname, - sizeof(mti->mti_svname)); - mti->mti_nid_count = 0; while (LNetGetId(i++, &id) != -ENOENT) { if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND) @@ -976,6 +979,17 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti) mti->mti_lustre_ver = LUSTRE_VERSION_CODE; mti->mti_config_ver = 0; + + if (ldd->ldd_magic == 0) { + /* no config, generate data for registration */ + return server_label2mti(sb, mti); + } + + strncpy(mti->mti_fsname, ldd->ldd_fsname, + sizeof(mti->mti_fsname)); + strncpy(mti->mti_svname, ldd->ldd_svname, + sizeof(mti->mti_svname)); + mti->mti_flags = ldd->ldd_flags; mti->mti_stripe_index = ldd->ldd_svindex; memcpy(mti->mti_uuid, ldd->ldd_uuid, sizeof(mti->mti_uuid)); @@ -987,6 +1001,35 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti) RETURN(0); } +static int mconf_set_label(struct dt_device *dt, char *label) +{ + struct lu_env env; + int rc; + + lu_env_init(&env, dt->dd_lu_dev.ld_type->ldt_ctx_tags); + rc = dt->dd_ops->dt_label_set(&env, dt, label); + lu_env_fini(&env); + return rc; +} + +static char *mconf_get_label(struct dt_device *dt) +{ + struct lu_env env; + char *label; + + lu_env_init(&env, dt->dd_lu_dev.ld_type->ldt_ctx_tags); + label = dt->dd_ops->dt_label_get(&env, dt); + lu_env_fini(&env); + + return label; +} + +static int mconf_sync_dev(struct dt_device *dt) +{ + return 0; +} + + /* Register an old or new target with the MGS. If needed MGS will construct startup logs and assign index */ int server_register_target(struct super_block *sb) @@ -1038,17 +1081,16 @@ int server_register_target(struct super_block *sb) strncpy(ldd->ldd_svname, mti->mti_svname, sizeof(ldd->ldd_svname)); /* or ldd_make_sv_name(ldd); */ - ldd_write(&mgc->obd_lvfs_ctxt, ldd); - err = fsfilt_set_label(mgc, lsi->lsi_srv_mnt->mnt_sb, - mti->mti_svname); + ldd_write(lsi->lsi_dt_dev, ldd); + err = mconf_set_label(lsi->lsi_dt_dev, mti->mti_svname); if (err) CERROR("Label set error %d\n", err); - label = fsfilt_get_label(mgc, lsi->lsi_srv_mnt->mnt_sb); + label = mconf_get_label(lsi->lsi_dt_dev); if (label) CDEBUG(D_MOUNT, "Disk label changed to %s\n", label); /* Flush the new ldd to disk */ - fsfilt_sync(mgc, lsi->lsi_srv_mnt->mnt_sb); + mconf_sync_dev(lsi->lsi_dt_dev); } out: @@ -1057,8 +1099,35 @@ out: RETURN(rc); } +static void stop_temp_site(struct super_block *sb) +{ + struct lustre_sb_info *lsi = s2lsi(sb); + struct lu_env env; + struct mconf_device *mdev; + int rc; + struct lu_site *site; + + LASSERT(lsi); + LASSERT(lsi->lsi_dt_dev); + + site = lsi->lsi_dt_dev->dd_lu_dev.ld_site; + if (site == NULL) + return; + + mdev = mconf_dev(site->ls_top_dev); + LASSERT(mdev); + + rc = lu_env_init(&env, mdev->mcf_lu_dev.ld_type->ldt_ctx_tags); + LASSERT(rc == 0); + lu_site_purge(&env, site, ~0); + lu_site_fini(site); + lu_env_fini(&env); + + lsi->lsi_dt_dev->dd_lu_dev.ld_site = NULL; +} + /* Start targets */ -static int server_start_targets(struct super_block *sb, struct vfsmount *mnt) +static int server_start_targets(struct super_block *sb, struct dt_device *dt) { struct obd_device *obd; struct lustre_sb_info *lsi = s2lsi(sb); @@ -1117,6 +1186,10 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt) /* Register with MGS */ rc = server_register_target(sb); + + /* destroy temporary site */ + stop_temp_site(sb); + if (rc && (lsi->lsi_ldd->ldd_flags & (LDD_F_NEED_INDEX | LDD_F_UPDATE | LDD_F_UPGRADE14))){ CERROR("Required registration failed for %s: %d\n", @@ -1139,8 +1212,8 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt) CDEBUG(D_MOUNT, "Cannot register with MGS: %d\n", rc); /* Let the target look up the mount using the target's name - (we can't pass the sb or mnt through class_process_config.) */ - rc = server_register_mount(lsi->lsi_ldd->ldd_svname, sb, mnt); + (we can't pass the sb or dt through class_process_config.) */ + rc = server_register_mount(lsi->lsi_ldd->ldd_svname, sb, dt); if (rc) GOTO(out_mgc, rc); @@ -1268,23 +1341,269 @@ static int lustre_put_lsi(struct super_block *sb) /*************** server mount ******************/ +static int mconf_object_init(const struct lu_env *env, struct lu_object *o, + const struct lu_object_conf *_) +{ + struct mconf_device *d = mconf_dev(o->lo_dev); + struct lu_device *under; + struct lu_object *below; + int rc = 0; + ENTRY; + + under = d->mcf_bottom; + below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under); + if (below != NULL) { + lu_object_add(o, below); + } else + rc = -ENOMEM; + + RETURN(rc); +} + +static void mconf_object_free(const struct lu_env *env, struct lu_object *o) +{ + struct mconf_object *mo = mconf_obj(o); + struct lu_object_header *h; + ENTRY; + + h = o->lo_header; + CDEBUG(D_INFO, "object free, fid = "DFID"\n", + PFID(lu_object_fid(o))); + + lu_object_fini(o); + lu_object_header_fini(h); + OBD_FREE_PTR(mo); + EXIT; +} + + +static const struct lu_object_operations mconf_obj_ops = { + .loo_object_init = mconf_object_init, + .loo_object_free = mconf_object_free +}; + +static struct lu_object * +mconf_object_alloc(const struct lu_env *env, + const struct lu_object_header *hdr, + struct lu_device *d) +{ + struct mconf_object *mo; + + ENTRY; + + OBD_ALLOC_PTR(mo); + if (mo != NULL) { + struct lu_object *o; + struct lu_object_header *h; + + o = &mo->mco_obj; + h = &mo->mco_header; + lu_object_header_init(h); + lu_object_init(o, h, d); + lu_object_add_top(h, o); + o->lo_ops = &mconf_obj_ops; + RETURN(o); + } else + RETURN(NULL); +} + +static const struct lu_device_operations mconf_lu_ops = { + .ldo_object_alloc = mconf_object_alloc, +}; + +static struct lu_device_type_operations mconf_device_type_ops = { +}; + +static struct lu_device_type mconf_device_type = { + .ldt_tags = LU_DEVICE_MC, + .ldt_name = LUSTRE_MCF_NAME, + .ldt_ops = &mconf_device_type_ops, + .ldt_ctx_tags = LCT_DT_THREAD +}; + + +static struct lu_device *try_start_osd(struct lustre_mount_data *lmd, + char *typename, + unsigned long s_flags) +{ + struct obd_type *type; + struct lu_device_type *ldt; + struct lu_device *d = NULL; + struct dt_device *dt; + struct lu_env env; + int rc; + struct lustre_cfg *lcfg; + struct lustre_cfg_bufs bufs; + + + /* find the type */ + type = class_get_type(typename); + if (!type) { + CERROR("Unknown type: '%s'\n", typename); + GOTO(out, rc = -ENODEV); + } + + ldt = type->typ_lu; + if (ldt == NULL) { + CERROR("type: '%s'\n", typename); + GOTO(out_type, rc = -EINVAL); + } + + rc = lu_env_init(&env, ldt->ldt_ctx_tags); + LASSERT(rc == 0); + + ldt->ldt_obd_type = type; + d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, NULL); + if (IS_ERR(d)) { + CERROR("Cannot allocate device: '%s'\n", typename); + GOTO(out_type, rc = -ENODEV); + } + + type->typ_refcnt++; + rc = ldt->ldt_ops->ldto_device_init(&env, d, NULL, NULL); + if (rc) { + CERROR("can't init device '%s', rc %d\n", typename, rc); + GOTO(out_alloc, rc); + } + + /* ask osd to mount underlying disk filesystem */ + lustre_cfg_bufs_reset(&bufs, lmd->lmd_dev); + lustre_cfg_bufs_set(&bufs, 1, &s_flags, sizeof(s_flags)); + lcfg = lustre_cfg_new(LCFG_SETUP, &bufs); + dt = lu2dt_dev(d); + rc = dt->dd_lu_dev.ld_ops->ldo_process_config(&env, d, lcfg); + lustre_cfg_free(lcfg); + + lu_device_get(d); + lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init); +out_type: +out_alloc: +out: + lu_env_fini(&env); + RETURN(d); +} + +static struct lu_device *start_osd(struct lustre_mount_data *lmd, + unsigned long s_flags) +{ + struct lu_device *d; + ENTRY; + + d = try_start_osd(lmd, LUSTRE_OSD_NAME, s_flags); + if (IS_ERR(d)) + d = try_start_osd(lmd, LUSTRE_DMU_NAME, s_flags); + RETURN(d); +} + +static int ldd_parse(struct mconf_device *mdev, struct lustre_disk_data *ldd) +{ + struct dt_device *dev = lu2dt_dev(mdev->mcf_bottom); + struct lu_env env; + int rc; + struct dt_object *file; + struct lu_fid fid; + struct lu_buf buf; + loff_t pos; + + rc = lu_env_init(&env, mdev->mcf_lu_dev.ld_type->ldt_ctx_tags); + LASSERT(rc == 0); + + file = dt_store_open(&env, dev, MOUNT_CONFIGS_DIR, CONFIGS_FILE, &fid); + if (IS_ERR(file)) + GOTO(out, rc = PTR_ERR(file)); + + buf.lb_buf = ldd; + buf.lb_len = sizeof(*ldd); + pos = 0; + rc = file->do_body_ops->dbo_read(&env, file, &buf, &pos, BYPASS_CAPA); + if (rc == buf.lb_len) { + if (ldd->ldd_magic != LDD_MAGIC) { + /* FIXME add swabbing support */ + CERROR("Bad magic in %s: %x!=%x\n", MOUNT_DATA_FILE, + ldd->ldd_magic, LDD_MAGIC); + GOTO(out, rc = -EINVAL); + } + + if (ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP) { + CERROR("%s: unsupported incompat filesystem feature(s) %x\n", + ldd->ldd_svname, + ldd->ldd_feature_incompat & ~LDD_INCOMPAT_SUPP); + GOTO(out, rc = -EINVAL); + } + if (ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP) { + CERROR("%s: unsupported read-only filesystem feature(s) %x\n", + ldd->ldd_svname, + ldd->ldd_feature_rocompat & ~LDD_ROCOMPAT_SUPP); + /* Do something like remount filesystem read-only */ + GOTO(out, rc = -EINVAL); + } + rc = 0; + } else if (rc >= 0) + rc = -EIO; + lu_object_put(&env, &file->do_lu); +out: + lu_env_fini(&env); + RETURN(rc); +} + + /* Kernel mount using mount options in MOUNT_DATA_FILE */ -static struct vfsmount *server_kernel_mount(struct super_block *sb) +static struct dt_device *server_kernel_mount(struct super_block *sb) { struct lvfs_run_ctxt mount_ctxt; struct lustre_sb_info *lsi = s2lsi(sb); struct lustre_disk_data *ldd; struct lustre_mount_data *lmd = lsi->lsi_lmd; + struct lu_device *dev; + struct mconf_device *mdev; struct vfsmount *mnt; char *options = NULL; unsigned long page, s_flags; struct page *__page; + struct lu_site *site; int rc; + ENTRY; OBD_ALLOC(ldd, sizeof(*ldd)); if (!ldd) RETURN(ERR_PTR(-ENOMEM)); + lsi->lsi_ldd = ldd; + + /* start OSD on given device */ + dev = start_osd(lmd, sb->s_flags); + LASSERT(!IS_ERR(dev)); + + lsi->lsi_dt_dev = lu2dt_dev(dev); + + /* create temporary site to access ldd */ + OBD_ALLOC_PTR(site); + LASSERT(site); + + /* create temporary top-device to access ldd */ + OBD_ALLOC_PTR(mdev); + LASSERT(mdev != NULL); + lu_device_init(&mdev->mcf_lu_dev, &mconf_device_type); + mdev->mcf_lu_dev.ld_ops = &mconf_lu_ops; + mdev->mcf_bottom = dev; + + rc = lu_site_init(site, &mdev->mcf_lu_dev); + LASSERT(rc == 0); + dev->ld_site = site; + rc = lu_site_init_finish(site); + LASSERT(rc == 0); + + rc = ldd_parse(mdev, ldd); + if (rc == -ENOENT) { + /* no configuration found, use disk label */ + stop_temp_site(sb); + } else + LASSERT(rc == 0); + + RETURN(lu2dt_dev(mdev->mcf_bottom)); + + + /* In the past, we have always used flags = 0. Note ext3/ldiskfs can't be mounted ro. */ @@ -1320,7 +1639,7 @@ static struct vfsmount *server_kernel_mount(struct super_block *sb) mount_ctxt.pwd = mnt->mnt_root; mount_ctxt.fs = get_ds(); - rc = ldd_parse(&mount_ctxt, ldd); + //rc = ldd_parse(&mount_ctxt, ldd); unlock_mntput(mnt); if (rc) { @@ -1363,7 +1682,7 @@ static struct vfsmount *server_kernel_mount(struct super_block *sb) OBD_PAGE_FREE(__page); lsi->lsi_ldd = ldd; /* freed at lsi cleanup */ CDEBUG(D_SUPER, "%s: mnt = %p\n", lmd->lmd_dev, mnt); - RETURN(mnt); + RETURN(NULL); out_free: if (__page) @@ -1379,6 +1698,7 @@ static void server_wait_finished(struct vfsmount *mnt) struct l_wait_info lwi; int retries = 330; + return; init_waitqueue_head(&waitq); while ((atomic_read(&mnt->mnt_count) > 1) && (retries > 0)) { @@ -1401,7 +1721,8 @@ static void server_put_super(struct super_block *sb) { struct lustre_sb_info *lsi = s2lsi(sb); struct obd_device *obd; - struct vfsmount *mnt = lsi->lsi_srv_mnt; + //struct vfsmount *mnt = lsi->lsi_srv_mnt; + struct vfsmount *mnt = NULL; /* XXX: */ char *tmpname, *extraname = NULL; int tmpname_sz; int lddflags = lsi->lsi_ldd->ldd_flags; @@ -1521,7 +1842,8 @@ static int server_statfs (struct dentry *dentry, struct kstatfs *buf) { struct super_block *sb = dentry->d_sb; #endif - struct vfsmount *mnt = s2lsi(sb)->lsi_srv_mnt; + //struct vfsmount *mnt = s2lsi(sb)->lsi_srv_mnt; + struct vfsmount *mnt = NULL; ENTRY; if (mnt && mnt->mnt_sb && mnt->mnt_sb->s_op->statfs) { @@ -1596,20 +1918,19 @@ static int server_fill_super_common(struct super_block *sb) static int server_fill_super(struct super_block *sb) { struct lustre_sb_info *lsi = s2lsi(sb); - struct vfsmount *mnt; + struct dt_device *dt; int rc; ENTRY; /* the One True Mount */ - mnt = server_kernel_mount(sb); - if (IS_ERR(mnt)) { - rc = PTR_ERR(mnt); + dt = server_kernel_mount(sb); + if (IS_ERR(dt)) { + rc = PTR_ERR(dt); CERROR("Unable to mount device %s: %d\n", lsi->lsi_lmd->lmd_dev, rc); lustre_put_lsi(sb); RETURN(rc); } - lsi->lsi_srv_mnt = mnt; LASSERT(lsi->lsi_ldd); CDEBUG(D_MOUNT, "Found service %s for fs '%s' on device %s\n", @@ -1622,7 +1943,8 @@ static int server_fill_super(struct super_block *sb) " the disk journal.\n", lsi->lsi_ldd->ldd_svname); lustre_put_lsi(sb); - unlock_mntput(mnt); + /* XXX: cleanup osd */ + LBUG(); RETURN(-EALREADY); } @@ -1638,9 +1960,16 @@ static int server_fill_super(struct super_block *sb) GOTO(out_mnt, rc); /* Set up all obd devices for service */ - if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) && + if (lsi->lsi_ldd->ldd_magic == 0) { + /* no configuration found, try to register on MGS and get conf */ + rc = server_start_targets(sb, dt); + if (rc < 0) { + CERROR("Unable to start targets: %d\n", rc); + GOTO(out_mnt, rc); + } + } else if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOSVC) && (IS_OST(lsi->lsi_ldd) || IS_MDT(lsi->lsi_ldd))) { - rc = server_start_targets(sb, mnt); + rc = server_start_targets(sb, dt); if (rc < 0) { CERROR("Unable to start targets: %d\n", rc); GOTO(out_mnt, rc); @@ -1859,6 +2188,56 @@ static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr) return 0; } +static int lmd_parse_mgs(struct lustre_mount_data *lmd, char *ptr) +{ + char *tail; + int length; + + if (lmd->lmd_mgs != NULL) { + OBD_FREE(lmd->lmd_mgs, strlen(lmd->lmd_mgs) + 1); + lmd->lmd_mgs = NULL; + } + + tail = strchr(ptr, ','); + if (tail == NULL) + length = strlen(ptr); + else + length = tail - ptr; + + OBD_ALLOC(lmd->lmd_mgs, length + 1); + if (lmd->lmd_mgs == NULL) + return -ENOMEM; + + memcpy(lmd->lmd_mgs, ptr, length); + lmd->lmd_mgs[length] = '\0'; + return 0; +} + +static int lmd_parse_fsname(struct lustre_mount_data *lmd, char *ptr) +{ + char *tail; + int length; + + if (lmd->lmd_fsname != NULL) { + OBD_FREE(lmd->lmd_fsname, strlen(lmd->lmd_fsname) + 1); + lmd->lmd_fsname = NULL; + } + + tail = strchr(ptr, ','); + if (tail == NULL) + length = strlen(ptr); + else + length = tail - ptr; + + OBD_ALLOC(lmd->lmd_fsname, length + 1); + if (lmd->lmd_fsname == NULL) + return -ENOMEM; + + memcpy(lmd->lmd_fsname, ptr, length); + lmd->lmd_fsname[length] = '\0'; + return 0; +} + /* mount -v -t lustre uml1:uml2:/lustre-client /mnt/lustre */ static int lmd_parse(char *options, struct lustre_mount_data *lmd) { @@ -1917,6 +2296,16 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd) if (rc) goto invalid; clear++; + } else if (strncmp(s1, "mgs=", 4) == 0) { + rc = lmd_parse_mgs(lmd, s1 + 4); + if (rc) + goto invalid; + clear++; + } else if (strncmp(s1, "fsname=", 7) == 0) { + rc = lmd_parse_fsname(lmd, s1 + 7); + if (rc) + goto invalid; + clear++; } /* Linux 2.4 doesn't pass the device, so we stuck it at the end of the options. */ diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index 970e4fb..27948e2 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -379,6 +379,7 @@ struct lu_object_operations filter_obj_ops = { .loo_object_print = filter_object_print }; +#if 0 static struct lu_device *filter_layer_setup(const struct lu_env *env, const char *typename, struct lu_device *child, @@ -446,9 +447,11 @@ out_type: out: return ERR_PTR(rc); } +#endif int filter_stack_init(const struct lu_env *env, - struct filter_device *m, struct lustre_cfg *cfg) + struct filter_device *m, struct lustre_cfg *cfg, + struct lustre_mount_info *lmi) { struct lu_device *d = &m->ofd_dt_dev.dd_lu_dev; struct lu_device *tmp; @@ -456,10 +459,10 @@ int filter_stack_init(const struct lu_env *env, ENTRY; /* init the stack */ - tmp = filter_layer_setup(env, LUSTRE_OSD_NAME, d, cfg); - if (IS_ERR(tmp)) { - RETURN(PTR_ERR(tmp)); - } + tmp = &lmi->lmi_dt->dd_lu_dev; + LASSERT(tmp); + tmp->ld_site = d->ld_site; + m->ofd_osd = lu2dt_dev(tmp); /* process setup config */ @@ -573,7 +576,7 @@ static int filter_init0(const struct lu_env *env, struct filter_device *m, struct lu_device_type *ldt, struct lustre_cfg *cfg) { const char *dev = lustre_cfg_string(cfg, 0); - struct filter_thread_info *info; + struct filter_thread_info *info = NULL; struct filter_obd *filter; struct lustre_mount_info *lmi; struct obd_device *obd; @@ -660,7 +663,7 @@ static int filter_init0(const struct lu_env *env, struct filter_device *m, } /* init the stack */ - rc = filter_stack_init(env, m, cfg); + rc = filter_stack_init(env, m, cfg, lmi); if (rc) { CERROR("Can't init device stack, rc %d\n", rc); GOTO(err_fini_proc, rc); diff --git a/lustre/ofd/ofd_fs.c b/lustre/ofd/ofd_fs.c index 8a2da7d..7547363 100644 --- a/lustre/ofd/ofd_fs.c +++ b/lustre/ofd/ofd_fs.c @@ -48,9 +48,6 @@ void filter_last_id_set(struct filter_device *ofd, obd_id id, obd_gr group) spin_lock(&ofd->ofd_objid_lock); if (ofd->ofd_last_objids[group] < id) ofd->ofd_last_objids[group] = id; - else - CWARN("Group ID "LPU64" is greater then new one "LPU64"!\n", - ofd->ofd_last_objids[group], id); spin_unlock(&ofd->ofd_objid_lock); } diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index 7d6ee8c..704e89e 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -299,9 +299,11 @@ struct filter_thread_info * filter_info_init(const struct lu_env *env, info = lu_context_key_get(&env->le_ctx, &filter_thread_key); LASSERT(info); +#if 0 LASSERT(info->fti_exp == 0); LASSERT(info->fti_env == 0); LASSERT(info->fti_attr.la_valid == 0); +#endif info->fti_env = env; info->fti_exp = exp; diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index 8ce15bb..a8edf8f 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -191,7 +191,6 @@ static int filter_obd_connect(const struct lu_env *env, struct obd_export **_exp { struct lsd_client_data *lcd = NULL; struct filter_export_data *fed; - struct filter_thread_info *info; struct obd_export *exp; struct filter_device *ofd; struct lustre_handle conn = { 0 }; @@ -216,7 +215,7 @@ static int filter_obd_connect(const struct lu_env *env, struct obd_export **_exp CERROR("Failure to refill session: '%d'\n", rc); GOTO(out, rc); } - info = filter_info_init(env, exp); + filter_info_init(env, exp); rc = filter_parse_connect_data(env, exp, data); if (rc) diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index 0fb479e..d737425 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -164,9 +164,9 @@ int filter_object_punch(const struct lu_env *env, struct filter_object *fo, filter_fmd_put(info->fti_exp, fmd); la_from_obdo(&attr, oa, OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME); - CERROR("attr=%llu\n", oa->o_valid); attr.la_size = start; attr.la_valid |= LA_SIZE; + attr.la_valid &= ~LA_TYPE; th = filter_trans_create(env, ofd); if (IS_ERR(th)) diff --git a/lustre/osd/osd_handler.c b/lustre/osd/osd_handler.c index 935e218..ccff18f 100644 --- a/lustre/osd/osd_handler.c +++ b/lustre/osd/osd_handler.c @@ -275,7 +275,7 @@ osd_pop_ctxt(struct osd_ctxt *save) static struct super_block *osd_sb(const struct osd_device *dev) { - return dev->od_mount->lmi_mnt->mnt_sb; + return dev->od_mnt->mnt_sb; } static journal_t *osd_journal(const struct osd_device *dev) @@ -616,6 +616,9 @@ static void osd_conf_get(const struct lu_env *env, param->ddp_max_name_len = LDISKFS_NAME_LEN; param->ddp_max_nlink = LDISKFS_LINK_MAX; param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits; + /* XXX: remove when new llog/mountconf over osd are ready -bzzz */ + param->ddp_mnt = osd_dt_dev(dev)->od_mnt; + param->ddp_mount_type = LDD_MT_LDISKFS; } /** @@ -918,7 +921,7 @@ static void osd_init_quota_ctxt(const struct lu_env *env, struct dt_device *d, struct dt_quota_ctxt *ctxt, void *data) { struct obd_device *obd = (void *)ctxt; - struct vfsmount *mnt = (struct vfsmount *)data; + struct vfsmount *mnt = osd_dt_dev(d)->od_mnt; ENTRY; obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb; @@ -3595,12 +3598,15 @@ static int osd_device_init(const struct lu_env *env, struct lu_device *d, { int rc; struct lu_context *ctx; + struct osd_device *osd = osd_dev(d); /* context for commit hooks */ - ctx = &osd_dev(d)->od_env_for_commit.le_ctx; + ctx = &osd->od_env_for_commit.le_ctx; rc = lu_context_init(ctx, LCT_MD_THREAD|LCT_DT_THREAD|LCT_REMEMBER|LCT_NOREF); if (rc == 0) { - rc = osd_procfs_init(osd_dev(d), name); + /* XXX: somehow pass device name here */ + if (name) + rc = osd_procfs_init(osd_dev(d), name); ctx->lc_cookie = 0x3; } return rc; @@ -3627,41 +3633,47 @@ static int osd_shutdown(const struct lu_env *env, struct osd_device *o) static int osd_mount(const struct lu_env *env, struct osd_device *o, struct lustre_cfg *cfg) { - struct lustre_mount_info *lmi; - const char *dev = lustre_cfg_string(cfg, 0); - struct lustre_disk_data *ldd; - struct lustre_sb_info *lsi; + const char *dev = lustre_cfg_string(cfg, 0); + const char *opts; + unsigned long page, s_flags, ldd_flags; + struct page *__page; + char *options = NULL; ENTRY; - if (o->od_mount != NULL) { - CERROR("Already mounted (%s)\n", dev); - RETURN(-EEXIST); - } + if (o->od_mnt != NULL) + RETURN(0); + + OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD); + if (__page == NULL) + RETURN(-ENOMEM); - /* get mount */ - lmi = server_get_mount(dev); - if (lmi == NULL) { - CERROR("Cannot get mount info for %s!\n", dev); - RETURN(-EFAULT); - } + s_flags = (unsigned long) lustre_cfg_buf(cfg, 1); + opts = lustre_cfg_string(cfg, 2); + ldd_flags = (unsigned long) lustre_cfg_buf(cfg, 3); - LASSERT(lmi != NULL); - /* save lustre_mount_info in dt_device */ - o->od_mount = lmi; + page = (unsigned long)cfs_page_address(__page); + options = (char *)page; + memset(options, 0, CFS_PAGE_SIZE); + if (opts == NULL) + strcat(options, "user_xattr,acl,iopen_nopriv"); + else + strcat(options, opts); - lsi = s2lsi(lmi->lmi_sb); - ldd = lsi->lsi_ldd; + o->od_mnt = ll_kern_mount("ldiskfs", s_flags, dev, (void *)options); + /* XXX: error handling */ + LASSERTF(!IS_ERR(o->od_mnt), "%ld\n", PTR_ERR(o->od_mnt)); - o->od_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd)); + o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS)); LASSERT(o->od_fsops); - if (ldd->ldd_flags & LDD_F_IAM_DIR) { + if (ldd_flags & LDD_F_IAM_DIR) { o->od_iop_mode = 0; LCONSOLE_WARN("OSD: IAM mode enabled\n"); } else o->od_iop_mode = 1; + OBD_PAGE_FREE(__page); o->od_obj_area = NULL; RETURN(0); @@ -3682,10 +3694,17 @@ static struct lu_device *osd_device_fini(const struct lu_env *env, RETURN (ERR_PTR(rc)); } + if (osd_dev(d)->od_mnt) { + mntput(osd_dev(d)->od_mnt); + osd_dev(d)->od_mnt = NULL; + } + +#if 0 if (osd_dev(d)->od_mount) server_put_mount(osd_dev(d)->od_mount->lmi_name, osd_dev(d)->od_mount->lmi_mnt); osd_dev(d)->od_mount = NULL; +#endif lu_context_fini(&osd_dev(d)->od_env_for_commit.le_ctx); RETURN(NULL); @@ -3714,6 +3733,7 @@ static struct lu_device *osd_device_alloc(const struct lu_env *env, dt_device_fini(&o->od_dt_dev); l = ERR_PTR(-ENOMEM); } + o->od_iop_mode = 1; } else l = ERR_PTR(result); @@ -3775,9 +3795,6 @@ static int osd_prepare(const struct lu_env *env, struct lu_device *dev) { struct osd_device *osd = osd_dev(dev); - struct lustre_sb_info *lsi; - struct lustre_disk_data *ldd; - struct lustre_mount_info *lmi; struct osd_thread_info *oti = osd_oti_get(env); struct dt_object *d; int result; @@ -3788,10 +3805,6 @@ static int osd_prepare(const struct lu_env *env, if (result != 0) RETURN(result); - lmi = osd->od_mount; - lsi = s2lsi(lmi->lmi_sb); - ldd = lsi->lsi_ldd; - if (lu_device_is_md(pdev)) { /* 2. setup local objects */ result = llo_local_objects_setup(env, lu2md_dev(pdev), diff --git a/lustre/osd/osd_internal.h b/lustre/osd/osd_internal.h index 8056971e..55ff80e 100644 --- a/lustre/osd/osd_internal.h +++ b/lustre/osd/osd_internal.h @@ -179,7 +179,8 @@ struct osd_device { /* super-class */ struct dt_device od_dt_dev; /* information about underlying file system */ - struct lustre_mount_info *od_mount; + //struct lustre_mount_info *od_mount; + struct vfsmount *od_mnt; /* object index */ struct osd_oi od_oi; /* diff --git a/lustre/osd/osd_lproc.c b/lustre/osd/osd_lproc.c index ed7fd6c..1c87a25 100644 --- a/lustre/osd/osd_lproc.c +++ b/lustre/osd/osd_lproc.c @@ -221,11 +221,13 @@ static int lprocfs_osd_rd_mntdev(char *page, char **start, off_t off, int count, struct osd_device *osd = data; LASSERT(osd != NULL); - LASSERT(osd->od_mount->lmi_mnt->mnt_devname); + /* XXX */ + //LASSERT(osd->od_mount->lmi_mnt->mnt_devname); *eof = 1; - return snprintf(page, count, "%s\n", - osd->od_mount->lmi_mnt->mnt_devname); + /* XXX */ + return snprintf(page, count, "%s\n", "ohoho"); + //osd->od_mount->lmi_mnt->mnt_devname); } struct lprocfs_vars lprocfs_osd_obd_vars[] = { diff --git a/lustre/osd/osd_oi.c b/lustre/osd/osd_oi.c index 7759133..0310455 100644 --- a/lustre/osd/osd_oi.c +++ b/lustre/osd/osd_oi.c @@ -82,7 +82,7 @@ struct oi_descr { static struct super_block *osd_sb(const struct osd_device *dev) { - return dev->od_mount->lmi_mnt->mnt_sb; + return dev->od_mnt->mnt_sb; } static journal_t *osd_journal(const struct osd_device *dev) -- 1.8.3.1