Whamcloud - gitweb
LU-3335 scrub: OI scrub on OST
[fs/lustre-release.git] / lustre / ptlrpc / sec_config.c
index 946f922..e1c25d3 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.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
-#ifndef EXPORT_SYMTAB
-#define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_SEC
 
 #include <libcfs/libcfs.h>
@@ -270,7 +267,7 @@ int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
         struct sptlrpc_rule *rules;
         int nslot;
 
-        might_sleep();
+        cfs_might_sleep();
 
         if (rset->srs_nrule < rset->srs_nslot)
                 return 0; 
@@ -328,7 +325,7 @@ int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
         int                       spec_dir, spec_net;
         int                       rc, n, match = 0;
 
-        might_sleep();
+        cfs_might_sleep();
 
         spec_net = rule_spec_net(rule);
         spec_dir = rule_spec_dir(rule);
@@ -452,8 +449,8 @@ void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
 
         for (n = 0; n < rset->srs_nrule; n++) {
                 r = &rset->srs_rules[n];
-                CWARN("<%02d> from %x to %x, net %x, rpc %x\n", n,
-                      r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
+                CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
+                       r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
         }
 }
 EXPORT_SYMBOL(sptlrpc_rule_set_dump);
@@ -468,7 +465,7 @@ static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
         struct sptlrpc_rule     *rule;
         int                      i, n, rc;
 
