Whamcloud - gitweb
branch: HEAD
[fs/lustre-release.git] / lustre / ptlrpc / gss / gss_cli_upcall.c
index 196fb9f..370004c 100644 (file)
@@ -150,7 +150,7 @@ int ctx_init_pack_request(struct obd_import *imp,
 }
 
 static
-int ctx_init_parse_reply(struct lustre_msg *msg,
+int ctx_init_parse_reply(struct lustre_msg *msg, int swabbed,
                          char __user *outbuf, long outlen)
 {
         struct gss_rep_header   *ghdr;
@@ -162,7 +162,7 @@ int ctx_init_parse_reply(struct lustre_msg *msg,
                 return -EPROTO;
         }
 
-        ghdr = (struct gss_rep_header *) gss_swab_header(msg, 0);
+        ghdr = (struct gss_rep_header *) gss_swab_header(msg, 0, swabbed);
         if (ghdr == NULL) {
                 CERROR("unable to extract gss reply header\n");
                 return -EPROTO;
@@ -248,8 +248,8 @@ int gss_do_ctx_init_rpc(__user char *buffer, unsigned long count)
         int                       rc;
 
         if (count != sizeof(param)) {
-                CERROR("ioctl size %lu, expect %lu, please check lgssd version\n",
-                        count, (unsigned long) sizeof(param));
+                CERROR("ioctl size %lu, expect %lu, please check lgss_keyring "
+                       "version\n", count, (unsigned long) sizeof(param));
                 RETURN(-EINVAL);
         }
         if (copy_from_user(&param, buffer, sizeof(param))) {
@@ -275,11 +275,40 @@ int gss_do_ctx_init_rpc(__user char *buffer, unsigned long count)
                 RETURN(-EINVAL);
         }
 
+        if (unlikely(!obd->obd_set_up)) {
+                CERROR("obd %s not setup\n", obdname);
+                RETURN(-EINVAL);
+        }
+
+        spin_lock(&obd->obd_dev_lock);
+        if (obd->obd_stopping) {
+                CERROR("obd %s has stopped\n", obdname);
+                spin_unlock(&obd->obd_dev_lock);
+                RETURN(-EINVAL);
+        }
+
+        if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
+            strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
+            strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
+                CERROR("obd %s is not a client device\n", obdname);
+                spin_unlock(&obd->obd_dev_lock);
+                RETURN(-EINVAL);
+        }
+        spin_unlock(&obd->obd_dev_lock);
+
+        down_read(&obd->u.cli.cl_sem);
+        if (obd->u.cli.cl_import == NULL) {
+                CERROR("obd %s: import has gone\n", obd->obd_name);
+                RETURN(-EINVAL);
+        }
         imp = class_import_get(obd->u.cli.cl_import);
-        LASSERT(imp->imp_sec);
+        up_read(&obd->u.cli.cl_sem);
 
-        /* force this import to use v2 msg */
-        imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
+        if (imp->imp_deactive) {
+                CERROR("import has been deactivated\n");
+                class_import_put(imp);
+                RETURN(-EINVAL);
+        }
 
         req = ptlrpc_request_alloc_pack(imp, &RQF_SEC_CTX, LUSTRE_OBD_VERSION,
                                         SEC_CTX_INIT);
@@ -327,6 +356,7 @@ int gss_do_ctx_init_rpc(__user char *buffer, unsigned long count)
 
         LASSERT(req->rq_repdata);
         lsize = ctx_init_parse_reply(req->rq_repdata,
+                                     ptlrpc_rep_need_swab(req),
                                      param.reply_buf, param.reply_buf_size);
         if (lsize < 0) {
                 param.status = (int) lsize;