Whamcloud - gitweb
LU-5580 ptlrpc: policy switch directly in tbf 49/11749/8
authorWu Libin <lwu@ddn.com>
Wed, 16 Jul 2014 05:26:08 +0000 (13:26 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 10 Jul 2015 03:03:27 +0000 (03:03 +0000)
Former version can't change nid to jobid(or reversely) directly in
tbf, it need to change to FIFO(or any other policy) first. This patch
fix this problem. It save the policy argument(like "nid" in tbf),
and if the policy start with a new argument(like "jobid"), it will
stop the former policy and start a new one.

This is also adapt to any other nrs policies if they have arguments.

Signed-off-by: Wu Libin <lwu@ddn.com>
Change-Id: I645af94d774f60e2081e3716b2f249fcab4930d4
Reviewed-on: http://review.whamcloud.com/11749
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre_nrs.h
lustre/ptlrpc/lproc_ptlrpc.c
lustre/ptlrpc/nrs.c

index 6552518..6f913d2 100644 (file)
@@ -380,6 +380,7 @@ struct ptlrpc_nrs {
 };
 
 #define NRS_POL_NAME_MAX               16
+#define NRS_POL_ARG_MAX                        16
 
 struct ptlrpc_nrs_pol_desc;
 
@@ -549,6 +550,10 @@ struct ptlrpc_nrs_pol_info {
         */
        char                            pi_name[NRS_POL_NAME_MAX];
        /**
+        * Policy argument
+        */
+       char                            pi_arg[NRS_POL_ARG_MAX];
+       /**
         * Current policy state
         */
        enum ptlrpc_nrs_pol_state       pi_state;
@@ -604,6 +609,10 @@ struct ptlrpc_nrs_policy {
         */
        long                            pol_ref;
        /**
+        * Human-readable policy argument
+        */
+       char                            pol_arg[NRS_POL_ARG_MAX];
+       /**
         * The NRS head this policy has been created at
         */
        struct ptlrpc_nrs              *pol_nrs;
index a86b460..739560a 100644 (file)
@@ -456,7 +456,9 @@ void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
        LASSERT(info != NULL);
        assert_spin_locked(&policy->pol_nrs->nrs_lock);
 
+       LASSERT(sizeof(info->pi_arg) == sizeof(policy->pol_arg));
        memcpy(info->pi_name, policy->pol_desc->pd_name, NRS_POL_NAME_MAX);
+       memcpy(info->pi_arg, policy->pol_arg, sizeof(policy->pol_arg));
 
        info->pi_fallback    = !!(policy->pol_flags & PTLRPC_NRS_FL_FALLBACK);
        info->pi_state       = policy->pol_state;
@@ -527,6 +529,8 @@ again:
                        if (i == 0) {
                                memcpy(infos[pol_idx].pi_name, tmp.pi_name,
                                       NRS_POL_NAME_MAX);
+                               memcpy(infos[pol_idx].pi_arg, tmp.pi_arg,
+                                      sizeof(tmp.pi_arg));
                                memcpy(&infos[pol_idx].pi_state, &tmp.pi_state,
                                       sizeof(tmp.pi_state));
                                infos[pol_idx].pi_fallback = tmp.pi_fallback;
@@ -538,6 +542,9 @@ again:
                                LASSERT(strncmp(infos[pol_idx].pi_name,
                                                tmp.pi_name,
                                                NRS_POL_NAME_MAX) == 0);
+                               LASSERT(strncmp(infos[pol_idx].pi_arg,
+                                               tmp.pi_arg,
+                                               sizeof(tmp.pi_arg)) == 0);
                                /**
                                 * Not asserting ptlrpc_nrs_pol_info::pi_state,
                                 * because it may be different between
@@ -590,12 +597,19 @@ again:
                   "high_priority_requests:");
 
        for (pol_idx = 0; pol_idx < num_pols; pol_idx++) {
-               seq_printf(m, "  - name: %s\n"
-                             "    state: %s\n"
+               if (strlen(infos[pol_idx].pi_arg) > 0)
+                       seq_printf(m, "  - name: %s %s\n",
+                                     infos[pol_idx].pi_name,
+                                     infos[pol_idx].pi_arg);
+               else
+                       seq_printf(m, "  - name: %s\n",
+                                     infos[pol_idx].pi_name);
+
+
+               seq_printf(m, "    state: %s\n"
                              "    fallback: %s\n"
                              "    queued: %-20d\n"
                              "    active: %-20d\n\n",
-                             infos[pol_idx].pi_name,
                              nrs_state2str(infos[pol_idx].pi_state),
                              infos[pol_idx].pi_fallback ? "yes" : "no",
                              (int)infos[pol_idx].pi_req_queued,
index 205762e..1b07c8a 100644 (file)
@@ -239,8 +239,23 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg)
                if (nrs->nrs_policy_fallback == NULL)
                        RETURN(-EPERM);
 
-               if (policy->pol_state == NRS_POL_STATE_STARTED)
-                       RETURN(0);
+               if (policy->pol_state == NRS_POL_STATE_STARTED) {
+                       /**
+                        * If the policy argument now is different from the last time,
+                        * stop the policy first and start it again with the new
+                        * argument.
+                        */
+                       if ((arg != NULL) && (strlen(arg) >= NRS_POL_ARG_MAX))
+                               return -EINVAL;
+
+                       if ((arg == NULL && strlen(policy->pol_arg) == 0) ||
+                           (arg != NULL && strcmp(policy->pol_arg, arg) == 0))
+                               RETURN(0);
+
+                       rc = nrs_policy_stop_locked(policy);
+                       if (rc)
+                               RETURN(-EAGAIN);
+               }
        }
 
        /**
@@ -255,6 +270,14 @@ static int nrs_policy_start_locked(struct ptlrpc_nrs_policy *policy, char *arg)
                RETURN(-ENODEV);
        }
 
+       if (arg != NULL) {
+               if (strlen(arg) + 1 > sizeof(policy->pol_arg)) {
+                       CERROR("NRS: arg '%s' is too long\n", arg);
+                       GOTO(out, rc = -E2BIG);
+               }
+               strncpy(policy->pol_arg, arg, sizeof(policy->pol_arg));
+       }
+
        /**
         * Serialize policy starting across the NRS head
         */