/* push / pop to root of obd store */ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx) { /* if there is underlaying dt_device then push_ctxt is not needed */ if (new_ctx->dt != NULL) return; //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n"); ASSERT_CTXT_MAGIC(new_ctx->magic); OBD_SET_CTXT_MAGIC(save); save->fs = get_fs(); LASSERT(d_count(current->fs->pwd.dentry)); LASSERT(d_count(new_ctx->pwd)); save->pwd = dget(current->fs->pwd.dentry); save->pwdmnt = mntget(current->fs->pwd.mnt); save->umask = current_umask(); LASSERT(save->pwd); LASSERT(save->pwdmnt); LASSERT(new_ctx->pwd); LASSERT(new_ctx->pwdmnt); current->fs->umask = 0; /* umask already applied on client */ set_fs(new_ctx->fs); ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd); }
static void osd_push_ctxt(const struct osd_device *dev, struct lvfs_run_ctxt *newctxt, struct lvfs_run_ctxt *save) { OBD_SET_CTXT_MAGIC(newctxt); newctxt->pwdmnt = dev->od_mnt; newctxt->pwd = dev->od_mnt->mnt_root; newctxt->fs = get_ds(); push_ctxt(save, newctxt, NULL); }
int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt) { struct mgs_obd *mgs = &obd->u.mgs; struct lvfs_run_ctxt saved; struct dentry *dentry; int rc; ENTRY; /* FIXME what's this? Do I need it? */ rc = cfs_cleanup_group_info(); if (rc) RETURN(rc); mgs->mgs_vfsmnt = mnt; mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb; rc = fsfilt_setup(obd, mgs->mgs_sb); if (rc) RETURN(rc); OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); 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.cb_ops = mgs_lvfs_ops; push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); /* Setup the configs dir */ dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MOUNT_CONFIGS_DIR, 0777, 1); if (IS_ERR(dentry)) { rc = PTR_ERR(dentry); CERROR("cannot create %s directory: rc = %d\n", MOUNT_CONFIGS_DIR, rc); GOTO(err_pop, rc); } mgs->mgs_configs_dir = dentry; /* create directory to store nid table versions */ dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MGS_NIDTBL_DIR, 0777, 1); if (IS_ERR(dentry)) { rc = PTR_ERR(dentry); CERROR("cannot create %s directory: rc = %d\n", MOUNT_CONFIGS_DIR, rc); GOTO(err_pop, rc); } else { dput(dentry); } err_pop: pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); return rc; }
/* push / pop to root of obd store */ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx, struct lvfs_ucred *uc) { /* if there is underlaying dt_device then push_ctxt is not needed */ if (new_ctx->dt != NULL) return; /* ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n"); */ ASSERT_CTXT_MAGIC(new_ctx->magic); OBD_SET_CTXT_MAGIC(save); save->fs = get_fs(); LASSERT(d_count(cfs_fs_pwd(current->fs))); LASSERT(d_count(new_ctx->pwd)); save->pwd = dget(cfs_fs_pwd(current->fs)); save->pwdmnt = mntget(cfs_fs_mnt(current->fs)); save->luc.luc_umask = current_umask(); save->ngroups = current_cred()->group_info->ngroups; LASSERT(save->pwd); LASSERT(save->pwdmnt); LASSERT(new_ctx->pwd); LASSERT(new_ctx->pwdmnt); if (uc) { struct cred *cred; save->luc.luc_uid = current_uid(); save->luc.luc_gid = current_gid(); save->luc.luc_fsuid = current_fsuid(); save->luc.luc_fsgid = current_fsgid(); save->luc.luc_cap = current_cap(); cred = prepare_creds(); if (cred) { cred->uid = uc->luc_uid; cred->gid = uc->luc_gid; cred->fsuid = uc->luc_fsuid; cred->fsgid = uc->luc_fsgid; cred->cap_effective = uc->luc_cap; commit_creds(cred); } push_group_info(save, uc->luc_ginfo ?: uc->luc_identity ? uc->luc_identity->mi_ginfo : NULL); } current->fs->umask = 0; /* umask already applied on client */ set_fs(new_ctx->fs); ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd); }
static void mds_init_ctxt(struct obd_device *obd, struct vfsmount *mnt) { struct mds_obd *mds = &obd->u.mds; mds->mds_obt.obt_vfsmnt = mnt; /* why not mnt->mnt_sb instead of mnt->mnt_root->d_inode->i_sb? */ obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb; obd->u.obt.obt_magic = OBT_MAGIC; fsfilt_setup(obd, obd->u.obt.obt_sb); OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); 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.cb_ops = mds_lvfs_ops; return; }
/* push / pop to root of obd store */ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx, struct lvfs_ucred *uc) { //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n"); ASSERT_CTXT_MAGIC(new_ctx->magic); OBD_SET_CTXT_MAGIC(save); save->fs = get_fs(); LASSERT(cfs_atomic_read(&cfs_fs_pwd(current->fs)->d_count)); LASSERT(cfs_atomic_read(&new_ctx->pwd->d_count)); save->pwd = dget(cfs_fs_pwd(current->fs)); save->pwdmnt = mntget(cfs_fs_mnt(current->fs)); save->luc.luc_umask = cfs_curproc_umask(); save->ngroups = current_cred()->group_info->ngroups; LASSERT(save->pwd); LASSERT(save->pwdmnt); LASSERT(new_ctx->pwd); LASSERT(new_ctx->pwdmnt); if (uc) { struct cred *cred; save->luc.luc_uid = current_uid(); save->luc.luc_gid = current_gid(); save->luc.luc_fsuid = current_fsuid(); save->luc.luc_fsgid = current_fsgid(); save->luc.luc_cap = current_cap(); if ((cred = prepare_creds())) { cred->uid = uc->luc_uid; cred->gid = uc->luc_gid; cred->fsuid = uc->luc_fsuid; cred->fsgid = uc->luc_fsgid; cred->cap_effective = uc->luc_cap; commit_creds(cred); } push_group_info(save, uc->luc_ginfo ?: uc->luc_identity ? uc->luc_identity->mi_ginfo : NULL); } current->fs->umask = 0; /* umask already applied on client */ set_fs(new_ctx->fs); ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd); }
/** * set llog methods and create LLOG_AGENT_ORIG_CTXT llog * object in obd_device */ static int mdd_hsm_actions_llog_init(const struct lu_env *env, struct mdd_device *m) { struct obd_device *obd = mdd2obd_dev(m); struct llog_ctxt *ctxt = NULL; int rc; ENTRY; OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); obd->obd_lvfs_ctxt.dt = m->mdd_bottom; rc = llog_setup(env, obd, &obd->obd_olg, LLOG_AGENT_ORIG_CTXT, obd, &hsm_actions_logops); if (rc) { CERROR("%s: hsm actions llog setup failed: rc = %d\n", obd->obd_name, rc); RETURN(rc); } ctxt = llog_get_context(obd, LLOG_AGENT_ORIG_CTXT); LASSERT(ctxt); rc = llog_open_create(env, ctxt, &ctxt->loc_handle, NULL, HSM_ACTIONS); if (rc) { CERROR("%s: hsm actions llog open_create failed: rc = %d\n", obd->obd_name, rc); GOTO(out_cleanup, rc); } rc = llog_cat_init_and_process(env, ctxt->loc_handle); if (rc) GOTO(out_close, rc); llog_ctxt_put(ctxt); RETURN(0); out_close: llog_cat_close(env, ctxt->loc_handle); ctxt->loc_handle = NULL; out_cleanup: llog_cleanup(env, ctxt); return rc; }
static int llog_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg) { struct obd_device *tgt; struct llog_ctxt *ctxt; struct dt_object *o; struct lu_env env; struct lu_context test_session; int rc; if (lcfg->lcfg_bufcount < 2) { CERROR("requires a TARGET OBD name\n"); return -EINVAL; } if (lcfg->lcfg_buflens[1] < 1) { CERROR("requires a TARGET OBD name\n"); return -EINVAL; } /* disk obd */ tgt = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) { CERROR("target device not attached or not set up (%s)\n", lustre_cfg_string(lcfg, 1)); return -EINVAL; } rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD); if (rc) return rc; rc = lu_context_init(&test_session, LCT_SESSION); if (rc) GOTO(cleanup_env, rc); test_session.lc_thread = (struct ptlrpc_thread *)current; lu_context_enter(&test_session); env.le_ses = &test_session; CWARN("Setup llog-test device over %s device\n", lustre_cfg_string(lcfg, 1)); OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); obd->obd_lvfs_ctxt.dt = lu2dt_dev(tgt->obd_lu_dev); rc = llog_setup(&env, tgt, &tgt->obd_olg, LLOG_TEST_ORIG_CTXT, tgt, &llog_osd_ops); if (rc) GOTO(cleanup_session, rc); /* use MGS llog dir for tests */ ctxt = llog_get_context(tgt, LLOG_CONFIG_ORIG_CTXT); LASSERT(ctxt); o = ctxt->loc_dir; llog_ctxt_put(ctxt); ctxt = llog_get_context(tgt, LLOG_TEST_ORIG_CTXT); LASSERT(ctxt); ctxt->loc_dir = o; llog_ctxt_put(ctxt); llog_test_rand = cfs_rand(); rc = llog_run_tests(&env, tgt); if (rc) llog_test_cleanup(obd); cleanup_session: lu_context_exit(&test_session); lu_context_fini(&test_session); cleanup_env: lu_env_fini(&env); return rc; }
static int mdd_changelog_llog_init(const struct lu_env *env, struct mdd_device *mdd) { struct obd_device *obd = mdd2obd_dev(mdd); struct llog_ctxt *ctxt = NULL, *uctxt = NULL; int rc; ENTRY; /* LU-2844 mdd setup failure should not cause umount oops */ if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CHANGELOG_INIT)) RETURN(-EIO); OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); obd->obd_lvfs_ctxt.dt = mdd->mdd_bottom; rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CHANGELOG_ORIG_CTXT, obd, &changelog_orig_logops); if (rc) { CERROR("%s: changelog llog setup failed: rc = %d\n", obd->obd_name, rc); RETURN(rc); } ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT); LASSERT(ctxt); rc = llog_open_create(env, ctxt, &ctxt->loc_handle, NULL, CHANGELOG_CATALOG); if (rc) GOTO(out_cleanup, rc); rc = llog_cat_init_and_process(env, ctxt->loc_handle); if (rc) GOTO(out_close, rc); rc = llog_cat_reverse_process(env, ctxt->loc_handle, changelog_init_cb, mdd); if (rc < 0) { CERROR("%s: changelog init failed: rc = %d\n", obd->obd_name, rc); GOTO(out_close, rc); } CDEBUG(D_IOCTL, "changelog starting index="LPU64"\n", mdd->mdd_cl.mc_index); /* setup user changelog */ rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CHANGELOG_USER_ORIG_CTXT, obd, &changelog_orig_logops); if (rc) { CERROR("%s: changelog users llog setup failed: rc = %d\n", obd->obd_name, rc); GOTO(out_close, rc); } uctxt = llog_get_context(obd, LLOG_CHANGELOG_USER_ORIG_CTXT); LASSERT(ctxt); rc = llog_open_create(env, uctxt, &uctxt->loc_handle, NULL, CHANGELOG_USERS); if (rc) GOTO(out_ucleanup, rc); uctxt->loc_handle->lgh_logops->lop_add = llog_cat_add_rec; uctxt->loc_handle->lgh_logops->lop_declare_add = llog_cat_declare_add_rec; rc = llog_cat_init_and_process(env, uctxt->loc_handle); if (rc) GOTO(out_uclose, rc); rc = llog_cat_reverse_process(env, uctxt->loc_handle, changelog_user_init_cb, mdd); if (rc < 0) { CERROR("%s: changelog user init failed: rc = %d\n", obd->obd_name, rc); GOTO(out_uclose, rc); } /* If we have registered users, assume we want changelogs on */ if (mdd->mdd_cl.mc_lastuser > 0) { rc = mdd_changelog_on(env, mdd, 1); if (rc < 0) GOTO(out_uclose, rc); } llog_ctxt_put(ctxt); llog_ctxt_put(uctxt); RETURN(0); out_uclose: llog_cat_close(env, uctxt->loc_handle); out_ucleanup: llog_cleanup(env, uctxt); out_close: llog_cat_close(env, ctxt->loc_handle); out_cleanup: llog_cleanup(env, ctxt); return rc; }