Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / obdclass / lu_tgt_pool.c
index bd8aa1d..410d6c9 100644 (file)
@@ -1,35 +1,14 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * 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 LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
+// SPDX-License-Identifier: GPL-2.0
+
 /*
  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
  * Use is subject to license terms.
  *
  * Copyright (c) 2012, 2017, Intel Corporation.
  */
+
 /*
  * This file is part of Lustre, http://www.lustre.org/
- */
-/*
- * lustre/target/tgt_pool.c
  *
  * This file handles creation, lookup, and removal of pools themselves, as
  * well as adding and removing targets to pools.
@@ -132,32 +111,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 +182,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 +190,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 +205,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 +221,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);