* in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see [sun.com URL with a
- * copy of GPLv2].
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
/* Establish a connection to the MGS.*/
static int mgs_connect(const struct lu_env *env,
- struct lustre_handle *conn, struct obd_device *obd,
+ struct obd_export **exp, struct obd_device *obd,
struct obd_uuid *cluuid, struct obd_connect_data *data,
void *localdata)
{
- struct obd_export *exp;
+ struct obd_export *lexp;
+ struct lustre_handle conn = { 0 };
int rc;
ENTRY;
- if (!conn || !obd || !cluuid)
+ if (!exp || !obd || !cluuid)
RETURN(-EINVAL);
- rc = class_connect(conn, obd, cluuid);
+ rc = class_connect(&conn, obd, cluuid);
if (rc)
RETURN(rc);
- exp = class_conn2export(conn);
- LASSERT(exp);
- exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_NULL;
+ lexp = class_conn2export(&conn);
+ LASSERT(lexp);
- mgs_counter_incr(exp, LPROC_MGS_CONNECT);
+ mgs_counter_incr(lexp, LPROC_MGS_CONNECT);
if (data != NULL) {
data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
- exp->exp_connect_flags = data->ocd_connect_flags;
+ lexp->exp_connect_flags = data->ocd_connect_flags;
data->ocd_version = LUSTRE_VERSION_CODE;
}
+ rc = mgs_client_add(obd, lexp, localdata);
+
if (rc) {
- class_disconnect(exp);
+ class_disconnect(lexp);
} else {
- class_export_put(exp);
+ *exp = lexp;
}
RETURN(rc);
}
+static int mgs_reconnect(const struct lu_env *env,
+ struct obd_export *exp, struct obd_device *obd,
+ struct obd_uuid *cluuid, struct obd_connect_data *data,
+ void *localdata)
+{
+ ENTRY;
+
+ if (exp == NULL || obd == NULL || cluuid == NULL)
+ RETURN(-EINVAL);
+
+ mgs_counter_incr(exp, LPROC_MGS_CONNECT);
+
+ if (data != NULL) {
+ data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
+ exp->exp_connect_flags = data->ocd_connect_flags;
+ data->ocd_version = LUSTRE_VERSION_CODE;
+ }
+
+ RETURN(0);
+}
+
static int mgs_disconnect(struct obd_export *exp)
{
int rc;
rc = class_disconnect(exp);
ldlm_cancel_locks_for_export(exp);
+ lprocfs_exp_cleanup(exp);
+
/* complete all outstanding replies */
spin_lock(&exp->exp_lock);
while (!list_empty(&exp->exp_outstanding_replies)) {
spin_lock(&svc->srv_lock);
list_del_init(&rs->rs_exp_list);
+ spin_lock(&rs->rs_lock);
ptlrpc_schedule_difficult_reply(rs);
+ spin_unlock(&rs->rs_lock);
spin_unlock(&svc->srv_lock);
}
spin_unlock(&exp->exp_lock);
if (IS_ERR(obd->obd_fsops))
GOTO(err_put, rc = PTR_ERR(obd->obd_fsops));
+ if (lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb))) {
+ CERROR("%s: Underlying device is marked as read-only. "
+ "Setup failed\n", obd->obd_name);
+ GOTO(err_ops, rc = -EROFS);
+ }
+
/* namespace for mgs llog */
obd->obd_namespace = ldlm_namespace_new(obd ,"MGS", LDLM_NAMESPACE_SERVER,
LDLM_NAMESPACE_MODEST);
ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
"mgs_ldlm_client", &obd->obd_ldlm_client);
- LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
-
rc = mgs_fs_setup(obd, mnt);
if (rc) {
CERROR("%s: MGS filesystem method init failed: rc = %d\n",
mgs->mgs_service =
ptlrpc_init_svc(MGS_NBUFS, MGS_BUFSIZE, MGS_MAXREQSIZE,
MGS_MAXREPSIZE, MGS_REQUEST_PORTAL,
- MGC_REPLY_PORTAL, 2000,
+ MGC_REPLY_PORTAL, 2,
mgs_handle, LUSTRE_MGS_NAME,
obd->obd_proc_entry, target_print_req,
MGS_THREADS_AUTO_MIN, MGS_THREADS_AUTO_MAX,
- "ll_mgs", LCT_MD_THREAD);
+ "ll_mgs", LCT_MD_THREAD, NULL);
if (!mgs->mgs_service) {
CERROR("failed to start service\n");
LDLM_PLAIN, NULL, LCK_EX,
&flags, ldlm_blocking_ast,
ldlm_completion_ast, NULL,
- fsname, 0, NULL, lockh);
+ fsname, 0, NULL, NULL, lockh);
if (rc)
CERROR("can't take cfg lock for %s (%d)\n", fsname, rc);
RETURN(0);
}
+static void mgs_revoke_lock(struct obd_device *obd, char *fsname,
+ struct lustre_handle *lockh)
+{
+ int lockrc;
+
+ if (fsname[0]) {
+ lockrc = mgs_get_cfg_lock(obd, fsname, lockh);
+ if (lockrc != ELDLM_OK)
+ CERROR("lock error %d for fs %s\n", lockrc,
+ fsname);
+ else
+ mgs_put_cfg_lock(lockh);
+ }
+}
+
/* rc=0 means ok
1 means update
<0 means error */
rc = mgs_check_index(obd, mti);
if (rc == 0) {
LCONSOLE_ERROR_MSG(0x13b, "%s claims to have registered, but "
- "this MGS does not know about it. Assuming"
- " writeconf.\n", mti->mti_svname);
- mti->mti_flags |= LDD_F_WRITECONF;
- rc = 1;
+ "this MGS does not know about it, preventing "
+ "registration.\n", mti->mti_svname);
+ rc = -ENOENT;
} else if (rc == -1) {
LCONSOLE_ERROR_MSG(0x13c, "Client log %s-client has "
"disappeared! Regenerating all logs.\n",
}
mti->mti_flags |= LDD_F_UPDATE;
/* Erased logs means start from scratch. */
- mti->mti_flags &= ~LDD_F_UPGRADE14;
+ mti->mti_flags &= ~LDD_F_UPGRADE14;
}
/* COMPAT_146 */
CERROR("Can't upgrade from 1.4 (%d)\n", rc);
GOTO(out, rc);
}
-
+
/* We're good to go */
mti->mti_flags |= LDD_F_UPDATE;
}
struct obd_device *obd = req->rq_export->exp_obd;
struct mgs_send_param *msp, *rep_msp;
struct lustre_handle lockh;
- int lockrc, rc;
+ int rc;
struct lustre_cfg_bufs bufs;
struct lustre_cfg *lcfg;
char fsname[MTI_NAME_MAXLEN];
RETURN(rc);
}
- /* Revoke lock so everyone updates. Should be alright if
- * someone was already reading while we were updating the logs,
- * so we don't really need to hold the lock while we're
- * writing.
- */
- if (fsname[0]) {
- lockrc = mgs_get_cfg_lock(obd, fsname, &lockh);
- if (lockrc != ELDLM_OK)
- CERROR("lock error %d for fs %s\n", lockrc,
- fsname);
- else
- mgs_put_cfg_lock(&lockh);
- }
+ /* request for update */
+ mgs_revoke_lock(obd, fsname, &lockh);
+
lustre_cfg_free(lcfg);
rc = req_capsule_server_pack(&req->rq_pill);
RETURN(rc);
}
+/*
+ * similar as in ost_connect_check_sptlrpc()
+ */
+static int mgs_connect_check_sptlrpc(struct ptlrpc_request *req)
+{
+ struct obd_export *exp = req->rq_export;
+ struct obd_device *obd = exp->exp_obd;
+ struct fs_db *fsdb;
+ struct sptlrpc_flavor flvr;
+ int rc = 0;
+
+ if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
+ rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
+ if (rc)
+ return rc;
+
+ down(&fsdb->fsdb_sem);
+ if (sptlrpc_rule_set_choose(&fsdb->fsdb_srpc_gen,
+ LUSTRE_SP_MGC, LUSTRE_SP_MGS,
+ req->rq_peer.nid,
+ &flvr) == 0) {
+ /* by defualt allow any flavors */
+ flvr.sf_rpc = SPTLRPC_FLVR_ANY;
+ }
+ up(&fsdb->fsdb_sem);
+
+ spin_lock(&exp->exp_lock);
+
+ exp->exp_sp_peer = req->rq_sp_from;
+ exp->exp_flvr = flvr;
+
+ if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
+ exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
+ CERROR("invalid rpc flavor %x, expect %x, from %s\n",
+ req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
+ libcfs_nid2str(req->rq_peer.nid));
+ rc = -EACCES;
+ }
+
+ spin_unlock(&exp->exp_lock);
+ } else {
+ if (exp->exp_sp_peer != req->rq_sp_from) {
+ CERROR("RPC source %s doesn't match %s\n",
+ sptlrpc_part2name(req->rq_sp_from),
+ sptlrpc_part2name(exp->exp_sp_peer));
+ rc = -EACCES;
+ } else {
+ rc = sptlrpc_target_export_check(exp, req);
+ }
+ }
+
+ return rc;
+}
+
/* Called whenever a target cleans up. */
/* XXX - Currently unused */
static int mgs_handle_target_del(struct ptlrpc_request *req)
LASSERT(current->journal_info == NULL);
opc = lustre_msg_get_opc(req->rq_reqmsg);
+
+ if (opc == SEC_CTX_INIT ||
+ opc == SEC_CTX_INIT_CONT ||
+ opc == SEC_CTX_FINI)
+ GOTO(out, rc = 0);
+
if (opc != MGS_CONNECT) {
if (req->rq_export == NULL) {
CERROR("lustre_mgs: operation %d on unconnected MGS\n",
/* MGS and MDS have same request format for connect */
req_capsule_set(&req->rq_pill, &RQF_MDS_CONNECT);
rc = target_handle_connect(req);
+ if (rc == 0)
+ rc = mgs_connect_check_sptlrpc(req);
+
if (!rc && (lustre_msg_get_conn_cnt(req->rq_reqmsg) > 1))
/* Make clients trying to reconnect after a MGS restart
happy; also requires obd_replayable */
RETURN(0);
}
+static inline int mgs_init_export(struct obd_export *exp)
+{
+ return ldlm_init_export(exp);
+}
+
static inline int mgs_destroy_export(struct obd_export *exp)
{
ENTRY;
target_destroy_export(exp);
+ mgs_client_free(exp);
+ ldlm_destroy_export(exp);
+
+ RETURN(0);
+}
+
+static int mgs_extract_fs_pool(char * arg, char *fsname, char *poolname)
+{
+ char *ptr;
+
+ ENTRY;
+ for (ptr = arg; (*ptr != '\0') && (*ptr != '.'); ptr++ ) {
+ *fsname = *ptr;
+ fsname++;
+ }
+ if (*ptr == '\0')
+ return -EINVAL;
+ *fsname = '\0';
+ ptr++;
+ strcpy(poolname, ptr);
RETURN(0);
}
+static int mgs_iocontrol_pool(struct obd_device *obd,
+ struct obd_ioctl_data *data)
+{
+ int rc;
+ struct lustre_handle lockh;
+ struct lustre_cfg *lcfg = NULL;
+ struct llog_rec_hdr rec;
+ char *fsname = NULL;
+ char *poolname = NULL;
+ ENTRY;
+
+ OBD_ALLOC(fsname, MTI_NAME_MAXLEN);
+ if (fsname == NULL)
+ RETURN(-ENOMEM);
+
+ OBD_ALLOC(poolname, LOV_MAXPOOLNAME + 1);
+ if (poolname == NULL) {
+ rc = -ENOMEM;
+ GOTO(out_pool, rc);
+ }
+ rec.lrh_len = llog_data_len(data->ioc_plen1);
+
+ if (data->ioc_type == LUSTRE_CFG_TYPE) {
+ rec.lrh_type = OBD_CFG_REC;
+ } else {
+ CERROR("unknown cfg record type:%d \n", data->ioc_type);
+ rc = -EINVAL;
+ GOTO(out_pool, rc);
+ }
+
+ if (data->ioc_plen1 > CFS_PAGE_SIZE) {
+ rc = -E2BIG;
+ GOTO(out_pool, rc);
+ }
+
+ OBD_ALLOC(lcfg, data->ioc_plen1);
+ if (lcfg == NULL)
+ GOTO(out_pool, rc = -ENOMEM);
+
+ if (copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1))
+ GOTO(out_pool, rc = -EFAULT);
+
+ if (lcfg->lcfg_bufcount < 2) {
+ GOTO(out_pool, rc = -EFAULT);
+ }
+
+ /* first arg is always <fsname>.<poolname> */
+ mgs_extract_fs_pool(lustre_cfg_string(lcfg, 1), fsname,
+ poolname);
+
+ switch (lcfg->lcfg_command) {
+ case LCFG_POOL_NEW: {
+ if (lcfg->lcfg_bufcount != 2)
+ RETURN(-EINVAL);
+ rc = mgs_pool_cmd(obd, LCFG_POOL_NEW, fsname,
+ poolname, NULL);
+ break;
+ }
+ case LCFG_POOL_ADD: {
+ if (lcfg->lcfg_bufcount != 3)
+ RETURN(-EINVAL);
+ rc = mgs_pool_cmd(obd, LCFG_POOL_ADD, fsname, poolname,
+ lustre_cfg_string(lcfg, 2));
+ break;
+ }
+ case LCFG_POOL_REM: {
+ if (lcfg->lcfg_bufcount != 3)
+ RETURN(-EINVAL);
+ rc = mgs_pool_cmd(obd, LCFG_POOL_REM, fsname, poolname,
+ lustre_cfg_string(lcfg, 2));
+ break;
+ }
+ case LCFG_POOL_DEL: {
+ if (lcfg->lcfg_bufcount != 2)
+ RETURN(-EINVAL);
+ rc = mgs_pool_cmd(obd, LCFG_POOL_DEL, fsname,
+ poolname, NULL);
+ break;
+ }
+ default: {
+ rc = -EINVAL;
+ GOTO(out_pool, rc);
+ }
+ }
+
+ if (rc) {
+ CERROR("OBD_IOC_POOL err %d, cmd %X for pool %s.%s\n",
+ rc, lcfg->lcfg_command, fsname, poolname);
+ GOTO(out_pool, rc);
+ }
+
+ /* request for update */
+ mgs_revoke_lock(obd, fsname, &lockh);
+
+out_pool:
+ if (lcfg != NULL)
+ OBD_FREE(lcfg, data->ioc_plen1);
+
+ if (fsname != NULL)
+ OBD_FREE(fsname, MTI_NAME_MAXLEN);
+
+ if (poolname != NULL)
+ OBD_FREE(poolname, LOV_MAXPOOLNAME + 1);
+
+ RETURN(rc);
+}
+
/* from mdt_iocontrol */
int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
void *karg, void *uarg)
struct lustre_cfg *lcfg;
struct llog_rec_hdr rec;
char fsname[MTI_NAME_MAXLEN];
- int lockrc;
rec.lrh_len = llog_data_len(data->ioc_plen1);
OBD_ALLOC(lcfg, data->ioc_plen1);
if (lcfg == NULL)
RETURN(-ENOMEM);
- rc = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1);
- if (rc)
- GOTO(out_free, rc);
+ if (copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1))
+ GOTO(out_free, rc = -EFAULT);
if (lcfg->lcfg_bufcount < 1)
GOTO(out_free, rc = -EINVAL);
someone was already reading while we were updating the logs,
so we don't really need to hold the lock while we're
writing (above). */
- if (fsname[0]) {
- lockrc = mgs_get_cfg_lock(obd, fsname, &lockh);
- if (lockrc != ELDLM_OK)
- CERROR("lock error %d for fs %s\n", lockrc,
- fsname);
- else
- mgs_put_cfg_lock(&lockh);
- }
+ mgs_revoke_lock(obd, fsname, &lockh);
out_free:
OBD_FREE(lcfg, data->ioc_plen1);
RETURN(rc);
}
+ case OBD_IOC_POOL: {
+ RETURN(mgs_iocontrol_pool(obd, data));
+ }
+
case OBD_IOC_DUMP_LOG: {
struct llog_ctxt *ctxt;
ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
static struct obd_ops mgs_obd_ops = {
.o_owner = THIS_MODULE,
.o_connect = mgs_connect,
+ .o_reconnect = mgs_reconnect,
.o_disconnect = mgs_disconnect,
.o_setup = mgs_setup,
.o_precleanup = mgs_precleanup,
.o_cleanup = mgs_cleanup,
+ .o_init_export = mgs_init_export,
.o_destroy_export = mgs_destroy_export,
.o_iocontrol = mgs_iocontrol,
.o_llog_init = mgs_llog_init,