/** * This is helper function to get llog directory object. It is used by named * llog operations to find/insert/delete llog entry from llog directory. * * \param[in] env execution environment * \param[in] ctxt llog context * * \retval dt_object of llog directory * \retval ERR_PTR of negative value on error */ struct dt_object *llog_osd_dir_get(const struct lu_env *env, struct llog_ctxt *ctxt) { struct dt_device *dt; struct dt_thread_info *dti = dt_info(env); struct dt_object *dir; int rc; dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt; if (ctxt->loc_dir == NULL) { rc = dt_root_get(env, dt, &dti->dti_fid); if (rc) return ERR_PTR(rc); dir = dt_locate(env, dt, &dti->dti_fid); if (!IS_ERR(dir) && !dt_try_as_dir(env, dir)) { lu_object_put(env, &dir->do_lu); return ERR_PTR(-ENOTDIR); } } else { lu_object_get(&ctxt->loc_dir->do_lu); dir = ctxt->loc_dir; } return dir; }
static int mdd_prepare(const struct lu_env *env, struct lu_device *pdev, struct lu_device *cdev) { struct mdd_device *mdd = lu2mdd_dev(cdev); struct lu_device *next = &mdd->mdd_child->dd_lu_dev; struct lu_fid fid; int rc; ENTRY; rc = next->ld_ops->ldo_prepare(env, cdev, next); if (rc) RETURN(rc); /* Setup local dirs */ fid.f_seq = FID_SEQ_LOCAL_NAME; fid.f_oid = 1; fid.f_ver = 0; rc = local_oid_storage_init(env, mdd->mdd_bottom, &fid, &mdd->mdd_los); if (rc) RETURN(rc); rc = dt_root_get(env, mdd->mdd_child, &mdd->mdd_local_root_fid); if (rc < 0) GOTO(out_los, rc); lu_root_fid(&fid); if (mdd_seq_site(mdd)->ss_node_id == 0) { 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); if (rc != 0) { CERROR("%s: create root fid failed: rc = %d\n", mdd2obd_dev(mdd)->obd_name, rc); GOTO(out_los, rc); } mdd->mdd_root_fid = fid; rc = mdd_dot_lustre_setup(env, mdd); if (rc != 0) { CERROR("%s: initializing .lustre failed: rc = %d\n", mdd2obd_dev(mdd)->obd_name, rc); GOTO(out_los, rc); } rc = mdd_compat_fixes(env, mdd); 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); if (rc < 0) GOTO(out_dot, rc); rc = mdd_changelog_init(env, mdd); if (rc != 0) { CERROR("%s: failed to initialize changelog: rc = %d\n", mdd2obd_dev(mdd)->obd_name, rc); GOTO(out_orph, rc); } rc = mdd_hsm_actions_llog_init(env, mdd); if (rc != 0) GOTO(out_changelog, rc); 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); GOTO(out_hsm, rc); } RETURN(0); out_hsm: mdd_hsm_actions_llog_fini(env, mdd); out_changelog: mdd_changelog_fini(env, mdd); out_orph: orph_index_fini(env, mdd); out_dot: 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; return rc; }
/* * Set up quota directory (either "quota_master" or "quota_slave") for a QMT or * QSD instance. This function is also used to create per-pool directory on * the quota master. * The directory is created with a local sequence if it does not exist already. * This function is called at ->ldo_prepare time when the full device stack is * configured. * * \param env - is the environment passed by the caller * \param dev - is the dt_device where to create the quota directory * \param parent - is the parent directory. If not specified, the directory * will be created under the root directory * \param name - is the name of quota directory to be created * * \retval - pointer to quota root dt_object on success, appropriate error * on failure */ struct dt_object *lquota_disk_dir_find_create(const struct lu_env *env, struct dt_device *dev, struct dt_object *parent, const char *name) { struct lquota_thread_info *qti = lquota_info(env); struct dt_object *qt_dir = NULL; struct local_oid_storage *los = NULL; int rc; ENTRY; /* Set up local storage to create the quota directory. * We use the sequence reserved for local named objects */ lu_local_name_obj_fid(&qti->qti_fid, 1); rc = local_oid_storage_init(env, dev, &qti->qti_fid, &los); if (rc) RETURN(ERR_PTR(rc)); if (parent == NULL) { /* Fetch dt object associated with root directory */ rc = dt_root_get(env, dev, &qti->qti_fid); if (rc) GOTO(out, rc); parent = dt_locate_at(env, dev, &qti->qti_fid, dev->dd_lu_dev.ld_site->ls_top_dev, NULL); if (IS_ERR(parent)) GOTO(out, rc = PTR_ERR(parent)); } else { lu_object_get(&parent->do_lu); } /* create quota directory to be used for all quota index files */ qt_dir = local_file_find_or_create(env, los, parent, name, S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO); if (IS_ERR(qt_dir)) GOTO(out, rc = PTR_ERR(qt_dir)); /* local_oid_storage_fini() will finalize the local storage device, * we have to open the object in another device stack */ qti->qti_fid = qt_dir->do_lu.lo_header->loh_fid; lu_object_put_nocache(env, &qt_dir->do_lu); qt_dir = dt_locate(env, dev, &qti->qti_fid); if (IS_ERR(qt_dir)) GOTO(out, rc = PTR_ERR(qt_dir)); if (!dt_try_as_dir(env, qt_dir)) GOTO(out, rc = -ENOTDIR); EXIT; out: if (parent != NULL && !IS_ERR(parent)) lu_object_put(env, &parent->do_lu); if (los != NULL) local_oid_storage_fini(env, los); if (rc) { if (qt_dir != NULL && !IS_ERR(qt_dir)) lu_object_put(env, &qt_dir->do_lu); qt_dir = ERR_PTR(rc); } return qt_dir; }