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/module.h>
48 #include <linux/pagemap.h>
54 #include <obd_class.h>
55 #include <lustre_log.h>
57 #include <libcfs/list.h>
58 #include <linux/lvfs.h>
59 #include <lustre_fsfilt.h>
60 #include <lustre_disk.h>
61 #include <lustre_param.h>
62 #include "mgs_internal.h"
64 static unsigned int ir_timeout;
66 static int nidtbl_is_sane(struct mgs_nidtbl *tbl)
68 struct mgs_nidtbl_target *tgt;
71 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
72 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
73 if (!tgt->mnt_version)
76 if (version >= tgt->mnt_version)
79 version = tgt->mnt_version;
85 * Fetch nidtbl entries whose version are not less than @version
86 * nidtbl entries will be packed in @pages by @unit_size units - entries
87 * shouldn't cross unit boundaries.
89 static int mgs_nidtbl_read(struct obd_export *exp, struct mgs_nidtbl *tbl,
90 struct mgs_config_res *res, cfs_page_t **pages,
91 int nrpages, int units_total, int unit_size)
93 struct mgs_nidtbl_target *tgt;
94 struct mgs_nidtbl_entry *entry;
95 struct mgs_nidtbl_entry *last_in_unit = NULL;
96 struct mgs_target_info *mti;
97 __u64 version = res->mcr_offset;
100 int bytes_in_unit = 0;
101 int units_in_page = 0;
106 /* make sure unit_size is power 2 */
107 LASSERT((unit_size & (unit_size - 1)) == 0);
108 LASSERT(nrpages << CFS_PAGE_SHIFT >= units_total * unit_size);
110 cfs_mutex_lock(&tbl->mn_lock);
111 LASSERT(nidtbl_is_sane(tbl));
113 /* no more entries ? */
114 if (version > tbl->mn_version) {
115 version = tbl->mn_version;
119 /* iterate over all targets to compose a bitmap by the type of llog.
120 * If the llog is for MDTs, llog entries for OSTs will be returned;
121 * otherwise, it's for clients, then llog entries for both OSTs and
122 * MDTs will be returned.
124 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
125 int entry_len = sizeof(*entry);
127 if (tgt->mnt_version < version)
130 /* write target recover information */
132 LASSERT(mti->mti_nid_count < MTI_NIDS_MAX);
133 entry_len += mti->mti_nid_count * sizeof(lnet_nid_t);
135 if (entry_len > unit_size) {
136 CWARN("nidtbl: too large entry: entry length %d,"
137 "unit size: %d\n", entry_len, unit_size);
138 GOTO(out, rc = -EOVERFLOW);
141 if (bytes_in_unit < entry_len) {
142 if (units_total == 0) {
147 /* check if we need to consume remaining bytes. */
148 if (last_in_unit != NULL && bytes_in_unit) {
150 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
151 /* May need to swab back to update the length.*/
152 if (exp->exp_need_mne_swab)
153 lustre_swab_mgs_nidtbl_entry(last_in_unit);
155 last_in_unit->mne_length += bytes_in_unit;
156 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
157 if (exp->exp_need_mne_swab)
158 lustre_swab_mgs_nidtbl_entry(last_in_unit);
161 buf += bytes_in_unit;
164 LASSERT((rc & (unit_size - 1)) == 0);
166 if (units_in_page == 0) {
167 /* allocate a new page */
168 pages[index] = cfs_alloc_page(CFS_ALLOC_STD);
169 if (pages[index] == NULL) {
174 /* destroy previous map */
176 cfs_kunmap(pages[index - 1]);
178 /* reassign buffer */
179 buf = cfs_kmap(pages[index]);
182 units_in_page = CFS_PAGE_SIZE / unit_size;
183 LASSERT(units_in_page > 0);
186 /* allocate an unit */
187 LASSERT(((long)buf & (unit_size - 1)) == 0);
188 bytes_in_unit = unit_size;
194 entry = (struct mgs_nidtbl_entry *)buf;
195 entry->mne_version = tgt->mnt_version;
196 entry->mne_instance = mti->mti_instance;
197 entry->mne_index = mti->mti_stripe_index;
198 entry->mne_length = entry_len;
199 entry->mne_type = tgt->mnt_type;
200 entry->mne_nid_type = 0;
201 entry->mne_nid_size = sizeof(lnet_nid_t);
202 entry->mne_nid_count = mti->mti_nid_count;
203 memcpy(entry->u.nids, mti->mti_nids,
204 mti->mti_nid_count * sizeof(lnet_nid_t));
206 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 6, 50, 0)
207 /* For LU-1644, swab entry for 2.2 clients. */
208 if (exp->exp_need_mne_swab)
209 lustre_swab_mgs_nidtbl_entry(entry);
212 version = tgt->mnt_version;
216 bytes_in_unit -= entry_len;
217 last_in_unit = entry;
219 CDEBUG(D_MGS, "fsname %s, entry size %d, pages %d/%d/%d/%d.\n",
220 tbl->mn_fsdb->fsdb_name, entry_len,
221 bytes_in_unit, index, nrpages, units_total);
224 cfs_kunmap(pages[index - 1]);
226 LASSERT(version <= tbl->mn_version);
227 res->mcr_size = tbl->mn_version;
228 res->mcr_offset = nobuf ? version : tbl->mn_version;
229 cfs_mutex_unlock(&tbl->mn_lock);
230 LASSERT(ergo(version == 1, rc == 0)); /* get the log first time */
232 CDEBUG(D_MGS, "Read IR logs %s return with %d, version %llu\n",
233 tbl->mn_fsdb->fsdb_name, rc, version);
237 static int nidtbl_update_version(const struct lu_env *env,
238 struct mgs_device *mgs,
239 struct mgs_nidtbl *tbl)
241 struct lvfs_run_ctxt saved;
242 struct file *file = NULL;
243 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
247 struct obd_device *obd = tbl->mn_fsdb->fsdb_obd;
250 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
251 LASSERT(sizeof(filename) < 32);
253 sprintf(filename, "%s/%s",
254 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
256 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
258 file = l_filp_open(filename, O_RDWR|O_CREAT, 0660);
260 version = cpu_to_le64(tbl->mn_version);
261 rc = lustre_fwrite(file, &version, sizeof(version), &off);
262 if (rc == sizeof(version))
265 fsfilt_sync(obd, obd->u.mgs.mgs_sb);
270 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
274 #define MGS_NIDTBL_VERSION_INIT 2
276 static int nidtbl_read_version(const struct lu_env *env,
277 struct mgs_device *mgs, struct mgs_nidtbl *tbl)
279 struct lvfs_run_ctxt saved;
280 struct file *file = NULL;
281 char filename[sizeof(MGS_NIDTBL_DIR) + 9];
285 struct obd_device *obd = tbl->mn_fsdb->fsdb_obd;
288 LASSERT(cfs_mutex_is_locked(&tbl->mn_lock));
289 LASSERT(sizeof(filename) < 32);
291 sprintf(filename, "%s/%s",
292 MGS_NIDTBL_DIR, tbl->mn_fsdb->fsdb_name);
294 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
296 file = l_filp_open(filename, O_RDONLY, 0);
298 rc = lustre_fread(file, &version, sizeof(version), &off);
299 if (rc == sizeof(version))
300 rc = cpu_to_le64(version);
302 rc = MGS_NIDTBL_VERSION_INIT;
304 CERROR("read version file %s error %d\n", filename, rc);
309 rc = MGS_NIDTBL_VERSION_INIT;
312 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
316 static int mgs_nidtbl_write(const struct lu_env *env, struct fs_db *fsdb,
317 struct mgs_target_info *mti)
319 struct mgs_nidtbl *tbl;
320 struct mgs_nidtbl_target *tgt;
322 int type = mti->mti_flags & LDD_F_SV_TYPE_MASK;
326 type &= ~LDD_F_SV_TYPE_MGS;
329 tbl = &fsdb->fsdb_nidtbl;
330 cfs_mutex_lock(&tbl->mn_lock);
331 cfs_list_for_each_entry(tgt, &tbl->mn_targets, mnt_list) {
332 struct mgs_target_info *info = &tgt->mnt_mti;
333 if (type == tgt->mnt_type &&
334 mti->mti_stripe_index == info->mti_stripe_index) {
342 GOTO(out, rc = -ENOMEM);
344 CFS_INIT_LIST_HEAD(&tgt->mnt_list);
346 tgt->mnt_version = 0; /* 0 means invalid */
347 tgt->mnt_type = type;
349 ++tbl->mn_nr_targets;
352 tgt->mnt_version = ++tbl->mn_version;
355 cfs_list_move_tail(&tgt->mnt_list, &tbl->mn_targets);
357 rc = nidtbl_update_version(env, fsdb->fsdb_mgs, tbl);
361 cfs_mutex_unlock(&tbl->mn_lock);
363 CERROR("Write NID table version for file system %s error %d\n",
364 fsdb->fsdb_name, rc);
368 static void mgs_nidtbl_fini_fs(struct fs_db *fsdb)
370 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
373 cfs_mutex_lock(&tbl->mn_lock);
374 tbl->mn_nr_targets = 0;
375 cfs_list_splice_init(&tbl->mn_targets, &head);
376 cfs_mutex_unlock(&tbl->mn_lock);
378 while (!cfs_list_empty(&head)) {
379 struct mgs_nidtbl_target *tgt;
380 tgt = list_entry(head.next, struct mgs_nidtbl_target, mnt_list);
381 cfs_list_del(&tgt->mnt_list);
386 static int mgs_nidtbl_init_fs(const struct lu_env *env, struct fs_db *fsdb)
388 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
390 CFS_INIT_LIST_HEAD(&tbl->mn_targets);
391 cfs_mutex_init(&tbl->mn_lock);
392 tbl->mn_nr_targets = 0;
394 cfs_mutex_lock(&tbl->mn_lock);
395 tbl->mn_version = nidtbl_read_version(env, fsdb->fsdb_mgs, tbl);
396 cfs_mutex_unlock(&tbl->mn_lock);
397 CDEBUG(D_MGS, "IR: current version is %llu\n", tbl->mn_version);
402 /* --------- Imperative Recovery relies on nidtbl stuff ------- */
403 void mgs_ir_notify_complete(struct fs_db *fsdb)
406 cfs_duration_t delta;
408 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
411 fsdb->fsdb_notify_count++;
412 delta = cfs_time_sub(cfs_time_current(), fsdb->fsdb_notify_start);
413 fsdb->fsdb_notify_total += delta;
414 if (delta > fsdb->fsdb_notify_max)
415 fsdb->fsdb_notify_max = delta;
417 cfs_duration_usec(delta, &tv);
418 CDEBUG(D_MGS, "Revoke recover lock of %s completed after %ld.%06lds\n",
419 fsdb->fsdb_name, tv.tv_sec, tv.tv_usec);
422 static int mgs_ir_notify(void *arg)
424 struct fs_db *fsdb = arg;
425 struct ldlm_res_id resid;
427 char name[sizeof(fsdb->fsdb_name) + 20];
429 LASSERTF(sizeof(name) < 32, "name is too large to be in stack.\n");
430 sprintf(name, "mgs_%s_notify", fsdb->fsdb_name);
433 cfs_complete(&fsdb->fsdb_notify_comp);
435 set_user_nice(current, -2);
437 mgc_fsname2resid(fsdb->fsdb_name, &resid, CONFIG_T_RECOVER);
439 struct l_wait_info lwi = { 0 };
441 l_wait_event(fsdb->fsdb_notify_waitq,
442 fsdb->fsdb_notify_stop ||
443 cfs_atomic_read(&fsdb->fsdb_notify_phase),
445 if (fsdb->fsdb_notify_stop)
448 CDEBUG(D_MGS, "%s woken up, phase is %d\n",
449 name, cfs_atomic_read(&fsdb->fsdb_notify_phase));
451 fsdb->fsdb_notify_start = cfs_time_current();
452 mgs_revoke_lock(fsdb->fsdb_mgs, fsdb, CONFIG_T_RECOVER);
455 cfs_complete(&fsdb->fsdb_notify_comp);
459 int mgs_ir_init_fs(const struct lu_env *env, struct mgs_device *mgs,
465 ir_timeout = OBD_IR_MGS_TIMEOUT;
467 fsdb->fsdb_ir_state = IR_FULL;
468 if (cfs_time_before(cfs_time_current_sec(),
469 mgs->mgs_start_time + ir_timeout))
470 fsdb->fsdb_ir_state = IR_STARTUP;
471 fsdb->fsdb_nonir_clients = 0;
472 CFS_INIT_LIST_HEAD(&fsdb->fsdb_clients);
474 /* start notify thread */
475 fsdb->fsdb_obd = mgs->mgs_obd;
476 fsdb->fsdb_mgs = mgs;
477 cfs_atomic_set(&fsdb->fsdb_notify_phase, 0);
478 cfs_waitq_init(&fsdb->fsdb_notify_waitq);
479 cfs_init_completion(&fsdb->fsdb_notify_comp);
480 rc = cfs_create_thread(mgs_ir_notify, fsdb, CFS_DAEMON_FLAGS);
482 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
484 CERROR("Start notify thread error %d\n", rc);
486 mgs_nidtbl_init_fs(env, fsdb);
490 void mgs_ir_fini_fs(struct mgs_device *mgs, struct fs_db *fsdb)
492 if (cfs_test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
495 mgs_fsc_cleanup_by_fsdb(fsdb);
497 mgs_nidtbl_fini_fs(fsdb);
499 LASSERT(cfs_list_empty(&fsdb->fsdb_clients));
501 fsdb->fsdb_notify_stop = 1;
502 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
503 cfs_wait_for_completion(&fsdb->fsdb_notify_comp);
506 /* caller must have held fsdb_mutex */
507 static inline void ir_state_graduate(struct fs_db *fsdb)
509 if (fsdb->fsdb_ir_state == IR_STARTUP) {
510 if (cfs_time_before(fsdb->fsdb_mgs->mgs_start_time + ir_timeout,
511 cfs_time_current_sec())) {
512 fsdb->fsdb_ir_state = IR_FULL;
513 if (fsdb->fsdb_nonir_clients)
514 fsdb->fsdb_ir_state = IR_PARTIAL;
519 int mgs_ir_update(const struct lu_env *env, struct mgs_device *mgs,
520 struct mgs_target_info *mti)
526 if (mti->mti_instance == 0)
529 rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
533 rc = mgs_nidtbl_write(env, fsdb, mti);
538 cfs_mutex_lock(&fsdb->fsdb_mutex);
539 ir_state_graduate(fsdb);
540 switch (fsdb->fsdb_ir_state) {
542 mti->mti_flags |= LDD_F_IR_CAPABLE;
552 cfs_mutex_unlock(&fsdb->fsdb_mutex);
554 LASSERT(ergo(mti->mti_flags & LDD_F_IR_CAPABLE, notify));
556 CDEBUG(D_MGS, "Try to revoke recover lock of %s\n",
558 cfs_atomic_inc(&fsdb->fsdb_notify_phase);
559 cfs_waitq_signal(&fsdb->fsdb_notify_waitq);
564 /* NID table can be cached by two entities: Clients and MDTs */
570 static int delogname(char *logname, char *fsname, int *typ)
576 ptr = strrchr(logname, '-');
580 /* decouple file system name. The llog name may be:
581 * - "prefix-fsname", prefix is "cliir" or "mdtir"
583 if (strncmp(ptr, "-mdtir", 6) == 0)
585 else if (strncmp(ptr, "-cliir", 6) == 0)
594 memcpy(fsname, logname, len);
601 int mgs_get_ir_logs(struct ptlrpc_request *req)
603 struct lu_env *env = req->rq_svc_thread->t_env;
604 struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
606 struct mgs_config_body *body;
607 struct mgs_config_res *res;
608 struct ptlrpc_bulk_desc *desc;
609 struct l_wait_info lwi;
619 cfs_page_t **pages = NULL;
622 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
626 if (body->mcb_type != CONFIG_T_RECOVER)
629 rc = delogname(body->mcb_name, fsname, &type);
633 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
637 bufsize = body->mcb_units << body->mcb_bits;
638 nrpages = (bufsize + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
639 if (nrpages > PTLRPC_MAX_BRW_PAGES)
642 CDEBUG(D_MGS, "Reading IR log %s bufsize %ld.\n",
643 body->mcb_name, bufsize);
645 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
649 rc = req_capsule_server_pack(&req->rq_pill);
653 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
655 GOTO(out, rc = -EINVAL);
657 res->mcr_offset = body->mcb_offset;
658 unit_size = min_t(int, 1 << body->mcb_bits, CFS_PAGE_SIZE);
659 bytes = mgs_nidtbl_read(req->rq_export, &fsdb->fsdb_nidtbl, res,
660 pages, nrpages, bufsize / unit_size, unit_size);
662 GOTO(out, rc = bytes);
664 /* start bulk transfer */
665 page_count = (bytes + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
666 LASSERT(page_count <= nrpages);
667 desc = ptlrpc_prep_bulk_exp(req, page_count,
668 BULK_PUT_SOURCE, MGS_BULK_PORTAL);
670 GOTO(out, rc = -ENOMEM);
672 for (i = 0; i < page_count && bytes > 0; i++) {
673 ptlrpc_prep_bulk_page(desc, pages[i], 0,
674 min_t(int, bytes, CFS_PAGE_SIZE));
675 bytes -= CFS_PAGE_SIZE;
678 rc = target_bulk_io(req->rq_export, desc, &lwi);
679 ptlrpc_free_bulk(desc);
683 for (i = 0; i < nrpages; i++) {
684 if (pages[i] == NULL)
686 cfs_free_page(pages[i]);
688 OBD_FREE(pages, sizeof(*pages) * nrpages);
693 static int lprocfs_ir_set_state(struct fs_db *fsdb, const char *buf)
695 const char *strings[] = IR_STRINGS;
699 for (i = 0; i < ARRAY_SIZE(strings); i++) {
700 if (strcmp(strings[i], buf) == 0) {
708 CDEBUG(D_MGS, "change fsr state of %s from %s to %s\n",
709 fsdb->fsdb_name, strings[fsdb->fsdb_ir_state], strings[state]);
710 cfs_mutex_lock(&fsdb->fsdb_mutex);
711 if (state == IR_FULL && fsdb->fsdb_nonir_clients)
713 fsdb->fsdb_ir_state = state;
714 cfs_mutex_unlock(&fsdb->fsdb_mutex);
719 static int lprocfs_ir_set_timeout(struct fs_db *fsdb, const char *buf)
724 static int lprocfs_ir_clear_stats(struct fs_db *fsdb, const char *buf)
729 fsdb->fsdb_notify_total = 0;
730 fsdb->fsdb_notify_max = 0;
731 fsdb->fsdb_notify_count = 0;
735 static struct lproc_ir_cmd {
738 int (*handler)(struct fs_db *, const char *);
740 { "state=", 6, lprocfs_ir_set_state },
741 { "timeout=", 8, lprocfs_ir_set_timeout },
742 { "0", 1, lprocfs_ir_clear_stats }
745 int lprocfs_wr_ir_state(struct file *file, const char *buffer,
746 unsigned long count, void *data)
748 struct fs_db *fsdb = data;
753 if (count > CFS_PAGE_SIZE)
756 OBD_ALLOC(kbuf, count + 1);
760 if (copy_from_user(kbuf, buffer, count)) {
761 OBD_FREE(kbuf, count);
765 kbuf[count] = 0; /* buffer is supposed to end with 0 */
766 if (kbuf[count - 1] == '\n')
770 /* fsname=<file system name> must be the 1st entry */
771 while (ptr != NULL) {
775 tmpptr = strchr(ptr, ';');
780 for (i = 0; i < ARRAY_SIZE(ir_cmds); i++) {
781 struct lproc_ir_cmd *cmd;
785 cmdlen = cmd->namelen;
786 if (strncmp(cmd->name, ptr, cmdlen) == 0) {
788 rc = cmd->handler(fsdb, ptr);
798 CERROR("Unable to process command: %s(%d)\n", ptr, rc);
799 OBD_FREE(kbuf, count + 1);
803 int lprocfs_rd_ir_state(struct seq_file *seq, void *data)
805 struct fs_db *fsdb = data;
806 struct mgs_nidtbl *tbl = &fsdb->fsdb_nidtbl;
807 const char *ir_strings[] = IR_STRINGS;
808 struct timeval tv_max;
811 /* mgs_live_seq_show() already holds fsdb_mutex. */
812 ir_state_graduate(fsdb);
814 seq_printf(seq, "\nimperative_recovery_state:\n");
817 " nonir_clients: %d\n"
818 " nidtbl_version: %lld\n",
819 ir_strings[fsdb->fsdb_ir_state], fsdb->fsdb_nonir_clients,
822 cfs_duration_usec(fsdb->fsdb_notify_total, &tv);
823 cfs_duration_usec(fsdb->fsdb_notify_max, &tv_max);
825 seq_printf(seq, " notify_duration_total: %lu.%06lu\n"
826 " notify_duation_max: %lu.%06lu\n"
827 " notify_count: %u\n",
828 tv.tv_sec, tv.tv_usec,
829 tv_max.tv_sec, tv_max.tv_usec,
830 fsdb->fsdb_notify_count);
835 int lprocfs_rd_ir_timeout(char *page, char **start, off_t off, int count,
836 int *eof, void *data)
839 return snprintf(page, count, "%d\n", ir_timeout);
842 int lprocfs_wr_ir_timeout(struct file *file, const char *buffer,
843 unsigned long count, void *data)
845 return lprocfs_wr_uint(file, buffer, count, &ir_timeout);
848 /* --------------- Handle non IR support clients --------------- */
849 /* attach a lustre file system to an export */
850 int mgs_fsc_attach(const struct lu_env *env, struct obd_export *exp,
853 struct mgs_export_data *data = &exp->u.eu_mgs_data;
854 struct mgs_device *mgs = exp2mgs_dev(exp);
856 struct mgs_fsc *fsc = NULL;
857 struct mgs_fsc *new_fsc = NULL;
862 rc = mgs_find_or_make_fsdb(env, mgs, fsname, &fsdb);
866 /* allocate a new fsc in case we need it in spinlock. */
867 OBD_ALLOC_PTR(new_fsc);
871 CFS_INIT_LIST_HEAD(&new_fsc->mfc_export_list);
872 CFS_INIT_LIST_HEAD(&new_fsc->mfc_fsdb_list);
873 new_fsc->mfc_fsdb = fsdb;
874 new_fsc->mfc_export = class_export_get(exp);
875 new_fsc->mfc_ir_capable =
876 !!(exp->exp_connect_flags & OBD_CONNECT_IMP_RECOV);
879 cfs_mutex_lock(&fsdb->fsdb_mutex);
881 /* tend to find it in export list because this list is shorter. */
882 cfs_spin_lock(&data->med_lock);
883 cfs_list_for_each_entry(fsc, &data->med_clients, mfc_export_list) {
884 if (strcmp(fsname, fsc->mfc_fsdb->fsdb_name) == 0) {
893 /* add it into export list. */
894 cfs_list_add(&fsc->mfc_export_list, &data->med_clients);
896 /* add into fsdb list. */
897 cfs_list_add(&fsc->mfc_fsdb_list, &fsdb->fsdb_clients);
898 if (!fsc->mfc_ir_capable) {
899 ++fsdb->fsdb_nonir_clients;
900 if (fsdb->fsdb_ir_state == IR_FULL)
901 fsdb->fsdb_ir_state = IR_PARTIAL;
905 cfs_spin_unlock(&data->med_lock);
906 cfs_mutex_unlock(&fsdb->fsdb_mutex);
909 class_export_put(new_fsc->mfc_export);
910 OBD_FREE_PTR(new_fsc);
915 void mgs_fsc_cleanup(struct obd_export *exp)
917 struct mgs_export_data *data = &exp->u.eu_mgs_data;
918 struct mgs_fsc *fsc, *tmp;
921 cfs_spin_lock(&data->med_lock);
922 cfs_list_splice_init(&data->med_clients, &head);
923 cfs_spin_unlock(&data->med_lock);
925 cfs_list_for_each_entry_safe(fsc, tmp, &head, mfc_export_list) {
926 struct fs_db *fsdb = fsc->mfc_fsdb;
928 LASSERT(fsc->mfc_export == exp);
930 cfs_mutex_lock(&fsdb->fsdb_mutex);
931 cfs_list_del_init(&fsc->mfc_fsdb_list);
932 if (fsc->mfc_ir_capable == 0) {
933 --fsdb->fsdb_nonir_clients;
934 LASSERT(fsdb->fsdb_ir_state != IR_FULL);
935 if (fsdb->fsdb_nonir_clients == 0 &&
936 fsdb->fsdb_ir_state == IR_PARTIAL)
937 fsdb->fsdb_ir_state = IR_FULL;
939 cfs_mutex_unlock(&fsdb->fsdb_mutex);
940 cfs_list_del_init(&fsc->mfc_export_list);
941 class_export_put(fsc->mfc_export);
946 /* must be called with fsdb->fsdb_mutex held */
947 void mgs_fsc_cleanup_by_fsdb(struct fs_db *fsdb)
949 struct mgs_fsc *fsc, *tmp;
951 cfs_list_for_each_entry_safe(fsc, tmp, &fsdb->fsdb_clients,
953 struct mgs_export_data *data = &fsc->mfc_export->u.eu_mgs_data;
955 LASSERT(fsdb == fsc->mfc_fsdb);
956 cfs_list_del_init(&fsc->mfc_fsdb_list);
958 cfs_spin_lock(&data->med_lock);
959 cfs_list_del_init(&fsc->mfc_export_list);
960 cfs_spin_unlock(&data->med_lock);
961 class_export_put(fsc->mfc_export);
965 fsdb->fsdb_nonir_clients = 0;
966 if (fsdb->fsdb_ir_state == IR_PARTIAL)
967 fsdb->fsdb_ir_state = IR_FULL;