Merge 3.11-rc3 into staging-next
[deliverable/linux.git] / drivers / staging / lustre / lustre / obdclass / obd_mount.c
1 /*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
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.
9 *
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).
15 *
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
19 *
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
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26 /*
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32 /*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 *
36 * lustre/obdclass/obd_mount.c
37 *
38 * Client mount routines
39 *
40 * Author: Nathan Rutman <nathan@clusterfs.com>
41 */
42
43
44 #define DEBUG_SUBSYSTEM S_CLASS
45 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
46 #define PRINT_CMD CDEBUG
47
48 #include <obd.h>
49 #include <lvfs.h>
50 #include <obd_class.h>
51 #include <lustre/lustre_user.h>
52 #include <lustre_log.h>
53 #include <lustre_disk.h>
54 #include <lustre_param.h>
55
56 static int (*client_fill_super)(struct super_block *sb,
57 struct vfsmount *mnt);
58
59 static void (*kill_super_cb)(struct super_block *sb);
60
61 /**************** config llog ********************/
62
63 /** Get a config log from the MGS and process it.
64 * This func is called for both clients and servers.
65 * Continue to process new statements appended to the logs
66 * (whenever the config lock is revoked) until lustre_end_log
67 * is called.
68 * @param sb The superblock is used by the MGC to write to the local copy of
69 * the config log
70 * @param logname The name of the llog to replicate from the MGS
71 * @param cfg Since the same mgc may be used to follow multiple config logs
72 * (e.g. ost1, ost2, client), the config_llog_instance keeps the state for
73 * this log, and is added to the mgc's list of logs to follow.
74 */
75 int lustre_process_log(struct super_block *sb, char *logname,
76 struct config_llog_instance *cfg)
77 {
78 struct lustre_cfg *lcfg;
79 struct lustre_cfg_bufs *bufs;
80 struct lustre_sb_info *lsi = s2lsi(sb);
81 struct obd_device *mgc = lsi->lsi_mgc;
82 int rc;
83 ENTRY;
84
85 LASSERT(mgc);
86 LASSERT(cfg);
87
88 OBD_ALLOC_PTR(bufs);
89 if (bufs == NULL)
90 RETURN(-ENOMEM);
91
92 /* mgc_process_config */
93 lustre_cfg_bufs_reset(bufs, mgc->obd_name);
94 lustre_cfg_bufs_set_string(bufs, 1, logname);
95 lustre_cfg_bufs_set(bufs, 2, cfg, sizeof(*cfg));
96 lustre_cfg_bufs_set(bufs, 3, &sb, sizeof(sb));
97 lcfg = lustre_cfg_new(LCFG_LOG_START, bufs);
98 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
99 lustre_cfg_free(lcfg);
100
101 OBD_FREE_PTR(bufs);
102
103 if (rc == -EINVAL)
104 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'"
105 "failed from the MGS (%d). Make sure this "
106 "client and the MGS are running compatible "
107 "versions of Lustre.\n",
108 mgc->obd_name, logname, rc);
109
110 if (rc)
111 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' "
112 "failed (%d). This may be the result of "
113 "communication errors between this node and "
114 "the MGS, a bad configuration, or other "
115 "errors. See the syslog for more "
116 "information.\n", mgc->obd_name, logname,
117 rc);
118
119 /* class_obd_list(); */
120 RETURN(rc);
121 }
122 EXPORT_SYMBOL(lustre_process_log);
123
124 /* Stop watching this config log for updates */
125 int lustre_end_log(struct super_block *sb, char *logname,
126 struct config_llog_instance *cfg)
127 {
128 struct lustre_cfg *lcfg;
129 struct lustre_cfg_bufs bufs;
130 struct lustre_sb_info *lsi = s2lsi(sb);
131 struct obd_device *mgc = lsi->lsi_mgc;
132 int rc;
133 ENTRY;
134
135 if (!mgc)
136 RETURN(-ENOENT);
137
138 /* mgc_process_config */
139 lustre_cfg_bufs_reset(&bufs, mgc->obd_name);
140 lustre_cfg_bufs_set_string(&bufs, 1, logname);
141 if (cfg)
142 lustre_cfg_bufs_set(&bufs, 2, cfg, sizeof(*cfg));
143 lcfg = lustre_cfg_new(LCFG_LOG_END, &bufs);
144 rc = obd_process_config(mgc, sizeof(*lcfg), lcfg);
145 lustre_cfg_free(lcfg);
146 RETURN(rc);
147 }
148 EXPORT_SYMBOL(lustre_end_log);
149
150 /**************** obd start *******************/
151
152 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
153 * lctl (and do for echo cli/srv.
154 */
155 int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
156 char *s1, char *s2, char *s3, char *s4)
157 {
158 struct lustre_cfg_bufs bufs;
159 struct lustre_cfg * lcfg = NULL;
160 int rc;
161
162 CDEBUG(D_TRACE, "lcfg %s %#x %s %s %s %s\n", cfgname,
163 cmd, s1, s2, s3, s4);
164
165 lustre_cfg_bufs_reset(&bufs, cfgname);
166 if (s1)
167 lustre_cfg_bufs_set_string(&bufs, 1, s1);
168 if (s2)
169 lustre_cfg_bufs_set_string(&bufs, 2, s2);
170 if (s3)
171 lustre_cfg_bufs_set_string(&bufs, 3, s3);
172 if (s4)
173 lustre_cfg_bufs_set_string(&bufs, 4, s4);
174
175 lcfg = lustre_cfg_new(cmd, &bufs);
176 lcfg->lcfg_nid = nid;
177 rc = class_process_config(lcfg);
178 lustre_cfg_free(lcfg);
179 return(rc);
180 }
181 EXPORT_SYMBOL(do_lcfg);
182
183 /** Call class_attach and class_setup. These methods in turn call
184 * obd type-specific methods.
185 */
186 int lustre_start_simple(char *obdname, char *type, char *uuid,
187 char *s1, char *s2, char *s3, char *s4)
188 {
189 int rc;
190 CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
191
192 rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, 0, 0);
193 if (rc) {
194 CERROR("%s attach error %d\n", obdname, rc);
195 return rc;
196 }
197 rc = do_lcfg(obdname, 0, LCFG_SETUP, s1, s2, s3, s4);
198 if (rc) {
199 CERROR("%s setup error %d\n", obdname, rc);
200 do_lcfg(obdname, 0, LCFG_DETACH, 0, 0, 0, 0);
201 }
202 return rc;
203 }
204
205 DEFINE_MUTEX(mgc_start_lock);
206
207 /** Set up a mgc obd to process startup logs
208 *
209 * \param sb [in] super block of the mgc obd
210 *
211 * \retval 0 success, otherwise error code
212 */
213 int lustre_start_mgc(struct super_block *sb)
214 {
215 struct obd_connect_data *data = NULL;
216 struct lustre_sb_info *lsi = s2lsi(sb);
217 struct obd_device *obd;
218 struct obd_export *exp;
219 struct obd_uuid *uuid;
220 class_uuid_t uuidc;
221 lnet_nid_t nid;
222 char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
223 char *ptr;
224 int recov_bk;
225 int rc = 0, i = 0, j, len;
226 ENTRY;
227
228 LASSERT(lsi->lsi_lmd);
229
230 /* Find the first non-lo MGS nid for our MGC name */
231 if (IS_SERVER(lsi)) {
232 /* mount -o mgsnode=nid */
233 ptr = lsi->lsi_lmd->lmd_mgs;
234 if (lsi->lsi_lmd->lmd_mgs &&
235 (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
236 i++;
237 } else if (IS_MGS(lsi)) {
238 lnet_process_id_t id;
239 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
240 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
241 continue;
242 nid = id.nid;
243 i++;
244 break;
245 }
246 }
247 } else { /* client */
248 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
249 ptr = lsi->lsi_lmd->lmd_dev;
250 if (class_parse_nid(ptr, &nid, &ptr) == 0)
251 i++;
252 }
253 if (i == 0) {
254 CERROR("No valid MGS nids found.\n");
255 RETURN(-EINVAL);
256 }
257
258 mutex_lock(&mgc_start_lock);
259
260 len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
261 OBD_ALLOC(mgcname, len);
262 OBD_ALLOC(niduuid, len + 2);
263 if (!mgcname || !niduuid)
264 GOTO(out_free, rc = -ENOMEM);
265 sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
266
267 mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
268
269 OBD_ALLOC_PTR(data);
270 if (data == NULL)
271 GOTO(out_free, rc = -ENOMEM);
272
273 obd = class_name2obd(mgcname);
274 if (obd && !obd->obd_stopping) {
275 rc = obd_set_info_async(NULL, obd->obd_self_export,
276 strlen(KEY_MGSSEC), KEY_MGSSEC,
277 strlen(mgssec), mgssec, NULL);
278 if (rc)
279 GOTO(out_free, rc);
280
281 /* Re-using an existing MGC */
282 atomic_inc(&obd->u.cli.cl_mgc_refcount);
283
284 /* IR compatibility check, only for clients */
285 if (lmd_is_client(lsi->lsi_lmd)) {
286 int has_ir;
287 int vallen = sizeof(*data);
288 __u32 *flags = &lsi->lsi_lmd->lmd_flags;
289
290 rc = obd_get_info(NULL, obd->obd_self_export,
291 strlen(KEY_CONN_DATA), KEY_CONN_DATA,
292 &vallen, data, NULL);
293 LASSERT(rc == 0);
294 has_ir = OCD_HAS_FLAG(data, IMP_RECOV);
295 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
296 /* LMD_FLG_NOIR is for test purpose only */
297 LCONSOLE_WARN(
298 "Trying to mount a client with IR setting "
299 "not compatible with current mgc. "
300 "Force to use current mgc setting that is "
301 "IR %s.\n",
302 has_ir ? "enabled" : "disabled");
303 if (has_ir)
304 *flags &= ~LMD_FLG_NOIR;
305 else
306 *flags |= LMD_FLG_NOIR;
307 }
308 }
309
310 recov_bk = 0;
311 /* If we are restarting the MGS, don't try to keep the MGC's
312 old connection, or registration will fail. */
313 if (IS_MGS(lsi)) {
314 CDEBUG(D_MOUNT, "New MGS with live MGC\n");
315 recov_bk = 1;
316 }
317
318 /* Try all connections, but only once (again).
319 We don't want to block another target from starting
320 (using its local copy of the log), but we do want to connect
321 if at all possible. */
322 recov_bk++;
323 CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
324 rc = obd_set_info_async(NULL, obd->obd_self_export,
325 sizeof(KEY_INIT_RECOV_BACKUP),
326 KEY_INIT_RECOV_BACKUP,
327 sizeof(recov_bk), &recov_bk, NULL);
328 GOTO(out, rc = 0);
329 }
330
331 CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
332
333 /* Add the primary nids for the MGS */
334 i = 0;
335 sprintf(niduuid, "%s_%x", mgcname, i);
336 if (IS_SERVER(lsi)) {
337 ptr = lsi->lsi_lmd->lmd_mgs;
338 if (IS_MGS(lsi)) {
339 /* Use local nids (including LO) */
340 lnet_process_id_t id;
341 while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
342 rc = do_lcfg(mgcname, id.nid,
343 LCFG_ADD_UUID, niduuid, 0,0,0);
344 }
345 } else {
346 /* Use mgsnode= nids */
347 /* mount -o mgsnode=nid */
348 if (lsi->lsi_lmd->lmd_mgs) {
349 ptr = lsi->lsi_lmd->lmd_mgs;
350 } else if (class_find_param(ptr, PARAM_MGSNODE,
351 &ptr) != 0) {
352 CERROR("No MGS nids given.\n");
353 GOTO(out_free, rc = -EINVAL);
354 }
355 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
356 rc = do_lcfg(mgcname, nid,
357 LCFG_ADD_UUID, niduuid, 0,0,0);
358 i++;
359 }
360 }
361 } else { /* client */
362 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
363 ptr = lsi->lsi_lmd->lmd_dev;
364 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
365 rc = do_lcfg(mgcname, nid,
366 LCFG_ADD_UUID, niduuid, 0,0,0);
367 i++;
368 /* Stop at the first failover nid */
369 if (*ptr == ':')
370 break;
371 }
372 }
373 if (i == 0) {
374 CERROR("No valid MGS nids found.\n");
375 GOTO(out_free, rc = -EINVAL);
376 }
377 lsi->lsi_lmd->lmd_mgs_failnodes = 1;
378
379 /* Random uuid for MGC allows easier reconnects */
380 OBD_ALLOC_PTR(uuid);
381 ll_generate_random_uuid(uuidc);
382 class_uuid_unparse(uuidc, uuid);
383
384 /* Start the MGC */
385 rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME,
386 (char *)uuid->uuid, LUSTRE_MGS_OBDNAME,
387 niduuid, 0, 0);
388 OBD_FREE_PTR(uuid);
389 if (rc)
390 GOTO(out_free, rc);
391
392 /* Add any failover MGS nids */
393 i = 1;
394 while (ptr && ((*ptr == ':' ||
395 class_find_param(ptr, PARAM_MGSNODE, &ptr) == 0))) {
396 /* New failover node */
397 sprintf(niduuid, "%s_%x", mgcname, i);
398 j = 0;
399 while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) {
400 j++;
401 rc = do_lcfg(mgcname, nid,
402 LCFG_ADD_UUID, niduuid, 0,0,0);
403 if (*ptr == ':')
404 break;
405 }
406 if (j > 0) {
407 rc = do_lcfg(mgcname, 0, LCFG_ADD_CONN,
408 niduuid, 0, 0, 0);
409 i++;
410 } else {
411 /* at ":/fsname" */
412 break;
413 }
414 }
415 lsi->lsi_lmd->lmd_mgs_failnodes = i;
416
417 obd = class_name2obd(mgcname);
418 if (!obd) {
419 CERROR("Can't find mgcobd %s\n", mgcname);
420 GOTO(out_free, rc = -ENOTCONN);
421 }
422
423 rc = obd_set_info_async(NULL, obd->obd_self_export,
424 strlen(KEY_MGSSEC), KEY_MGSSEC,
425 strlen(mgssec), mgssec, NULL);
426 if (rc)
427 GOTO(out_free, rc);
428
429 /* Keep a refcount of servers/clients who started with "mount",
430 so we know when we can get rid of the mgc. */
431 atomic_set(&obd->u.cli.cl_mgc_refcount, 1);
432
433 /* Try all connections, but only once. */
434 recov_bk = 1;
435 rc = obd_set_info_async(NULL, obd->obd_self_export,
436 sizeof(KEY_INIT_RECOV_BACKUP),
437 KEY_INIT_RECOV_BACKUP,
438 sizeof(recov_bk), &recov_bk, NULL);
439 if (rc)
440 /* nonfatal */
441 CWARN("can't set %s %d\n", KEY_INIT_RECOV_BACKUP, rc);
442
443 /* We connect to the MGS at setup, and don't disconnect until cleanup */
444 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_AT |
445 OBD_CONNECT_FULL20 | OBD_CONNECT_IMP_RECOV |
446 OBD_CONNECT_LVB_TYPE;
447
448 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
449 data->ocd_connect_flags |= OBD_CONNECT_MNE_SWAB;
450 #else
451 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
452 #endif
453
454 if (lmd_is_client(lsi->lsi_lmd) &&
455 lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)
456 data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV;
457 data->ocd_version = LUSTRE_VERSION_CODE;
458 rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
459 if (rc) {
460 CERROR("connect failed %d\n", rc);
461 GOTO(out, rc);
462 }
463
464 obd->u.cli.cl_mgc_mgsexp = exp;
465
466 out:
467 /* Keep the mgc info in the sb. Note that many lsi's can point
468 to the same mgc.*/
469 lsi->lsi_mgc = obd;
470 out_free:
471 mutex_unlock(&mgc_start_lock);
472
473 if (data)
474 OBD_FREE_PTR(data);
475 if (mgcname)
476 OBD_FREE(mgcname, len);
477 if (niduuid)
478 OBD_FREE(niduuid, len + 2);
479 RETURN(rc);
480 }
481
482 static int lustre_stop_mgc(struct super_block *sb)
483 {
484 struct lustre_sb_info *lsi = s2lsi(sb);
485 struct obd_device *obd;
486 char *niduuid = 0, *ptr = 0;
487 int i, rc = 0, len = 0;
488 ENTRY;
489
490 if (!lsi)
491 RETURN(-ENOENT);
492 obd = lsi->lsi_mgc;
493 if (!obd)
494 RETURN(-ENOENT);
495 lsi->lsi_mgc = NULL;
496
497 mutex_lock(&mgc_start_lock);
498 LASSERT(atomic_read(&obd->u.cli.cl_mgc_refcount) > 0);
499 if (!atomic_dec_and_test(&obd->u.cli.cl_mgc_refcount)) {
500 /* This is not fatal, every client that stops
501 will call in here. */
502 CDEBUG(D_MOUNT, "mgc still has %d references.\n",
503 atomic_read(&obd->u.cli.cl_mgc_refcount));
504 GOTO(out, rc = -EBUSY);
505 }
506
507 /* The MGC has no recoverable data in any case.
508 * force shotdown set in umount_begin */
509 obd->obd_no_recov = 1;
510
511 if (obd->u.cli.cl_mgc_mgsexp) {
512 /* An error is not fatal, if we are unable to send the
513 disconnect mgs ping evictor cleans up the export */
514 rc = obd_disconnect(obd->u.cli.cl_mgc_mgsexp);
515 if (rc)
516 CDEBUG(D_MOUNT, "disconnect failed %d\n", rc);
517 }
518
519 /* Save the obdname for cleaning the nid uuids, which are
520 obdname_XX */
521 len = strlen(obd->obd_name) + 6;
522 OBD_ALLOC(niduuid, len);
523 if (niduuid) {
524 strcpy(niduuid, obd->obd_name);
525 ptr = niduuid + strlen(niduuid);
526 }
527
528 rc = class_manual_cleanup(obd);
529 if (rc)
530 GOTO(out, rc);
531
532 /* Clean the nid uuids */
533 if (!niduuid)
534 GOTO(out, rc = -ENOMEM);
535
536 for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
537 sprintf(ptr, "_%x", i);
538 rc = do_lcfg(LUSTRE_MGC_OBDNAME, 0, LCFG_DEL_UUID,
539 niduuid, 0, 0, 0);
540 if (rc)
541 CERROR("del MDC UUID %s failed: rc = %d\n",
542 niduuid, rc);
543 }
544 out:
545 if (niduuid)
546 OBD_FREE(niduuid, len);
547
548 /* class_import_put will get rid of the additional connections */
549 mutex_unlock(&mgc_start_lock);
550 RETURN(rc);
551 }
552
553 /***************** lustre superblock **************/
554
555 struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
556 {
557 struct lustre_sb_info *lsi;
558 ENTRY;
559
560 OBD_ALLOC_PTR(lsi);
561 if (!lsi)
562 RETURN(NULL);
563 OBD_ALLOC_PTR(lsi->lsi_lmd);
564 if (!lsi->lsi_lmd) {
565 OBD_FREE_PTR(lsi);
566 RETURN(NULL);
567 }
568
569 lsi->lsi_lmd->lmd_exclude_count = 0;
570 lsi->lsi_lmd->lmd_recovery_time_soft = 0;
571 lsi->lsi_lmd->lmd_recovery_time_hard = 0;
572 s2lsi_nocast(sb) = lsi;
573 /* we take 1 extra ref for our setup */
574 atomic_set(&lsi->lsi_mounts, 1);
575
576 /* Default umount style */
577 lsi->lsi_flags = LSI_UMOUNT_FAILOVER;
578
579 RETURN(lsi);
580 }
581
582 static int lustre_free_lsi(struct super_block *sb)
583 {
584 struct lustre_sb_info *lsi = s2lsi(sb);
585 ENTRY;
586
587 LASSERT(lsi != NULL);
588 CDEBUG(D_MOUNT, "Freeing lsi %p\n", lsi);
589
590 /* someone didn't call server_put_mount. */
591 LASSERT(atomic_read(&lsi->lsi_mounts) == 0);
592
593 if (lsi->lsi_lmd != NULL) {
594 if (lsi->lsi_lmd->lmd_dev != NULL)
595 OBD_FREE(lsi->lsi_lmd->lmd_dev,
596 strlen(lsi->lsi_lmd->lmd_dev) + 1);
597 if (lsi->lsi_lmd->lmd_profile != NULL)
598 OBD_FREE(lsi->lsi_lmd->lmd_profile,
599 strlen(lsi->lsi_lmd->lmd_profile) + 1);
600 if (lsi->lsi_lmd->lmd_mgssec != NULL)
601 OBD_FREE(lsi->lsi_lmd->lmd_mgssec,
602 strlen(lsi->lsi_lmd->lmd_mgssec) + 1);
603 if (lsi->lsi_lmd->lmd_opts != NULL)
604 OBD_FREE(lsi->lsi_lmd->lmd_opts,
605 strlen(lsi->lsi_lmd->lmd_opts) + 1);
606 if (lsi->lsi_lmd->lmd_exclude_count)
607 OBD_FREE(lsi->lsi_lmd->lmd_exclude,
608 sizeof(lsi->lsi_lmd->lmd_exclude[0]) *
609 lsi->lsi_lmd->lmd_exclude_count);
610 if (lsi->lsi_lmd->lmd_mgs != NULL)
611 OBD_FREE(lsi->lsi_lmd->lmd_mgs,
612 strlen(lsi->lsi_lmd->lmd_mgs) + 1);
613 if (lsi->lsi_lmd->lmd_osd_type != NULL)
614 OBD_FREE(lsi->lsi_lmd->lmd_osd_type,
615 strlen(lsi->lsi_lmd->lmd_osd_type) + 1);
616 if (lsi->lsi_lmd->lmd_params != NULL)
617 OBD_FREE(lsi->lsi_lmd->lmd_params, 4096);
618
619 OBD_FREE(lsi->lsi_lmd, sizeof(*lsi->lsi_lmd));
620 }
621
622 LASSERT(lsi->lsi_llsbi == NULL);
623 OBD_FREE(lsi, sizeof(*lsi));
624 s2lsi_nocast(sb) = NULL;
625
626 RETURN(0);
627 }
628
629 /* The lsi has one reference for every server that is using the disk -
630 e.g. MDT, MGS, and potentially MGC */
631 int lustre_put_lsi(struct super_block *sb)
632 {
633 struct lustre_sb_info *lsi = s2lsi(sb);
634 ENTRY;
635
636 LASSERT(lsi != NULL);
637
638 CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
639 if (atomic_dec_and_test(&lsi->lsi_mounts)) {
640 if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
641 obd_disconnect(lsi->lsi_osd_exp);
642 /* wait till OSD is gone */
643 obd_zombie_barrier();
644 }
645 lustre_free_lsi(sb);
646 RETURN(1);
647 }
648 RETURN(0);
649 }
650
651 /*** SERVER NAME ***
652 * <FSNAME><SEPERATOR><TYPE><INDEX>
653 * FSNAME is between 1 and 8 characters (inclusive).
654 * Excluded characters are '/' and ':'
655 * SEPERATOR is either ':' or '-'
656 * TYPE: "OST", "MDT", etc.
657 * INDEX: Hex representation of the index
658 */
659
660 /** Get the fsname ("lustre") from the server name ("lustre-OST003F").
661 * @param [in] svname server name including type and index
662 * @param [out] fsname Buffer to copy filesystem name prefix into.
663 * Must have at least 'strlen(fsname) + 1' chars.
664 * @param [out] endptr if endptr isn't NULL it is set to end of fsname
665 * rc < 0 on error
666 */
667 int server_name2fsname(const char *svname, char *fsname, const char **endptr)
668 {
669 const char *dash;
670
671 dash = svname + strnlen(svname, 8); /* max fsname length is 8 */
672 for (; dash > svname && *dash != '-' && *dash != ':'; dash--)
673 ;
674 if (dash == svname)
675 return -EINVAL;
676
677 if (fsname != NULL) {
678 strncpy(fsname, svname, dash - svname);
679 fsname[dash - svname] = '\0';
680 }
681
682 if (endptr != NULL)
683 *endptr = dash;
684
685 return 0;
686 }
687 EXPORT_SYMBOL(server_name2fsname);
688
689 /**
690 * Get service name (svname) from string
691 * rc < 0 on error
692 * if endptr isn't NULL it is set to end of fsname *
693 */
694 int server_name2svname(const char *label, char *svname, const char **endptr,
695 size_t svsize)
696 {
697 int rc;
698 const char *dash;
699
700 /* We use server_name2fsname() just for parsing */
701 rc = server_name2fsname(label, NULL, &dash);
702 if (rc != 0)
703 return rc;
704
705 if (endptr != NULL)
706 *endptr = dash;
707
708 if (strlcpy(svname, dash + 1, svsize) >= svsize)
709 return -E2BIG;
710
711 return 0;
712 }
713 EXPORT_SYMBOL(server_name2svname);
714
715
716 /* Get the index from the obd name.
717 rc = server type, or
718 rc < 0 on error
719 if endptr isn't NULL it is set to end of name */
720 int server_name2index(const char *svname, __u32 *idx, const char **endptr)
721 {
722 unsigned long index;
723 int rc;
724 const char *dash;
725
726 /* We use server_name2fsname() just for parsing */
727 rc = server_name2fsname(svname, NULL, &dash);
728 if (rc != 0)
729 return rc;
730
731 dash++;
732
733 if (strncmp(dash, "MDT", 3) == 0)
734 rc = LDD_F_SV_TYPE_MDT;
735 else if (strncmp(dash, "OST", 3) == 0)
736 rc = LDD_F_SV_TYPE_OST;
737 else
738 return -EINVAL;
739
740 dash += 3;
741
742 if (strncmp(dash, "all", 3) == 0) {
743 if (endptr != NULL)
744 *endptr = dash + 3;
745 return rc | LDD_F_SV_ALL;
746 }
747
748 index = simple_strtoul(dash, (char **)endptr, 16);
749 if (idx != NULL)
750 *idx = index;
751
752 /* Account for -mdc after index that is possible when specifying mdt */
753 if (endptr != NULL && strncmp(LUSTRE_MDC_NAME, *endptr + 1,
754 sizeof(LUSTRE_MDC_NAME)-1) == 0)
755 *endptr += sizeof(LUSTRE_MDC_NAME);
756
757 return rc;
758 }
759 EXPORT_SYMBOL(server_name2index);
760
761 /*************** mount common betweeen server and client ***************/
762
763 /* Common umount */
764 int lustre_common_put_super(struct super_block *sb)
765 {
766 int rc;
767 ENTRY;
768
769 CDEBUG(D_MOUNT, "dropping sb %p\n", sb);
770
771 /* Drop a ref to the MGC */
772 rc = lustre_stop_mgc(sb);
773 if (rc && (rc != -ENOENT)) {
774 if (rc != -EBUSY) {
775 CERROR("Can't stop MGC: %d\n", rc);
776 RETURN(rc);
777 }
778 /* BUSY just means that there's some other obd that
779 needs the mgc. Let him clean it up. */
780 CDEBUG(D_MOUNT, "MGC still in use\n");
781 }
782 /* Drop a ref to the mounted disk */
783 lustre_put_lsi(sb);
784 lu_types_stop();
785 RETURN(rc);
786 }
787 EXPORT_SYMBOL(lustre_common_put_super);
788
789 static void lmd_print(struct lustre_mount_data *lmd)
790 {
791 int i;
792
793 PRINT_CMD(D_MOUNT, " mount data:\n");
794 if (lmd_is_client(lmd))
795 PRINT_CMD(D_MOUNT, "profile: %s\n", lmd->lmd_profile);
796 PRINT_CMD(D_MOUNT, "device: %s\n", lmd->lmd_dev);
797 PRINT_CMD(D_MOUNT, "flags: %x\n", lmd->lmd_flags);
798
799 if (lmd->lmd_opts)
800 PRINT_CMD(D_MOUNT, "options: %s\n", lmd->lmd_opts);
801
802 if (lmd->lmd_recovery_time_soft)
803 PRINT_CMD(D_MOUNT, "recovery time soft: %d\n",
804 lmd->lmd_recovery_time_soft);
805
806 if (lmd->lmd_recovery_time_hard)
807 PRINT_CMD(D_MOUNT, "recovery time hard: %d\n",
808 lmd->lmd_recovery_time_hard);
809
810 for (i = 0; i < lmd->lmd_exclude_count; i++) {
811 PRINT_CMD(D_MOUNT, "exclude %d: OST%04x\n", i,
812 lmd->lmd_exclude[i]);
813 }
814 }
815
816 /* Is this server on the exclusion list */
817 int lustre_check_exclusion(struct super_block *sb, char *svname)
818 {
819 struct lustre_sb_info *lsi = s2lsi(sb);
820 struct lustre_mount_data *lmd = lsi->lsi_lmd;
821 __u32 index;
822 int i, rc;
823 ENTRY;
824
825 rc = server_name2index(svname, &index, NULL);
826 if (rc != LDD_F_SV_TYPE_OST)
827 /* Only exclude OSTs */
828 RETURN(0);
829
830 CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
831 index, lmd->lmd_exclude_count, lmd->lmd_dev);
832
833 for(i = 0; i < lmd->lmd_exclude_count; i++) {
834 if (index == lmd->lmd_exclude[i]) {
835 CWARN("Excluding %s (on exclusion list)\n", svname);
836 RETURN(1);
837 }
838 }
839 RETURN(0);
840 }
841
842 /* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */
843 static int lmd_make_exclusion(struct lustre_mount_data *lmd, const char *ptr)
844 {
845 const char *s1 = ptr, *s2;
846 __u32 index, *exclude_list;
847 int rc = 0, devmax;
848 ENTRY;
849
850 /* The shortest an ost name can be is 8 chars: -OST0000.
851 We don't actually know the fsname at this time, so in fact
852 a user could specify any fsname. */
853 devmax = strlen(ptr) / 8 + 1;
854
855 /* temp storage until we figure out how many we have */
856 OBD_ALLOC(exclude_list, sizeof(index) * devmax);
857 if (!exclude_list)
858 RETURN(-ENOMEM);
859
860 /* we enter this fn pointing at the '=' */
861 while (*s1 && *s1 != ' ' && *s1 != ',') {
862 s1++;
863 rc = server_name2index(s1, &index, &s2);
864 if (rc < 0) {
865 CERROR("Can't parse server name '%s': rc = %d\n",
866 s1, rc);
867 break;
868 }
869 if (rc == LDD_F_SV_TYPE_OST)
870 exclude_list[lmd->lmd_exclude_count++] = index;
871 else
872 CDEBUG(D_MOUNT, "ignoring exclude %.*s: type = %#x\n",
873 (uint)(s2-s1), s1, rc);
874 s1 = s2;
875 /* now we are pointing at ':' (next exclude)
876 or ',' (end of excludes) */
877 if (lmd->lmd_exclude_count >= devmax)
878 break;
879 }
880 if (rc >= 0) /* non-err */
881 rc = 0;
882
883 if (lmd->lmd_exclude_count) {
884 /* permanent, freed in lustre_free_lsi */
885 OBD_ALLOC(lmd->lmd_exclude, sizeof(index) *
886 lmd->lmd_exclude_count);
887 if (lmd->lmd_exclude) {
888 memcpy(lmd->lmd_exclude, exclude_list,
889 sizeof(index) * lmd->lmd_exclude_count);
890 } else {
891 rc = -ENOMEM;
892 lmd->lmd_exclude_count = 0;
893 }
894 }
895 OBD_FREE(exclude_list, sizeof(index) * devmax);
896 RETURN(rc);
897 }
898
899 static int lmd_parse_mgssec(struct lustre_mount_data *lmd, char *ptr)
900 {
901 char *tail;
902 int length;
903
904 if (lmd->lmd_mgssec != NULL) {
905 OBD_FREE(lmd->lmd_mgssec, strlen(lmd->lmd_mgssec) + 1);
906 lmd->lmd_mgssec = NULL;
907 }
908
909 tail = strchr(ptr, ',');
910 if (tail == NULL)
911 length = strlen(ptr);
912 else
913 length = tail - ptr;
914
915 OBD_ALLOC(lmd->lmd_mgssec, length + 1);
916 if (lmd->lmd_mgssec == NULL)
917 return -ENOMEM;
918
919 memcpy(lmd->lmd_mgssec, ptr, length);
920 lmd->lmd_mgssec[length] = '\0';
921 return 0;
922 }
923
924 static int lmd_parse_string(char **handle, char *ptr)
925 {
926 char *tail;
927 int length;
928
929 if ((handle == NULL) || (ptr == NULL))
930 return -EINVAL;
931
932 if (*handle != NULL) {
933 OBD_FREE(*handle, strlen(*handle) + 1);
934 *handle = NULL;
935 }
936
937 tail = strchr(ptr, ',');
938 if (tail == NULL)
939 length = strlen(ptr);
940 else
941 length = tail - ptr;
942
943 OBD_ALLOC(*handle, length + 1);
944 if (*handle == NULL)
945 return -ENOMEM;
946
947 memcpy(*handle, ptr, length);
948 (*handle)[length] = '\0';
949
950 return 0;
951 }
952
953 /* Collect multiple values for mgsnid specifiers */
954 static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
955 {
956 lnet_nid_t nid;
957 char *tail = *ptr;
958 char *mgsnid;
959 int length;
960 int oldlen = 0;
961
962 /* Find end of nidlist */
963 while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
964 length = tail - *ptr;
965 if (length == 0) {
966 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
967 return -EINVAL;
968 }
969
970 if (lmd->lmd_mgs != NULL)
971 oldlen = strlen(lmd->lmd_mgs) + 1;
972
973 OBD_ALLOC(mgsnid, oldlen + length + 1);
974 if (mgsnid == NULL)
975 return -ENOMEM;
976
977 if (lmd->lmd_mgs != NULL) {
978 /* Multiple mgsnid= are taken to mean failover locations */
979 memcpy(mgsnid, lmd->lmd_mgs, oldlen);
980 mgsnid[oldlen - 1] = ':';
981 OBD_FREE(lmd->lmd_mgs, oldlen);
982 }
983 memcpy(mgsnid + oldlen, *ptr, length);
984 mgsnid[oldlen + length] = '\0';
985 lmd->lmd_mgs = mgsnid;
986 *ptr = tail;
987
988 return 0;
989 }
990
991 /** Parse mount line options
992 * e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre
993 * dev is passed as device=uml1:/lustre by mount.lustre
994 */
995 static int lmd_parse(char *options, struct lustre_mount_data *lmd)
996 {
997 char *s1, *s2, *devname = NULL;
998 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
999 int rc = 0;
1000 ENTRY;
1001
1002 LASSERT(lmd);
1003 if (!options) {
1004 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that "
1005 "/sbin/mount.lustre is installed.\n");
1006 RETURN(-EINVAL);
1007 }
1008
1009 /* Options should be a string - try to detect old lmd data */
1010 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1011 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of "
1012 "/sbin/mount.lustre. Please install "
1013 "version %s\n", LUSTRE_VERSION_STRING);
1014 RETURN(-EINVAL);
1015 }
1016 lmd->lmd_magic = LMD_MAGIC;
1017
1018 OBD_ALLOC(lmd->lmd_params, 4096);
1019 if (lmd->lmd_params == NULL)
1020 RETURN(-ENOMEM);
1021 lmd->lmd_params[0] = '\0';
1022
1023 /* Set default flags here */
1024
1025 s1 = options;
1026 while (*s1) {
1027 int clear = 0;
1028 int time_min = OBD_RECOVERY_TIME_MIN;
1029
1030 /* Skip whitespace and extra commas */
1031 while (*s1 == ' ' || *s1 == ',')
1032 s1++;
1033
1034 /* Client options are parsed in ll_options: eg. flock,
1035 user_xattr, acl */
1036
1037 /* Parse non-ldiskfs options here. Rather than modifying
1038 ldiskfs, we just zero these out here */
1039 if (strncmp(s1, "abort_recov", 11) == 0) {
1040 lmd->lmd_flags |= LMD_FLG_ABORT_RECOV;
1041 clear++;
1042 } else if (strncmp(s1, "recovery_time_soft=", 19) == 0) {
1043 lmd->lmd_recovery_time_soft = max_t(int,
1044 simple_strtoul(s1 + 19, NULL, 10), time_min);
1045 clear++;
1046 } else if (strncmp(s1, "recovery_time_hard=", 19) == 0) {
1047 lmd->lmd_recovery_time_hard = max_t(int,
1048 simple_strtoul(s1 + 19, NULL, 10), time_min);
1049 clear++;
1050 } else if (strncmp(s1, "noir", 4) == 0) {
1051 lmd->lmd_flags |= LMD_FLG_NOIR; /* test purpose only. */
1052 clear++;
1053 } else if (strncmp(s1, "nosvc", 5) == 0) {
1054 lmd->lmd_flags |= LMD_FLG_NOSVC;
1055 clear++;
1056 } else if (strncmp(s1, "nomgs", 5) == 0) {
1057 lmd->lmd_flags |= LMD_FLG_NOMGS;
1058 clear++;
1059 } else if (strncmp(s1, "noscrub", 7) == 0) {
1060 lmd->lmd_flags |= LMD_FLG_NOSCRUB;
1061 clear++;
1062 } else if (strncmp(s1, PARAM_MGSNODE,
1063 sizeof(PARAM_MGSNODE) - 1) == 0) {
1064 s2 = s1 + sizeof(PARAM_MGSNODE) - 1;
1065 /* Assume the next mount opt is the first
1066 invalid nid we get to. */
1067 rc = lmd_parse_mgs(lmd, &s2);
1068 if (rc)
1069 goto invalid;
1070 clear++;
1071 } else if (strncmp(s1, "writeconf", 9) == 0) {
1072 lmd->lmd_flags |= LMD_FLG_WRITECONF;
1073 clear++;
1074 } else if (strncmp(s1, "update", 6) == 0) {
1075 lmd->lmd_flags |= LMD_FLG_UPDATE;
1076 clear++;
1077 } else if (strncmp(s1, "virgin", 6) == 0) {
1078 lmd->lmd_flags |= LMD_FLG_VIRGIN;
1079 clear++;
1080 } else if (strncmp(s1, "noprimnode", 10) == 0) {
1081 lmd->lmd_flags |= LMD_FLG_NO_PRIMNODE;
1082 clear++;
1083 } else if (strncmp(s1, "mgssec=", 7) == 0) {
1084 rc = lmd_parse_mgssec(lmd, s1 + 7);
1085 if (rc)
1086 goto invalid;
1087 clear++;
1088 /* ost exclusion list */
1089 } else if (strncmp(s1, "exclude=", 8) == 0) {
1090 rc = lmd_make_exclusion(lmd, s1 + 7);
1091 if (rc)
1092 goto invalid;
1093 clear++;
1094 } else if (strncmp(s1, "mgs", 3) == 0) {
1095 /* We are an MGS */
1096 lmd->lmd_flags |= LMD_FLG_MGS;
1097 clear++;
1098 } else if (strncmp(s1, "svname=", 7) == 0) {
1099 rc = lmd_parse_string(&lmd->lmd_profile, s1 + 7);
1100 if (rc)
1101 goto invalid;
1102 clear++;
1103 } else if (strncmp(s1, "param=", 6) == 0) {
1104 int length;
1105 char *tail = strchr(s1 + 6, ',');
1106 if (tail == NULL)
1107 length = strlen(s1);
1108 else
1109 length = tail - s1;
1110 length -= 6;
1111 strncat(lmd->lmd_params, s1 + 6, length);
1112 strcat(lmd->lmd_params, " ");
1113 clear++;
1114 } else if (strncmp(s1, "osd=", 4) == 0) {
1115 rc = lmd_parse_string(&lmd->lmd_osd_type, s1 + 4);
1116 if (rc)
1117 goto invalid;
1118 clear++;
1119 }
1120 /* Linux 2.4 doesn't pass the device, so we stuck it at the
1121 end of the options. */
1122 else if (strncmp(s1, "device=", 7) == 0) {
1123 devname = s1 + 7;
1124 /* terminate options right before device. device
1125 must be the last one. */
1126 *s1 = '\0';
1127 break;
1128 }
1129
1130 /* Find next opt */
1131 s2 = strchr(s1, ',');
1132 if (s2 == NULL) {
1133 if (clear)
1134 *s1 = '\0';
1135 break;
1136 }
1137 s2++;
1138 if (clear)
1139 memmove(s1, s2, strlen(s2) + 1);
1140 else
1141 s1 = s2;
1142 }
1143
1144 if (!devname) {
1145 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name "
1146 "(need mount option 'device=...')\n");
1147 goto invalid;
1148 }
1149
1150 s1 = strstr(devname, ":/");
1151 if (s1) {
1152 ++s1;
1153 lmd->lmd_flags |= LMD_FLG_CLIENT;
1154 /* Remove leading /s from fsname */
1155 while (*++s1 == '/') ;
1156 /* Freed in lustre_free_lsi */
1157 OBD_ALLOC(lmd->lmd_profile, strlen(s1) + 8);
1158 if (!lmd->lmd_profile)
1159 RETURN(-ENOMEM);
1160 sprintf(lmd->lmd_profile, "%s-client", s1);
1161 }
1162
1163 /* Freed in lustre_free_lsi */
1164 OBD_ALLOC(lmd->lmd_dev, strlen(devname) + 1);
1165 if (!lmd->lmd_dev)
1166 RETURN(-ENOMEM);
1167 strcpy(lmd->lmd_dev, devname);
1168
1169 /* Save mount options */
1170 s1 = options + strlen(options) - 1;
1171 while (s1 >= options && (*s1 == ',' || *s1 == ' '))
1172 *s1-- = 0;
1173 if (*options != 0) {
1174 /* Freed in lustre_free_lsi */
1175 OBD_ALLOC(lmd->lmd_opts, strlen(options) + 1);
1176 if (!lmd->lmd_opts)
1177 RETURN(-ENOMEM);
1178 strcpy(lmd->lmd_opts, options);
1179 }
1180
1181 lmd_print(lmd);
1182 lmd->lmd_magic = LMD_MAGIC;
1183
1184 RETURN(rc);
1185
1186 invalid:
1187 CERROR("Bad mount options %s\n", options);
1188 RETURN(-EINVAL);
1189 }
1190
1191 struct lustre_mount_data2 {
1192 void *lmd2_data;
1193 struct vfsmount *lmd2_mnt;
1194 };
1195
1196 /** This is the entry point for the mount call into Lustre.
1197 * This is called when a server or client is mounted,
1198 * and this is where we start setting things up.
1199 * @param data Mount options (e.g. -o flock,abort_recov)
1200 */
1201 int lustre_fill_super(struct super_block *sb, void *data, int silent)
1202 {
1203 struct lustre_mount_data *lmd;
1204 struct lustre_mount_data2 *lmd2 = data;
1205 struct lustre_sb_info *lsi;
1206 int rc;
1207 ENTRY;
1208
1209 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
1210
1211 lsi = lustre_init_lsi(sb);
1212 if (!lsi)
1213 RETURN(-ENOMEM);
1214 lmd = lsi->lsi_lmd;
1215
1216 /*
1217 * Disable lockdep during mount, because mount locking patterns are
1218 * `special'.
1219 */
1220 lockdep_off();
1221
1222 /*
1223 * LU-639: the obd cleanup of last mount may not finish yet, wait here.
1224 */
1225 obd_zombie_barrier();
1226
1227 /* Figure out the lmd from the mount options */
1228 if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
1229 lustre_put_lsi(sb);
1230 GOTO(out, rc = -EINVAL);
1231 }
1232
1233 if (lmd_is_client(lmd)) {
1234 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
1235 if (!client_fill_super) {
1236 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for "
1237 "client mount! Is the 'lustre' "
1238 "module loaded?\n");
1239 lustre_put_lsi(sb);
1240 rc = -ENODEV;
1241 } else {
1242 rc = lustre_start_mgc(sb);
1243 if (rc) {
1244 lustre_put_lsi(sb);
1245 GOTO(out, rc);
1246 }
1247 /* Connect and start */
1248 /* (should always be ll_fill_super) */
1249 rc = (*client_fill_super)(sb, lmd2->lmd2_mnt);
1250 /* c_f_s will call lustre_common_put_super on failure */
1251 }
1252 } else {
1253 CERROR("This is client-side-only module, "
1254 "cannot handle server mount.\n");
1255 rc = -EINVAL;
1256 }
1257
1258 /* If error happens in fill_super() call, @lsi will be killed there.
1259 * This is why we do not put it here. */
1260 GOTO(out, rc);
1261 out:
1262 if (rc) {
1263 CERROR("Unable to mount %s (%d)\n",
1264 s2lsi(sb) ? lmd->lmd_dev : "", rc);
1265 } else {
1266 CDEBUG(D_SUPER, "Mount %s complete\n",
1267 lmd->lmd_dev);
1268 }
1269 lockdep_on();
1270 return rc;
1271 }
1272
1273
1274 /* We can't call ll_fill_super by name because it lives in a module that
1275 must be loaded after this one. */
1276 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
1277 struct vfsmount *mnt))
1278 {
1279 client_fill_super = cfs;
1280 }
1281 EXPORT_SYMBOL(lustre_register_client_fill_super);
1282
1283 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb))
1284 {
1285 kill_super_cb = cfs;
1286 }
1287 EXPORT_SYMBOL(lustre_register_kill_super_cb);
1288
1289 /***************** FS registration ******************/
1290 struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
1291 const char *devname, void *data)
1292 {
1293 struct lustre_mount_data2 lmd2 = { data, NULL };
1294
1295 return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
1296 }
1297
1298 void lustre_kill_super(struct super_block *sb)
1299 {
1300 struct lustre_sb_info *lsi = s2lsi(sb);
1301
1302 if (kill_super_cb && lsi && !IS_SERVER(lsi))
1303 (*kill_super_cb)(sb);
1304
1305 kill_anon_super(sb);
1306 }
1307
1308 /** Register the "lustre" fs type
1309 */
1310 struct file_system_type lustre_fs_type = {
1311 .owner = THIS_MODULE,
1312 .name = "lustre",
1313 .mount = lustre_mount,
1314 .kill_sb = lustre_kill_super,
1315 .fs_flags = FS_BINARY_MOUNTDATA | FS_REQUIRES_DEV |
1316 FS_HAS_FIEMAP | FS_RENAME_DOES_D_MOVE,
1317 };
1318
1319 int lustre_register_fs(void)
1320 {
1321 return register_filesystem(&lustre_fs_type);
1322 }
1323
1324 int lustre_unregister_fs(void)
1325 {
1326 return unregister_filesystem(&lustre_fs_type);
1327 }
This page took 0.086755 seconds and 6 git commands to generate.