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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mgs/mgs_nids.c
38 * NID table management for lustre.
40 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
43 #define DEBUG_SUBSYSTEM S_MGS
44 #define D_MGS D_CONFIG
46 #include <linux/kthread.h>
47 #include <linux/pagemap.h>
50 #include <obd_class.h>
51 #include <lustre_disk.h>
53 #include "mgs_internal.h"
55 static unsigned int ir_timeout;
57 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
59 struct mgs_nidtbl_target *tgt;
62 LASSERT(mutex_is_locked(&tbl->mn_lock));
63 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
64 if (!tgt->mnt_version)
67 if (version >= tgt->mnt_version)
70 version = tgt->mnt_version;
76 * Fetch nidtbl entries whose version are not less than @version
77 * nidtbl entries will be packed in @pages by @unit_size units - entries
78 * shouldn't cross unit boundaries.
80 static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
81 struct mgs_config_res *res, struct page **pages,
82 int nrpages, int units_total, int unit_size)
84 struct mgs_nidtbl_target *tgt;
85 struct mgs_nidtbl_entry *entry;
86 struct mgs_nidtbl_entry *last_in_unit = NULL;
87 struct mgs_target_info *mti;
88 __u64 version = res->mcr_offset;
91 int bytes_in_unit = 0;
92 int units_in_page = 0;
97 /* make sure unit_size is power 2 */
98 LASSERT((unit_size & (unit_size - 1)) == 0);
99 LASSERT(nrpages << PAGE_CACHE_SHIFT >= units_total * unit_size);
101 mutex_lock(&tbl->mn_lock);
102 LASSERT(nidtbl_is_sane(tbl));
104 /* no more entries ? */
105 if (version > tbl->mn_version) {
106 version = tbl->mn_version;
110 /* iterate over all targets to compose a bitmap by the type of llog.
111 * If the llog is for MDTs, llog entries for OSTs will be returned;
112 * otherwise, it's for clients, then llog entries for both OSTs and
113 * MDTs will be returned.
115 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
116 int entry_len = sizeof(*entry);
118 if (tgt->mnt_version < version)
121 /* write target recover information */
123 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
124 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
126 if (entry_len > unit_size) {
127 CWARN("nidtbl: too large entry: entry length %d,"
128 "unit size: %d\n", entry_len, unit_size);
129 GOTO(out, rc = -EOVERFLOW);
132 if (bytes_in_unit < entry_len) {
133 if (units_total == 0) {
138 /* check if we need to consume remaining bytes. */
139 if (last_in_unit != NULL && bytes_in_unit) {
140 last_in_unit->mne_length += bytes_in_unit;
142 buf += bytes_in_unit;
145 LASSERT((rc & (unit_size - 1)) == 0);
147 if (units_in_page == 0) {
148 /* allocate a new page */
149 pages[index] = alloc_page(GFP_KERNEL);
150 if (pages[index] == NULL) {
155 /* destroy previous map */
157 kunmap(pages[index - 1]);
159 /* reassign buffer */
160 buf = kmap(pages[index]);
163 units_in_page = PAGE_CACHE_SIZE / unit_size;
164 LASSERT(units_in_page > 0);
167 /* allocate an unit */
168 LASSERT(((long)buf & (unit_size - 1)) == 0);
169 bytes_in_unit = unit_size;
175 entry = (struct mgs_nidtbl_entry *)buf;
176 entry->mne_version = tgt->mnt_version;
177 entry->mne_instance = mti->mti_instance;
178 entry->mne_index = mti->mti_stripe_index;
179 entry->mne_length = entry_len;
180 entry->mne_type = tgt->mnt_type;
181 entry->mne_nid_type = 0;
182 entry->mne_nid_size = sizeof(lnet_nid_t);
183 entry->mne_nid_count = mti->mti_nid_count;
184 memcpy(entry->u.nids, mti->mti_nids,
185 mti->mti_nid_count * sizeof(lnet_nid_t));
187 version = tgt->mnt_version;
191 bytes_in_unit -= entry_len;
192 last_in_unit = entry;
194 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
195 tbl->mn_fsdb->fsdb_name, entry_len,
196 bytes_in_unit, index, nrpages, units_total);
199 kunmap(pages[index - 1]);
201 LASSERT(version <= tbl->mn_version);
202 res->mcr_size = tbl->mn_version;
203 res->mcr_offset = nobuf ? version : tbl->mn_version;
204 mutex_unlock(&tbl->mn_lock);
205 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
207 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
208 tbl->mn_fsdb->fsdb_name, rc, version);
212 static int nidtbl_update_version(const struct lu_env *env,
213 struct mgs_device *mgs,
214 struct mgs_nidtbl *tbl)
216 struct dt_object *fsdb;
219 struct lu_buf buf = {
221 .lb_len = sizeof(version)
227 LASSERT(mutex_is_locked(&tbl->mn_lock));
229 fsdb = local_file_find_or_create(env, mgs->mgs_los, mgs->mgs_nidtbl_dir,
230 tbl->mn_fsdb->fsdb_name,
231 S_IFREG | S_IRUGO | S_IWUSR);
233 RETURN(PTR_ERR(fsdb));
235 th = dt_trans_create(env, mgs->mgs_bottom);
237 GOTO(out_put, rc = PTR_ERR(th));
239 th->th_sync = 1; /* update table synchronously */
240 rc = dt_declare_record_write(env, fsdb, &buf, off, th);
244 rc = dt_trans_start_local(env, mgs->mgs_bottom, th);
248 version = cpu_to_le64(tbl->mn_version);
249 rc = dt_record_write(env, fsdb, &buf, &off, th);
252 dt_trans_stop(env, mgs->mgs_bottom, th);
254 lu_object_put(env, &fsdb->do_lu);
258 #define MGS_NIDTBL_VERSION_INIT 2
260 static int nidtbl_read_version(const struct lu_env *env,
261 struct mgs_device *mgs, struct mgs_nidtbl *tbl,
264 struct dt_object *fsdb;
267 struct lu_buf buf = {
269 .lb_len = sizeof(tmpver)
275 LASSERT(mutex_is_locked(&tbl->mn_lock));
277 LASSERT(mgs->mgs_nidtbl_dir);
278 rc = dt_lookup_dir(env, mgs->mgs_nidtbl_dir, tbl->mn_fsdb->fsdb_name,
281 *version = MGS_NIDTBL_VERSION_INIT;
287 fsdb = dt_locate_at(env, mgs->mgs_bottom, &fid,
288 &mgs->mgs_dt_dev.dd_lu_dev, NULL);
290 RETURN(PTR_ERR(fsdb));
292 rc = dt_read(env, fsdb, &buf, &off);
293 if (rc == buf.lb_len) {
294 *version = le64_to_cpu(tmpver);
296 } else if (rc == 0) {
297 *version = MGS_NIDTBL_VERSION_INIT;
299 CERROR("%s: read version file %s error %d\n",
300 mgs->mgs_obd->obd_name, tbl->mn_fsdb->fsdb_name, rc);
302 lu_object_put(env, &fsdb->do_lu);
306 static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
307 struct mgs_target_info *mti)
309 struct mgs_nidtbl *tbl;
310 struct mgs_nidtbl_target *tgt;
312 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
316 type &= ~LDD_F_SV_TYPE_MGS;
319 tbl = &fsdb->fsdb_nidtbl;
320 mutex_lock(&tbl->mn_lock);
321 list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
322 struct mgs_target_info *info = &tgt->mnt_mti;
324 if (type == tgt->mnt_type &&
325 mti->mti_stripe_index == info->mti_stripe_index) {
333 GOTO(out, rc = -ENOMEM);
335 INIT_LIST_HEAD(&tgt->mnt_list);
337 tgt->mnt_version = 0; /* 0 means invalid */
338 tgt->mnt_type = type;
340 ++tbl->mn_nr_targets;
343 tgt->mnt_version = ++tbl->mn_version;
346 list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
348 rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
352 mutex_unlock(&tbl->mn_lock);
354 CERROR("Write NID table version for file system %s error %d\n",
355 fsdb->fsdb_name, rc);
359 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
361 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
362 struct list_head head = LIST_HEAD_INIT(head);
364 mutex_lock(&tbl->mn_lock);
365 tbl->mn_nr_targets = 0;
366 list_splice_init(&tbl->mn_targets, &head);
367 mutex_unlock(&tbl->mn_lock);
369 while (!list_empty(&head)) {
370 struct mgs_nidtbl_target *tgt;
371 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
372 list_del(&tgt->mnt_list);
377 static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
379 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
382 INIT_LIST_HEAD(&tbl->mn_targets);
383 mutex_init(&tbl->mn_lock);
384 tbl->mn_nr_targets = 0;
386 mutex_lock(&tbl->mn_lock);
387 rc = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl, &tbl->mn_version);
388 mutex_unlock(&tbl->mn_lock);
390 CERROR("%s: IR: failed to read current version, rc = %d\n",
391 fsdb->fsdb_mgs->mgs_obd->obd_name, rc);
393 CDEBUG(D_MGS, "IR: current version is %llu\n",
399 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
400 void mgs_ir_notify_complete(struct fs_db *fsdb)
403 cfs_duration_t delta;
405 atomic_set(&fsdb->fsdb_notify_phase, 0);
408 fsdb->fsdb_notify_count++;
409 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
410 fsdb->fsdb_notify_total += delta;
411 if (delta > fsdb->fsdb_notify_max)
412 fsdb->fsdb_notify_max = delta;
414 cfs_duration_usec(delta, &tv);
415 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
416 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
419 static int mgs_ir_notify(void *arg)
421 struct fs_db *fsdb = arg;
422 struct ldlm_res_id resid;
424 char name[sizeof(fsdb->fsdb_name) + 20];
426 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
427 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
429 complete(&fsdb->fsdb_notify_comp);
431 set_user_nice(current, -2);
433 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
435 struct l_wait_info lwi = { 0 };
437 l_wait_event(fsdb->fsdb_notify_waitq,
438 fsdb->fsdb_notify_stop ||
439 atomic_read(&fsdb->fsdb_notify_phase),
441 if (fsdb->fsdb_notify_stop)
444 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
445 name, atomic_read(&fsdb->fsdb_notify_phase));
447 fsdb->fsdb_notify_start = cfs_time_current();
448 mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
451 complete(&fsdb->fsdb_notify_comp);
455 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
458 struct task_struct *task;
461 ir_timeout = OBD_IR_MGS_TIMEOUT;
463 fsdb->fsdb_ir_state = IR_FULL;
464 if (cfs_time_before(cfs_time_current_sec(),
465 mgs->mgs_start_time + ir_timeout))
466 fsdb->fsdb_ir_state = IR_STARTUP;
467 fsdb->fsdb_nonir_clients = 0;
468 INIT_LIST_HEAD(&fsdb->fsdb_clients);
470 /* start notify thread */
471 fsdb->fsdb_mgs = mgs;
472 atomic_set(&fsdb->fsdb_notify_phase, 0);
473 init_waitqueue_head(&fsdb->fsdb_notify_waitq);
474 init_completion(&fsdb->fsdb_notify_comp);
476 task = kthread_run(mgs_ir_notify, fsdb,
477 "mgs_%s_notify", fsdb->fsdb_name);
479 wait_for_completion(&fsdb->fsdb_notify_comp);
481 CERROR("Start notify thread error %ld\n", PTR_ERR(task));
483 mgs_nidtbl_init_fs(env, fsdb);
487 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
489 if (test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
492 mgs_fsc_cleanup_by_fsdb(fsdb);
494 mgs_nidtbl_fini_fs(fsdb);
496 LASSERT(list_empty(&fsdb->fsdb_clients));
498 fsdb->fsdb_notify_stop = 1;
499 wake_up(&fsdb->fsdb_notify_waitq);
500 wait_for_completion(&fsdb->fsdb_notify_comp);
503 /* caller must have held fsdb_mutex */
504 static inline void ir_state_graduate(struct fs_db *fsdb)
506 if (fsdb->fsdb_ir_state == IR_STARTUP) {
507 if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
508 cfs_time_current_sec())) {
509 fsdb->fsdb_ir_state = IR_FULL;
510 if (fsdb->fsdb_nonir_clients)
511 fsdb->fsdb_ir_state = IR_PARTIAL;
516 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
517 struct mgs_target_info *mti)
523 if (mti->mti_instance == 0)
526 rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
530 rc = mgs_nidtbl_write(env, fsdb, mti);
535 mutex_lock(&fsdb->fsdb_mutex);
536 ir_state_graduate(fsdb);
537 switch (fsdb->fsdb_ir_state) {
539 mti->mti_flags |= LDD_F_IR_CAPABLE;
549 mutex_unlock(&fsdb->fsdb_mutex);
551 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
553 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
555 atomic_inc(&fsdb->fsdb_notify_phase);
556 wake_up(&fsdb->fsdb_notify_waitq);
561 /* NID table can be cached by two entities: Clients and MDTs */
567 static int delogname(char *logname, char *fsname, int *typ)
573 ptr = strrchr(logname, '-');
577 /* decouple file system name. The llog name may be:
578 * - "prefix-fsname", prefix is "cliir" or "mdtir"
580 if (strncmp(ptr, "-mdtir", 6) == 0)
582 else if (strncmp(ptr, "-cliir", 6) == 0)
591 memcpy(fsname, logname, len);
598 int mgs_get_ir_logs(struct ptlrpc_request *req)
600 struct lu_env *env = req->rq_svc_thread->t_env;
601 struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
603 struct mgs_config_body *body;
604 struct mgs_config_res *res;
605 struct ptlrpc_bulk_desc *desc;
606 struct l_wait_info lwi;
616 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 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
634 bufsize = body->mcb_units << body->mcb_bits;
635 nrpages = (bufsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
636 if (nrpages > PTLRPC_MAX_BRW_PAGES)
639 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
640 body->mcb_name, bufsize);
642 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
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_CACHE_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_CACHE_SIZE - 1) >> PAGE_CACHE_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,
672 bytes -= PAGE_CACHE_SIZE;
675 rc = target_bulk_io(req->rq_export, desc, &lwi);
676 ptlrpc_free_bulk(desc);
679 for (i = 0; i < nrpages; i++) {
680 if (pages[i] == NULL)
682 __free_page(pages[i]);
684 OBD_FREE(pages, sizeof(*pages) * nrpages);
688 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
690 const char *strings[] = IR_STRINGS;
694 for (i = 0; i < ARRAY_SIZE(strings); i++) {
695 if (strcmp(strings[i], buf) == 0) {
703 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
704 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
705 mutex_lock(&fsdb->fsdb_mutex);
706 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
708 fsdb->fsdb_ir_state = state;
709 mutex_unlock(&fsdb->fsdb_mutex);
714 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
719 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
724 fsdb->fsdb_notify_total = 0;
725 fsdb->fsdb_notify_max = 0;
726 fsdb->fsdb_notify_count = 0;
730 static struct lproc_ir_cmd {
733 int (*handler)(struct fs_db *, const char *);
735 { "state=", 6, lprocfs_ir_set_state },
736 { "timeout=", 8, lprocfs_ir_set_timeout },
737 { "0", 1, lprocfs_ir_clear_stats }
740 int lprocfs_wr_ir_state(struct file *file, const char __user *buffer,
741 size_t count, void *data)
743 struct fs_db *fsdb = data;
748 if (count == 0 || count >= PAGE_CACHE_SIZE)
751 OBD_ALLOC(kbuf, count + 1);
755 if (copy_from_user(kbuf, buffer, count)) {
756 OBD_FREE(kbuf, count + 1);
760 kbuf[count] = 0; /* buffer is supposed to end with 0 */
761 if (kbuf[count - 1] == '\n')
765 /* fsname=<file system name> must be the 1st entry */
766 while (ptr != NULL) {
770 tmpptr = strchr(ptr, ';');
775 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
776 struct lproc_ir_cmd *cmd;
780 cmdlen = cmd->namelen;
781 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
783 rc = cmd->handler(fsdb, ptr);
793 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
794 OBD_FREE(kbuf, count + 1);
798 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
800 struct fs_db *fsdb = data;
801 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
802 const char *ir_strings[] = IR_STRINGS;
803 struct timeval tv_max;
806 /* mgs_live_seq_show() already holds fsdb_mutex. */
807 ir_state_graduate(fsdb);
809 seq_printf(seq, "\nimperative_recovery_state:\n");
812 " nonir_clients: %d\n"
813 " nidtbl_version: %lld\n",
814 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
817 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
818 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
820 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
821 " notify_duation_max: %lu.%06lu\n"
822 " notify_count: %u\n",
823 tv.tv_sec, tv.tv_usec,
824 tv_max.tv_sec, tv_max.tv_usec,
825 fsdb->fsdb_notify_count);
830 int lprocfs_ir_timeout_seq_show(struct seq_file *m, void *data)
832 return lprocfs_uint_seq_show(m, &ir_timeout);
835 ssize_t lprocfs_ir_timeout_seq_write(struct file *file,
836 const char __user *buffer,
837 size_t count, loff_t *off)
839 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
842 /* --------------- Handle non IR support clients --------------- */
843 /* attach a lustre file system to an export */
844 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
847 struct mgs_export_data *data = &exp->u.eu_mgs_data;
848 struct mgs_device *mgs = exp2mgs_dev(exp);
850 struct mgs_fsc *fsc = NULL;
851 struct mgs_fsc *new_fsc = NULL;
856 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
860 /* allocate a new fsc in case we need it in spinlock. */
861 OBD_ALLOC_PTR(new_fsc);
865 INIT_LIST_HEAD(&new_fsc->mfc_export_list);
866 INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
867 new_fsc->mfc_fsdb = fsdb;
868 new_fsc->mfc_export = class_export_get(exp);
869 new_fsc->mfc_ir_capable = !!(exp_connect_flags(exp) &
870 OBD_CONNECT_IMP_RECOV);
873 mutex_lock(&fsdb->fsdb_mutex);
875 /* tend to find it in export list because this list is shorter. */
876 spin_lock(&data->med_lock);
877 list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
878 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
887 /* add it into export list. */
888 list_add(&fsc->mfc_export_list, &data->med_clients);
890 /* add into fsdb list. */
891 list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
892 if (!fsc->mfc_ir_capable) {
893 ++fsdb->fsdb_nonir_clients;
894 if (fsdb->fsdb_ir_state == IR_FULL)
895 fsdb->fsdb_ir_state = IR_PARTIAL;
899 spin_unlock(&data->med_lock);
900 mutex_unlock(&fsdb->fsdb_mutex);
903 class_export_put(new_fsc->mfc_export);
904 OBD_FREE_PTR(new_fsc);
909 void mgs_fsc_cleanup(struct obd_export *exp)
911 struct mgs_export_data *data = &exp->u.eu_mgs_data;
912 struct mgs_fsc *fsc, *tmp;
913 struct list_head head = LIST_HEAD_INIT(head);
915 spin_lock(&data->med_lock);
916 list_splice_init(&data->med_clients, &head);
917 spin_unlock(&data->med_lock);
919 list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
920 struct fs_db *fsdb = fsc->mfc_fsdb;
922 LASSERT(fsc->mfc_export == exp);
924 mutex_lock(&fsdb->fsdb_mutex);
925 list_del_init(&fsc->mfc_fsdb_list);
926 if (fsc->mfc_ir_capable == 0) {
927 --fsdb->fsdb_nonir_clients;
928 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
929 if (fsdb->fsdb_nonir_clients == 0 &&
930 fsdb->fsdb_ir_state == IR_PARTIAL)
931 fsdb->fsdb_ir_state = IR_FULL;
933 mutex_unlock(&fsdb->fsdb_mutex);
934 list_del_init(&fsc->mfc_export_list);
935 class_export_put(fsc->mfc_export);
940 /* must be called with fsdb->fsdb_mutex held */
941 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
943 struct mgs_fsc *fsc, *tmp;
945 list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
947 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
949 LASSERT(fsdb == fsc->mfc_fsdb);
950 list_del_init(&fsc->mfc_fsdb_list);
952 spin_lock(&data->med_lock);
953 list_del_init(&fsc->mfc_export_list);
954 spin_unlock(&data->med_lock);
955 class_export_put(fsc->mfc_export);
959 fsdb->fsdb_nonir_clients = 0;
960 if (fsdb->fsdb_ir_state == IR_PARTIAL)
961 fsdb->fsdb_ir_state = IR_FULL;