Whamcloud - gitweb
LU-14895 client: allow case-insensitive checksum types
[fs/lustre-release.git] / lustre / ptlrpc / sec_config.c
index 920a1d2..3f476ba 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #define DEBUG_SUBSYSTEM S_SEC
@@ -168,12 +167,12 @@ static void get_default_flavor(struct sptlrpc_flavor *sf)
 
 static void sptlrpc_rule_init(struct sptlrpc_rule *rule)
 {
-        rule->sr_netid = LNET_NIDNET(LNET_NID_ANY);
-        rule->sr_from = LUSTRE_SP_ANY;
-        rule->sr_to = LUSTRE_SP_ANY;
-        rule->sr_padding = 0;
+       rule->sr_netid = LNET_NET_ANY;
+       rule->sr_from = LUSTRE_SP_ANY;
+       rule->sr_to = LUSTRE_SP_ANY;
+       rule->sr_padding = 0;
 
-        get_default_flavor(&rule->sr_flvr);
+       get_default_flavor(&rule->sr_flvr);
 }
 
 /*
@@ -181,70 +180,69 @@ static void sptlrpc_rule_init(struct sptlrpc_rule *rule)
  */
 int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
 {
-        char           *flavor, *dir;
-        int             rc;
+       char *flavor, *dir;
+       int rc;
 
-        sptlrpc_rule_init(rule);
+       sptlrpc_rule_init(rule);
 
-        flavor = strchr(param, '=');
-        if (flavor == NULL) {
-                CERROR("invalid param, no '='\n");
-                RETURN(-EINVAL);
-        }
-        *flavor++ = '\0';
-
-        dir = strchr(param, '.');
-        if (dir)
-                *dir++ = '\0';
-
-        /* 1.1 network */
-        if (strcmp(param, "default")) {
-                rule->sr_netid = libcfs_str2net(param);
-                if (rule->sr_netid == LNET_NIDNET(LNET_NID_ANY)) {
-                        CERROR("invalid network name: %s\n", param);
-                        RETURN(-EINVAL);
-                }
-        }
+       flavor = strchr(param, '=');
+       if (flavor == NULL) {
+               CERROR("invalid param, no '='\n");
+               RETURN(-EINVAL);
+       }
+       *flavor++ = '\0';
+
+       dir = strchr(param, '.');
+       if (dir)
+               *dir++ = '\0';
+
+       /* 1.1 network */
+       if (strcmp(param, "default")) {
+               rule->sr_netid = libcfs_str2net(param);
+               if (rule->sr_netid == LNET_NET_ANY) {
+                       CERROR("invalid network name: %s\n", param);
+                       RETURN(-EINVAL);
+               }
+       }
 
-        /* 1.2 direction */
-        if (dir) {
-                if (!strcmp(dir, "mdt2ost")) {
-                        rule->sr_from = LUSTRE_SP_MDT;
-                        rule->sr_to = LUSTRE_SP_OST;
-                } else if (!strcmp(dir, "mdt2mdt")) {
-                        rule->sr_from = LUSTRE_SP_MDT;
-                        rule->sr_to = LUSTRE_SP_MDT;
-                } else if (!strcmp(dir, "cli2ost")) {
-                        rule->sr_from = LUSTRE_SP_CLI;
-                        rule->sr_to = LUSTRE_SP_OST;
-                } else if (!strcmp(dir, "cli2mdt")) {
-                        rule->sr_from = LUSTRE_SP_CLI;
-                        rule->sr_to = LUSTRE_SP_MDT;
-                } else {
-                        CERROR("invalid rule dir segment: %s\n", dir);
-                        RETURN(-EINVAL);
-                }
-        }
+       /* 1.2 direction */
+       if (dir) {
+               if (!strcmp(dir, "mdt2ost")) {
+                       rule->sr_from = LUSTRE_SP_MDT;
+                       rule->sr_to = LUSTRE_SP_OST;
+               } else if (!strcmp(dir, "mdt2mdt")) {
+                       rule->sr_from = LUSTRE_SP_MDT;
+                       rule->sr_to = LUSTRE_SP_MDT;
+               } else if (!strcmp(dir, "cli2ost")) {
+                       rule->sr_from = LUSTRE_SP_CLI;
+                       rule->sr_to = LUSTRE_SP_OST;
+               } else if (!strcmp(dir, "cli2mdt")) {
+                       rule->sr_from = LUSTRE_SP_CLI;
+                       rule->sr_to = LUSTRE_SP_MDT;
+               } else {
+                       CERROR("invalid rule dir segment: %s\n", dir);
+                       RETURN(-EINVAL);
+               }
+       }
 
-        /* 2.1 flavor */
-        rc = sptlrpc_parse_flavor(flavor, &rule->sr_flvr);
-        if (rc)
-                RETURN(-EINVAL);
+       /* 2.1 flavor */
+       rc = sptlrpc_parse_flavor(flavor, &rule->sr_flvr);
+       if (rc)
+               RETURN(-EINVAL);
 
-        RETURN(0);
+       RETURN(0);
 }
 EXPORT_SYMBOL(sptlrpc_parse_rule);
 
 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
 {
-        LASSERT(rset->srs_nslot ||
-                (rset->srs_nrule == 0 && rset->srs_rules == NULL));
+       LASSERT(rset->srs_nslot ||
+               (rset->srs_nrule == 0 && rset->srs_rules == NULL));
 
-        if (rset->srs_nslot) {
-                OBD_FREE(rset->srs_rules,
-                         rset->srs_nslot * sizeof(*rset->srs_rules));
-                sptlrpc_rule_set_init(rset);
-        }
+       if (rset->srs_nslot) {
+               OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
+               sptlrpc_rule_set_init(rset);
+       }
 }
 EXPORT_SYMBOL(sptlrpc_rule_set_free);
 
