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, Whamcloud, Inc.
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
47 #include <linux/pagemap.h>
51 #include <obd_class.h>
52 #include <lustre_fsfilt.h>
53 #include <lustre_disk.h>
55 #include "mgs_internal.h"
57 static unsigned int ir_timeout;
59 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
61 struct mgs_nidtbl_target *tgt;
64 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
65 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
66 if (!tgt->mnt_version)
69 if (version >= tgt->mnt_version)
72 version = tgt->mnt_version;
78 * Fetch nidtbl entries whose version are not less than @version
79 * nidtbl entries will be packed in @pages by @unit_size units - entries
80 * shouldn't cross unit boundaries.
82 static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
83 struct mgs_config_res *res, cfs_page_t **pages,
84 int nrpages, int units_total, int unit_size)
86 struct mgs_nidtbl_target *tgt;
87 struct mgs_nidtbl_entry *entry;
88 struct mgs_nidtbl_entry *last_in_unit = NULL;
89 struct mgs_target_info *mti;
90 __u64 version = res->mcr_offset;
93 int bytes_in_unit = 0;
94 int units_in_page = 0;
99 /* make sure unit_size is power 2 */
100 LASSERT((unit_size & (unit_size - 1)) == 0);
101 LASSERT(nrpages << CFS_PAGE_SHIFT >= units_total * unit_size);
103 cfs_mutex_lock(&tbl->mn_lock);
104 LASSERT(nidtbl_is_sane(tbl));
106 /* no more entries ? */
107 if (version > tbl->mn_version) {
108 version = tbl->mn_version;
112 /* iterate over all targets to compose a bitmap by the type of llog.
113 * If the llog is for MDTs, llog entries for OSTs will be returned;
114 * otherwise, it's for clients, then llog entries for both OSTs and
115 * MDTs will be returned.
117 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
118 int entry_len = sizeof(*entry);
120 if (tgt->mnt_version < version)
123 /* write target recover information */
125 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
126 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
128 if (entry_len > unit_size) {
129 CWARN("nidtbl: too large entry: entry length %d,"
130 "unit size: %d\n", entry_len, unit_size);
131 GOTO(out, rc = -EOVERFLOW);
134 if (bytes_in_unit < entry_len) {
135 if (units_total == 0) {
140 /* check if we need to consume remaining bytes. */
141 if (last_in_unit != NULL && bytes_in_unit) {
142 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
143 /* May need to swab back to update the length.*/
144 if (exp->exp_need_mne_swab)
145 lustre_swab_mgs_nidtbl_entry(last_in_unit);
147 last_in_unit->mne_length += bytes_in_unit;
148 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
149 if (exp->exp_need_mne_swab)
150 lustre_swab_mgs_nidtbl_entry(last_in_unit);
153 buf += bytes_in_unit;
156 LASSERT((rc & (unit_size - 1)) == 0);
158 if (units_in_page == 0) {
159 /* allocate a new page */
160 pages[index] = cfs_alloc_page(CFS_ALLOC_STD);
161 if (pages[index] == NULL) {
166 /* destroy previous map */
168 cfs_kunmap(pages[index - 1]);
170 /* reassign buffer */
171 buf = cfs_kmap(pages[index]);
174 units_in_page = CFS_PAGE_SIZE / unit_size;
175 LASSERT(units_in_page > 0);
178 /* allocate an unit */
179 LASSERT(((long)buf & (unit_size - 1)) == 0);
180 bytes_in_unit = unit_size;
186 entry = (struct mgs_nidtbl_entry *)buf;
187 entry->mne_version = tgt->mnt_version;
188 entry->mne_instance = mti->mti_instance;
189 entry->mne_index = mti->mti_stripe_index;
190 entry->mne_length = entry_len;
191 entry->mne_type = tgt->mnt_type;
192 entry->mne_nid_type = 0;
193 entry->mne_nid_size = sizeof(lnet_nid_t);
194 entry->mne_nid_count = mti->mti_nid_count;
195 memcpy(entry->u.nids, mti->mti_nids,
196 mti->mti_nid_count * sizeof(lnet_nid_t));
198 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
199 /* For LU-1644, swab entry for 2.2 clients. */
200 if (exp->exp_need_mne_swab)
201 lustre_swab_mgs_nidtbl_entry(entry);
204 version = tgt->mnt_version;
208 bytes_in_unit -= entry_len;
209 last_in_unit = entry;
211 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
212 tbl->mn_fsdb->fsdb_name, entry_len,
213 bytes_in_unit, index, nrpages, units_total);
216 cfs_kunmap(pages[index - 1]);
218 LASSERT(version <= tbl->mn_version);
219 res->mcr_size = tbl->mn_version;
220 res->mcr_offset = nobuf ? version : tbl->mn_version;
221 cfs_mutex_unlock(&tbl->mn_lock);
222 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
224 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
225 tbl->mn_fsdb->fsdb_name, rc, version);
229 static int nidtbl_update_version(const struct lu_env *env,
230 struct mgs_device *mgs,
231 struct mgs_nidtbl *tbl)
233 struct lvfs_run_ctxt saved;
234 struct file *file = NULL;
235 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
239 struct obd_device *obd = tbl->mn_fsdb->fsdb_obd;
242 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
243 LASSERT(sizeof(filename) < 32);
245 sprintf(filename, "%s/%s",
246 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
248 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
250 file = l_filp_open(filename, O_RDWR|O_CREAT, 0660);
252 version = cpu_to_le64(tbl->mn_version);
253 rc = lustre_fwrite(file, &version, sizeof(version), &off);
254 if (rc == sizeof(version))
257 fsfilt_sync(obd, obd->u.mgs.mgs_sb);
262 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
266 #define MGS_NIDTBL_VERSION_INIT 2
268 static int nidtbl_read_version(const struct lu_env *env,
269 struct mgs_device *mgs, struct mgs_nidtbl *tbl)
271 struct lvfs_run_ctxt saved;
272 struct file *file = NULL;
273 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
277 struct obd_device *obd = tbl->mn_fsdb->fsdb_obd;
280 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
281 LASSERT(sizeof(filename) < 32);
283 sprintf(filename, "%s/%s",
284 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
286 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
288 file = l_filp_open(filename, O_RDONLY, 0);
290 rc = lustre_fread(file, &version, sizeof(version), &off);
291 if (rc == sizeof(version))
292 rc = cpu_to_le64(version);
294 rc = MGS_NIDTBL_VERSION_INIT;
296 CERROR("read version file %s error %d\n", filename, rc);
301 rc = MGS_NIDTBL_VERSION_INIT;
304 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
308 static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
309 struct mgs_target_info *mti)
311 struct mgs_nidtbl *tbl;
312 struct mgs_nidtbl_target *tgt;
314 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
318 type &= ~LDD_F_SV_TYPE_MGS;
321 tbl = &fsdb->fsdb_nidtbl;
322 cfs_mutex_lock(&tbl->mn_lock);
323 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
324 struct mgs_target_info *info = &tgt->mnt_mti;
325 if (type == tgt->mnt_type &&
326 mti->mti_stripe_index == info->mti_stripe_index) {
334 GOTO(out, rc = -ENOMEM);
336 CFS_INIT_LIST_HEAD(&tgt->mnt_list);
338 tgt->mnt_version = 0; /* 0 means invalid */
339 tgt->mnt_type = type;
341 ++tbl->mn_nr_targets;
344 tgt->mnt_version = ++tbl->mn_version;
347 cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
349 rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
353 cfs_mutex_unlock(&tbl->mn_lock);
355 CERROR("Write NID table version for file system %s error %d\n",
356 fsdb->fsdb_name, rc);
360 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
362 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
365 cfs_mutex_lock(&tbl->mn_lock);
366 tbl->mn_nr_targets = 0;
367 cfs_list_splice_init(&tbl->mn_targets, &head);
368 cfs_mutex_unlock(&tbl->mn_lock);
370 while (!cfs_list_empty(&head)) {
371 struct mgs_nidtbl_target *tgt;
372 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
373 cfs_list_del(&tgt->mnt_list);
378 static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
380 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
382 CFS_INIT_LIST_HEAD(&tbl->mn_targets);
383 cfs_mutex_init(&tbl->mn_lock);
384 tbl->mn_nr_targets = 0;
386 cfs_mutex_lock(&tbl->mn_lock);
387 tbl->mn_version = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl);
388 cfs_mutex_unlock(&tbl->mn_lock);
389 CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
394 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
395 void mgs_ir_notify_complete(struct fs_db *fsdb)
398 cfs_duration_t delta;
400 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
403 fsdb->fsdb_notify_count++;
404 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
405 fsdb->fsdb_notify_total += delta;
406 if (delta > fsdb->fsdb_notify_max)
407 fsdb->fsdb_notify_max = delta;
409 cfs_duration_usec(delta, &tv);
410 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
411 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
414 static int mgs_ir_notify(void *arg)
416 struct fs_db *fsdb = arg;
417 struct ldlm_res_id resid;
419 char name[sizeof(fsdb->fsdb_name) + 20];
421 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
422 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
425 cfs_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 cfs_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, cfs_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 cfs_complete(&fsdb->fsdb_notify_comp);
451 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
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 CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
466 /* start notify thread */
467 fsdb->fsdb_obd = mgs->mgs_obd;
468 fsdb->fsdb_mgs = mgs;
469 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
470 cfs_waitq_init(&fsdb->fsdb_notify_waitq);
471 cfs_init_completion(&fsdb->fsdb_notify_comp);
472 rc = cfs_create_thread(mgs_ir_notify, fsdb, CFS_DAEMON_FLAGS);
474 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
476 CERROR("Start notify thread error %d\n", rc);
478 mgs_nidtbl_init_fs(env, fsdb);
482 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
484 if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
487 mgs_fsc_cleanup_by_fsdb(fsdb);
489 mgs_nidtbl_fini_fs(fsdb);
491 LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
493 fsdb->fsdb_notify_stop = 1;
494 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
495 cfs_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 (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
503 cfs_time_current_sec())) {
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 cfs_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 cfs_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 cfs_atomic_inc(&fsdb->fsdb_notify_phase);
551 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
556 /* NID table can be cached by two entities: Clients and MDTs */
562 static int delogname(char *logname, char *fsname, int *typ)
568 ptr = strrchr(logname, '-');
572 /* decouple file system name. The llog name may be:
573 * - "prefix-fsname", prefix is "cliir" or "mdtir"
575 if (strncmp(ptr, "-mdtir", 6) == 0)
577 else if (strncmp(ptr, "-cliir", 6) == 0)
586 memcpy(fsname, logname, len);
593 int mgs_get_ir_logs(struct ptlrpc_request *req)
595 struct lu_env *env = req->rq_svc_thread->t_env;
596 struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
598 struct mgs_config_body *body;
599 struct mgs_config_res *res;
600 struct ptlrpc_bulk_desc *desc;
601 struct l_wait_info lwi;
611 cfs_page_t **pages = NULL;
614 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
618 if (body->mcb_type != CONFIG_T_RECOVER)
621 rc = delogname(body->mcb_name, fsname, &type);
625 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
629 bufsize = body->mcb_units << body->mcb_bits;
630 nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
631 if (nrpages > PTLRPC_MAX_BRW_PAGES)
634 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
635 body->mcb_name, bufsize);
637 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
641 rc = req_capsule_server_pack(&req->rq_pill);
645 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
647 GOTO(out, rc = -EINVAL);
649 res->mcr_offset = body->mcb_offset;
650 unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
651 bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
652 pages, nrpages, bufsize / unit_size, unit_size);
654 GOTO(out, rc = bytes);
656 /* start bulk transfer */
657 page_count = (bytes + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
658 LASSERT(page_count <= nrpages);
659 desc = ptlrpc_prep_bulk_exp(req, page_count,
660 BULK_PUT_SOURCE, MGS_BULK_PORTAL);
662 GOTO(out, rc = -ENOMEM);
664 for (i = 0; i < page_count && bytes > 0; i++) {
665 ptlrpc_prep_bulk_page(desc, pages[i], 0,
666 min_t(int, bytes, CFS_PAGE_SIZE));
667 bytes -= CFS_PAGE_SIZE;
670 rc = target_bulk_io(req->rq_export, desc, &lwi);
671 ptlrpc_free_bulk(desc);
675 for (i = 0; i < nrpages; i++) {
676 if (pages[i] == NULL)
678 cfs_free_page(pages[i]);
680 OBD_FREE(pages, sizeof(*pages) * nrpages);
685 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
687 const char *strings[] = IR_STRINGS;
691 for (i = 0; i < ARRAY_SIZE(strings); i++) {
692 if (strcmp(strings[i], buf) == 0) {
700 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
701 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
702 cfs_mutex_lock(&fsdb->fsdb_mutex);
703 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
705 fsdb->fsdb_ir_state = state;
706 cfs_mutex_unlock(&fsdb->fsdb_mutex);
711 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
716 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
721 fsdb->fsdb_notify_total = 0;
722 fsdb->fsdb_notify_max = 0;
723 fsdb->fsdb_notify_count = 0;
727 static struct lproc_ir_cmd {
730 int (*handler)(struct fs_db *, const char *);
732 { "state=", 6, lprocfs_ir_set_state },
733 { "timeout=", 8, lprocfs_ir_set_timeout },
734 { "0", 1, lprocfs_ir_clear_stats }
737 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
738 unsigned long count, void *data)
740 struct fs_db *fsdb = data;
745 if (count > CFS_PAGE_SIZE)
748 OBD_ALLOC(kbuf, count + 1);
752 if (copy_from_user(kbuf, buffer, count)) {
753 OBD_FREE(kbuf, count);
757 kbuf[count] = 0; /* buffer is supposed to end with 0 */
758 if (kbuf[count - 1] == '\n')
762 /* fsname=<file system name> must be the 1st entry */
763 while (ptr != NULL) {
767 tmpptr = strchr(ptr, ';');
772 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
773 struct lproc_ir_cmd *cmd;
777 cmdlen = cmd->namelen;
778 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
780 rc = cmd->handler(fsdb, ptr);
790 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
791 OBD_FREE(kbuf, count + 1);
795 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
797 struct fs_db *fsdb = data;
798 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
799 const char *ir_strings[] = IR_STRINGS;
800 struct timeval tv_max;
803 /* mgs_live_seq_show() already holds fsdb_mutex. */
804 ir_state_graduate(fsdb);
806 seq_printf(seq, "\nimperative_recovery_state:\n");
809 " nonir_clients: %d\n"
810 " nidtbl_version: %lld\n",
811 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
814 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
815 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
817 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
818 " notify_duation_max: %lu.%06lu\n"
819 " notify_count: %u\n",
820 tv.tv_sec, tv.tv_usec,
821 tv_max.tv_sec, tv_max.tv_usec,
822 fsdb->fsdb_notify_count);
827 int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
828 int *eof, void *data)
831 return snprintf(page, count, "%d\n", ir_timeout);
834 int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
835 unsigned long count, void *data)
837 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
840 /* --------------- Handle non IR support clients --------------- */
841 /* attach a lustre file system to an export */
842 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
845 struct mgs_export_data *data = &exp->u.eu_mgs_data;
846 struct mgs_device *mgs = exp2mgs_dev(exp);
848 struct mgs_fsc *fsc = NULL;
849 struct mgs_fsc *new_fsc = NULL;
854 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
858 /* allocate a new fsc in case we need it in spinlock. */
859 OBD_ALLOC_PTR(new_fsc);
863 CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
864 CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
865 new_fsc->mfc_fsdb = fsdb;
866 new_fsc->mfc_export = class_export_get(exp);
867 new_fsc->mfc_ir_capable =
868 !!(exp->exp_connect_flags & OBD_CONNECT_IMP_RECOV);
871 cfs_mutex_lock(&fsdb->fsdb_mutex);
873 /* tend to find it in export list because this list is shorter. */
874 cfs_spin_lock(&data->med_lock);
875 cfs_list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
876 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
885 /* add it into export list. */
886 cfs_list_add(&fsc->mfc_export_list, &data->med_clients);
888 /* add into fsdb list. */
889 cfs_list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
890 if (!fsc->mfc_ir_capable) {
891 ++fsdb->fsdb_nonir_clients;
892 if (fsdb->fsdb_ir_state == IR_FULL)
893 fsdb->fsdb_ir_state = IR_PARTIAL;
897 cfs_spin_unlock(&data->med_lock);
898 cfs_mutex_unlock(&fsdb->fsdb_mutex);
901 class_export_put(new_fsc->mfc_export);
902 OBD_FREE_PTR(new_fsc);
907 void mgs_fsc_cleanup(struct obd_export *exp)
909 struct mgs_export_data *data = &exp->u.eu_mgs_data;
910 struct mgs_fsc *fsc, *tmp;
913 cfs_spin_lock(&data->med_lock);
914 cfs_list_splice_init(&data->med_clients, &head);
915 cfs_spin_unlock(&data->med_lock);
917 cfs_list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
918 struct fs_db *fsdb = fsc->mfc_fsdb;
920 LASSERT(fsc->mfc_export == exp);
922 cfs_mutex_lock(&fsdb->fsdb_mutex);
923 cfs_list_del_init(&fsc->mfc_fsdb_list);
924 if (fsc->mfc_ir_capable == 0) {
925 --fsdb->fsdb_nonir_clients;
926 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
927 if (fsdb->fsdb_nonir_clients == 0 &&
928 fsdb->fsdb_ir_state == IR_PARTIAL)
929 fsdb->fsdb_ir_state = IR_FULL;
931 cfs_mutex_unlock(&fsdb->fsdb_mutex);
932 cfs_list_del_init(&fsc->mfc_export_list);
933 class_export_put(fsc->mfc_export);
938 /* must be called with fsdb->fsdb_mutex held */
939 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
941 struct mgs_fsc *fsc, *tmp;
943 cfs_list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
945 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
947 LASSERT(fsdb == fsc->mfc_fsdb);
948 cfs_list_del_init(&fsc->mfc_fsdb_list);
950 cfs_spin_lock(&data->med_lock);
951 cfs_list_del_init(&fsc->mfc_export_list);
952 cfs_spin_unlock(&data->med_lock);
953 class_export_put(fsc->mfc_export);
957 fsdb->fsdb_nonir_clients = 0;
958 if (fsdb->fsdb_ir_state == IR_PARTIAL)
959 fsdb->fsdb_ir_state = IR_FULL;