4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * This file is part of Lustre, http://www.lustre.org/
25 * lustre/obdclass/lu_qos.c
28 * These are the only exported functions, they provide some generic
29 * infrastructure for object allocation QoS
33 #define DEBUG_SUBSYSTEM S_CLASS
35 #include <linux/module.h>
36 #include <linux/list.h>
37 #include <libcfs/libcfs.h>
38 #include <libcfs/libcfs_hash.h> /* hash_long() */
39 #include <libcfs/linux/linux-mem.h>
40 #include <obd_class.h>
41 #include <obd_support.h>
42 #include <lustre_disk.h>
43 #include <lustre_fid.h>
44 #include <lu_object.h>
47 * Add a new target to Quality of Service (QoS) target table.
49 * Add a new MDT/OST target to the structure representing an OSS. Resort the
50 * list of known MDSs/OSSs by the number of MDTs/OSTs attached to each MDS/OSS.
51 * The MDS/OSS list is protected internally and no external locking is required.
53 * \param[in] qos lu_qos data
54 * \param[in] ltd target description
56 * \retval 0 on success
57 * \retval -ENOMEM on error
59 int lqos_add_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd)
61 struct lu_svr_qos *svr = NULL;
62 struct lu_svr_qos *tempsvr;
63 struct obd_export *exp = ltd->ltd_exp;
70 down_write(&qos->lq_rw_sem);
72 * a bit hacky approach to learn NID of corresponding connection
73 * but there is no official API to access information like this
76 list_for_each_entry(svr, &qos->lq_svr_list, lsq_svr_list) {
77 if (obd_uuid_equals(&svr->lsq_uuid,
78 &exp->exp_connection->c_remote_uuid)) {
89 GOTO(out, rc = -ENOMEM);
90 memcpy(&svr->lsq_uuid, &exp->exp_connection->c_remote_uuid,
91 sizeof(svr->lsq_uuid));
95 /* Assume we have to move this one */
96 list_del(&svr->lsq_svr_list);
100 ltd->ltd_qos.ltq_svr = svr;
102 CDEBUG(D_OTHER, "add tgt %s to server %s (%d targets)\n",
103 obd_uuid2str(<d->ltd_uuid), obd_uuid2str(&svr->lsq_uuid),
107 * Add sorted by # of tgts. Find the first entry that we're
110 list_for_each_entry(tempsvr, &qos->lq_svr_list, lsq_svr_list) {
111 if (svr->lsq_tgt_count > tempsvr->lsq_tgt_count)
115 * ...and add before it. If we're the first or smallest, tempsvr
116 * points to the list head, and we add to the end.
118 list_add_tail(&svr->lsq_svr_list, &tempsvr->lsq_svr_list);
121 qos->lq_rr.lqr_dirty = 1;
124 up_write(&qos->lq_rw_sem);
127 EXPORT_SYMBOL(lqos_add_tgt);
130 * Remove MDT/OST target from QoS table.
132 * Removes given MDT/OST target from QoS table and releases related
133 * MDS/OSS structure if no target remain on the MDS/OSS.
135 * \param[in] qos lu_qos data
136 * \param[in] ltd target description
138 * \retval 0 on success
139 * \retval -ENOENT if no server was found
141 int lqos_del_tgt(struct lu_qos *qos, struct lu_tgt_desc *ltd)
143 struct lu_svr_qos *svr;
148 down_write(&qos->lq_rw_sem);
149 svr = ltd->ltd_qos.ltq_svr;
151 GOTO(out, rc = -ENOENT);
153 svr->lsq_tgt_count--;
154 if (svr->lsq_tgt_count == 0) {
155 CDEBUG(D_OTHER, "removing server %s\n",
156 obd_uuid2str(&svr->lsq_uuid));
157 list_del(&svr->lsq_svr_list);
158 ltd->ltd_qos.ltq_svr = NULL;
163 qos->lq_rr.lqr_dirty = 1;
165 up_write(&qos->lq_rw_sem);
168 EXPORT_SYMBOL(lqos_del_tgt);