Whamcloud - gitweb
New tag 2.15.63
[fs/lustre-release.git] / lustre / obdclass / lu_tgt_pool.c
index bd8aa1d..7ef83ce 100644 (file)
@@ -132,32 +132,36 @@ EXPORT_SYMBOL(lu_tgt_pool_extend);
  * \retval             0 if target could be added to the pool
  * \retval             negative error if target \a idx was not added
  */
-int lu_tgt_pool_add(struct lu_tgt_pool *op, __u32 idx, unsigned int min_count)
+int lu_tgt_pool_add_lock(struct lu_tgt_pool *op, __u32 idx,
+                        unsigned int min_count, bool lock)
 {
        unsigned int i;
        int rc = 0;
        ENTRY;
 
-       down_write(&op->op_rw_sem);
-
-       rc = lu_tgt_pool_extend(op, min_count);
-       if (rc)
-               GOTO(out, rc);
+       if (lock)
+               down_write(&op->op_rw_sem);
 
        /* search ost in pool array */
        for (i = 0; i < op->op_count; i++) {
                if (op->op_array[i] == idx)
                        GOTO(out, rc = -EEXIST);
        }
+
+       rc = lu_tgt_pool_extend(op, min_count);
+       if (rc)
+               GOTO(out, rc);
+
        /* ost not found we add it */
        op->op_array[op->op_count] = idx;
        op->op_count++;
        EXIT;
 out:
-       up_write(&op->op_rw_sem);
+       if (lock)
+               up_write(&op->op_rw_sem);
        return rc;
 }
-EXPORT_SYMBOL(lu_tgt_pool_add);
+EXPORT_SYMBOL(lu_tgt_pool_add_lock);
 
 /**
  * Remove an existing pool from the system.
@@ -199,7 +203,7 @@ EXPORT_SYMBOL(lu_tgt_pool_remove);
 
 int lu_tgt_check_index(int idx, struct lu_tgt_pool *osts)
 {
-       int rc, i;
+       int i, rc = -ENOENT;
        ENTRY;
 
        down_read(&osts->op_rw_sem);
@@ -207,7 +211,6 @@ int lu_tgt_check_index(int idx, struct lu_tgt_pool *osts)
                if (osts->op_array[i] == idx)
                        GOTO(out, rc = 0);
        }
-       rc = -ENOENT;
        EXIT;
 out:
        up_read(&osts->op_rw_sem);
@@ -223,15 +226,13 @@ EXPORT_SYMBOL(lu_tgt_check_index);
  * deleted from memory.
  *
  * \param[in] op       pool to be freed.
- *
- * \retval             0 on success or if pool was already freed
  */
-int lu_tgt_pool_free(struct lu_tgt_pool *op)
+void lu_tgt_pool_free(struct lu_tgt_pool *op)
 {
        ENTRY;
 
        if (op->op_size == 0)
-               RETURN(0);
+               RETURN_EXIT;
 
        down_write(&op->op_rw_sem);
 
@@ -241,6 +242,6 @@ int lu_tgt_pool_free(struct lu_tgt_pool *op)
        op->op_size = 0;
 
        up_write(&op->op_rw_sem);
-       RETURN(0);
+       EXIT;
 }
 EXPORT_SYMBOL(lu_tgt_pool_free);