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, 2015, 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 unsigned int 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;
93 /* make sure unit_size is power 2 */
94 LASSERT((unit_size & (unit_size - 1)) == 0);
95 LASSERT(nrpages << PAGE_SHIFT >= units_total * unit_size);
97 mutex_lock(&tbl->mn_lock);
98 LASSERT(nidtbl_is_sane(tbl));
100 /* no more entries ? */
101 if (version > tbl->mn_version) {
102 version = tbl->mn_version;
106 /* iterate over all targets to compose a bitmap by the type of llog.
107 * If the llog is for MDTs, llog entries for OSTs will be returned;
108 * otherwise, it's for clients, then llog entries for both OSTs and
109 * MDTs will be returned.
111 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
112 int entry_len = sizeof(*entry);
114 if (tgt->mnt_version < version)
117 /* write target recover information */
119 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
120 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
122 if (entry_len > unit_size) {
123 CWARN("nidtbl: too large entry: entry length %d,"
124 "unit size: %d\n", entry_len, unit_size);
125 GOTO(out, rc = -EOVERFLOW);
128 if (bytes_in_unit < entry_len) {
129 if (units_total == 0) {
134 /* check if we need to consume remaining bytes. */
135 if (last_in_unit != NULL && bytes_in_unit) {
136 last_in_unit->mne_length += bytes_in_unit;
138 buf += bytes_in_unit;
141 LASSERT((rc & (unit_size - 1)) == 0);
143 if (units_in_page == 0) {
144 /* allocate a new page */
145 pages[index] = alloc_page(GFP_KERNEL);
146 if (pages[index] == NULL) {
151 /* destroy previous map */
153 kunmap(pages[index - 1]);
155 /* reassign buffer */
156 buf = kmap(pages[index]);
159 units_in_page = PAGE_SIZE / unit_size;
160 LASSERT(units_in_page > 0);
163 /* allocate an unit */
164 LASSERT(((long)buf & (unit_size - 1)) == 0);
165 bytes_in_unit = unit_size;
171 entry = (struct mgs_nidtbl_entry *)buf;
172 entry->mne_version = tgt->mnt_version;
173 entry->mne_instance = mti->mti_instance;
174 entry->mne_index = mti->mti_stripe_index;
175 entry->mne_length = entry_len;
176 entry->mne_type = tgt->mnt_type;
177 entry->mne_nid_type = 0;
178 entry->mne_nid_size = sizeof(lnet_nid_t);
179 entry->mne_nid_count = mti->mti_nid_count;
180 memcpy(entry->u.nids, mti->mti_nids,
181 mti->mti_nid_count * sizeof(lnet_nid_t));
183 version = tgt->mnt_version;
187 bytes_in_unit -= entry_len;
188 last_in_unit = entry;
190 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
191 tbl->mn_fsdb->fsdb_name, entry_len,
192 bytes_in_unit, index, nrpages, units_total);
195 kunmap(pages[index - 1]);
197 LASSERT(version <= tbl->mn_version);
198 res->mcr_size = tbl->mn_version;
199 res->mcr_offset = nobuf ? version : tbl->mn_version;
200 mutex_unlock(&tbl->mn_lock);
201 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
203 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
204 tbl->mn_fsdb->fsdb_name, rc, version);
208 static int nidtbl_update_version(const struct lu_env *env,
209 struct mgs_device *mgs,
210 struct mgs_nidtbl *tbl)
212 struct dt_object *fsdb;
215 struct lu_buf buf = {
217 .lb_len = sizeof(version)
223 LASSERT(mutex_is_locked(&tbl->mn_lock));
225 fsdb = local_file_find_or_create(env, mgs->mgs_los, mgs->mgs_nidtbl_dir,
226 tbl->mn_fsdb->fsdb_name,
227 S_IFREG | S_IRUGO | S_IWUSR);
229 RETURN(PTR_ERR(fsdb));
231 th = dt_trans_create(env, mgs->mgs_bottom);
233 GOTO(out_put, rc = PTR_ERR(th));
235 th->th_sync = 1; /* update table synchronously */
236 rc = dt_declare_record_write(env, fsdb, &buf, off, th);
240 rc = dt_trans_start_local(env, mgs->mgs_bottom, th);
244 version = cpu_to_le64(tbl->mn_version);
245 rc = dt_record_write(env, fsdb, &buf, &off, th);
248 dt_trans_stop(env, mgs->mgs_bottom, th);
250 lu_object_put(env, &fsdb->do_lu);
254 #define MGS_NIDTBL_VERSION_INIT 2
256 static int nidtbl_read_version(const struct lu_env *env,
257 struct mgs_device *mgs, struct mgs_nidtbl *tbl,
260 struct dt_object *fsdb;
263 struct lu_buf buf = {
265 .lb_len = sizeof(tmpver)
271 LASSERT(mutex_is_locked(&tbl->mn_lock));
273 LASSERT(mgs->mgs_nidtbl_dir);
274 rc = dt_lookup_dir(env, mgs->mgs_nidtbl_dir, tbl->mn_fsdb->fsdb_name,
277 *version = MGS_NIDTBL_VERSION_INIT;
283 fsdb = dt_locate_at(env, mgs->mgs_bottom, &fid,
284 &mgs->mgs_dt_dev.dd_lu_dev, NULL);
286 RETURN(PTR_ERR(fsdb));
288 rc = dt_read(env, fsdb, &buf, &off);
289 if (rc == buf.lb_len) {
290 *version = le64_to_cpu(tmpver);
292 } else if (rc == 0) {
293 *version = MGS_NIDTBL_VERSION_INIT;
295 CERROR("%s: read version file %s error %d\n",
296 mgs->mgs_obd->obd_name, tbl->mn_fsdb->fsdb_name, rc);
298 lu_object_put(env, &fsdb->do_lu);
302 static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
303 struct mgs_target_info *mti)
305 struct mgs_nidtbl *tbl;
306 struct mgs_nidtbl_target *tgt;
308 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
312 type &= ~LDD_F_SV_TYPE_MGS;
315 tbl = &fsdb->fsdb_nidtbl;
316 mutex_lock(&tbl->mn_lock);
317 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
318 struct mgs_target_info *info = &tgt->mnt_mti;
320 if (type == tgt->mnt_type &&
321 mti->mti_stripe_index == info->mti_stripe_index) {
329 GOTO(out, rc = -ENOMEM);
331 INIT_LIST_HEAD(&tgt->mnt_list);
333 tgt->mnt_version = 0; /* 0 means invalid */
334 tgt->mnt_type = type;
336 ++tbl->mn_nr_targets;
339 tgt->mnt_version = ++tbl->mn_version;
342 list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
344 rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
348 mutex_unlock(&tbl->mn_lock);
350 CERROR("Write NID table version for file system %s error %d\n",
351 fsdb->fsdb_name, rc);
355 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
357 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
358 struct list_head head = LIST_HEAD_INIT(head);
360 mutex_lock(&tbl->mn_lock);
361 tbl->mn_nr_targets = 0;
362 list_splice_init(&tbl->mn_targets, &head);
363 mutex_unlock(&tbl->mn_lock);
365 while (!list_empty(&head)) {
366 struct mgs_nidtbl_target *tgt;
367 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
368 list_del(&tgt->mnt_list);
373 static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
375 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
378 INIT_LIST_HEAD(&tbl->mn_targets);
379 mutex_init(&tbl->mn_lock);
380 tbl->mn_nr_targets = 0;
382 mutex_lock(&tbl->mn_lock);
383 rc = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl, &tbl->mn_version);
384 mutex_unlock(&tbl->mn_lock);
386 CERROR("%s: IR: failed to read current version, rc = %d\n",
387 fsdb->fsdb_mgs->mgs_obd->obd_name, rc);
389 CDEBUG(D_MGS, "IR: current version is %llu\n",
395 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
396 void mgs_ir_notify_complete(struct fs_db *fsdb)
399 cfs_duration_t delta;
401 atomic_set(&fsdb->fsdb_notify_phase, 0);
404 fsdb->fsdb_notify_count++;
405 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
406 fsdb->fsdb_notify_total += delta;
407 if (delta > fsdb->fsdb_notify_max)
408 fsdb->fsdb_notify_max = delta;
410 cfs_duration_usec(delta, &tv);
411 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
412 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
415 static int mgs_ir_notify(void *arg)
417 struct fs_db *fsdb = arg;
418 struct ldlm_res_id resid;
420 char name[sizeof(fsdb->fsdb_name) + 20];
422 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
423 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
425 complete(&fsdb->fsdb_notify_comp);
427 set_user_nice(current, -2);
429 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
431 struct l_wait_info lwi = { 0 };
433 l_wait_event(fsdb->fsdb_notify_waitq,
434 fsdb->fsdb_notify_stop ||
435 atomic_read(&fsdb->fsdb_notify_phase),
437 if (fsdb->fsdb_notify_stop)
440 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
441 name, atomic_read(&fsdb->fsdb_notify_phase));
443 fsdb->fsdb_notify_start = cfs_time_current();
444 mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
447 complete(&fsdb->fsdb_notify_comp);
451 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
454 struct task_struct *task;
457 ir_timeout = OBD_IR_MGS_TIMEOUT;
459 fsdb->fsdb_ir_state = IR_FULL;
460 if (cfs_time_before(cfs_time_current_sec(),
461 mgs->mgs_start_time + ir_timeout))
462 fsdb->fsdb_ir_state = IR_STARTUP;
463 fsdb->fsdb_nonir_clients = 0;
464 INIT_LIST_HEAD(&fsdb->fsdb_clients);
466 /* start notify thread */
467 fsdb->fsdb_mgs = mgs;
468 atomic_set(&fsdb->fsdb_notify_phase, 0);
469 init_waitqueue_head(&fsdb->fsdb_notify_waitq);
470 init_completion(&fsdb->fsdb_notify_comp);
472 task = kthread_run(mgs_ir_notify, fsdb,
473 "mgs_%s_notify", fsdb->fsdb_name);
475 wait_for_completion(&fsdb->fsdb_notify_comp);
477 CERROR("Start notify thread error %ld\n", PTR_ERR(task));
479 mgs_nidtbl_init_fs(env, fsdb);
483 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
485 if (test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
488 mgs_fsc_cleanup_by_fsdb(fsdb);
490 mgs_nidtbl_fini_fs(fsdb);
492 LASSERT(list_empty(&fsdb->fsdb_clients));
494 fsdb->fsdb_notify_stop = 1;
495 wake_up(&fsdb->fsdb_notify_waitq);
496 wait_for_completion(&fsdb->fsdb_notify_comp);
499 /* caller must have held fsdb_mutex */
500 static inline void ir_state_graduate(struct fs_db *fsdb)
502 if (fsdb->fsdb_ir_state == IR_STARTUP) {
503 if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
504 cfs_time_current_sec())) {
505 fsdb->fsdb_ir_state = IR_FULL;
506 if (fsdb->fsdb_nonir_clients)
507 fsdb->fsdb_ir_state = IR_PARTIAL;
512 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
513 struct mgs_target_info *mti)
519 if (mti->mti_instance == 0)
522 rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
526 rc = mgs_nidtbl_write(env, fsdb, mti);
531 mutex_lock(&fsdb->fsdb_mutex);
532 ir_state_graduate(fsdb);
533 switch (fsdb->fsdb_ir_state) {
535 mti->mti_flags |= LDD_F_IR_CAPABLE;
545 mutex_unlock(&fsdb->fsdb_mutex);
547 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
549 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
551 atomic_inc(&fsdb->fsdb_notify_phase);
552 wake_up(&fsdb->fsdb_notify_waitq);
557 /* NID table can be cached by two entities: Clients and MDTs */
563 static int delogname(char *logname, char *fsname, int *typ)
569 ptr = strrchr(logname, '-');
573 /* decouple file system name. The llog name may be:
574 * - "prefix-fsname", prefix is "cliir" or "mdtir"
576 if (strncmp(ptr, "-mdtir", 6) == 0)
578 else if (strncmp(ptr, "-cliir", 6) == 0)
587 memcpy(fsname, logname, len);
594 int mgs_get_ir_logs(struct ptlrpc_request *req)
596 struct lu_env *env = req->rq_svc_thread->t_env;
597 struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
599 struct mgs_config_body *body;
600 struct mgs_config_res *res;
601 struct ptlrpc_bulk_desc *desc;
602 struct l_wait_info lwi;
612 struct page **pages = NULL;
615 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
619 if (body->mcb_type != CONFIG_T_RECOVER)
622 rc = delogname(body->mcb_name, fsname, &type);
626 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
630 bufsize = body->mcb_units << body->mcb_bits;
631 nrpages = (bufsize + PAGE_SIZE - 1) >> PAGE_SHIFT;
632 if (nrpages > PTLRPC_MAX_BRW_PAGES)
635 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
636 body->mcb_name, bufsize);
638 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
642 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
644 GOTO(out, rc = -EINVAL);
646 res->mcr_offset = body->mcb_offset;
647 unit_size = min_t(int, 1 << body->mcb_bits, PAGE_SIZE);
648 bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
649 pages, nrpages, bufsize / unit_size, unit_size);
651 GOTO(out, rc = bytes);
653 /* start bulk transfer */
654 page_count = (bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
655 LASSERT(page_count <= nrpages);
656 desc = ptlrpc_prep_bulk_exp(req, page_count, 1,
657 PTLRPC_BULK_PUT_SOURCE |
658 PTLRPC_BULK_BUF_KIOV,
660 &ptlrpc_bulk_kiov_pin_ops);
662 GOTO(out, rc = -ENOMEM);
664 for (i = 0; i < page_count && bytes > 0; i++) {
665 desc->bd_frag_ops->add_kiov_frag(desc, pages[i], 0,
671 rc = target_bulk_io(req->rq_export, desc, &lwi);
672 ptlrpc_free_bulk(desc);
675 for (i = 0; i < nrpages; i++) {
676 if (pages[i] == NULL)
678 __free_page(pages[i]);
680 OBD_FREE(pages, sizeof(*pages) * nrpages);
684 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
686 const char *strings[] = IR_STRINGS;
690 for (i = 0; i < ARRAY_SIZE(strings); i++) {
691 if (strcmp(strings[i], buf) == 0) {
699 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
700 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
701 mutex_lock(&fsdb->fsdb_mutex);
702 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
704 fsdb->fsdb_ir_state = state;
705 mutex_unlock(&fsdb->fsdb_mutex);
710 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
715 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
720 fsdb->fsdb_notify_total = 0;
721 fsdb->fsdb_notify_max = 0;
722 fsdb->fsdb_notify_count = 0;
726 static struct lproc_ir_cmd {
729 int (*handler)(struct fs_db *, const char *);
731 { "state=", 6, lprocfs_ir_set_state },
732 { "timeout=", 8, lprocfs_ir_set_timeout },
733 { "0", 1, lprocfs_ir_clear_stats }
736 int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
737 size_t count, void *data)
739 struct fs_db *fsdb = data;
744 if (count == 0 || count >= PAGE_SIZE)
747 OBD_ALLOC(kbuf, count + 1);
751 if (copy_from_user(kbuf, buffer, count)) {
752 OBD_FREE(kbuf, count + 1);
756 kbuf[count] = 0; /* buffer is supposed to end with 0 */
757 if (kbuf[count - 1] == '\n')
761 /* fsname=<file system name> must be the 1st entry */
762 while (ptr != NULL) {
766 tmpptr = strchr(ptr, ';');
771 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
772 struct lproc_ir_cmd *cmd;
776 cmdlen = cmd->namelen;
777 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
779 rc = cmd->handler(fsdb, ptr);
789 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
790 OBD_FREE(kbuf, count + 1);
794 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
796 struct fs_db *fsdb = data;
797 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
798 const char *ir_strings[] = IR_STRINGS;
799 struct timeval tv_max;
802 /* mgs_live_seq_show() already holds fsdb_mutex. */
803 ir_state_graduate(fsdb);
805 seq_printf(seq, "\nimperative_recovery_state:\n");
808 " nonir_clients: %d\n"
809 " nidtbl_version: %lld\n",
810 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
813 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
814 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
816 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
817 " notify_duation_max: %lu.%06lu\n"
818 " notify_count: %u\n",
819 tv.tv_sec, tv.tv_usec,
820 tv_max.tv_sec, tv_max.tv_usec,
821 fsdb->fsdb_notify_count);
826 int lprocfs_ir_timeout_seq_show(struct seq_file *m, void *data)
828 return lprocfs_uint_seq_show(m, &ir_timeout);
831 ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
832 const char __user *buffer,
833 size_t count, loff_t *off)
835 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
838 /* --------------- Handle non IR support clients --------------- */
839 /* attach a lustre file system to an export */
840 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
843 struct mgs_export_data *data = &exp->u.eu_mgs_data;
844 struct mgs_device *mgs = exp2mgs_dev(exp);
846 struct mgs_fsc *fsc = NULL;
847 struct mgs_fsc *new_fsc = NULL;
852 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
856 /* allocate a new fsc in case we need it in spinlock. */
857 OBD_ALLOC_PTR(new_fsc);
861 INIT_LIST_HEAD(&new_fsc->mfc_export_list);
862 INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
863 new_fsc->mfc_fsdb = fsdb;
864 new_fsc->mfc_export = class_export_get(exp);
865 new_fsc->mfc_ir_capable = !!(exp_connect_flags(exp) &
866 OBD_CONNECT_IMP_RECOV);
869 mutex_lock(&fsdb->fsdb_mutex);
871 /* tend to find it in export list because this list is shorter. */
872 spin_lock(&data->med_lock);
873 list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
874 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
883 /* add it into export list. */
884 list_add(&fsc->mfc_export_list, &data->med_clients);
886 /* add into fsdb list. */
887 list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
888 if (!fsc->mfc_ir_capable) {
889 ++fsdb->fsdb_nonir_clients;
890 if (fsdb->fsdb_ir_state == IR_FULL)
891 fsdb->fsdb_ir_state = IR_PARTIAL;
895 spin_unlock(&data->med_lock);
896 mutex_unlock(&fsdb->fsdb_mutex);
899 class_export_put(new_fsc->mfc_export);
900 OBD_FREE_PTR(new_fsc);
905 void mgs_fsc_cleanup(struct obd_export *exp)
907 struct mgs_export_data *data = &exp->u.eu_mgs_data;
908 struct mgs_fsc *fsc, *tmp;
909 struct list_head head = LIST_HEAD_INIT(head);
911 spin_lock(&data->med_lock);
912 list_splice_init(&data->med_clients, &head);
913 spin_unlock(&data->med_lock);
915 list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
916 struct fs_db *fsdb = fsc->mfc_fsdb;
918 LASSERT(fsc->mfc_export == exp);
920 mutex_lock(&fsdb->fsdb_mutex);
921 list_del_init(&fsc->mfc_fsdb_list);
922 if (fsc->mfc_ir_capable == 0) {
923 --fsdb->fsdb_nonir_clients;
924 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
925 if (fsdb->fsdb_nonir_clients == 0 &&
926 fsdb->fsdb_ir_state == IR_PARTIAL)
927 fsdb->fsdb_ir_state = IR_FULL;
929 mutex_unlock(&fsdb->fsdb_mutex);
930 list_del_init(&fsc->mfc_export_list);
931 class_export_put(fsc->mfc_export);
936 /* must be called with fsdb->fsdb_mutex held */
937 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
939 struct mgs_fsc *fsc, *tmp;
941 list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
943 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
945 LASSERT(fsdb == fsc->mfc_fsdb);
946 list_del_init(&fsc->mfc_fsdb_list);
948 spin_lock(&data->med_lock);
949 list_del_init(&fsc->mfc_export_list);
950 spin_unlock(&data->med_lock);
951 class_export_put(fsc->mfc_export);
955 fsdb->fsdb_nonir_clients = 0;
956 if (fsdb->fsdb_ir_state == IR_PARTIAL)
957 fsdb->fsdb_ir_state = IR_FULL;