Whamcloud - gitweb
LU-13168 tests: verify truncated xattr is handled
[fs/lustre-release.git] / lustre / target / tgt_main.c
index 2f9f381..bdd05e7 100644 (file)
 
 /* This must be longer than the longest string below */
 #define SYNC_STATES_MAXLEN 16
-static char *sync_on_cancel_states[] = {"never",
-                                       "blocking",
-                                       "always" };
+static const char * const sync_lock_cancel_states[] = {
+       [SYNC_LOCK_CANCEL_NEVER]        = "never",
+       [SYNC_LOCK_CANCEL_BLOCKING]     = "blocking",
+       [SYNC_LOCK_CANCEL_ALWAYS]       = "always",
+};
 
 /**
  * Show policy for handling dirty data under a lock being cancelled.
@@ -53,16 +55,17 @@ static char *sync_on_cancel_states[] = {"never",
  * \retval             0 and buffer filled with data on success
  * \retval             negative value on error
  */
-static ssize_t sync_lock_cancel_show(struct kobject *kobj,
-                                    struct attribute *attr, char *buf)
+ssize_t sync_lock_cancel_show(struct kobject *kobj,
+                             struct attribute *attr, char *buf)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        struct lu_target *tgt = obd->u.obt.obt_lut;
 
        return sprintf(buf, "%s\n",
-                      sync_on_cancel_states[tgt->lut_sync_lock_cancel]);
+                      sync_lock_cancel_states[tgt->lut_sync_lock_cancel]);
 }
+EXPORT_SYMBOL(sync_lock_cancel_show);
 
 /**
  * Change policy for handling dirty data under a lock being cancelled.
@@ -85,22 +88,21 @@ static ssize_t sync_lock_cancel_show(struct kobject *kobj,
  * \retval             \a count on success
  * \retval             negative value on error
  */
-static ssize_t sync_lock_cancel_store(struct kobject *kobj,
-                                     struct attribute *attr,
-                                     const char *buffer, size_t count)
+ssize_t sync_lock_cancel_store(struct kobject *kobj, struct attribute *attr,
+                              const char *buffer, size_t count)
 {
        struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        struct lu_target *tgt = obd->u.obt.obt_lut;
        int val = -1;
-       int i;
+       enum tgt_sync_lock_cancel slc;
 
        if (count == 0 || count >= SYNC_STATES_MAXLEN)
                return -EINVAL;
 
-       for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) {
-               if (strcmp(buffer, sync_on_cancel_states[i]) == 0) {
-                       val = i;
+       for (slc = 0; slc < ARRAY_SIZE(sync_lock_cancel_states); slc++) {
+               if (strcmp(buffer, sync_lock_cancel_states[slc]) == 0) {
+                       val = slc;
                        break;
                }
        }
@@ -120,6 +122,7 @@ static ssize_t sync_lock_cancel_store(struct kobject *kobj,
        spin_unlock(&tgt->lut_flags_lock);
        return count;
 }
+EXPORT_SYMBOL(sync_lock_cancel_store);
 LUSTRE_RW_ATTR(sync_lock_cancel);
 
 /**
@@ -415,7 +418,7 @@ int tgt_init(const struct lu_env *env, struct lu_target *lut,
        sptlrpc_rule_set_init(&lut->lut_sptlrpc_rset);
 
        spin_lock_init(&lut->lut_flags_lock);
-       lut->lut_sync_lock_cancel = NEVER_SYNC_ON_CANCEL;
+       lut->lut_sync_lock_cancel = SYNC_LOCK_CANCEL_NEVER;
 
        spin_lock_init(&lut->lut_slc_locks_guard);
        INIT_LIST_HEAD(&lut->lut_slc_locks);