Whamcloud - gitweb
LU-1855 build: fix 'out-of-bounds access' errors
[fs/lustre-release.git] / lustre / ptlrpc / sec.c
index 3487211..c4aa034 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -38,9 +38,6 @@
  * Author: Eric Mei <ericm@clusterfs.com>
  */
 
-#ifndef EXPORT_SYMTAB
-#define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_SEC
 
 #include <libcfs/libcfs.h>
@@ -120,7 +117,7 @@ EXPORT_SYMBOL(sptlrpc_unregister_policy);
 static
 struct ptlrpc_sec_policy * sptlrpc_wireflavor2policy(__u32 flavor)
 {
-        static CFS_DECLARE_MUTEX(load_mutex);
+        static CFS_DEFINE_MUTEX(load_mutex);
         static cfs_atomic_t       loaded = CFS_ATOMIC_INIT(0);
         struct ptlrpc_sec_policy *policy;
         __u16                     number = SPTLRPC_FLVR_POLICY(flavor);
@@ -143,16 +140,17 @@ struct ptlrpc_sec_policy * sptlrpc_wireflavor2policy(__u32 flavor)
                         break;
 
                 /* try to load gss module, once */
-                cfs_mutex_down(&load_mutex);
+                cfs_mutex_lock(&load_mutex);
                 if (cfs_atomic_read(&loaded) == 0) {
                         if (cfs_request_module("ptlrpc_gss") == 0)
-                                CWARN("module ptlrpc_gss loaded on demand\n");
+                                CDEBUG(D_SEC,
+                                       "module ptlrpc_gss loaded on demand\n");
                         else
                                 CERROR("Unable to load module ptlrpc_gss\n");
 
                         cfs_atomic_set(&loaded, 1);
                 }
-                cfs_mutex_up(&load_mutex);
+                cfs_mutex_unlock(&load_mutex);
         }
 
         return policy;
@@ -237,21 +235,20 @@ EXPORT_SYMBOL(sptlrpc_flavor2name);
 
 char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize)
 {
-        buf[0] = '\0';
+       buf[0] = '\0';
 
-        if (flags & PTLRPC_SEC_FL_REVERSE)
-                strncat(buf, "reverse,", bufsize);
-        if (flags & PTLRPC_SEC_FL_ROOTONLY)
-                strncat(buf, "rootonly,", bufsize);
-        if (flags & PTLRPC_SEC_FL_UDESC)
-                strncat(buf, "udesc,", bufsize);
-        if (flags & PTLRPC_SEC_FL_BULK)
-                strncat(buf, "bulk,", bufsize);
-        if (buf[0] == '\0')
-                strncat(buf, "-,", bufsize);
+       if (flags & PTLRPC_SEC_FL_REVERSE)
+               strlcat(buf, "reverse,", bufsize);
+       if (flags & PTLRPC_SEC_FL_ROOTONLY)
+               strlcat(buf, "rootonly,", bufsize);
+       if (flags & PTLRPC_SEC_FL_UDESC)
+               strlcat(buf, "udesc,", bufsize);
+       if (flags & PTLRPC_SEC_FL_BULK)
+               strlcat(buf, "bulk,", bufsize);
+       if (buf[0] == '\0')
+               strlcat(buf, "-,", bufsize);
 
-        buf[bufsize - 1] = '\0';
-        return buf;
+       return buf;
 }
 EXPORT_SYMBOL(sptlrpc_secflags2str);
 
@@ -469,12 +466,12 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,
         LASSERT(req->rq_reqlen);
         LASSERT(req->rq_replen);
 
-        CWARN("req %p: switch ctx %p(%u->%s) -> %p(%u->%s), "
-              "switch sec %p(%s) -> %p(%s)\n", req,
-              oldctx, oldctx->cc_vcred.vc_uid, sec2target_str(oldctx->cc_sec),
-              newctx, newctx->cc_vcred.vc_uid, sec2target_str(newctx->cc_sec),
-              oldctx->cc_sec, oldctx->cc_sec->ps_policy->sp_name,
-              newctx->cc_sec, newctx->cc_sec->ps_policy->sp_name);
+        CDEBUG(D_SEC, "req %p: switch ctx %p(%u->%s) -> %p(%u->%s), "
+               "switch sec %p(%s) -> %p(%s)\n", req,
+               oldctx, oldctx->cc_vcred.vc_uid, sec2target_str(oldctx->cc_sec),
+               newctx, newctx->cc_vcred.vc_uid, sec2target_str(newctx->cc_sec),
+               oldctx->cc_sec, oldctx->cc_sec->ps_policy->sp_name,
+               newctx->cc_sec, newctx->cc_sec->ps_policy->sp_name);
 
         /* save flavor */
         old_flvr = req->rq_flvr;
@@ -552,8 +549,9 @@ int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
                 /*
                  * still get the old dead ctx, usually means system too busy
                  */
-                CWARN("ctx (%p, fl %lx) doesn't switch, relax a little bit\n",
-                      newctx, newctx->cc_flags);
+                CDEBUG(D_SEC,
+                       "ctx (%p, fl %lx) doesn't switch, relax a little bit\n",
+                       newctx, newctx->cc_flags);
 
                 cfs_schedule_timeout_and_set_state(CFS_TASK_INTERRUPTIBLE,
                                                    CFS_HZ);
