struct list_head tj_linkage;
};
-#define MAX_U32_STR_LEN 10
-#define NRS_TBF_KEY_LEN (LNET_NIDSTR_SIZE + LUSTRE_JOBID_SIZE + \
- MAX_U32_STR_LEN + MAX_U32_STR_LEN + 3 + 2)
-
enum nrs_tbf_flag {
- NRS_TBF_FLAG_INVALID = 0x0000000,
- NRS_TBF_FLAG_JOBID = 0x0000001,
- NRS_TBF_FLAG_NID = 0x0000002,
- NRS_TBF_FLAG_OPCODE = 0x0000004,
- NRS_TBF_FLAG_GENERIC = 0x0000008,
- NRS_TBF_FLAG_UID = 0x0000010,
- NRS_TBF_FLAG_GID = 0x0000020,
+ NRS_TBF_FLAG_INVALID = 0x0000000,
+ NRS_TBF_FLAG_JOBID = 0x0000001,
+ NRS_TBF_FLAG_NID = 0x0000002,
+ NRS_TBF_FLAG_OPCODE = 0x0000004,
+ NRS_TBF_FLAG_UID = 0x0000008,
+ NRS_TBF_FLAG_GID = 0x0000010,
+ NRS_TBF_FLAG_GENERIC = 0x0000020,
};
struct tbf_id {
struct list_head nti_linkage;
};
+struct nrs_tbf_key {
+ struct lnet_nid tk_nid;
+ __u32 tk_opcode;
+ struct tbf_id tk_id; /* UID and GID */
+ char tk_jobid[LUSTRE_JOBID_SIZE];
+};
+
struct nrs_tbf_client {
/** Resource object for policy instance. */
struct ptlrpc_nrs_resource tc_res;
/** Node in the hash table. */
struct rhash_head tc_rhash;
struct hlist_node tc_hnode;
- /** NID of the client. */
- struct lnet_nid tc_nid;
- /** Jobid of the client. */
- char tc_jobid[LUSTRE_JOBID_SIZE];
- /** opcode of the client. */
- __u32 tc_opcode;
- /** gid or uid of the client. */
- struct tbf_id tc_id;
- /** Hash key of the client. */
- char tc_key[NRS_TBF_KEY_LEN];
+ /** Key of the TBF cli. */
+ struct nrs_tbf_key tc_key;
/** Reference number of the client. */
refcount_t tc_ref;
/** Lock to protect rule and linkage. */
struct rcu_head tc_rcu_head;
};
+#define tc_nid tc_key.tk_nid
+#define tc_opcode tc_key.tk_opcode
+#define tc_id tc_key.tk_id
+#define tc_jobid tc_key.tk_jobid
+
#define MAX_TBF_NAME (16)
enum nrs_rule_flags {
nrs_tbf_hop_hash(struct cfs_hash *hs, const void *key,
const unsigned int bits)
{
- return cfs_hash_djb2_hash(key, strlen(key), bits);
+ return cfs_hash_djb2_hash(key, sizeof(struct nrs_tbf_key), bits);
}
-static int nrs_tbf_hop_keycmp(const void *key, struct hlist_node *hnode)
+static int nrs_tbf_hop_keycmp(const void *data, struct hlist_node *hnode)
{
+ struct nrs_tbf_key *key = (struct nrs_tbf_key *)data;
struct nrs_tbf_client *cli = hlist_entry(hnode,
struct nrs_tbf_client,
tc_hnode);
- return (strcmp(cli->tc_key, key) == 0);
+ return nid_same(&cli->tc_nid, &key->tk_nid) &&
+ cli->tc_opcode == key->tk_opcode &&
+ cli->tc_id.ti_uid == key->tk_id.ti_uid &&
+ cli->tc_id.ti_gid == key->tk_id.ti_gid &&
+ strcmp(cli->tc_jobid, key->tk_jobid) == 0;
}
static void *nrs_tbf_hop_key(struct hlist_node *hnode)
struct nrs_tbf_client *cli = hlist_entry(hnode,
struct nrs_tbf_client,
tc_hnode);
- return cli->tc_key;
+ return &cli->tc_key;
}
static void nrs_tbf_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
static struct nrs_tbf_client *
nrs_tbf_cli_hash_lookup(struct cfs_hash *hs, struct cfs_hash_bd *bd,
- const char *key)
+ struct nrs_tbf_key *key)
{
struct hlist_node *hnode;
struct nrs_tbf_client *cli;
- hnode = cfs_hash_bd_lookup_locked(hs, bd, (void *)key);
+ hnode = cfs_hash_bd_lookup_locked(hs, bd, key);
if (hnode == NULL)
return NULL;
return rc;
}
-static inline void nrs_tbf_cli_gen_key(struct nrs_tbf_client *cli,
- struct ptlrpc_request *req,
- char *keystr, size_t keystr_sz)
+static inline void nrs_tbf_cli_gen_key(struct ptlrpc_request *req,
+ struct nrs_tbf_key *key)
{
const char *jobid;
- u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
- struct tbf_id id;
- nrs_tbf_id_cli_set(req, &id, NRS_TBF_FLAG_UID | NRS_TBF_FLAG_GID);
+ key->tk_nid = req->rq_peer.nid;
+ key->tk_opcode = lustre_msg_get_opc(req->rq_reqmsg);
+ nrs_tbf_id_cli_set(req, &key->tk_id, NRS_TBF_FLAG_UID | NRS_TBF_FLAG_GID);
+
jobid = lustre_msg_get_jobid(req->rq_reqmsg);
if (jobid == NULL)
jobid = NRS_TBF_JOBID_NULL;
-
- snprintf(keystr, keystr_sz, "%s_%s_%d_%u_%u", jobid,
- libcfs_nidstr(&req->rq_peer.nid), opc, id.ti_uid,
- id.ti_gid);
-
- if (cli) {
- INIT_LIST_HEAD(&cli->tc_lru);
- strscpy(cli->tc_key, keystr, sizeof(cli->tc_key));
- strscpy(cli->tc_jobid, jobid, sizeof(cli->tc_jobid));
- cli->tc_nid = req->rq_peer.nid;
- cli->tc_opcode = opc;
- cli->tc_id = id;
- }
+ strscpy(key->tk_jobid, jobid, sizeof(key->tk_jobid));
}
static struct nrs_tbf_client *
struct nrs_tbf_client *cli;
struct cfs_hash *hs = head->th_cli_hash;
struct cfs_hash_bd bd;
- char keystr[NRS_TBF_KEY_LEN];
+ struct nrs_tbf_key key;
- nrs_tbf_cli_gen_key(NULL, req, keystr, sizeof(keystr));
- cfs_hash_bd_get_and_lock(hs, (void *)keystr, &bd, 1);
- cli = nrs_tbf_cli_hash_lookup(hs, &bd, keystr);
+ memset(&key, 0, sizeof(key));
+ nrs_tbf_cli_gen_key(req, &key);
+ cfs_hash_bd_get_and_lock(hs, &key, &bd, 1);
+ cli = nrs_tbf_cli_hash_lookup(hs, &bd, &key);
cfs_hash_bd_unlock(hs, &bd, 1);
return cli;
nrs_tbf_cli_findadd(struct nrs_tbf_head *head,
struct nrs_tbf_client *cli)
{
- const char *key;
+ struct nrs_tbf_key *key;
struct nrs_tbf_client *ret;
struct cfs_hash *hs = head->th_cli_hash;
struct cfs_hash_bd bd;
- key = cli->tc_key;
- cfs_hash_bd_get_and_lock(hs, (void *)key, &bd, 1);
+ key = &cli->tc_key;
+ cfs_hash_bd_get_and_lock(hs, key, &bd, 1);
ret = nrs_tbf_cli_hash_lookup(hs, &bd, key);
if (ret == NULL) {
cfs_hash_bd_add_locked(hs, &bd, &cli->tc_hnode);
nrs_tbf_generic_cli_init(struct nrs_tbf_client *cli,
struct ptlrpc_request *req)
{
- char keystr[NRS_TBF_KEY_LEN];
-
- nrs_tbf_cli_gen_key(cli, req, keystr, sizeof(keystr));
+ nrs_tbf_cli_gen_key(req, &cli->tc_key);
+ INIT_LIST_HEAD(&cli->tc_lru);
}
static void