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 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mgs/mgs_nids.c
34 * NID table management for lustre.
36 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
39 #define DEBUG_SUBSYSTEM S_MGS
40 #define D_MGS D_CONFIG
42 #include <linux/kthread.h>
43 #include <linux/pagemap.h>
46 #include <obd_class.h>
47 #include <lustre_disk.h>
49 #include "mgs_internal.h"
51 static time64_t ir_timeout;
53 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
55 struct mgs_nidtbl_target *tgt;
58 LASSERT(mutex_is_locked(&tbl->mn_lock));
59 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
60 if (!tgt->mnt_version)
63 if (version >= tgt->mnt_version)
66 version = tgt->mnt_version;
72 * Fetch nidtbl entries whose version are not less than @version
73 * nidtbl entries will be packed in @pages by @unit_size units - entries
74 * shouldn't cross unit boundaries.
76 static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
77 struct mgs_config_res *res, struct page **pages,
78 int nrpages, int units_total, int unit_size)
80 struct mgs_nidtbl_target *tgt;
81 struct mgs_nidtbl_entry *entry;
82 struct mgs_nidtbl_entry *last_in_unit = NULL;
83 struct mgs_target_info *mti;
84 __u64 version = res->mcr_offset;
87 int bytes_in_unit = 0;
88 int units_in_page = 0;
94 /* make sure unit_size is power 2 */
95 LASSERT((unit_size & (unit_size - 1)) == 0);
96 LASSERT(nrpages << PAGE_SHIFT >= units_total * unit_size);
98 mutex_lock(&tbl->mn_lock);
99 LASSERT(nidtbl_is_sane(tbl));
101 /* no more entries ? */
102 if (version > tbl->mn_version) {
103 version = tbl->mn_version;
108 * iterate over all targets to compose a bitmap by the type of llog.
109 * If the llog is for MDTs, llog entries for OSTs will be returned;
110 * otherwise, it's for clients, then llog entries for both OSTs and
111 * MDTs will be returned.
113 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
114 int entry_len = sizeof(*entry);
116 if (tgt->mnt_version < version)
119 /* write target recover information */
121 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
122 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
124 if (entry_len > unit_size) {
125 CWARN("nidtbl: too large entry: entry length %d, unit size: %d\n",
126 entry_len, unit_size);
127 GOTO(out, rc = -EOVERFLOW);
130 if (bytes_in_unit < entry_len) {
131 if (units_total == 0) {
136 /* check if we need to consume remaining bytes. */
137 if (last_in_unit && bytes_in_unit) {
138 last_in_unit->mne_length += bytes_in_unit;
140 buf += bytes_in_unit;
143 LASSERT((rc & (unit_size - 1)) == 0);
145 if (units_in_page == 0) {
146 /* allocate a new page */
147 pages[index] = alloc_page(GFP_KERNEL);
153 /* destroy previous map */
155 kunmap(pages[index - 1]);
157 /* reassign buffer */
158 buf = kmap(pages[index]);
161 units_in_page = PAGE_SIZE / unit_size;
162 LASSERT(units_in_page > 0);
165 /* allocate an unit */
166 LASSERT(((long)buf & (unit_size - 1)) == 0);
167 bytes_in_unit = unit_size;
173 entry = (struct mgs_nidtbl_entry *)buf;
174 entry->mne_version = tgt->mnt_version;
175 entry->mne_instance = mti->mti_instance;
176 entry->mne_index = mti->mti_stripe_index;
177 entry->mne_length = entry_len;
178 entry->mne_type = tgt->mnt_type;
179 entry->mne_nid_type = 0;
180 entry->mne_nid_size = sizeof(lnet_nid_t);
181 entry->mne_nid_count = mti->mti_nid_count;
182 memcpy(entry->u.nids, mti->mti_nids,
183 mti->mti_nid_count * sizeof(lnet_nid_t));
185 version = tgt->mnt_version;
189 bytes_in_unit -= entry_len;
190 last_in_unit = entry;
192 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
193 tbl->mn_fsdb->fsdb_name, entry_len,
194 bytes_in_unit, index, nrpages, units_total);
197 kunmap(pages[index - 1]);
199 LASSERT(version <= tbl->mn_version);
200 res->mcr_size = tbl->mn_version;
201 res->mcr_offset = nobuf ? version : tbl->mn_version;
202 mutex_unlock(&tbl->mn_lock);
203 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
205 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
206 tbl->mn_fsdb->fsdb_name, rc, version);
210 static int nidtbl_update_version(const struct lu_env *env,
211 struct mgs_device *mgs,
212 struct mgs_nidtbl *tbl)
214 struct dt_object *fsdb;
217 struct lu_buf buf = {
219 .lb_len = sizeof(version)
226 if (mgs->mgs_bottom->dd_rdonly)
229 LASSERT(mutex_is_locked(&tbl->mn_lock));
231 fsdb = local_file_find_or_create(env, mgs->mgs_los, mgs->mgs_nidtbl_dir,
232 tbl->mn_fsdb->fsdb_name,
233 S_IFREG | S_IRUGO | S_IWUSR);
235 RETURN(PTR_ERR(fsdb));
237 th = dt_trans_create(env, mgs->mgs_bottom);
239 GOTO(out_put, rc = PTR_ERR(th));
241 th->th_sync = 1; /* update table synchronously */
242 rc = dt_declare_record_write(env, fsdb, &buf, off, th);
246 rc = dt_trans_start_local(env, mgs->mgs_bottom, th);
250 version = cpu_to_le64(tbl->mn_version);
251 rc = dt_record_write(env, fsdb, &buf, &off, th);
254 dt_trans_stop(env, mgs->mgs_bottom, th);
256 dt_object_put(env, fsdb);
260 #define MGS_NIDTBL_VERSION_INIT 2
262 static int nidtbl_read_version(const struct lu_env *env,
263 struct mgs_device *mgs, struct mgs_nidtbl *tbl,
266 struct dt_object *fsdb;
269 struct lu_buf buf = {
271 .lb_len = sizeof(tmpver)
278 LASSERT(mutex_is_locked(&tbl->mn_lock));
280 LASSERT(mgs->mgs_nidtbl_dir);
281 rc = dt_lookup_dir(env, mgs->mgs_nidtbl_dir, tbl->mn_fsdb->fsdb_name,
284 *version = MGS_NIDTBL_VERSION_INIT;
290 fsdb = dt_locate_at(env, mgs->mgs_bottom, &fid,
291 &mgs->mgs_dt_dev.dd_lu_dev, NULL);
293 RETURN(PTR_ERR(fsdb));
295 rc = dt_read(env, fsdb, &buf, &off);
296 if (rc == buf.lb_len) {
297 *version = le64_to_cpu(tmpver);
299 } else if (rc == 0) {
300 *version = MGS_NIDTBL_VERSION_INIT;
302 CERROR("%s: read version file %s error %d\n",
303 mgs->mgs_obd->obd_name, tbl->mn_fsdb->fsdb_name, rc);
305 dt_object_put(env, fsdb);
309 static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
310 struct mgs_target_info *mti)
312 struct mgs_nidtbl *tbl;
313 struct mgs_nidtbl_target *tgt;
315 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
320 type &= ~LDD_F_SV_TYPE_MGS;
323 tbl = &fsdb->fsdb_nidtbl;
324 mutex_lock(&tbl->mn_lock);
325 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
326 struct mgs_target_info *info = &tgt->mnt_mti;
328 if (type == tgt->mnt_type &&
329 mti->mti_stripe_index == info->mti_stripe_index) {
337 GOTO(out, rc = -ENOMEM);
339 INIT_LIST_HEAD(&tgt->mnt_list);
341 tgt->mnt_version = 0; /* 0 means invalid */
342 tgt->mnt_type = type;
344 ++tbl->mn_nr_targets;
347 tgt->mnt_version = ++tbl->mn_version;
350 list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
352 rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
356 mutex_unlock(&tbl->mn_lock);
358 CERROR("Write NID table version for file system %s error %d\n",
359 fsdb->fsdb_name, rc);
363 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
365 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
366 struct list_head head = LIST_HEAD_INIT(head);
368 mutex_lock(&tbl->mn_lock);
369 tbl->mn_nr_targets = 0;
370 list_splice_init(&tbl->mn_targets, &head);
371 mutex_unlock(&tbl->mn_lock);
373 while (!list_empty(&head)) {
374 struct mgs_nidtbl_target *tgt;
376 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
377 list_del(&tgt->mnt_list);
382 static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
384 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
387 INIT_LIST_HEAD(&tbl->mn_targets);
388 mutex_init(&tbl->mn_lock);
389 tbl->mn_nr_targets = 0;
391 mutex_lock(&tbl->mn_lock);
392 rc = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl, &tbl->mn_version);
393 mutex_unlock(&tbl->mn_lock);
395 CERROR("%s: IR: failed to read current version, rc = %d\n",
396 fsdb->fsdb_mgs->mgs_obd->obd_name, rc);
398 CDEBUG(D_MGS, "IR: current version is %llu\n",
404 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
405 void mgs_ir_notify_complete(struct fs_db *fsdb)
407 struct timespec64 ts;
410 atomic_set(&fsdb->fsdb_notify_phase, 0);
413 fsdb->fsdb_notify_count++;
414 delta = ktime_sub(ktime_get(), fsdb->fsdb_notify_start);
415 fsdb->fsdb_notify_total = ktime_add(fsdb->fsdb_notify_total, delta);
416 if (ktime_after(delta, fsdb->fsdb_notify_max))
417 fsdb->fsdb_notify_max = delta;
419 ts = ktime_to_timespec64(fsdb->fsdb_notify_max);
420 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %lld.%09lds\n",
421 fsdb->fsdb_name, (s64)ts.tv_sec, ts.tv_nsec);
424 static int mgs_ir_notify(void *arg)
426 struct fs_db *fsdb = arg;
427 struct ldlm_res_id resid;
428 char name[sizeof(fsdb->fsdb_name) + 16];
430 CLASSERT(sizeof(name) < 40); /* name is too large to be on stack */
432 snprintf(name, sizeof(name) - 1, "mgs_%s_notify", fsdb->fsdb_name);
433 complete(&fsdb->fsdb_notify_comp);
434 set_user_nice(current, -2);
435 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
437 struct l_wait_info lwi = { 0 };
439 l_wait_event(fsdb->fsdb_notify_waitq,
440 fsdb->fsdb_notify_stop ||
441 atomic_read(&fsdb->fsdb_notify_phase),
443 if (fsdb->fsdb_notify_stop)
446 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
447 name, atomic_read(&fsdb->fsdb_notify_phase));
449 fsdb->fsdb_notify_start = ktime_get();
450 mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
453 complete(&fsdb->fsdb_notify_comp);
457 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
460 struct task_struct *task;
463 ir_timeout = (time64_t)OBD_IR_MGS_TIMEOUT;
465 fsdb->fsdb_ir_state = IR_FULL;
466 if (mgs->mgs_start_time + ir_timeout > ktime_get_real_seconds())
467 fsdb->fsdb_ir_state = IR_STARTUP;
468 fsdb->fsdb_nonir_clients = 0;
469 /* start notify thread */
470 fsdb->fsdb_mgs = mgs;
471 task = kthread_run(mgs_ir_notify, fsdb,
472 "mgs_%s_notify", fsdb->fsdb_name);
474 wait_for_completion(&fsdb->fsdb_notify_comp);
476 CERROR("Start notify thread error %ld\n", PTR_ERR(task));
478 mgs_nidtbl_init_fs(env, fsdb);
482 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
484 if (test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
487 mgs_fsc_cleanup_by_fsdb(fsdb);
489 mgs_nidtbl_fini_fs(fsdb);
491 LASSERT(list_empty(&fsdb->fsdb_clients));
493 fsdb->fsdb_notify_stop = 1;
494 wake_up(&fsdb->fsdb_notify_waitq);
495 wait_for_completion(&fsdb->fsdb_notify_comp);
498 /* caller must have held fsdb_mutex */
499 static inline void ir_state_graduate(struct fs_db *fsdb)
501 if (fsdb->fsdb_ir_state == IR_STARTUP) {
502 if (ktime_get_real_seconds() >
503 fsdb->fsdb_mgs->mgs_start_time + ir_timeout) {
504 fsdb->fsdb_ir_state = IR_FULL;
505 if (fsdb->fsdb_nonir_clients)
506 fsdb->fsdb_ir_state = IR_PARTIAL;
511 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
512 struct mgs_target_info *mti)
518 if (mti->mti_instance == 0)
521 rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
525 rc = mgs_nidtbl_write(env, fsdb, mti);
530 mutex_lock(&fsdb->fsdb_mutex);
531 ir_state_graduate(fsdb);
532 switch (fsdb->fsdb_ir_state) {
534 mti->mti_flags |= LDD_F_IR_CAPABLE;
544 mutex_unlock(&fsdb->fsdb_mutex);
546 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
548 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
550 atomic_inc(&fsdb->fsdb_notify_phase);
551 wake_up(&fsdb->fsdb_notify_waitq);
555 mgs_put_fsdb(mgs, fsdb);
559 /* NID table can be cached by two entities: Clients and MDTs */
565 static int delogname(char *logname, char *fsname, int *typ)
571 ptr = strrchr(logname, '-');
576 * decouple file system name. The llog name may be:
577 * - "prefix-fsname", prefix is "cliir" or "mdtir"
579 if (strncmp(ptr, "-mdtir", 6) == 0)
581 else if (strncmp(ptr, "-cliir", 6) == 0)
590 memcpy(fsname, logname, len);
597 int mgs_get_ir_logs(struct ptlrpc_request *req)
599 struct lu_env *env = req->rq_svc_thread->t_env;
600 struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
601 struct fs_db *fsdb = NULL;
602 struct mgs_config_body *body;
603 struct mgs_config_res *res;
604 struct ptlrpc_bulk_desc *desc;
605 struct l_wait_info lwi;
615 struct page **pages = NULL;
619 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
623 if (body->mcb_type != CONFIG_T_RECOVER)
626 rc = delogname(body->mcb_name, fsname, &type);
630 bufsize = body->mcb_units << body->mcb_bits;
631 nrpages = (bufsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
632 if (nrpages > PTLRPC_MAX_BRW_PAGES)
635 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
639 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
640 body->mcb_name, bufsize);
642 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
644 GOTO(out, rc = -ENOMEM);
646 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
648 GOTO(out, rc = -EINVAL);
650 res->mcr_offset = body->mcb_offset;
651 unit_size = min_t(int, 1 << body->mcb_bits, PAGE_SIZE);
652 bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
653 pages, nrpages, bufsize / unit_size, unit_size);
655 GOTO(out, rc = bytes);
657 /* start bulk transfer */
658 page_count = (bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
659 LASSERT(page_count <= nrpages);
660 desc = ptlrpc_prep_bulk_exp(req, page_count, 1,
661 PTLRPC_BULK_PUT_SOURCE |
662 PTLRPC_BULK_BUF_KIOV,
664 &ptlrpc_bulk_kiov_pin_ops);
666 GOTO(out, rc = -ENOMEM);
668 for (i = 0; i < page_count && bytes > 0; i++) {
669 desc->bd_frag_ops->add_kiov_frag(desc, pages[i], 0,
675 rc = target_bulk_io(req->rq_export, desc, &lwi);
676 ptlrpc_free_bulk(desc);
682 for (i = 0; i < nrpages; i++) {
686 __free_page(pages[i]);
689 OBD_FREE(pages, sizeof(*pages) * nrpages);
693 mgs_put_fsdb(mgs, fsdb);
698 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
700 const char *strings[] = IR_STRINGS;
704 for (i = 0; i < ARRAY_SIZE(strings); i++) {
705 if (strcmp(strings[i], buf) == 0) {
713 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
714 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
715 mutex_lock(&fsdb->fsdb_mutex);
716 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
718 fsdb->fsdb_ir_state = state;
719 mutex_unlock(&fsdb->fsdb_mutex);
724 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
729 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
734 fsdb->fsdb_notify_total = ktime_set(0, 0);
735 fsdb->fsdb_notify_max = ktime_set(0, 0);
736 fsdb->fsdb_notify_count = 0;
740 static struct lproc_ir_cmd {
743 int (*handler)(struct fs_db *, const char *);
745 { "state=", 6, lprocfs_ir_set_state },
746 { "timeout=", 8, lprocfs_ir_set_timeout },
747 { "0", 1, lprocfs_ir_clear_stats }
750 int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
751 size_t count, void *data)
753 struct fs_db *fsdb = data;
758 if (count == 0 || count >= PAGE_SIZE)
761 OBD_ALLOC(kbuf, count + 1);
765 if (copy_from_user(kbuf, buffer, count)) {
766 OBD_FREE(kbuf, count + 1);
770 kbuf[count] = 0; /* buffer is supposed to end with 0 */
771 if (kbuf[count - 1] == '\n')
775 /* fsname=<file system name> must be the 1st entry */
780 tmpptr = strchr(ptr, ';');
785 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
786 struct lproc_ir_cmd *cmd;
790 cmdlen = cmd->namelen;
791 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
793 rc = cmd->handler(fsdb, ptr);
803 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
804 OBD_FREE(kbuf, count + 1);
808 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
810 struct fs_db *fsdb = data;
811 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
812 const char *ir_strings[] = IR_STRINGS;
813 struct timespec64 ts_max;
814 struct timespec64 ts;
816 /* mgs_live_seq_show() already holds fsdb_mutex. */
817 ir_state_graduate(fsdb);
819 seq_printf(seq, "\nimperative_recovery_state:\n");
822 " nonir_clients: %d\n"
823 " nidtbl_version: %lld\n",
824 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
827 ts = ktime_to_timespec64(fsdb->fsdb_notify_total);
828 ts_max = ktime_to_timespec64(fsdb->fsdb_notify_max);
830 seq_printf(seq, " notify_duration_total: %lld.%09ld\n"
831 " notify_duation_max: %lld.%09ld\n"
832 " notify_count: %u\n",
833 (s64)ts.tv_sec, ts.tv_nsec,
834 (s64)ts_max.tv_sec, ts_max.tv_nsec,
835 fsdb->fsdb_notify_count);
840 int lprocfs_ir_timeout_seq_show(struct seq_file *m, void *data)
842 seq_printf(m, "%lld\n", ir_timeout);
846 ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
847 const char __user *buffer,
848 size_t count, loff_t *off)
850 return kstrtoll_from_user(buffer, count, 0, &ir_timeout);
853 /* --------------- Handle non IR support clients --------------- */
854 /* attach a lustre file system to an export */
855 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
858 struct mgs_export_data *data = &exp->u.eu_mgs_data;
859 struct mgs_device *mgs = exp2mgs_dev(exp);
860 struct fs_db *fsdb = NULL;
861 struct mgs_fsc *fsc = NULL;
862 struct mgs_fsc *new_fsc = NULL;
868 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
872 /* allocate a new fsc in case we need it in spinlock. */
873 OBD_ALLOC_PTR(new_fsc);
875 GOTO(out, rc = -ENOMEM);
877 INIT_LIST_HEAD(&new_fsc->mfc_export_list);
878 INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
879 new_fsc->mfc_fsdb = fsdb;
880 new_fsc->mfc_export = class_export_get(exp);
881 new_fsc->mfc_ir_capable = !!(exp_connect_flags(exp) &
882 OBD_CONNECT_IMP_RECOV);
885 mutex_lock(&fsdb->fsdb_mutex);
887 /* tend to find it in export list because this list is shorter. */
888 spin_lock(&data->med_lock);
889 list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
890 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
899 /* add it into export list. */
900 list_add(&fsc->mfc_export_list, &data->med_clients);
902 /* add into fsdb list. */
903 list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
904 if (!fsc->mfc_ir_capable) {
905 ++fsdb->fsdb_nonir_clients;
906 if (fsdb->fsdb_ir_state == IR_FULL)
907 fsdb->fsdb_ir_state = IR_PARTIAL;
911 spin_unlock(&data->med_lock);
912 mutex_unlock(&fsdb->fsdb_mutex);
915 class_export_put(new_fsc->mfc_export);
916 OBD_FREE_PTR(new_fsc);
920 mgs_put_fsdb(mgs, fsdb);
924 void mgs_fsc_cleanup(struct obd_export *exp)
926 struct mgs_export_data *data = &exp->u.eu_mgs_data;
927 struct mgs_fsc *fsc, *tmp;
928 struct list_head head = LIST_HEAD_INIT(head);
930 spin_lock(&data->med_lock);
931 list_splice_init(&data->med_clients, &head);
932 spin_unlock(&data->med_lock);
934 list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
935 struct fs_db *fsdb = fsc->mfc_fsdb;
937 LASSERT(fsc->mfc_export == exp);
939 mutex_lock(&fsdb->fsdb_mutex);
940 list_del_init(&fsc->mfc_fsdb_list);
941 if (fsc->mfc_ir_capable == 0) {
942 --fsdb->fsdb_nonir_clients;
943 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
944 if (fsdb->fsdb_nonir_clients == 0 &&
945 fsdb->fsdb_ir_state == IR_PARTIAL)
946 fsdb->fsdb_ir_state = IR_FULL;
948 mutex_unlock(&fsdb->fsdb_mutex);
949 list_del_init(&fsc->mfc_export_list);
950 class_export_put(fsc->mfc_export);
955 /* must be called with fsdb->fsdb_mutex held */
956 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
958 struct mgs_fsc *fsc, *tmp;
960 list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
962 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
964 LASSERT(fsdb == fsc->mfc_fsdb);
965 list_del_init(&fsc->mfc_fsdb_list);
967 spin_lock(&data->med_lock);
968 list_del_init(&fsc->mfc_export_list);
969 spin_unlock(&data->med_lock);
970 class_export_put(fsc->mfc_export);
974 fsdb->fsdb_nonir_clients = 0;
975 if (fsdb->fsdb_ir_state == IR_PARTIAL)
976 fsdb->fsdb_ir_state = IR_FULL;