Whamcloud - gitweb
LU-4931 ladvise: Add dontneed advice support for ladvise
[fs/lustre-release.git] / lustre / include / lustre_nrs_tbf.h
index 57c0a99..0e5c929 100644 (file)
@@ -6,22 +6,22 @@
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 only,
  * as published by the Free Software Foundation.
-
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.  A copy is
- * included in the COPYING file that accompanied this code.
-
+ * GNU General Public License version 2 for more details.
+ *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
 /*
  * Copyright (C) 2013 DataDirect Networks, Inc.
  *
+ * Copyright (c) 2014, Intel Corporation.
  */
 /*
  *
@@ -31,7 +31,6 @@
 
 #ifndef _LUSTRE_NRS_TBF_H
 #define _LUSTRE_NRS_TBF_H
-#include <lustre_net.h>
 
 /* \name tbf
  *
@@ -45,22 +44,24 @@ struct nrs_tbf_cmd;
 
 struct nrs_tbf_jobid {
        char            *tj_id;
-       cfs_list_t       tj_linkage;
+       struct list_head tj_linkage;
 };
 
 struct nrs_tbf_client {
        /** Resource object for policy instance. */
        struct ptlrpc_nrs_resource       tc_res;
        /** Node in the hash table. */
-       cfs_hlist_node_t                 tc_hnode;
+       struct hlist_node                tc_hnode;
        /** NID of the client. */
        lnet_nid_t                       tc_nid;
        /** Jobid of the client. */
-       char                             tc_jobid[JOBSTATS_JOBID_SIZE];
+       char                             tc_jobid[LUSTRE_JOBID_SIZE];
        /** Reference number of the client. */
-       cfs_atomic_t                     tc_ref;
-       /** Likage to rule. */
-       cfs_list_t                       tc_linkage;
+       atomic_t                         tc_ref;
+       /** Lock to protect rule and linkage. */
+       spinlock_t                       tc_rule_lock;
+       /** Linkage to rule. */
+       struct list_head                 tc_linkage;
        /** Pointer to rule. */
        struct nrs_tbf_rule             *tc_rule;
        /** Generation of the rule matched. */
