Whamcloud - gitweb
New release 2.15.64
[fs/lustre-release.git] / lustre / include / lustre_nrs_tbf.h
index 0e5c929..738794a 100644 (file)
 struct nrs_tbf_head;
 struct nrs_tbf_cmd;
 
+#define NRS_TBF_MATCH_FULL     0x0000001
+#define NRS_TBF_MATCH_WILDCARD 0x0000002
+
 struct nrs_tbf_jobid {
        char            *tj_id;
+       __u32            tj_match_flag;
        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,
+};
+
+struct tbf_id {
+       enum nrs_tbf_flag       ti_type;
+       u32                     ti_uid;
+       u32                     ti_gid;
+};
+
+struct nrs_tbf_id {
+       struct tbf_id           nti_id;
+       struct list_head        nti_linkage;
+};
+
 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. */
-       lnet_nid_t                       tc_nid;
+       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];
        /** Reference number of the client. */
-       atomic_t                         tc_ref;
+       refcount_t                       tc_ref;
        /** Lock to protect rule and linkage. */
        spinlock_t                       tc_rule_lock;
        /** Linkage to rule. */
@@ -76,10 +112,17 @@ struct nrs_tbf_client {
        __u64                            tc_depth;
        /** Time check-point. */
        __u64                            tc_check_time;
+       /** Deadline of a class */
+       __u64                            tc_deadline;
+       /**
+        * Time residue: the remainder of elapsed time
+        * divided by nsecs when dequeue a request.
+        */
+       __u64                            tc_nsecs_resid;
        /** List of queued requests. */
        struct list_head                 tc_list;
        /** Node in binary heap. */
-       struct cfs_binheap_node          tc_node;
+       struct binheap_node              tc_node;
        /** Whether the client is in heap. */
        bool                             tc_in_heap;
        /** Sequence of the newest rule. */
@@ -89,12 +132,19 @@ struct nrs_tbf_client {
         * nrs_tbf_head::th_cli_hash.
         */
        struct list_head                 tc_lru;
+       /**
+        * RCU head for rhashtable handling
+        */
+       struct rcu_head                  tc_rcu_head;
 };
 
 #define MAX_TBF_NAME (16)
 
-#define NTRS_STOPPING  0x0000001
-#define NTRS_DEFAULT   0x0000002
+enum nrs_rule_flags {
+       NTRS_STOPPING   = 0x00000001,
+       NTRS_DEFAULT    = 0x00000002,
+       NTRS_REALTIME   = 0x00000004,
+};
 
 struct nrs_tbf_rule {
        /** Name of the rule. */
@@ -111,10 +161,23 @@ struct nrs_tbf_rule {
        struct list_head                 tr_jobids;
        /** Jobid list string of the rule.*/
        char                            *tr_jobids_str;
+       /** uid/gid list of the rule. */
+       struct list_head                tr_ids;
+       /** uid/gid list string of the rule. */
+       char                            *tr_ids_str;
+       /** Opcode bitmap of the rule. */
+       unsigned long                   *tr_opcodes;
+       u32                             tr_opcodes_cnt;
+       /** Opcode list string of the rule.*/
+       char                            *tr_opcodes_str;
+       /** Condition list of the rule.*/
+       struct list_head                tr_conds;
+       /** Generic condition string of the rule. */
+       char                            *tr_conds_str;
        /** RPC/s limit. */
        __u64                            tr_rpc_rate;
        /** Time to wait for next token. */
-       __u64                            tr_nsecs;
+       u64                              tr_nsecs_per_rpc;
        /** Token bucket depth. */
        __u64                            tr_depth;
        /** Lock to protect the list of clients. */
@@ -122,7 +185,7 @@ struct nrs_tbf_rule {
        /** List of client. */
        struct list_head                 tr_cli_list;
        /** Flags of the rule. */
-       __u32                            tr_flags;
+       enum nrs_rule_flags              tr_flags;
        /** Usage Reference count taken on the rule. */
        atomic_t                         tr_ref;
        /** Generation of the rule. */
@@ -149,10 +212,17 @@ struct nrs_tbf_ops {
 
 #define NRS_TBF_TYPE_JOBID     "jobid"
 #define NRS_TBF_TYPE_NID       "nid"
+#define NRS_TBF_TYPE_OPCODE    "opcode"
+#define NRS_TBF_TYPE_GENERIC   "generic"
+#define NRS_TBF_TYPE_UID       "uid"
+#define NRS_TBF_TYPE_GID       "gid"
 #define NRS_TBF_TYPE_MAX_LEN   20
-#define NRS_TBF_FLAG_INVALID   0
-#define NRS_TBF_FLAG_JOBID     0x0000001
-#define NRS_TBF_FLAG_NID       0x0000002
+
+struct nrs_tbf_type {
+       const char              *ntt_name;
+       enum nrs_tbf_flag        ntt_flag;
+       struct nrs_tbf_ops      *ntt_ops;
+};
 
 struct nrs_tbf_bucket {
        /**
@@ -171,6 +241,10 @@ struct nrs_tbf_head {
         */
        struct ptlrpc_nrs_resource       th_res;
        /**
+        * Hash of clients.
+        */
+       struct rhashtable                th_cli_rhash ____cacheline_aligned_in_smp;
+       /**
         * List of rules.
         */
        struct list_head                 th_list;
@@ -201,7 +275,7 @@ struct nrs_tbf_head {
        /**
         * Heap of queues.
         */
-       struct cfs_binheap              *th_binheap;
+       struct binheap                  *th_binheap;
        /**
         * Hash of clients.
         */
@@ -240,8 +314,13 @@ struct nrs_tbf_cmd {
                        char                    *ts_nids_str;
                        struct list_head         ts_jobids;
                        char                    *ts_jobids_str;
+                       struct list_head         ts_ids;
+                       char                    *ts_ids_str;
+                       char                    *ts_opcodes_str;
+                       struct list_head         ts_conds;
+                       char                    *ts_conds_str;
                        __u32                    ts_valid_type;
-                       __u32                    ts_rule_flags;
+                       enum nrs_rule_flags      ts_rule_flags;
                        char                    *ts_next_name;
                } tc_start;
                struct nrs_tbf_cmd_change {
@@ -251,6 +330,34 @@ struct nrs_tbf_cmd {
        } u;
 };
 
+enum nrs_tbf_field {
+       NRS_TBF_FIELD_NID,
+       NRS_TBF_FIELD_JOBID,
+       NRS_TBF_FIELD_OPCODE,
+       NRS_TBF_FIELD_UID,
+       NRS_TBF_FIELD_GID,
+       NRS_TBF_FIELD_MAX
+};
+
+struct nrs_tbf_expression {
+       enum nrs_tbf_field       te_field;
+       struct list_head         te_cond;
+       unsigned long           *te_opcodes;
+       u32                      te_opcodes_cnt;
+       struct list_head         te_linkage;
+};
+
+struct nrs_tbf_conjunction {
+       /**
+        * link to disjunction.
+        */
+       struct list_head tc_linkage;
+       /**
+        * list of logical conjunction
+        */
+       struct list_head tc_expressions;
+};
+
 struct nrs_tbf_req {
        /**
         * Linkage to queue.
@@ -264,21 +371,18 @@ struct nrs_tbf_req {
 
 /**
  * TBF policy operations.
+ *
+ * Read the the data of a TBF policy.
  */
-enum nrs_ctl_tbf {
-       /**
-        * Read the the data of a TBF policy.
-        */
-       NRS_CTL_TBF_RD_RULE = PTLRPC_NRS_CTL_1ST_POL_SPEC,
-       /**
-        * Write the the data of a TBF policy.
-        */
-       NRS_CTL_TBF_WR_RULE,
-       /**
-        * Read the TBF policy type preset by proc entry "nrs_policies".
-        */
-       NRS_CTL_TBF_RD_TYPE_FLAG,
-};
+#define NRS_CTL_TBF_RD_RULE PTLRPC_NRS_CTL_POL_SPEC_01
+/**
+ * Write the the data of a TBF policy.
+ */
+#define NRS_CTL_TBF_WR_RULE PTLRPC_NRS_CTL_POL_SPEC_02
+/**
+ * Read the TBF policy type preset by proc entry "nrs_policies".
+ */
+#define NRS_CTL_TBF_RD_TYPE_FLAG PTLRPC_NRS_CTL_POL_SPEC_03
 
 /** @} tbf */
 #endif