-/* -*- 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.
/*
* 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>
*/
int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
{
- struct sptlrpc_rule *rules;
- int nslot;
+ struct sptlrpc_rule *rules;
+ int nslot;
- cfs_might_sleep();
+ might_sleep();
- if (rset->srs_nrule < rset->srs_nslot)
- return 0;
+ if (rset->srs_nrule < rset->srs_nslot)
+ return 0;
- nslot = rset->srs_nslot + 8;
+ nslot = rset->srs_nslot + 8;
/* better use realloc() if available */
OBD_ALLOC(rules, nslot * sizeof(*rset->srs_rules));
int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
struct sptlrpc_rule *rule)
{
- struct sptlrpc_rule *p = rset->srs_rules;
- int spec_dir, spec_net;
- int rc, n, match = 0;
+ struct sptlrpc_rule *p = rset->srs_rules;
+ int spec_dir, spec_net;
+ int rc, n, match = 0;
- cfs_might_sleep();
+ might_sleep();
- spec_net = rule_spec_net(rule);
- spec_dir = rule_spec_dir(rule);
+ spec_net = rule_spec_net(rule);
+ spec_dir = rule_spec_dir(rule);
for (n = 0; n < rset->srs_nrule; n++) {
p = &rset->srs_rules[n];
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);
enum lustre_sec_part to,
struct sptlrpc_rule_set *rset)
{
- struct sptlrpc_rule_set *src[2] = { gen, tgt };
- struct sptlrpc_rule *rule;
- int i, n, rc;
+ struct sptlrpc_rule_set *src[2] = { gen, tgt };
+ struct sptlrpc_rule *rule;
+ int i, n, rc;
- cfs_might_sleep();
+ might_sleep();
- /* merge general rules firstly, then target-specific rules */
- for (i = 0; i < 2; i++) {
- if (src[i] == NULL)
- continue;
+ /* merge general rules firstly, then target-specific rules */
+ for (i = 0; i < 2; i++) {
+ if (src[i] == NULL)
+ continue;
for (n = 0; n < src[i]->srs_nrule; n++) {
rule = &src[i]->srs_rules[n];
cfs_list_t sc_tgts; /* target-specific rules */
};
-static cfs_mutex_t sptlrpc_conf_lock;
+static struct mutex sptlrpc_conf_lock;
static CFS_LIST_HEAD(sptlrpc_confs);
static inline int is_hex(char c)
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);
cfs_list_add(&conf_tgt->sct_list, &conf->sc_tgts);
}
if (conf == NULL)
return NULL;
- strcpy(conf->sc_fsname, fsname);
+ if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
+ sizeof(conf->sc_fsname)) {
+ OBD_FREE_PTR(conf);
+ return NULL;
+ }
sptlrpc_rule_set_init(&conf->sc_rset);
CFS_INIT_LIST_HEAD(&conf->sc_tgts);
cfs_list_add(&conf->sc_list, &sptlrpc_confs);
if (conf == NULL) {
target2fsname(target, fsname, sizeof(fsname));
- cfs_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");
} else {
rc = sptlrpc_conf_merge_rule(conf, target, &rule);
}
- cfs_mutex_unlock(&sptlrpc_conf_lock);
+ mutex_unlock(&sptlrpc_conf_lock);
} else {
- LASSERT(cfs_mutex_is_locked(&sptlrpc_conf_lock));
+ LASSERT(mutex_is_locked(&sptlrpc_conf_lock));
rc = sptlrpc_conf_merge_rule(conf, target, &rule);
}
if (logname2fsname(logname, fsname, sizeof(fsname)))
return;
- cfs_mutex_lock(&sptlrpc_conf_lock);
+ mutex_lock(&sptlrpc_conf_lock);
conf = sptlrpc_conf_get(fsname, 0);
- if (conf && conf->sc_local) {
- LASSERT(conf->sc_updated == 0);
- sptlrpc_conf_free_rsets(conf);
- }
- conf->sc_modified = 0;
-
- cfs_mutex_unlock(&sptlrpc_conf_lock);
+ if (conf) {
+ if (conf->sc_local) {
+ LASSERT(conf->sc_updated == 0);
+ sptlrpc_conf_free_rsets(conf);
+ }
+ conf->sc_modified = 0;
+ }
+
+ mutex_unlock(&sptlrpc_conf_lock);
}
EXPORT_SYMBOL(sptlrpc_conf_log_update_begin);
if (logname2fsname(logname, fsname, sizeof(fsname)))
return;
- cfs_mutex_lock(&sptlrpc_conf_lock);
+ mutex_lock(&sptlrpc_conf_lock);
conf = sptlrpc_conf_get(fsname, 0);
if (conf) {
conf->sc_updated = 1;
}
- cfs_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;
- cfs_mutex_lock(&sptlrpc_conf_lock);
- conf = sptlrpc_conf_get(fsname, 1);
- cfs_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);
if (logname2fsname(logname, fsname, sizeof(fsname)))
return;
- cfs_mutex_lock(&sptlrpc_conf_lock);
+ mutex_lock(&sptlrpc_conf_lock);
conf = sptlrpc_conf_get(fsname, 0);
if (conf)
sptlrpc_conf_free(conf);
- cfs_mutex_unlock(&sptlrpc_conf_lock);
+ mutex_unlock(&sptlrpc_conf_lock);
}
EXPORT_SYMBOL(sptlrpc_conf_log_stop);
target2fsname(target->uuid, name, sizeof(name));
- cfs_mutex_lock(&sptlrpc_conf_lock);
+ mutex_lock(&sptlrpc_conf_lock);
conf = sptlrpc_conf_get(name, 0);
if (conf == NULL)
rc = sptlrpc_rule_set_choose(&conf->sc_rset, from, to, nid, sf);
out:
- cfs_mutex_unlock(&sptlrpc_conf_lock);
+ mutex_unlock(&sptlrpc_conf_lock);
if (rc == 0)
get_default_flavor(sf);
CDEBUG(D_SEC, "obd %s\n", obd->u.cli.cl_target_uuid.uuid);
/* serialize with connect/disconnect import */
- cfs_down_read(&obd->u.cli.cl_sem);
-
- imp = obd->u.cli.cl_import;
- if (imp) {
- cfs_spin_lock(&imp->imp_lock);
- if (imp->imp_sec)
- imp->imp_sec_expire = cfs_time_current_sec() +
- SEC_ADAPT_DELAY;
- cfs_spin_unlock(&imp->imp_lock);
- }
-
- cfs_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);
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);
int rc;
ENTRY;
- ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
- if (ctxt == NULL) {
- CERROR("missing llog context\n");
- RETURN(-EINVAL);
- }
+ ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
+ if (ctxt == NULL)
+ RETURN(-EINVAL);
- push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+ push_ctxt(&saved, &obd->obd_lvfs_ctxt);
- dentry = lookup_one_len(MOUNT_CONFIGS_DIR, cfs_fs_pwd(current->fs),
- strlen(MOUNT_CONFIGS_DIR));
+ dentry = ll_lookup_one_len(MOUNT_CONFIGS_DIR, current->fs->pwd.dentry,
+ strlen(MOUNT_CONFIGS_DIR));
if (IS_ERR(dentry)) {
rc = PTR_ERR(dentry);
CERROR("cannot lookup %s directory: rc = %d\n",
}
/* 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);
+ dput(dentry);
out_ctx:
- pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- llog_ctxt_put(ctxt);
- CDEBUG(D_SEC, "target %s: write local sptlrpc conf: rc = %d\n",
- obd->obd_name, rc);
- RETURN(rc);
+ pop_ctxt(&saved, &obd->obd_lvfs_ctxt);
+ llog_ctxt_put(ctxt);
+ CDEBUG(D_SEC, "target %s: write local sptlrpc conf: rc = %d\n",
+ obd->obd_name, rc);
+ 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);
RETURN(-EINVAL);
}
- push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
+ push_ctxt(&saved, &obd->obd_lvfs_ctxt);
- 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);
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;
}
out_close:
- llog_close(llh);
+ llog_close(NULL, llh);
out_pop:
- pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- llog_ctxt_put(ctxt);
- CDEBUG(D_SEC, "target %s: read local sptlrpc conf: rc = %d\n",
- obd->obd_name, rc);
- RETURN(rc);
+ pop_ctxt(&saved, &obd->obd_lvfs_ctxt);
+ llog_ctxt_put(ctxt);
+ CDEBUG(D_SEC, "target %s: read local sptlrpc conf: rc = %d\n",
+ obd->obd_name, rc);
+ RETURN(rc);
}
#endif /* __KRENEL__ */
target2fsname(obd->obd_uuid.uuid, fsname, sizeof(fsname));
- cfs_mutex_lock(&sptlrpc_conf_lock);
+ mutex_lock(&sptlrpc_conf_lock);
conf = sptlrpc_conf_get(fsname, 0);
if (conf == NULL) {
conf_tgt ? &conf_tgt->sct_rset: NULL,
LUSTRE_SP_ANY, sp_dst, rset);
out:
- cfs_mutex_unlock(&sptlrpc_conf_lock);
+ mutex_unlock(&sptlrpc_conf_lock);
RETURN(rc);
}
EXPORT_SYMBOL(sptlrpc_conf_target_get_rules);
int sptlrpc_conf_init(void)
{
- cfs_mutex_init(&sptlrpc_conf_lock);
+ mutex_init(&sptlrpc_conf_lock);
return 0;
}
{
struct sptlrpc_conf *conf, *conf_next;
- cfs_mutex_lock(&sptlrpc_conf_lock);
+ mutex_lock(&sptlrpc_conf_lock);
cfs_list_for_each_entry_safe(conf, conf_next, &sptlrpc_confs, sc_list) {
sptlrpc_conf_free(conf);
}
LASSERT(cfs_list_empty(&sptlrpc_confs));
- cfs_mutex_unlock(&sptlrpc_conf_lock);
+ mutex_unlock(&sptlrpc_conf_lock);
}