@@ -76,9 +77,9 @@ struct nrs_tbf_client {
        /** Time check-point. */
        __u64                            tc_check_time;
        /** List of queued requests. */
-       cfs_list_t                       tc_list;
+       struct list_head                 tc_list;
        /** Node in binary heap. */
-       cfs_binheap_node_t               tc_node;
+       struct cfs_binheap_node          tc_node;
        /** Whether the client is in heap. */
        bool                             tc_in_heap;
        /** Sequence of the newest rule. */
@@ -87,7 +88,7 @@ struct nrs_tbf_client {
         * Linkage into LRU list. Protected bucket lock of
         * nrs_tbf_head::th_cli_hash.
         */
-       cfs_list_t                       tc_lru;
+       struct list_head                 tc_lru;
 };
 
 #define MAX_TBF_NAME (16)
@@ -101,13 +102,13 @@ struct nrs_tbf_rule {
        /** Head belongs to. */
        struct nrs_tbf_head             *tr_head;
        /** Likage to head. */
-       cfs_list_t                       tr_linkage;
+       struct list_head                 tr_linkage;
        /** Nid list of the rule. */
-       cfs_list_t                       tr_nids;
+       struct list_head                 tr_nids;
        /** Nid list string of the rule.*/
        char                            *tr_nids_str;
        /** Jobid list of the rule. */
-       cfs_list_t                       tr_jobids;
+       struct list_head                 tr_jobids;
        /** Jobid list string of the rule.*/
        char                            *tr_jobids_str;
        /** RPC/s limit. */
@@ -116,12 +117,14 @@ struct nrs_tbf_rule {
        __u64                            tr_nsecs;
        /** Token bucket depth. */
        __u64                            tr_depth;
+       /** Lock to protect the list of clients. */
+       spinlock_t                       tr_rule_lock;
        /** List of client. */
-       cfs_list_t                       tr_cli_list;
+       struct list_head                 tr_cli_list;
        /** Flags of the rule. */
        __u32                            tr_flags;
        /** Usage Reference count taken on the rule. */
-       cfs_atomic_t                     tr_ref;
+       atomic_t                         tr_ref;
        /** Generation of the rule. */
        __u64                            tr_generation;
 };
@@ -138,23 +141,16 @@ struct nrs_tbf_ops {
        int (*o_rule_init)(struct ptlrpc_nrs_policy *,
                           struct nrs_tbf_rule *,
                           struct nrs_tbf_cmd *);
-       int (*o_rule_dump)(struct nrs_tbf_rule *,
-                          char *,
-                          int);
+       int (*o_rule_dump)(struct nrs_tbf_rule *, struct seq_file *);
        int (*o_rule_match)(struct nrs_tbf_rule *,
                            struct nrs_tbf_client *);
        void (*o_rule_fini)(struct nrs_tbf_rule *);
 };
 
-struct nrs_tbf_dump {
-       char                            *td_buff;
-       int                              td_size;
-       int                              td_length;
-};
-
 #define NRS_TBF_TYPE_JOBID     "jobid"
 #define NRS_TBF_TYPE_NID       "nid"
 #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
 
@@ -163,7 +159,7 @@ struct nrs_tbf_bucket {
         * LRU list, updated on each access to client. Protected by
         * bucket lock of nrs_tbf_head::th_cli_hash.
         */
-       cfs_list_t      ntb_lru;
+       struct list_head        ntb_lru;
 };
 
 /**
@@ -177,7 +173,7 @@ struct nrs_tbf_head {
        /**
         * List of rules.
         */
-       cfs_list_t                       th_list;
+       struct list_head                 th_list;
        /**
         * Lock to protect the list of rules.
         */
@@ -185,7 +181,7 @@ struct nrs_tbf_head {
        /**
         * Generation of rules.
         */
-       cfs_atomic_t                     th_rule_sequence;
+       atomic_t                         th_rule_sequence;
        /**
         * Default rule.
         */
@@ -193,9 +189,7 @@ struct nrs_tbf_head {
        /**
         * Timer for next token.
         */
-#if defined(__KERNEL__) && defined(__linux__)
        struct hrtimer                   th_timer;
-#endif
        /**
         * Deadline of the timer.
         */
@@ -207,11 +201,11 @@ struct nrs_tbf_head {
        /**
         * Heap of queues.
         */
-       cfs_binheap_t                   *th_binheap;
+       struct cfs_binheap              *th_binheap;
        /**
         * Hash of clients.
         */
-       cfs_hash_t                      *th_cli_hash;
+       struct cfs_hash                 *th_cli_hash;
        /**
         * Type of TBF policy.
         */
@@ -233,26 +227,35 @@ struct nrs_tbf_head {
 enum nrs_tbf_cmd_type {
        NRS_CTL_TBF_START_RULE = 0,
        NRS_CTL_TBF_STOP_RULE,
-       NRS_CTL_TBF_CHANGE_RATE,
+       NRS_CTL_TBF_CHANGE_RULE,
 };
 
 struct nrs_tbf_cmd {
-       enum nrs_tbf_cmd_type    tc_cmd;
-       char                    *tc_name;
-       __u64                    tc_rpc_rate;
-       cfs_list_t               tc_nids;
-       char                    *tc_nids_str;
-       cfs_list_t               tc_jobids;
-       char                    *tc_jobids_str;
-       __u32                    tc_valid_types;
-       __u32                    tc_rule_flags;
+       enum nrs_tbf_cmd_type                    tc_cmd;
+       char                                    *tc_name;
+       union {
+               struct nrs_tbf_cmd_start {
+                       __u64                    ts_rpc_rate;
+                       struct list_head         ts_nids;
+                       char                    *ts_nids_str;
+                       struct list_head         ts_jobids;
+                       char                    *ts_jobids_str;
+                       __u32                    ts_valid_type;
+                       __u32                    ts_rule_flags;
+                       char                    *ts_next_name;
+               } tc_start;
+               struct nrs_tbf_cmd_change {
+                       __u64                    tc_rpc_rate;
+                       char                    *tc_next_name;
+               } tc_change;
+       } u;
 };
 
 struct nrs_tbf_req {
        /**
         * Linkage to queue.
         */
-       cfs_list_t              tr_list;
+       struct list_head        tr_list;
        /**
         * Sequence of the request.
         */
@@ -271,6 +274,10 @@ enum nrs_ctl_tbf {
         * 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,
 };
 
 /** @} tbf */