@@ -823,6 +821,7 @@ void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode)
         case OST_READ:
         case MDS_READPAGE:
         case MGS_CONFIG_READ:
+       case OBD_IDX_READ:
                 req->rq_bulk_read = 1;
                 break;
         case OST_WRITE:
@@ -1384,11 +1383,11 @@ static void sptlrpc_import_sec_adapt_inplace(struct obd_import *imp,
         char    str1[32], str2[32];
 
         if (sec->ps_flvr.sf_flags != sf->sf_flags)
-                CWARN("changing sec flags: %s -> %s\n",
-                      sptlrpc_secflags2str(sec->ps_flvr.sf_flags,
-                                           str1, sizeof(str1)),
-                      sptlrpc_secflags2str(sf->sf_flags,
-                                           str2, sizeof(str2)));
+                CDEBUG(D_SEC, "changing sec flags: %s -> %s\n",
+                       sptlrpc_secflags2str(sec->ps_flvr.sf_flags,
+                                            str1, sizeof(str1)),
+                       sptlrpc_secflags2str(sf->sf_flags,
+                                            str2, sizeof(str2)));
 
         cfs_spin_lock(&sec->ps_lock);
         flavor_copy(&sec->ps_flvr, sf);
@@ -1454,11 +1453,11 @@ int sptlrpc_import_sec_adapt(struct obd_import *imp,
                 if (flavor_equal(&sf, &sec->ps_flvr))
                         GOTO(out, rc);
 
-                CWARN("import %s->%s: changing flavor %s -> %s\n",
-                      imp->imp_obd->obd_name,
-                      obd_uuid2str(&conn->c_remote_uuid),
-                      sptlrpc_flavor2name(&sec->ps_flvr, str, sizeof(str)),
-                      sptlrpc_flavor2name(&sf, str2, sizeof(str2)));
+                CDEBUG(D_SEC, "import %s->%s: changing flavor %s -> %s\n",
+                       imp->imp_obd->obd_name,
+                       obd_uuid2str(&conn->c_remote_uuid),
+                       sptlrpc_flavor2name(&sec->ps_flvr, str, sizeof(str)),
+                       sptlrpc_flavor2name(&sf, str2, sizeof(str2)));
 
                 if (SPTLRPC_FLVR_POLICY(sf.sf_rpc) ==
                     SPTLRPC_FLVR_POLICY(sec->ps_flvr.sf_rpc) &&
@@ -1467,15 +1466,16 @@ int sptlrpc_import_sec_adapt(struct obd_import *imp,
                         sptlrpc_import_sec_adapt_inplace(imp, sec, &sf);
                         GOTO(out, rc);
                 }
-        } else if (sptlrpc_flavor2name_base(sf.sf_rpc) != SPTLRPC_FLVR_NULL) {
-                LCONSOLE_INFO("import %s->%s netid %x: select flavor %s\n",
-                              imp->imp_obd->obd_name,
-                              obd_uuid2str(&conn->c_remote_uuid),
-                              LNET_NIDNET(conn->c_self),
-                              sptlrpc_flavor2name(&sf, str, sizeof(str)));
+        } else if (SPTLRPC_FLVR_BASE(sf.sf_rpc) !=
+                   SPTLRPC_FLVR_BASE(SPTLRPC_FLVR_NULL)) {
+                CDEBUG(D_SEC, "import %s->%s netid %x: select flavor %s\n",
+                       imp->imp_obd->obd_name,
+                       obd_uuid2str(&conn->c_remote_uuid),
+                       LNET_NIDNET(conn->c_self),
+                       sptlrpc_flavor2name(&sf, str, sizeof(str)));
         }
 
-        cfs_mutex_down(&imp->imp_sec_mutex);
+        cfs_mutex_lock(&imp->imp_sec_mutex);
 
         newsec = sptlrpc_sec_create(imp, svc_ctx, &sf, sp);
         if (newsec) {
@@ -1487,7 +1487,7 @@ int sptlrpc_import_sec_adapt(struct obd_import *imp,
                 rc = -EPERM;
         }
 
-        cfs_mutex_up(&imp->imp_sec_mutex);
+        cfs_mutex_unlock(&imp->imp_sec_mutex);
 out:
         sptlrpc_sec_put(sec);
         RETURN(rc);
@@ -2108,7 +2108,7 @@ int sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
         rc = policy->sp_sops->alloc_rs(req, msglen);
         if (unlikely(rc == -ENOMEM)) {
                 /* failed alloc, try emergency pool */
-                rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_service);
+               rs = lustre_get_emerg_rs(req->rq_rqbd->rqbd_svcpt);
                 if (rs == NULL)
                         RETURN(-ENOMEM);
 
@@ -2296,6 +2296,7 @@ int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
 }
 EXPORT_SYMBOL(sptlrpc_cli_unwrap_bulk_write);
 
+#ifdef HAVE_SERVER_SUPPORT
 /**
  * Performe transformation upon outgoing bulk read.
  */
@@ -2377,6 +2378,8 @@ int sptlrpc_svc_prep_bulk(struct ptlrpc_request *req,
 }
 EXPORT_SYMBOL(sptlrpc_svc_prep_bulk);
 
+#endif /* HAVE_SERVER_SUPPORT */
+
 /****************************************
  * user descriptor helpers              *
  ****************************************/