@@ -263,43 +261,42 @@ int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
 
        nslot = rset->srs_nslot + 8;
 
-        /* better use realloc() if available */
-        OBD_ALLOC(rules, nslot * sizeof(*rset->srs_rules));
-        if (rules == NULL)
-                return -ENOMEM;
+       /* better use realloc() if available */
+       OBD_ALLOC_PTR_ARRAY(rules, nslot);
+       if (rules == NULL)
+               return -ENOMEM;
 
-        if (rset->srs_nrule) {
-                LASSERT(rset->srs_nslot && rset->srs_rules);
-                memcpy(rules, rset->srs_rules,
-                       rset->srs_nrule * sizeof(*rset->srs_rules));
+       if (rset->srs_nrule) {
+               LASSERT(rset->srs_nslot && rset->srs_rules);
+               memcpy(rules, rset->srs_rules,
+                      rset->srs_nrule * sizeof(*rset->srs_rules));
 
-                OBD_FREE(rset->srs_rules,
-                         rset->srs_nslot * sizeof(*rset->srs_rules));
-        }
+               OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
+       }
 
-        rset->srs_rules = rules;
-        rset->srs_nslot = nslot;
-        return 0;
+       rset->srs_rules = rules;
+       rset->srs_nslot = nslot;
+       return 0;
 }
 
 static inline int rule_spec_dir(struct sptlrpc_rule *rule)
 {
-        return (rule->sr_from != LUSTRE_SP_ANY ||
-                rule->sr_to != LUSTRE_SP_ANY);
+       return (rule->sr_from != LUSTRE_SP_ANY ||
+               rule->sr_to != LUSTRE_SP_ANY);
 }
 static inline int rule_spec_net(struct sptlrpc_rule *rule)
 {
-        return (rule->sr_netid != LNET_NIDNET(LNET_NID_ANY));
+       return (rule->sr_netid != LNET_NET_ANY);
 }
 static inline int rule_match_dir(struct sptlrpc_rule *r1,
                                  struct sptlrpc_rule *r2)
 {
-        return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
+       return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
 }
 static inline int rule_match_net(struct sptlrpc_rule *r1,
                                  struct sptlrpc_rule *r2)
 {
-        return (r1->sr_netid == r2->sr_netid);
+       return (r1->sr_netid == r2->sr_netid);
 }
 
 /*
@@ -398,35 +395,35 @@ EXPORT_SYMBOL(sptlrpc_rule_set_merge);
  * return 1 if a match found, otherwise return 0.
  */
 int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
-                            enum lustre_sec_part from,
-                            enum lustre_sec_part to,
-                            lnet_nid_t nid,
-                            struct sptlrpc_flavor *sf)
+                           enum lustre_sec_part from,
+                           enum lustre_sec_part to,
+                           lnet_nid_t nid,
+                           struct sptlrpc_flavor *sf)
 {
-        struct sptlrpc_rule    *r;
-        int                     n;
+       struct sptlrpc_rule *r;
+       int n;
 
-        for (n = 0; n < rset->srs_nrule; n++) {
-                r = &rset->srs_rules[n];
+       for (n = 0; n < rset->srs_nrule; n++) {
+               r = &rset->srs_rules[n];
 
-                if (LNET_NIDNET(nid) != LNET_NIDNET(LNET_NID_ANY) &&
-                    r->sr_netid != LNET_NIDNET(LNET_NID_ANY) &&
-                    LNET_NIDNET(nid) != r->sr_netid)
-                        continue;
+               if (LNET_NIDNET(nid) != LNET_NET_ANY &&
+                   r->sr_netid != LNET_NET_ANY &&
+                   LNET_NIDNET(nid) != r->sr_netid)
+                       continue;
 
-                if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
-                    from != r->sr_from)
-                        continue;
+               if (from != LUSTRE_SP_ANY && r->sr_from != LUSTRE_SP_ANY &&
+                   from != r->sr_from)
+                       continue;
 
-                if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
-                    to != r->sr_to)
-                        continue;
+               if (to != LUSTRE_SP_ANY && r->sr_to != LUSTRE_SP_ANY &&
+                   to != r->sr_to)
+                       continue;
 
-                *sf = r->sr_flvr;
-                return 1;
-        }
+               *sf = r->sr_flvr;
+               return 1;
+       }
 
-        return 0;
+       return 0;
 }
 
 void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
@@ -897,8 +894,9 @@ void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
  */
 void sptlrpc_conf_client_adapt(struct obd_device *obd)
 {
-        struct obd_import  *imp;
-        ENTRY;
+       struct obd_import  *imp;
+       int rc;
+       ENTRY;
 
        LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
                strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
@@ -907,10 +905,7 @@ void sptlrpc_conf_client_adapt(struct obd_device *obd)
        CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
 
        /* serialize with connect/disconnect import */
-       down_read_nested(&obd->u.cli.cl_sem, OBD_CLI_SEM_MDCOSC);
-
-       imp = obd->u.cli.cl_import;
-       if (imp) {
+       with_imp_locked_nested(obd, imp, rc, OBD_CLI_SEM_MDCOSC) {
                write_lock(&imp->imp_sec_lock);
                if (imp->imp_sec)
                        imp->imp_sec_expire = ktime_get_real_seconds() +
@@ -918,7 +913,6 @@ void sptlrpc_conf_client_adapt(struct obd_device *obd)
                write_unlock(&imp->imp_sec_lock);
        }
 
-       up_read(&obd->u.cli.cl_sem);
        EXIT;
 }
 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);