X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdd%2Fmdd_device.c;h=80ff70eb4ad0fbf38cef336d9a0305a4c7256994;hb=76f0977b7ea5d46836cb459deb7b9ad9e781d585;hp=648fb1b278ed8789e37b0d7f3867219cfa82a49b;hpb=e53d1c18ea9f8c08d55d573e8f0993e582c44c20;p=fs%2Flustre-release.git diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 648fb1b..80ff70e 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -57,6 +57,7 @@ static struct lu_device_type mdd_device_type; static const char mdd_root_dir_name[] = "ROOT"; static const char mdd_obf_dir_name[] = "fid"; +static const char mdd_lpf_dir_name[] = "lost+found"; /* Slab for MDD object allocation */ struct kmem_cache *mdd_object_kmem; @@ -564,7 +565,8 @@ static int obf_lookup(const struct lu_env *env, struct md_object *p, GOTO(out, rc = -EINVAL); } - if (!fid_is_norm(f) && !fid_is_igif(f) && !fid_is_root(f)) { + if (!fid_is_norm(f) && !fid_is_igif(f) && !fid_is_root(f) && + !fid_seq_is_dot(f->f_seq)) { CWARN("%s: "DFID" is invalid, sequence should be " ">= "LPX64" or within ["LPX64","LPX64"].\n", mdd2obd_dev(mdd)->obd_name, PFID(f), @@ -589,42 +591,61 @@ out: return rc; } -static int obf_create(const struct lu_env *env, struct md_object *pobj, - const struct lu_name *lname, struct md_object *child, - struct md_op_spec *spec, struct md_attr* ma) +static int mdd_dummy_create(const struct lu_env *env, + struct md_object *pobj, + const struct lu_name *lname, + struct md_object *child, + struct md_op_spec *spec, + struct md_attr* ma) { - return -EPERM; + return -EPERM; } -static int obf_rename(const struct lu_env *env, - struct md_object *src_pobj, struct md_object *tgt_pobj, - const struct lu_fid *lf, const struct lu_name *lsname, - struct md_object *tobj, const struct lu_name *ltname, - struct md_attr *ma) +static int mdd_dummy_rename(const struct lu_env *env, + struct md_object *src_pobj, + struct md_object *tgt_pobj, + const struct lu_fid *lf, + const struct lu_name *lsname, + struct md_object *tobj, + const struct lu_name *ltname, + struct md_attr *ma) { - return -EPERM; + return -EPERM; } -static int obf_link(const struct lu_env *env, struct md_object *tgt_obj, - struct md_object *src_obj, const struct lu_name *lname, - struct md_attr *ma) +static int mdd_dummy_link(const struct lu_env *env, + struct md_object *tgt_obj, + struct md_object *src_obj, + const struct lu_name *lname, + struct md_attr *ma) { - return -EPERM; + return -EPERM; } -static int obf_unlink(const struct lu_env *env, struct md_object *pobj, - struct md_object *cobj, const struct lu_name *lname, - struct md_attr *ma, int no_name) +static int mdd_dummy_unlink(const struct lu_env *env, + struct md_object *pobj, + struct md_object *cobj, + const struct lu_name *lname, + struct md_attr *ma, + int no_name) { return -EPERM; } static struct md_dir_operations mdd_obf_dir_ops = { - .mdo_lookup = obf_lookup, - .mdo_create = obf_create, - .mdo_rename = obf_rename, - .mdo_link = obf_link, - .mdo_unlink = obf_unlink + .mdo_lookup = obf_lookup, + .mdo_create = mdd_dummy_create, + .mdo_rename = mdd_dummy_rename, + .mdo_link = mdd_dummy_link, + .mdo_unlink = mdd_dummy_unlink +}; + +static struct md_dir_operations mdd_lpf_dir_ops = { + .mdo_lookup = mdd_lookup, + .mdo_create = mdd_dummy_create, + .mdo_rename = mdd_dummy_rename, + .mdo_link = mdd_dummy_link, + .mdo_unlink = mdd_dummy_unlink }; static struct md_object *mdo_locate(const struct lu_env *env, @@ -645,6 +666,33 @@ static struct md_object *mdo_locate(const struct lu_env *env, return mdo; } +static int mdd_lpf_setup(const struct lu_env *env, struct mdd_device *m) +{ + struct md_object *mdo; + struct mdd_object *mdd_lpf; + struct lu_fid fid = LU_LPF_FID; + int rc; + ENTRY; + + rc = mdd_local_file_create(env, m, mdd_object_fid(m->mdd_dot_lustre), + mdd_lpf_dir_name, S_IFDIR | S_IRUSR | S_IXUSR, + &fid); + if (rc != 0) + RETURN(rc); + + mdo = mdo_locate(env, &m->mdd_md_dev, &fid); + if (IS_ERR(mdo)) + RETURN(PTR_ERR(mdo)); + + LASSERT(lu_object_exists(&mdo->mo_lu)); + + mdd_lpf = md2mdd_obj(mdo); + mdd_lpf->mod_obj.mo_dir_ops = &mdd_lpf_dir_ops; + m->mdd_dot_lustre_objs.mdd_lpf = mdd_lpf; + + RETURN(0); +} + /** * Create special in-memory "fid" object for open-by-fid. */ @@ -673,6 +721,23 @@ static int mdd_obf_setup(const struct lu_env *env, struct mdd_device *m) return 0; } +static void mdd_dot_lustre_cleanup(const struct lu_env *env, + struct mdd_device *m) +{ + if (m->mdd_dot_lustre_objs.mdd_lpf != NULL) { + mdd_object_put(env, m->mdd_dot_lustre_objs.mdd_lpf); + m->mdd_dot_lustre_objs.mdd_lpf = NULL; + } + if (m->mdd_dot_lustre_objs.mdd_obf != NULL) { + mdd_object_put(env, m->mdd_dot_lustre_objs.mdd_obf); + m->mdd_dot_lustre_objs.mdd_obf = NULL; + } + if (m->mdd_dot_lustre != NULL) { + mdd_object_put(env, m->mdd_dot_lustre); + m->mdd_dot_lustre = NULL; + } +} + /** Setup ".lustre" directory object */ static int mdd_dot_lustre_setup(const struct lu_env *env, struct mdd_device *m) { @@ -702,10 +767,19 @@ static int mdd_dot_lustre_setup(const struct lu_env *env, struct mdd_device *m) mdd2obd_dev(m)->obd_name, rc); GOTO(out, rc); } + + rc = mdd_lpf_setup(env, m); + if (rc != 0) { + CERROR("%s: error initializing \"lost+found\": rc = %d.\n", + mdd2obd_dev(m)->obd_name, rc); + GOTO(out, rc); + } + RETURN(0); + out: - mdd_object_put(env, m->mdd_dot_lustre); - m->mdd_dot_lustre = NULL; + mdd_dot_lustre_cleanup(env, m); + return rc; } @@ -789,10 +863,7 @@ static void mdd_device_shutdown(const struct lu_env *env, struct mdd_device *m, mdd_hsm_actions_llog_fini(env, m); mdd_changelog_fini(env, m); orph_index_fini(env, m); - if (m->mdd_dot_lustre_objs.mdd_obf) - mdd_object_put(env, m->mdd_dot_lustre_objs.mdd_obf); - if (m->mdd_dot_lustre) - mdd_object_put(env, m->mdd_dot_lustre); + mdd_dot_lustre_cleanup(env, m); if (m->mdd_los != NULL) local_oid_storage_fini(env, m->mdd_los); lu_site_purge(env, mdd2lu_dev(m)->ld_site, ~0); @@ -892,6 +963,12 @@ out_put: return 0; } +static int mdd_lfsck_out_notify(const struct lu_env *env, void *data, + enum lfsck_events event) +{ + return 0; +} + static int mdd_prepare(const struct lu_env *env, struct lu_device *pdev, struct lu_device *cdev) @@ -920,8 +997,8 @@ static int mdd_prepare(const struct lu_env *env, if (rc < 0) GOTO(out_los, rc); + lu_root_fid(&fid); if (mdd_seq_site(mdd)->ss_node_id == 0) { - lu_root_fid(&fid); rc = mdd_local_file_create(env, mdd, &mdd->mdd_local_root_fid, mdd_root_dir_name, S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO, &fid); @@ -930,8 +1007,8 @@ static int mdd_prepare(const struct lu_env *env, mdd2obd_dev(mdd)->obd_name, rc); GOTO(out_los, rc); } - mdd->mdd_root_fid = fid; + mdd->mdd_root_fid = fid; rc = mdd_dot_lustre_setup(env, mdd); if (rc != 0) { CERROR("%s: initializing .lustre failed: rc = %d\n", @@ -940,9 +1017,12 @@ static int mdd_prepare(const struct lu_env *env, } rc = mdd_compat_fixes(env, mdd); - if (rc) - GOTO(out_los, rc); - + if (rc != 0) + GOTO(out_dot, rc); + } else { + /* Normal client usually send root access to MDT0 directly, + * the root FID on non-MDT0 will only be used by echo client. */ + mdd->mdd_root_fid = fid; } rc = orph_index_init(env, mdd); @@ -960,7 +1040,9 @@ static int mdd_prepare(const struct lu_env *env, if (rc != 0) GOTO(out_changelog, rc); - rc = lfsck_register(env, mdd->mdd_bottom, mdd->mdd_child, true); + rc = lfsck_register(env, mdd->mdd_bottom, mdd->mdd_child, + mdd2obd_dev(mdd), mdd_lfsck_out_notify, + mdd, true); if (rc != 0) { CERROR("%s: failed to initialize lfsck: rc = %d\n", mdd2obd_dev(mdd)->obd_name, rc); @@ -974,12 +1056,8 @@ out_changelog: out_orph: orph_index_fini(env, mdd); out_dot: - if (mdd_seq_site(mdd)->ss_node_id == 0) { - mdd_object_put(env, mdd->mdd_dot_lustre); - mdd->mdd_dot_lustre = NULL; - mdd_object_put(env, mdd->mdd_dot_lustre_objs.mdd_obf); - mdd->mdd_dot_lustre_objs.mdd_obf = NULL; - } + if (mdd_seq_site(mdd)->ss_node_id == 0) + mdd_dot_lustre_cleanup(env, mdd); out_los: local_oid_storage_fini(env, mdd->mdd_los); mdd->mdd_los = NULL; @@ -1008,16 +1086,18 @@ static int mdd_root_get(const struct lu_env *env, * No permission check is needed. */ static int mdd_statfs(const struct lu_env *env, struct md_device *m, - struct obd_statfs *sfs) + struct obd_statfs *sfs) { - struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); - int rc; + struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev); + int rc; - ENTRY; + ENTRY; - rc = mdd_child_ops(mdd)->dt_statfs(env, mdd->mdd_child, sfs); + rc = mdd_child_ops(mdd)->dt_statfs(env, mdd->mdd_child, sfs); - RETURN(rc); + sfs->os_namelen = min_t(__u32, sfs->os_namelen, NAME_MAX); + + RETURN(rc); } /* @@ -1072,7 +1152,7 @@ static struct lu_device *mdd_device_free(const struct lu_env *env, struct mdd_device *m = lu2mdd_dev(lu); ENTRY; - LASSERT(cfs_atomic_read(&lu->ld_ref) == 0); + LASSERT(atomic_read(&lu->ld_ref) == 0); md_device_fini(&m->mdd_md_dev); OBD_FREE_PTR(m); RETURN(NULL); @@ -1152,15 +1232,26 @@ static int mdd_obd_disconnect(struct obd_export *exp) RETURN(rc); } -static int mdd_obd_health_check(const struct lu_env *env, - struct obd_device *obd) +static int mdd_obd_get_info(const struct lu_env *env, struct obd_export *exp, + __u32 keylen, void *key, __u32 *vallen, void *val, + struct lov_stripe_md *lsm) { - struct mdd_device *mdd = lu2mdd_dev(obd->obd_lu_dev); - int rc; - ENTRY; + int rc = -EINVAL; + + if (KEY_IS(KEY_OSP_CONNECTED)) { + struct obd_device *obd = exp->exp_obd; + struct mdd_device *mdd; + + if (!obd->obd_set_up || obd->obd_stopping) + RETURN(-EAGAIN); + + mdd = lu2mdd_dev(obd->obd_lu_dev); + LASSERT(mdd); + rc = obd_get_info(env, mdd->mdd_child_exp, keylen, key, vallen, + val, lsm); + RETURN(rc); + } - LASSERT(mdd); - rc = obd_health_check(env, mdd->mdd_child_exp->exp_obd); RETURN(rc); } @@ -1168,30 +1259,9 @@ static struct obd_ops mdd_obd_device_ops = { .o_owner = THIS_MODULE, .o_connect = mdd_obd_connect, .o_disconnect = mdd_obd_disconnect, - .o_health_check = mdd_obd_health_check + .o_get_info = mdd_obd_get_info, }; -/* - * context key constructor/destructor: - * mdd_capainfo_key_init, mdd_capainfo_key_fini - */ -LU_KEY_INIT_FINI(mdd_capainfo, struct md_capainfo); - -struct lu_context_key mdd_capainfo_key = { - .lct_tags = LCT_SESSION, - .lct_init = mdd_capainfo_key_init, - .lct_fini = mdd_capainfo_key_fini -}; - -struct md_capainfo *md_capainfo(const struct lu_env *env) -{ - /* NB, in mdt_init0 */ - if (env->le_ses == NULL) - return NULL; - return lu_context_key_get(env->le_ses, &mdd_capainfo_key); -} -EXPORT_SYMBOL(md_capainfo); - static int mdd_changelog_user_register(const struct lu_env *env, struct mdd_device *mdd, int *id) { @@ -1408,11 +1478,8 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, RETURN(rc); } case OBD_IOC_STOP_LFSCK: { - rc = lfsck_stop(env, mdd->mdd_bottom, false); - RETURN(rc); - } - case OBD_IOC_PAUSE_LFSCK: { - rc = lfsck_stop(env, mdd->mdd_bottom, true); + rc = lfsck_stop(env, mdd->mdd_bottom, + (struct lfsck_stop *)karg); RETURN(rc); } } @@ -1444,7 +1511,7 @@ static int mdd_iocontrol(const struct lu_env *env, struct md_device *m, } /* type constructor/destructor: mdd_type_init, mdd_type_fini */ -LU_TYPE_INIT_FINI(mdd, &mdd_thread_key, &mdd_capainfo_key); +LU_TYPE_INIT_FINI(mdd, &mdd_thread_key); const struct md_device_operations mdd_ops = { .mdo_statfs = mdd_statfs, @@ -1513,8 +1580,11 @@ static int __init mdd_mod_init(void) hsm_actions_logops.lop_add = llog_cat_add_rec; hsm_actions_logops.lop_declare_add = llog_cat_declare_add_rec; - rc = class_register_type(&mdd_obd_device_ops, NULL, lvars.module_vars, - LUSTRE_MDD_NAME, &mdd_device_type); + rc = class_register_type(&mdd_obd_device_ops, NULL, NULL, +#ifndef HAVE_ONLY_PROCFS_SEQ + lvars.module_vars, +#endif + LUSTRE_MDD_NAME, &mdd_device_type); if (rc) lu_kmem_fini(mdd_caches); return rc;