-        might_sleep();
+        cfs_might_sleep();
 
         /* merge general rules firstly, then target-specific rules */
         for (i = 0; i < 2; i++) {
@@ -503,19 +500,19 @@ static int sptlrpc_rule_set_extract(struct sptlrpc_rule_set *gen,
  **********************************/
 
 struct sptlrpc_conf_tgt {
-        struct list_head        sct_list;
+        cfs_list_t              sct_list;
         char                    sct_name[MAX_OBD_NAME];
         struct sptlrpc_rule_set sct_rset;
 };
 
 struct sptlrpc_conf {
-        struct list_head        sc_list;
+        cfs_list_t              sc_list;
         char                    sc_fsname[MTI_NAME_MAXLEN];
         unsigned int            sc_modified;  /* modified during updating */
         unsigned int            sc_updated:1, /* updated copy from MGS */
                                 sc_local:1;   /* local copy from target */
         struct sptlrpc_rule_set sc_rset;      /* fs general rules */
-        struct list_head        sc_tgts;      /* target-specific rules */
+        cfs_list_t              sc_tgts;      /* target-specific rules */
 };
 
 static struct mutex sptlrpc_conf_lock;
@@ -558,13 +555,13 @@ static void sptlrpc_conf_free_rsets(struct sptlrpc_conf *conf)
 
         sptlrpc_rule_set_free(&conf->sc_rset);
 
-        list_for_each_entry_safe(conf_tgt, conf_tgt_next,
-                                 &conf->sc_tgts, sct_list) {
+        cfs_list_for_each_entry_safe(conf_tgt, conf_tgt_next,
+                                     &conf->sc_tgts, sct_list) {
                 sptlrpc_rule_set_free(&conf_tgt->sct_rset);
-                list_del(&conf_tgt->sct_list);
+                cfs_list_del(&conf_tgt->sct_list);
                 OBD_FREE_PTR(conf_tgt);
         }
-        LASSERT(list_empty(&conf->sc_tgts));
+        LASSERT(cfs_list_empty(&conf->sc_tgts));
 
         conf->sc_updated = 0;
         conf->sc_local = 0;
@@ -575,7 +572,7 @@ static void sptlrpc_conf_free(struct sptlrpc_conf *conf)
         CDEBUG(D_SEC, "free sptlrpc conf %s\n", conf->sc_fsname);
 
         sptlrpc_conf_free_rsets(conf);
-        list_del(&conf->sc_list);
+        cfs_list_del(&conf->sc_list);
         OBD_FREE_PTR(conf);
 }
 
@@ -586,7 +583,7 @@ struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
 {
         struct sptlrpc_conf_tgt *conf_tgt;
 
-        list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
+        cfs_list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
                 if (strcmp(conf_tgt->sct_name, name) == 0)
                         return conf_tgt;
         }
@@ -596,9 +593,9 @@ struct sptlrpc_conf_tgt *sptlrpc_conf_get_tgt(struct sptlrpc_conf *conf,
 
         OBD_ALLOC_PTR(conf_tgt);
         if (conf_tgt) {
-                strncpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
+               strlcpy(conf_tgt->sct_name, name, sizeof(conf_tgt->sct_name));
                 sptlrpc_rule_set_init(&conf_tgt->sct_rset);
-                list_add(&conf_tgt->sct_list, &conf->sc_tgts);
+                cfs_list_add(&conf_tgt->sct_list, &conf->sc_tgts);
         }
 
         return conf_tgt;
@@ -610,7 +607,7 @@ struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
 {
         struct sptlrpc_conf *conf;
 
-        list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
+        cfs_list_for_each_entry(conf, &sptlrpc_confs, sc_list) {
                 if (strcmp(conf->sc_fsname, fsname) == 0)
                         return conf;
         }
@@ -625,7 +622,7 @@ struct sptlrpc_conf *sptlrpc_conf_get(const char *fsname,
         strcpy(conf->sc_fsname, fsname);
         sptlrpc_rule_set_init(&conf->sc_rset);
         CFS_INIT_LIST_HEAD(&conf->sc_tgts);
-        list_add(&conf->sc_list, &sptlrpc_confs);
+        cfs_list_add(&conf->sc_list, &sptlrpc_confs);
 
         CDEBUG(D_SEC, "create sptlrpc conf %s\n", conf->sc_fsname);
         return conf;
@@ -699,7 +696,7 @@ static int __sptlrpc_process_config(struct lustre_cfg *lcfg,
         if (conf == NULL) {
                 target2fsname(target, fsname, sizeof(fsname));
 
-                mutex_lock(&sptlrpc_conf_lock);
+               mutex_lock(&sptlrpc_conf_lock);
                 conf = sptlrpc_conf_get(fsname, 0);
                 if (conf == NULL) {
                         CERROR("can't find conf\n");
@@ -707,9 +704,9 @@ static int __sptlrpc_process_config(struct lustre_cfg *lcfg,
                 } else {
                         rc = sptlrpc_conf_merge_rule(conf, target, &rule);
                 }
-                mutex_unlock(&sptlrpc_conf_lock);
+               mutex_unlock(&sptlrpc_conf_lock);
         } else {
-                LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
+               LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
                 rc = sptlrpc_conf_merge_rule(conf, target, &rule);
         }
 
@@ -751,7 +748,7 @@ void sptlrpc_conf_log_update_begin(const char *logname)
         if (logname2fsname(logname, fsname, sizeof(fsname)))
                 return;
 
-        mutex_lock(&sptlrpc_conf_lock);
+       mutex_lock(&sptlrpc_conf_lock);
 
         conf = sptlrpc_conf_get(fsname, 0);
         if (conf && conf->sc_local) {
@@ -760,7 +757,7 @@ void sptlrpc_conf_log_update_begin(const char *logname)
         }
         conf->sc_modified = 0;
 
-        mutex_unlock(&sptlrpc_conf_lock);
+       mutex_unlock(&sptlrpc_conf_lock);
 }
 EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
 
@@ -775,7 +772,7 @@ void sptlrpc_conf_log_update_end(const char *logname)
         if (logname2fsname(logname, fsname, sizeof(fsname)))
                 return;
 
-        mutex_lock(&sptlrpc_conf_lock);
+       mutex_lock(&sptlrpc_conf_lock);
 
         conf = sptlrpc_conf_get(fsname, 0);
         if (conf) {
@@ -789,21 +786,20 @@ void sptlrpc_conf_log_update_end(const char *logname)
                 conf->sc_updated = 1;
         }
 
-        mutex_unlock(&sptlrpc_conf_lock);
+       mutex_unlock(&sptlrpc_conf_lock);
 }
 EXPORT_SYMBOL(sptlrpc_conf_log_update_end);
 
 void sptlrpc_conf_log_start(const char *logname)
 {
-        struct sptlrpc_conf *conf;
         char                 fsname[16];
 
         if (logname2fsname(logname, fsname, sizeof(fsname)))
                 return;
 
-        mutex_lock(&sptlrpc_conf_lock);
-        conf = sptlrpc_conf_get(fsname, 1);
-        mutex_unlock(&sptlrpc_conf_lock);
+       mutex_lock(&sptlrpc_conf_lock);
+        sptlrpc_conf_get(fsname, 1);
+       mutex_unlock(&sptlrpc_conf_lock);
 }
 EXPORT_SYMBOL(sptlrpc_conf_log_start);
 
@@ -815,11 +811,11 @@ void sptlrpc_conf_log_stop(const char *logname)
         if (logname2fsname(logname, fsname, sizeof(fsname)))
                 return;
 
-        mutex_lock(&sptlrpc_conf_lock);
+       mutex_lock(&sptlrpc_conf_lock);
         conf = sptlrpc_conf_get(fsname, 0);
         if (conf)
                 sptlrpc_conf_free(conf);
-        mutex_unlock(&sptlrpc_conf_lock);
+       mutex_unlock(&sptlrpc_conf_lock);
 }
 EXPORT_SYMBOL(sptlrpc_conf_log_stop);
 
@@ -861,7 +857,7 @@ void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
 
         target2fsname(target->uuid, name, sizeof(name));
 
-        mutex_lock(&sptlrpc_conf_lock);
+       mutex_lock(&sptlrpc_conf_lock);
 
         conf = sptlrpc_conf_get(name, 0);
         if (conf == NULL)
@@ -883,7 +879,7 @@ void sptlrpc_conf_choose_flavor(enum lustre_sec_part from,
 
         rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to, nid, sf);
 out:
-        mutex_unlock(&sptlrpc_conf_lock);
+       mutex_unlock(&sptlrpc_conf_lock);
 
         if (rc == 0)
                 get_default_flavor(sf);
@@ -921,19 +917,19 @@ 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(&obd->u.cli.cl_sem);
-
-        imp = obd->u.cli.cl_import;
-        if (imp) {
-                spin_lock(&imp->imp_lock);
-                if (imp->imp_sec)
-                        imp->imp_sec_expire = cfs_time_current_sec() +
-                                              SEC_ADAPT_DELAY;
-                spin_unlock(&imp->imp_lock);
-        }
-
-        up_read(&obd->u.cli.cl_sem);
-        EXIT;
+       down_read(&obd->u.cli.cl_sem);
+
+       imp = obd->u.cli.cl_import;
+       if (imp) {
+               spin_lock(&imp->imp_lock);
+               if (imp->imp_sec)
+                       imp->imp_sec_expire = cfs_time_current_sec() +
+                               SEC_ADAPT_DELAY;
+               spin_unlock(&imp->imp_lock);
+       }
+
+       up_read(&obd->u.cli.cl_sem);
+       EXIT;
 }
 EXPORT_SYMBOL(sptlrpc_conf_client_adapt);
 
@@ -987,7 +983,7 @@ static int sptlrpc_record_rule_set(struct llog_handle *llh,
                                         lcfg->lcfg_buflens);
                 rec.lrh_len = llog_data_len(buflen);
                 rec.lrh_type = OBD_CFG_REC;
-                rc = llog_write_rec(llh, &rec, NULL, 0, (void *)lcfg, -1);
+               rc = llog_write(NULL, llh, &rec, NULL, 0, (void *)lcfg, -1);
                 if (rc)
                         CERROR("failed to write a rec: rc = %d\n", rc);
                 lustre_cfg_free(lcfg);
@@ -1002,7 +998,7 @@ static int sptlrpc_record_rules(struct llog_handle *llh,
 
         sptlrpc_record_rule_set(llh, conf->sc_fsname, &conf->sc_rset);
 
-        list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
+        cfs_list_for_each_entry(conf_tgt, &conf->sc_tgts, sct_list) {
                 sptlrpc_record_rule_set(llh, conf_tgt->sct_name,
                                         &conf_tgt->sct_rset);
         }
@@ -1024,15 +1020,13 @@ int sptlrpc_target_local_copy_conf(struct obd_device *obd,
         ENTRY;
 
         ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
-        if (ctxt == NULL) {
-                CERROR("missing llog context\n");
+       if (ctxt == NULL)
                 RETURN(-EINVAL);
-        }
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
 
-        dentry = lookup_one_len(MOUNT_CONFIGS_DIR, cfs_fs_pwd(current->fs),
-                                strlen(MOUNT_CONFIGS_DIR));
+        dentry = ll_lookup_one_len(MOUNT_CONFIGS_DIR, cfs_fs_pwd(current->fs),
+                                   strlen(MOUNT_CONFIGS_DIR));
         if (IS_ERR(dentry)) {
                 rc = PTR_ERR(dentry);
                 CERROR("cannot lookup %s directory: rc = %d\n",
@@ -1041,41 +1035,28 @@ int sptlrpc_target_local_copy_conf(struct obd_device *obd,
         }
 
         /* erase the old tmp log */
-        rc = llog_create(ctxt, &llh, NULL, LOG_SPTLRPC_TMP);
-        if (rc == 0) {
-                rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
-                if (rc == 0) {
-                        rc = llog_destroy(llh);
-                        llog_free_handle(llh);
-                } else {
-                        llog_close(llh);
-                }
-        }
-
-        if (rc) {
-                CERROR("target %s: cannot erase temporary sptlrpc log: "
-                       "rc = %d\n", obd->obd_name, rc);
-                GOTO(out_dput, rc);
-        }
-
-        /* write temporary log */
-        rc = llog_create(ctxt, &llh, NULL, LOG_SPTLRPC_TMP);
-        if (rc)
-                GOTO(out_dput, rc);
-        rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
+       rc = llog_erase(NULL, ctxt, NULL, LOG_SPTLRPC_TMP);
+       if (rc < 0 && rc != -ENOENT) {
+               CERROR("%s: cannot erase temporary sptlrpc log: rc = %d\n",
+                      obd->obd_name, rc);
+               GOTO(out_dput, rc);
+       }
+
+       /* write temporary log */
+       rc = llog_open_create(NULL, ctxt, &llh, NULL, LOG_SPTLRPC_TMP);
+       if (rc)
+               GOTO(out_dput, rc);
+       rc = llog_init_handle(NULL, llh, LLOG_F_IS_PLAIN, NULL);
         if (rc)
                 GOTO(out_close, rc);
 
         rc = sptlrpc_record_rules(llh, conf);
 
 out_close:
-        llog_close(llh);
-
-        if (rc == 0) {
-                rc = lustre_rename(dentry, obd->obd_lvfs_ctxt.pwdmnt,
-                                   LOG_SPTLRPC_TMP, LOG_SPTLRPC);
-        }
-
+       llog_close(NULL, llh);
+       if (rc == 0)
+               rc = lustre_rename(dentry, obd->obd_lvfs_ctxt.pwdmnt,
+                                  LOG_SPTLRPC_TMP, LOG_SPTLRPC);
 out_dput:
         l_dput(dentry);
 out_ctx:
@@ -1086,9 +1067,9 @@ out_ctx:
         RETURN(rc);
 }
 
-static int local_read_handler(struct llog_handle *llh,
-                              struct llog_rec_hdr *rec,
-                              void *data)
+static int local_read_handler(const struct lu_env *env,
+                             struct llog_handle *llh,
+                             struct llog_rec_hdr *rec, void *data)
 {
         struct sptlrpc_conf  *conf = (struct sptlrpc_conf *) data;
         struct lustre_cfg    *lcfg = (struct lustre_cfg *)(rec + 1);
@@ -1137,11 +1118,14 @@ int sptlrpc_target_local_read_conf(struct obd_device *obd,
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
 
-        rc = llog_create(ctxt, &llh, NULL, LOG_SPTLRPC);
-        if (rc)
-                GOTO(out_pop, rc);
+       rc = llog_open(NULL, ctxt, &llh, NULL, LOG_SPTLRPC, LLOG_OPEN_EXISTS);
+       if (rc < 0) {
+               if (rc == -ENOENT)
+                       rc = 0;
+               GOTO(out_pop, rc);
+       }
 
-        rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
+       rc = llog_init_handle(NULL, llh, LLOG_F_IS_PLAIN, NULL);
         if (rc)
                 GOTO(out_close, rc);
 
@@ -1150,7 +1134,7 @@ int sptlrpc_target_local_read_conf(struct obd_device *obd,
                 GOTO(out_close, rc = 0);
         }
 
-        rc = llog_process(llh, local_read_handler, (void *) conf, NULL);
+       rc = llog_process(NULL, llh, local_read_handler, (void *)conf, NULL);
 
         if (rc == 0) {
                 conf->sc_local = 1;
@@ -1159,7 +1143,7 @@ int sptlrpc_target_local_read_conf(struct obd_device *obd,
         }
 
 out_close:
-        llog_close(llh);
+       llog_close(NULL, llh);
 out_pop:
         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
         llog_ctxt_put(ctxt);
@@ -1197,7 +1181,7 @@ int sptlrpc_conf_target_get_rules(struct obd_device *obd,
 
         target2fsname(obd->obd_uuid.uuid, fsname, sizeof(fsname));
 
-        mutex_lock(&sptlrpc_conf_lock);
+       mutex_lock(&sptlrpc_conf_lock);
 
         conf = sptlrpc_conf_get(fsname, 0);
         if (conf == NULL) {
@@ -1234,14 +1218,14 @@ int sptlrpc_conf_target_get_rules(struct obd_device *obd,
                                       conf_tgt ? &conf_tgt->sct_rset: NULL,
                                       LUSTRE_SP_ANY, sp_dst, rset);
 out:
-        mutex_unlock(&sptlrpc_conf_lock);
+       mutex_unlock(&sptlrpc_conf_lock);
         RETURN(rc);
 }
 EXPORT_SYMBOL(sptlrpc_conf_target_get_rules);
 
 int  sptlrpc_conf_init(void)
 {
-        mutex_init(&sptlrpc_conf_lock);
+       mutex_init(&sptlrpc_conf_lock);
         return 0;
 }
 
@@ -1249,10 +1233,10 @@ void sptlrpc_conf_fini(void)
 {
         struct sptlrpc_conf  *conf, *conf_next;
 
-        mutex_lock(&sptlrpc_conf_lock);
-        list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list) {
+       mutex_lock(&sptlrpc_conf_lock);
+        cfs_list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list) {
                 sptlrpc_conf_free(conf);
         }
-        LASSERT(list_empty(&sptlrpc_confs));
-        mutex_unlock(&sptlrpc_conf_lock);
+        LASSERT(cfs_list_empty(&sptlrpc_confs));
+       mutex_unlock(&sptlrpc_conf_lock);
 }