lustre improvements
cover lustre improvements
This is an ad-hoc collection of improvments and bug fixes (mostly my bugs :-( )
Most interesting is that handling of 'mount' is moved from obdclass to llite, which seems to be a more fitting place for it.
Thanks,
NeilBrown
---
NeilBrown (9):
lustre: merge linux-debug.c into debug.c
lustre: llog: use GFP_KERNEL for all allocations.
lustre: move server_name2index to obd_config.c
lustre: move lustre_check_exclusion to obd_config.c
lustre: move filesystem mounting from obdclass to llite
lustre: hold ptlrpc active for lustre_start_mgc()
lustre: ll_fill_super() must put sb on all failure paths.
lustre: ensure libcfs is set up for ioctls.
lustre: lnet: discard LNET_LOCK()
.../staging/lustre/include/linux/lnet/lib-lnet.h | 3 .../lustre/lnet/klnds/socklnd/socklnd_proto.c | 8 drivers/staging/lustre/lnet/libcfs/Makefile | 1 drivers/staging/lustre/lnet/libcfs/debug.c | 86 + drivers/staging/lustre/lnet/libcfs/linux-debug.c | 142 -- drivers/staging/lustre/lnet/libcfs/module.c | 3 drivers/staging/lustre/lnet/libcfs/tracefile.h | 4 drivers/staging/lustre/lnet/selftest/rpc.c | 2 drivers/staging/lustre/lustre/include/obd_class.h | 7 drivers/staging/lustre/lustre/llite/Makefile | 2 .../staging/lustre/lustre/llite/llite_internal.h | 3 drivers/staging/lustre/lustre/llite/llite_lib.c | 16 drivers/staging/lustre/lustre/llite/mount.c | 1216 ++++++++++++++++++ drivers/staging/lustre/lustre/llite/super25.c | 8 drivers/staging/lustre/lustre/obdclass/Makefile | 2 drivers/staging/lustre/lustre/obdclass/class_obd.c | 6 drivers/staging/lustre/lustre/obdclass/llog.c | 6 .../staging/lustre/lustre/obdclass/obd_config.c | 111 ++ drivers/staging/lustre/lustre/obdclass/obd_mount.c | 1353 -------------------- 19 files changed, 1440 insertions(+), 1539 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux-debug.c create mode 100644 drivers/staging/lustre/lustre/llite/mount.c delete mode 100644 drivers/staging/lustre/lustre/obdclass/obd_mount.c
--
Signature
PATCH 1/9 lustre: merge linux-debug.c into debug.c
There is no important difference between the contents of these files, so merge them into one.
--- drivers/staging/lustre/lnet/libcfs/Makefile | 1 drivers/staging/lustre/lnet/libcfs/debug.c | 86 +++++++++++++ drivers/staging/lustre/lnet/libcfs/linux-debug.c | 142 ---------------------- drivers/staging/lustre/lnet/libcfs/tracefile.h | 4 - 4 files changed, 86 insertions(+), 147 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux-debug.c
drivers/staging/lustre/lnet/libcfs/Makefile +0 -1
@@ -4,7 +4,6 @@ ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LNET) += libcfs.o -libcfs-obj-y += linux-debug.o libcfs-obj-y += linux-crypto.o libcfs-obj-y += linux-crypto-adler.o
drivers/staging/lustre/lnet/libcfs/debug.c +86 -0
98 lines not on this page · raw message
drivers/staging/lustre/lnet/libcfs/linux-debug.c deleted +0 -142
142 lines not on this page · raw message
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -4
@@ -51,8 +51,6 @@ extern long long cfs_tracefile_size;*/ extern char lnet_debug_log_upcall[1024 ]; -void libcfs_run_debug_log_upcall (char *file); -int cfs_tracefile_dump_all_pages (char *filename);void cfs_trace_debug_print (void );void cfs_trace_flush_pages (void );
@@ -73,8 +71,6 @@ int cfs_trace_set_debug_mb(int mb);int cfs_trace_get_debug_mb (void );void libcfs_debug_dumplog_internal (void *arg); -void libcfs_register_panic_notifier (void ); -void libcfs_unregister_panic_notifier (void );extern int libcfs_panic_in_progress;#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))
PATCH 1/9 lustre: merge linux-debug.c into debug.c
Quoted 3 lines
There is no important difference between the contents of these files, so merge them into one.
Quoted 298 lines
Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lnet/libcfs/Makefile | 1 drivers/staging/lustre/lnet/libcfs/debug.c | 86 +++++++++++++ drivers/staging/lustre/lnet/libcfs/linux-debug.c | 142 ---------------------- drivers/staging/lustre/lnet/libcfs/tracefile.h | 4 - 4 files changed, 86 insertions(+), 147 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux-debug.cdrivers/staging/lustre/lnet/libcfs/Makefile +0
-1@@ -4,7 +4,6 @@ ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LNET) += libcfs.o -libcfs-obj-y += linux-debug.o libcfs-obj-y += linux-crypto.o libcfs-obj-y += linux-crypto-adler.odrivers/staging/lustre/lnet/libcfs/debug.c +86
-0@@ -327,6 +327,40 @@ libcfs_debug_str2mask(int *mask, const char *str, int is_subsys) 0xffffffff); } +char lnet_debug_log_upcall[1024 ] ="/usr/lib/lustre/lnet_debug_log_upcall" ; + +/** +* Upcall function once a Lustre log has been dumped. +* +* \param file path of the dumped log +*/ +static void libcfs_run_debug_log_upcall (char *file) +{ +char *argv[3 ]; +int rc; +static const char *const envp[] = { +"HOME=/" , +"PATH=/sbin:/bin:/usr/sbin:/usr/bin" , +NULL + }; + + argv[0 ] = lnet_debug_log_upcall; + +LASSERTF (file,"called on a null filename\n" ); + argv[1 ] = file;/* only need to pass the path of the file */ + + argv[2 ] =NULL ; + + rc =call_usermodehelper (argv[0 ], argv, (char **)envp,1 ); +if (rc <0 && rc != -ENOENT ) { +CERROR ("Error %d invoking LNET debug log upcall %s %s; check /sys/kernel/debug/lnet/debug_log_upcall\n" , + rc, argv[0 ], argv[1 ]); + }else { +CDEBUG (D_HA ,"Invoked LNET debug log upcall %s %s\n" , + argv[0 ], argv[1 ]); + } +} +/** * Dump Lustre log to ::debug_file_path by calling tracefile_dump_all_pages() */ @@ -389,6 +423,58 @@ void libcfs_debug_dumplog(void) }EXPORT_SYMBOL (libcfs_debug_dumplog); +/* coverity[+kill] */ +void __noreturn lbug_with_loc (struct libcfs_debug_msg_data *msgdata) +{ + libcfs_catastrophe =1 ; +libcfs_debug_msg (msgdata,"LBUG\n" ); + +if (in_interrupt ()) { +panic ("LBUG in interrupt.\n" ); +/* not reached */ + } + +dump_stack (); +if (!libcfs_panic_on_lbug) +libcfs_debug_dumplog (); +if (libcfs_panic_on_lbug) +panic ("LBUG" ); +set_current_state (TASK_UNINTERRUPTIBLE ); +while (1 ) +schedule (); +} +EXPORT_SYMBOL (lbug_with_loc); + +static int panic_notifier (struct notifier_block *self,unsigned long unused1, +void *unused2) +{ +if (libcfs_panic_in_progress) +return 0 ; + + libcfs_panic_in_progress =1 ; +mb (); + +return 0 ; +} + +static struct notifier_block libcfs_panic_notifier = { + .notifier_call = panic_notifier, + .next =NULL , + .priority =10000 , +}; + +static void libcfs_register_panic_notifier (void ) +{ +atomic_notifier_chain_register (&panic_notifier_list, + &libcfs_panic_notifier); +} + +static void libcfs_unregister_panic_notifier (void ) +{ +atomic_notifier_chain_unregister (&panic_notifier_list, + &libcfs_panic_notifier); +} +int libcfs_debug_init (unsigned long bufsize) {unsigned int max = libcfs_debug_mb;drivers/staging/lustre/lnet/libcfs/linux-debug.c deleted +0
-142@@ -1,142 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* GPL HEADER START -* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 only, -* as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License version 2 for more details (a copy is included -* in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU General Public License -* version 2 along with this program; If not, see -* http://www.gnu.org/licenses/gpl-2.0.html -* -* GPL HEADER END -*/ -/* -* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. -* Use is subject to license terms. -* -* Copyright (c) 2012, Intel Corporation. -*/ -/* -* This file is part of Lustre, http://www.lustre.org/ -* Lustre is a trademark of Sun Microsystems, Inc. -* -* libcfs/libcfs/linux/linux-debug.c -* -* Author: Phil Schwan <[email protected]> -*/ - -#include <linux/module.h> -#include <linux/kmod.h> -#include <linux/notifier.h> -#include <linux/kernel.h> -#include <linux/mm.h> -#include <linux/string.h> -#include <linux/stat.h> -#include <linux/errno.h> -#include <linux/unistd.h> -#include <linux/interrupt.h> -#include <linux/completion.h> -#include <linux/fs.h> -#include <linux/uaccess.h> - -# define DEBUG_SUBSYSTEM S_LNET - -#include "tracefile.h" - -#include <linux/kallsyms.h> - -char lnet_debug_log_upcall[1024 ] ="/usr/lib/lustre/lnet_debug_log_upcall" ; - -/** -* Upcall function once a Lustre log has been dumped. -* -* \param file path of the dumped log -*/ -void libcfs_run_debug_log_upcall (char *file) -{ -char *argv[3 ]; -int rc; -static const char *const envp[] = { -"HOME=/" , -"PATH=/sbin:/bin:/usr/sbin:/usr/bin" , -NULL - }; - - argv[0 ] = lnet_debug_log_upcall; - -LASSERTF (file,"called on a null filename\n" ); - argv[1 ] = file;/* only need to pass the path of the file */ - - argv[2 ] =NULL ; - - rc =call_usermodehelper (argv[0 ], argv, (char **)envp,1 ); -if (rc <0 && rc != -ENOENT ) { -CERROR ("Error %d invoking LNET debug log upcall %s %s; check /sys/kernel/debug/lnet/debug_log_upcall\n" , - rc, argv[0 ], argv[1 ]); - }else { -CDEBUG (D_HA ,"Invoked LNET debug log upcall %s %s\n" , - argv[0 ], argv[1 ]); - } -} - -/* coverity[+kill] */ -void __noreturn lbug_with_loc (struct libcfs_debug_msg_data *msgdata) -{ - libcfs_catastrophe =1 ; -libcfs_debug_msg (msgdata,"LBUG\n" ); - -if (in_interrupt ()) { -panic ("LBUG in interrupt.\n" ); -/* not reached */ - } - -dump_stack (); -if (!libcfs_panic_on_lbug) -libcfs_debug_dumplog (); -if (libcfs_panic_on_lbug) -panic ("LBUG" ); -set_current_state (TASK_UNINTERRUPTIBLE ); -while (1 ) -schedule (); -} -EXPORT_SYMBOL (lbug_with_loc); - -static int panic_notifier (struct notifier_block *self,unsigned long unused1, -void *unused2) -{ -if (libcfs_panic_in_progress) -return 0 ; - - libcfs_panic_in_progress =1 ; -mb (); - -return 0 ; -} - -static struct notifier_block libcfs_panic_notifier = { - .notifier_call = panic_notifier, - .next =NULL , - .priority =10000 , -}; - -void libcfs_register_panic_notifier (void ) -{ -atomic_notifier_chain_register (&panic_notifier_list, - &libcfs_panic_notifier); -} - -void libcfs_unregister_panic_notifier (void ) -{ -atomic_notifier_chain_unregister (&panic_notifier_list, - &libcfs_panic_notifier); -}drivers/staging/lustre/lnet/libcfs/tracefile.h +0
-4@@ -51,8 +51,6 @@ extern long long cfs_tracefile_size;*/ extern char lnet_debug_log_upcall[1024 ]; -void libcfs_run_debug_log_upcall (char *file); -int cfs_tracefile_dump_all_pages (char *filename);void cfs_trace_debug_print (void );void cfs_trace_flush_pages (void );@@ -73,8 +71,6 @@ int cfs_trace_set_debug_mb(int mb);int cfs_trace_get_debug_mb (void );void libcfs_debug_dumplog_internal (void *arg); -void libcfs_register_panic_notifier (void ); -void libcfs_unregister_panic_notifier (void );extern int libcfs_panic_in_progress;#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))
PATCH 2/9 lustre: llog: use GFP_KERNEL for all allocations.
In reply to NeilBrownProcessing the log happens at mount time so memory allocations will not trigger write-out to this filesystem which might deadlock.
So use of GFP_NOFS is not needed. GFP_KERNEL is preferred, especially for kvmalloc() which doesn't try the 'vmalloc' option when GFP_KERNEL is not specified.
--- drivers/staging/lustre/lustre/obdclass/llog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/lustre/lustre/obdclass/llog.c +3 -3
@@ -59,7 +59,7 @@ static struct llog_handle *llog_alloc_handle(void) {struct llog_handle *loghandle; - loghandle =kzalloc (sizeof (*loghandle),GFP_NOFS ); + loghandle =kzalloc (sizeof (*loghandle),GFP_KERNEL );if (!loghandle)return NULL ;
@@ -242,7 +242,7 @@ static int llog_process_thread(void *arg)/* expect chunk_size to be power of two */ LASSERT (is_power_of_2 (chunk_size)); - buf =kvzalloc (chunk_size,GFP_NOFS ); + buf =kvzalloc (chunk_size,GFP_KERNEL );if (!buf) { lpi->lpi_rc = -ENOMEM ;return 0 ;
@@ -421,7 +421,7 @@ int llog_process_or_fork(const struct lu_env *env,struct llog_process_info *lpi;int rc; - lpi =kzalloc (sizeof (*lpi),GFP_NOFS ); + lpi =kzalloc (sizeof (*lpi),GFP_KERNEL );if (!lpi)return -ENOMEM ; lpi->lpi_loghandle = loghandle;
PATCH 2/9 lustre: llog: use GFP_KERNEL for all allocations.
Quoted 8 lines
Processing the log happens at mount time so memory allocations will not trigger write-out to this filesystem which might deadlock.
So use ofGFP_NOFSis not needed.GFP_KERNELis preferred, especially forkvmalloc()which doesn't try the 'vmalloc' option whenGFP_KERNELis not specified.
Quoted 39 lines
Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lustre/obdclass/llog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/staging/lustre/lustre/obdclass/llog.c +3
-3@@ -59,7 +59,7 @@ static struct llog_handle *llog_alloc_handle(void) {struct llog_handle *loghandle; - loghandle =kzalloc (sizeof (*loghandle),GFP_NOFS ); + loghandle =kzalloc (sizeof (*loghandle),GFP_KERNEL );if (!loghandle)return NULL ;@@ -242,7 +242,7 @@ static int llog_process_thread(void *arg)/* expect chunk_size to be power of two */ LASSERT (is_power_of_2 (chunk_size)); - buf =kvzalloc (chunk_size,GFP_NOFS ); + buf =kvzalloc (chunk_size,GFP_KERNEL );if (!buf) { lpi->lpi_rc = -ENOMEM ;return 0 ;@@ -421,7 +421,7 @@ int llog_process_or_fork(const struct lu_env *env,struct llog_process_info *lpi;int rc; - lpi =kzalloc (sizeof (*lpi),GFP_NOFS ); + lpi =kzalloc (sizeof (*lpi),GFP_KERNEL );if (!lpi)return -ENOMEM ; lpi->lpi_loghandle = loghandle;
PATCH 3/9 lustre: move server_name2index to obd_config.c
In reply to NeilBrownThis is preparation for moving filesystem mounting into llite/.server_name2index belongs in obdclass, but the rest of obd_mount.c fits better in llite. So move it and server_name2fsname() across to obd_config.c, and expect it for later using by llite.
--- drivers/staging/lustre/lustre/include/obd_class.h | 2 .../staging/lustre/lustre/obdclass/obd_config.c | 86 ++++++++++++++++++++ drivers/staging/lustre/lustre/obdclass/obd_mount.c | 84 -------------------- 3 files changed, 88 insertions(+), 84 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +2 -0
@@ -134,6 +134,8 @@ int class_config_llog_handler(const struct lu_env *env,struct llog_handle *handle, struct llog_rec_hdr *rec, void *data);int class_add_uuid (const char *uuid,__u64 nid); +int server_name2index (const char *svname,__u32 *idx, +const char **endptr);/* obdecho */ void lprocfs_echo_init_vars (struct lprocfs_static_vars *lvars);
drivers/staging/lustre/lustre/obdclass/obd_config.c +86 -0
98 lines not on this page · raw message
drivers/staging/lustre/lustre/obdclass/obd_mount.c +0 -84
90 lines not on this page · raw message
PATCH 3/9 lustre: move server_name2index to obd_config.c
Quoted 7 lines
This is preparation for moving filesystem mounting into llite/.
server_name2indexbelongs in obdclass, but the rest ofobd_mount.cfits better in llite. So move it andserver_name2fsname()across toobd_config.c, and expect it for later using by llite.
Hmm. These are very different from the OpenSFS branch. Appears some rearranging of the code dropped some stuff. I will look into cleaning separating the server and client.
Quoted 222 lines
Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lustre/include/obd_class.h | 2 .../staging/lustre/lustre/obdclass/obd_config.c | 86 ++++++++++++++++++++ drivers/staging/lustre/lustre/obdclass/obd_mount.c | 84 -------------------- 3 files changed, 88 insertions(+), 84 deletions(-)drivers/staging/lustre/lustre/include/obd_class.h +2
-0@@ -134,6 +134,8 @@ int class_config_llog_handler(const struct lu_env *env,struct llog_handle *handle, struct llog_rec_hdr *rec, void *data);int class_add_uuid (const char *uuid,__u64 nid); +int server_name2index (const char *svname,__u32 *idx, +const char **endptr);/* obdecho */ void lprocfs_echo_init_vars (struct lprocfs_static_vars *lvars);drivers/staging/lustre/lustre/obdclass/obd_config.c +86
-0@@ -46,6 +46,7 @@#include <lustre_log.h> #include <uapi/linux/lustre/lustre_param.h> #include <obd_class.h> +#include <lustre_disk.h> #include "llog_internal.h" @@ -1172,6 +1173,91 @@ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, }EXPORT_SYMBOL (class_process_proc_param); +/*** SERVER NAME *** +* <FSNAME><SEPARATOR><TYPE><INDEX> +* FSNAME is between 1 and 8 characters (inclusive). +* Excluded characters are '/' and ':' +* SEPARATOR is either ':' or '-' +* TYPE: "OST", "MDT", etc. +* INDEX: Hex representation of the index +*/ + +/** Get the fsname ("lustre") from the server name ("lustre-OST003F"). +* @param [in] svname server name including type and index +* @param [out] fsname Buffer to copy filesystem name prefix into. +* Must have at least 'strlen(fsname) + 1' chars. +* @param [out] endptr if endptr isn't NULL it is set to end of fsname +* rc < 0 on error +*/ +static int server_name2fsname (const char *svname,char *fsname, +const char **endptr) +{ +const char *dash; + + dash = svname +strnlen (svname,8 );/* max fsname length is 8 */ +for (; dash > svname && *dash !='-' && *dash !=':' ; dash--) + ; +if (dash == svname) +return -EINVAL ; + +if (fsname) { +strncpy (fsname, svname, dash - svname); + fsname[dash - svname] ='\0' ; + } + +if (endptr) + *endptr = dash; + +return 0 ; +} + +/* Get the index from the obd name. +* rc = server type, or +* rc < 0 on error +* if endptr isn't NULL it is set to end of name +*/ +int server_name2index (const char *svname,__u32 *idx, +const char **endptr) +{ +unsigned long index; +int rc; +const char *dash; + +/* We use server_name2fsname() just for parsing */ + rc =server_name2fsname (svname,NULL , &dash); +if (rc !=0 ) +return rc; + + dash++; + +if (strncmp (dash,"MDT" ,3 ) ==0 ) + rc =LDD_F_SV_TYPE_MDT ; +else if (strncmp (dash,"OST" ,3 ) ==0 ) + rc =LDD_F_SV_TYPE_OST ; +else +return -EINVAL ; + + dash +=3 ; + +if (strncmp (dash,"all" ,3 ) ==0 ) { +if (endptr) + *endptr = dash +3 ; +return rc |LDD_F_SV_ALL ; + } + + index =simple_strtoul (dash, (char **)endptr,16 ); +if (idx) + *idx = index; + +/* Account for -mdc after index that is possible when specifying mdt */ +if (endptr &&strncmp (LUSTRE_MDC_NAME , *endptr +1 , +sizeof (LUSTRE_MDC_NAME ) -1 ) ==0 ) + *endptr +=sizeof (LUSTRE_MDC_NAME ); + +return rc; +} +EXPORT_SYMBOL (server_name2index); +/** Parse a configuration llog, doing various manipulations on them * for various reasons, (modifications for compatibility, skip obsolete * records, change uuids, etc), then class_process_config() resulting drivers/staging/lustre/lustre/obdclass/obd_mount.c +0
-84@@ -579,90 +579,6 @@ static int lustre_put_lsi(struct super_block *sb)return 0 ; } -/*** SERVER NAME *** -* <FSNAME><SEPARATOR><TYPE><INDEX> -* FSNAME is between 1 and 8 characters (inclusive). -* Excluded characters are '/' and ':' -* SEPARATOR is either ':' or '-' -* TYPE: "OST", "MDT", etc. -* INDEX: Hex representation of the index -*/ - -/** Get the fsname ("lustre") from the server name ("lustre-OST003F"). -* @param [in] svname server name including type and index -* @param [out] fsname Buffer to copy filesystem name prefix into. -* Must have at least 'strlen(fsname) + 1' chars. -* @param [out] endptr if endptr isn't NULL it is set to end of fsname -* rc < 0 on error -*/ -static int server_name2fsname (const char *svname,char *fsname, -const char **endptr) -{ -const char *dash; - - dash = svname +strnlen (svname,8 );/* max fsname length is 8 */ -for (; dash > svname && *dash !='-' && *dash !=':' ; dash--) - ; -if (dash == svname) -return -EINVAL ; - -if (fsname) { -strncpy (fsname, svname, dash - svname); - fsname[dash - svname] ='\0' ; - } - -if (endptr) - *endptr = dash; - -return 0 ; -} - -/* Get the index from the obd name. -* rc = server type, or -* rc < 0 on error -* if endptr isn't NULL it is set to end of name -*/ -static int server_name2index (const char *svname,__u32 *idx, -const char **endptr) -{ -unsigned long index; -int rc; -const char *dash; - -/* We use server_name2fsname() just for parsing */ - rc =server_name2fsname (svname,NULL , &dash); -if (rc !=0 ) -return rc; - - dash++; - -if (strncmp (dash,"MDT" ,3 ) ==0 ) - rc =LDD_F_SV_TYPE_MDT ; -else if (strncmp (dash,"OST" ,3 ) ==0 ) - rc =LDD_F_SV_TYPE_OST ; -else -return -EINVAL ; - - dash +=3 ; - -if (strncmp (dash,"all" ,3 ) ==0 ) { -if (endptr) - *endptr = dash +3 ; -return rc |LDD_F_SV_ALL ; - } - - index =simple_strtoul (dash, (char **)endptr,16 ); -if (idx) - *idx = index; - -/* Account for -mdc after index that is possible when specifying mdt */ -if (endptr &&strncmp (LUSTRE_MDC_NAME , *endptr +1 , -sizeof (LUSTRE_MDC_NAME ) -1 ) ==0 ) - *endptr +=sizeof (LUSTRE_MDC_NAME ); - -return rc; -} -/*************** mount common between server and client ***************/ /* Common umount */
PATCH 4/9 lustre: move lustre_check_exclusion to obd_config.c
In reply to NeilBrownlustre_check_exclusion is only used in obd_config.c, so move the code there
Note that a CDEBUG is changed from D_MOUNT to D_INFO. This prepares for obd_mount to move to llite/
--- drivers/staging/lustre/lustre/include/obd_class.h | 1 - .../staging/lustre/lustre/obdclass/obd_config.c | 25 ++++++++++++++++++++ drivers/staging/lustre/lustre/obdclass/obd_mount.c | 25 -------------------- 3 files changed, 25 insertions(+), 26 deletions(-)
drivers/staging/lustre/lustre/include/obd_class.h +0 -1
@@ -1559,7 +1559,6 @@ extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);/* obd_mount.c */ int lustre_unregister_fs (void );int lustre_register_fs (void ); -int lustre_check_exclusion (struct super_block *sb,char *svname);/* sysctl.c */ int obd_sysctl_init (void );
drivers/staging/lustre/lustre/obdclass/obd_config.c +25 -0
@@ -1258,6 +1258,31 @@ int server_name2index(const char *svname, __u32 *idx, }EXPORT_SYMBOL (server_name2index); +/* Is this server on the exclusion list */ +static int lustre_check_exclusion (struct super_block *sb,char *svname) +{ +struct lustre_sb_info *lsi =s2lsi (sb); +struct lustre_mount_data *lmd = lsi->lsi_lmd; +__u32 index; +int i, rc; + + rc =server_name2index (svname, &index,NULL ); +if (rc !=LDD_F_SV_TYPE_OST ) +/* Only exclude OSTs */ +return 0 ; + +CDEBUG (D_INFO ,"Check exclusion %s (%d) in %d of %s\n" , svname, + index, lmd->lmd_exclude_count, lmd->lmd_dev); + +for (i =0 ; i < lmd->lmd_exclude_count; i++) { +if (index == lmd->lmd_exclude[i]) { +CWARN ("Excluding %s (on exclusion list)\n" , svname); +return 1 ; + } + } +return 0 ; +} +/** Parse a configuration llog, doing various manipulations on them * for various reasons, (modifications for compatibility, skip obsolete * records, change uuids, etc), then class_process_config() resulting
drivers/staging/lustre/lustre/obdclass/obd_mount.c +0 -25
@@ -633,31 +633,6 @@ static void lmd_print(struct lustre_mount_data *lmd) } } -/* Is this server on the exclusion list */ -int lustre_check_exclusion (struct super_block *sb,char *svname) -{ -struct lustre_sb_info *lsi =s2lsi (sb); -struct lustre_mount_data *lmd = lsi->lsi_lmd; -__u32 index; -int i, rc; - - rc =server_name2index (svname, &index,NULL ); -if (rc !=LDD_F_SV_TYPE_OST ) -/* Only exclude OSTs */ -return 0 ; - -CDEBUG (D_MOUNT ,"Check exclusion %s (%d) in %d of %s\n" , svname, - index, lmd->lmd_exclude_count, lmd->lmd_dev); - -for (i =0 ; i < lmd->lmd_exclude_count; i++) { -if (index == lmd->lmd_exclude[i]) { -CWARN ("Excluding %s (on exclusion list)\n" , svname); -return 1 ; - } - } -return 0 ; -} -/* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */ static int lmd_make_exclusion (struct lustre_mount_data *lmd,const char *ptr) {
PATCH 4/9 lustre: move lustre_check_exclusion to obd_config.c
Quoted 5 lines
lustre_check_exclusionis only used inobd_config.c, so move the code there
Note that a CDEBUG is changed fromD_MOUNTtoD_INFO. This prepares forobd_mountto move to llite/
Quoted 94 lines
Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lustre/include/obd_class.h | 1 - .../staging/lustre/lustre/obdclass/obd_config.c | 25 ++++++++++++++++++++ drivers/staging/lustre/lustre/obdclass/obd_mount.c | 25 -------------------- 3 files changed, 25 insertions(+), 26 deletions(-)drivers/staging/lustre/lustre/include/obd_class.h +0
-1@@ -1559,7 +1559,6 @@ extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);/* obd_mount.c */ int lustre_unregister_fs (void );int lustre_register_fs (void ); -int lustre_check_exclusion (struct super_block *sb,char *svname);/* sysctl.c */ int obd_sysctl_init (void );drivers/staging/lustre/lustre/obdclass/obd_config.c +25
-0@@ -1258,6 +1258,31 @@ int server_name2index(const char *svname, __u32 *idx, }EXPORT_SYMBOL (server_name2index); +/* Is this server on the exclusion list */ +static int lustre_check_exclusion (struct super_block *sb,char *svname) +{ +struct lustre_sb_info *lsi =s2lsi (sb); +struct lustre_mount_data *lmd = lsi->lsi_lmd; +__u32 index; +int i, rc; + + rc =server_name2index (svname, &index,NULL ); +if (rc !=LDD_F_SV_TYPE_OST ) +/* Only exclude OSTs */ +return 0 ; + +CDEBUG (D_INFO ,"Check exclusion %s (%d) in %d of %s\n" , svname, + index, lmd->lmd_exclude_count, lmd->lmd_dev); + +for (i =0 ; i < lmd->lmd_exclude_count; i++) { +if (index == lmd->lmd_exclude[i]) { +CWARN ("Excluding %s (on exclusion list)\n" , svname); +return 1 ; + } + } +return 0 ; +} +/** Parse a configuration llog, doing various manipulations on them * for various reasons, (modifications for compatibility, skip obsolete * records, change uuids, etc), then class_process_config() resulting drivers/staging/lustre/lustre/obdclass/obd_mount.c +0
-25@@ -633,31 +633,6 @@ static void lmd_print(struct lustre_mount_data *lmd) } } -/* Is this server on the exclusion list */ -int lustre_check_exclusion (struct super_block *sb,char *svname) -{ -struct lustre_sb_info *lsi =s2lsi (sb); -struct lustre_mount_data *lmd = lsi->lsi_lmd; -__u32 index; -int i, rc; - - rc =server_name2index (svname, &index,NULL ); -if (rc !=LDD_F_SV_TYPE_OST ) -/* Only exclude OSTs */ -return 0 ; - -CDEBUG (D_MOUNT ,"Check exclusion %s (%d) in %d of %s\n" , svname, - index, lmd->lmd_exclude_count, lmd->lmd_dev); - -for (i =0 ; i < lmd->lmd_exclude_count; i++) { -if (index == lmd->lmd_exclude[i]) { -CWARN ("Excluding %s (on exclusion list)\n" , svname); -return 1 ; - } - } -return 0 ; -} -/* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */ static int lmd_make_exclusion (struct lustre_mount_data *lmd,const char *ptr) {
PATCH 5/9 lustre: move filesystem mounting from obdclass to llite
In reply to NeilBrownAll filesystem-api aspects of the lustre filesystem are in llite, except mounting which is in obdclass.
This is probably because the name filesystem type is/was used for mounting an lustre filesystem on the client, and for mounting a data-store on the server.
This is a confusion that is best discarded and forgotten.
So move the mount handling into llite.
This removes that rather awkward requirment that obdclass needed to request_module() the lustre module, and makes lustre_fill_super() significantly simpler.
Several symbols don't need to be exported any more as they are now part of llite which is the only module that uses them.
--- drivers/staging/lustre/lustre/include/obd_class.h | 4 drivers/staging/lustre/lustre/llite/Makefile | 2 .../staging/lustre/lustre/llite/llite_internal.h | 3 drivers/staging/lustre/lustre/llite/mount.c | 1208 +++++++++++++++++++ drivers/staging/lustre/lustre/llite/super25.c | 8 drivers/staging/lustre/lustre/obdclass/Makefile | 2 drivers/staging/lustre/lustre/obdclass/class_obd.c | 6 drivers/staging/lustre/lustre/obdclass/obd_mount.c | 1244 -------------------- 8 files changed, 1218 insertions(+), 1259 deletions(-) create mode 100644 drivers/staging/lustre/lustre/llite/mount.c delete mode 100644 drivers/staging/lustre/lustre/obdclass/obd_mount.c
drivers/staging/lustre/lustre/include/obd_class.h +0 -4
@@ -1556,10 +1556,6 @@ struct lwp_register_item {*/ extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); -/* obd_mount.c */ -int lustre_unregister_fs (void ); -int lustre_register_fs (void ); -/* sysctl.c */ int obd_sysctl_init (void );
drivers/staging/lustre/lustre/llite/Makefile +1 -1
@@ -3,7 +3,7 @@ ccflags-y += -I$(srctree)/drivers/staging/lustre/include ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LUSTRE_FS) += lustre.o -lustre-y := dcache.o dir.o file.o llite_lib.o llite_nfs.o \ +lustre-y := mount.o dcache.o dir.o file.o llite_lib.o llite_nfs.o \ rw.o rw26.o namei.o symlink.o llite_mmap.o range_lock.o \ xattr.o xattr_cache.o xattr_security.o \ super25.o statahead.o glimpse.o lcommon_cl.o lcommon_misc.o \
drivers/staging/lustre/lustre/llite/llite_internal.h +3 -0
@@ -1351,4 +1351,7 @@ void cl_inode_fini(struct inode *inode);__u64 cl_fid_build_ino (const struct lu_fid *fid,int api32);__u32 cl_fid_build_gen (const struct lu_fid *fid); +int lustre_unregister_fs (void ); +int lustre_register_fs (void ); +#endif /* LLITE_INTERNAL_H */
drivers/staging/lustre/lustre/llite/mount.c new file +1208 -0
1,208 lines not on this page · raw message
drivers/staging/lustre/lustre/llite/super25.c +5 -3
@@ -145,10 +145,11 @@ static int __init lustre_init(void)if (rc !=0 ) goto out_inode_fini_env; -lustre_register_super_ops (THIS_MODULE , ll_fill_super, ll_kill_super);lustre_register_client_process_config (ll_process_config); -return 0 ; + rc =lustre_register_fs (); + +return rc; out_inode_fini_env:cl_env_put (cl_inode_fini_env, &cl_inode_fini_refcheck);
@@ -166,7 +167,8 @@ static int __init lustre_init(void) static void __exit lustre_exit(void) { -lustre_register_super_ops (NULL ,NULL ,NULL ); +lustre_unregister_fs (); +lustre_register_client_process_config (NULL );debugfs_remove (llite_root);
drivers/staging/lustre/lustre/obdclass/Makefile +1 -1
@@ -8,5 +8,5 @@ obdclass-y := module.o sysctl.o \ llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o debug.o \ genops.o uuid.o lprocfs_status.o lprocfs_counters.o \ lustre_handles.o lustre_peer.o statfs_pack.o linkea.o \ - obdo.o obd_config.o obd_mount.o lu_object.o lu_ref.o \ + obdo.o obd_config.o lu_object.o lu_ref.o \ cl_object.o cl_page.o cl_lock.o cl_io.o kernelcomm.o
drivers/staging/lustre/lustre/obdclass/class_obd.c +0 -6
@@ -510,18 +510,12 @@ static int __init obdclass_init(void)return err; err =llog_info_init (); -if (err) -return err; - - err =lustre_register_fs ();return err; }static void obdclass_exit (void ) { -lustre_unregister_fs (); -misc_deregister (&obd_psdev);llog_info_fini ();cl_global_fini ();
drivers/staging/lustre/lustre/obdclass/obd_mount.c deleted +0 -1244
1,244 lines not on this page · raw message
PATCH 5/9 lustre: move filesystem mounting from obdclass to llite
Quoted 8 lines
All filesystem-api aspects of the lustre filesystem are in llite, except mounting which is in obdclass.
This is probably because the name filesystem type is/was used for mounting an lustre filesystem on the client, and for mounting a data-store on the server.
This is a confusion that is best discarded and forgotten.
Quoted 8 lines
So move the mount handling into llite.
This removes that rather awkward requirment that obdclass needed to
request_module()the lustre module, and makeslustre_fill_super()significantly simpler.Several symbols don't need to be exported any more as they are now part of llite which is the only module that uses them.
Nak. The majority of this code is shared between both server and client code. Moving this directly to llite would make server code dependent on llite which is what is not desired. Things like lustre_process_log() and lustre_end_log() have no client or server specific code and all nodes running lustre independent of the function of the node execute these code paths. Please see obd_mount_server.c to see what functions are used.
Do you mind if I take a stab at this ?
Quoted 2,583 lines
Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lustre/include/obd_class.h | 4 drivers/staging/lustre/lustre/llite/Makefile | 2 .../staging/lustre/lustre/llite/llite_internal.h | 3 drivers/staging/lustre/lustre/llite/mount.c | 1208 +++++++++++++++++++ drivers/staging/lustre/lustre/llite/super25.c | 8 drivers/staging/lustre/lustre/obdclass/Makefile | 2 drivers/staging/lustre/lustre/obdclass/class_obd.c | 6 drivers/staging/lustre/lustre/obdclass/obd_mount.c | 1244 -------------------- 8 files changed, 1218 insertions(+), 1259 deletions(-) create mode 100644 drivers/staging/lustre/lustre/llite/mount.c delete mode 100644 drivers/staging/lustre/lustre/obdclass/obd_mount.cdrivers/staging/lustre/lustre/include/obd_class.h +0
-4@@ -1556,10 +1556,6 @@ struct lwp_register_item {*/ extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); -/* obd_mount.c */ -int lustre_unregister_fs (void ); -int lustre_register_fs (void ); -/* sysctl.c */ int obd_sysctl_init (void );drivers/staging/lustre/lustre/llite/Makefile +1
-1@@ -3,7 +3,7 @@ ccflags-y += -I$(srctree)/drivers/staging/lustre/include ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LUSTRE_FS) += lustre.o -lustre-y := dcache.o dir.o file.o llite_lib.o llite_nfs.o \ +lustre-y := mount.o dcache.o dir.o file.o llite_lib.o llite_nfs.o \ rw.o rw26.o namei.o symlink.o llite_mmap.o range_lock.o \ xattr.o xattr_cache.o xattr_security.o \ super25.o statahead.o glimpse.o lcommon_cl.o lcommon_misc.o \drivers/staging/lustre/lustre/llite/llite_internal.h +3
-0@@ -1351,4 +1351,7 @@ void cl_inode_fini(struct inode *inode);__u64 cl_fid_build_ino (const struct lu_fid *fid,int api32);__u32 cl_fid_build_gen (const struct lu_fid *fid); +int lustre_unregister_fs (void ); +int lustre_register_fs (void ); +#endif /* LLITE_INTERNAL_H */ drivers/staging/lustre/lustre/llite/mount.c new file +1208
-0@@ -0,0 +1,1208 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* GPL HEADER START +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 only, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License version 2 for more details (a copy is included +* in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU General Public License +* version 2 along with this program; If not, see +* http://www.gnu.org/licenses/gpl-2.0.html +* +* GPL HEADER END +*/ +/* +* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. +* Use is subject to license terms. +* +* Copyright (c) 2011, 2015, Intel Corporation. +*/ +/* +* This file is part of Lustre, http://www.lustre.org/ +* Lustre is a trademark of Sun Microsystems, Inc. +* +* lustre/obdclass/obd_mount.c +* +* Client mount routines +* +* Author: Nathan Rutman <[email protected]> +*/ + +#define DEBUG_SUBSYSTEM S_CLASS +#define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */) +#define PRINT_CMD CDEBUG + +#include <linux/random.h> +#include <obd.h> +#include <obd_class.h> +#include <uapi/linux/lustre/lustre_idl.h> +#include <lustre_log.h> +#include <lustre_disk.h> +#include <uapi/linux/lustre/lustre_param.h> +#include <llite_internal.h> + +/**************** config llog ********************/ + +/** Get a config log from the MGS and process it. +* This func is called for both clients and servers. +* Continue to process new statements appended to the logs +* (whenever the config lock is revoked) until lustre_end_log +* is called. +* @param sb The superblock is used by the MGC to write to the local copy of +* the config log +* @param logname The name of the llog to replicate from the MGS +* @param cfg Since the same mgc may be used to follow multiple config logs +* (e.g. ost1, ost2, client), the config_llog_instance keeps the state for +* this log, and is added to the mgc's list of logs to follow. +*/ +int lustre_process_log (struct super_block *sb,char *logname, +struct config_llog_instance *cfg) +{ +struct lustre_cfg *lcfg; +struct lustre_cfg_bufs *bufs; +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *mgc = lsi->lsi_mgc; +int rc; + +LASSERT (mgc); +LASSERT (cfg); + + bufs =kzalloc (sizeof (*bufs),GFP_NOFS ); +if (!bufs) +return -ENOMEM ; + +/* mgc_process_config */ +lustre_cfg_bufs_reset (bufs, mgc->obd_name); +lustre_cfg_bufs_set_string (bufs,1 , logname); +lustre_cfg_bufs_set (bufs,2 , cfg,sizeof (*cfg)); +lustre_cfg_bufs_set (bufs,3 , &sb,sizeof (sb)); + lcfg =kzalloc (lustre_cfg_len (bufs->lcfg_bufcount, bufs->lcfg_buflen), +GFP_NOFS ); +if (!lcfg) { + rc = -ENOMEM ; + goto out; + } +lustre_cfg_init (lcfg,LCFG_LOG_START , bufs); + + rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); +kfree (lcfg); +out: +kfree (bufs); + +if (rc == -EINVAL ) +LCONSOLE_ERROR_MSG (0x15b ,"%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n" , + mgc->obd_name, logname, rc); + +else if (rc) +LCONSOLE_ERROR_MSG (0x15c ,"%s: The configuration from log '%s' failed (%d). This may be the result of communication errors between this node and the MGS, a bad configuration, or other errors. See the syslog for more information.\n" , + mgc->obd_name, logname, + rc); + +/* class_obd_list(); */ +return rc; +} + +/* Stop watching this config log for updates */ +int lustre_end_log (struct super_block *sb,char *logname, +struct config_llog_instance *cfg) +{ +struct lustre_cfg *lcfg; +struct lustre_cfg_bufs bufs; +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *mgc = lsi->lsi_mgc; +int rc; + +if (!mgc) +return -ENOENT ; + +/* mgc_process_config */ +lustre_cfg_bufs_reset (&bufs, mgc->obd_name); +lustre_cfg_bufs_set_string (&bufs,1 , logname); +if (cfg) +lustre_cfg_bufs_set (&bufs,2 , cfg,sizeof (*cfg)); + lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), +GFP_NOFS ); +if (!lcfg) +return -ENOMEM ; +lustre_cfg_init (lcfg,LCFG_LOG_END , &bufs); + + rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); +kfree (lcfg); +return rc; +} + +/**************** obd start *******************/ + +/** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from +* lctl (and do for echo cli/srv. +*/ +static int do_lcfg (char *cfgname,lnet_nid_t nid,int cmd, +char *s1,char *s2,char *s3,char *s4) +{ +struct lustre_cfg_bufs bufs; +struct lustre_cfg *lcfg =NULL ; +int rc; + +CDEBUG (D_TRACE ,"lcfg %s %#x %s %s %s %s\n" , cfgname, + cmd, s1, s2, s3, s4); + +lustre_cfg_bufs_reset (&bufs, cfgname); +if (s1) +lustre_cfg_bufs_set_string (&bufs,1 , s1); +if (s2) +lustre_cfg_bufs_set_string (&bufs,2 , s2); +if (s3) +lustre_cfg_bufs_set_string (&bufs,3 , s3); +if (s4) +lustre_cfg_bufs_set_string (&bufs,4 , s4); + + lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), +GFP_NOFS ); +if (!lcfg) +return -ENOMEM ; +lustre_cfg_init (lcfg, cmd, &bufs); + lcfg->lcfg_nid = nid; + rc =class_process_config (lcfg); +kfree (lcfg); +return rc; +} + +/** Call class_attach and class_setup. These methods in turn call +* obd type-specific methods. +*/ +static int lustre_start_simple (char *obdname,char *type,char *uuid, +char *s1,char *s2,char *s3,char *s4) +{ +int rc; + +CDEBUG (D_MOUNT ,"Starting obd %s (typ=%s)\n" , obdname, type); + + rc =do_lcfg (obdname,0 ,LCFG_ATTACH , type, uuid,NULL ,NULL ); +if (rc) { +CERROR ("%s attach error %d\n" , obdname, rc); +return rc; + } + rc =do_lcfg (obdname,0 ,LCFG_SETUP , s1, s2, s3, s4); +if (rc) { +CERROR ("%s setup error %d\n" , obdname, rc); +do_lcfg (obdname,0 ,LCFG_DETACH ,NULL ,NULL ,NULL ,NULL ); + } +return rc; +} + +static DEFINE_MUTEX (mgc_start_lock); + +/** Set up a mgc obd to process startup logs +* +* \param sb [in] super block of the mgc obd +* +* \retval 0 success, otherwise error code +*/ +int lustre_start_mgc (struct super_block *sb) +{ +struct obd_connect_data *data =NULL ; +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *obd; +struct obd_export *exp; +struct obd_uuid *uuid; +class_uuid_t uuidc; +lnet_nid_t nid; +char nidstr[LNET_NIDSTR_SIZE ]; +char *mgcname =NULL , *niduuid =NULL , *mgssec =NULL ; +char *ptr; +int rc =0 , i =0 , j; + +LASSERT (lsi->lsi_lmd); + +/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ + ptr = lsi->lsi_lmd->lmd_dev; +if (class_parse_nid (ptr, &nid, &ptr) ==0 ) + i++; +if (i ==0 ) { +CERROR ("No valid MGS nids found.\n" ); +return -EINVAL ; + } + +mutex_lock (&mgc_start_lock); + +libcfs_nid2str_r (nid, nidstr,sizeof (nidstr)); + mgcname =kasprintf (GFP_NOFS , +"%s%s" ,LUSTRE_MGC_OBDNAME , nidstr); + niduuid =kasprintf (GFP_NOFS ,"%s_%x" , mgcname,0 ); +if (!mgcname || !niduuid) { + rc = -ENOMEM ; + goto out_free; + } + + mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec :"" ; + + data =kzalloc (sizeof (*data),GFP_NOFS ); +if (!data) { + rc = -ENOMEM ; + goto out_free; + } + + obd =class_name2obd (mgcname); +if (obd && !obd->obd_stopping) { +int recov_bk; + + rc =obd_set_info_async (NULL , obd->obd_self_export, +strlen (KEY_MGSSEC ),KEY_MGSSEC , +strlen (mgssec), mgssec,NULL ); +if (rc) + goto out_free; + +/* Re-using an existing MGC */ +atomic_inc (&obd->u.cli.cl_mgc_refcount); + +/* IR compatibility check, only for clients */ +if (lmd_is_client (lsi->lsi_lmd)) { +int has_ir; +int vallen =sizeof (*data); +__u32 *flags = &lsi->lsi_lmd->lmd_flags; + + rc =obd_get_info (NULL , obd->obd_self_export, +strlen (KEY_CONN_DATA ),KEY_CONN_DATA , + &vallen, data); +LASSERT (rc ==0 ); + has_ir =OCD_HAS_FLAG (data,IMP_RECOV ); +if (has_ir ^ !(*flags &LMD_FLG_NOIR )) { +/* LMD_FLG_NOIR is for test purpose only */ +LCONSOLE_WARN ( +"Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n" , + has_ir ?"enabled" :"disabled" ); +if (has_ir) + *flags &= ~LMD_FLG_NOIR ; +else + *flags |=LMD_FLG_NOIR ; + } + } + + recov_bk =0 ; + +/* Try all connections, but only once (again). +* We don't want to block another target from starting +* (using its local copy of the log), but we do want to connect +* if at all possible. +*/ + recov_bk++; +CDEBUG (D_MOUNT ,"%s: Set MGC reconnect %d\n" , mgcname, + recov_bk); + rc =obd_set_info_async (NULL , obd->obd_self_export, +sizeof (KEY_INIT_RECOV_BACKUP ), +KEY_INIT_RECOV_BACKUP , +sizeof (recov_bk), &recov_bk,NULL ); + rc =0 ; + goto out; + } + +CDEBUG (D_MOUNT ,"Start MGC '%s'\n" , mgcname); + +/* Add the primary nids for the MGS */ + i =0 ; +/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ + ptr = lsi->lsi_lmd->lmd_dev; +while (class_parse_nid (ptr, &nid, &ptr) ==0 ) { + rc =do_lcfg (mgcname, nid, +LCFG_ADD_UUID , niduuid,NULL ,NULL ,NULL ); +if (!rc) + i++; +/* Stop at the first failover nid */ +if (*ptr ==':' ) +break ; + } +if (i ==0 ) { +CERROR ("No valid MGS nids found.\n" ); + rc = -EINVAL ; + goto out_free; + } + lsi->lsi_lmd->lmd_mgs_failnodes =1 ; + +/* Random uuid for MGC allows easier reconnects */ + uuid =kzalloc (sizeof (*uuid),GFP_NOFS ); +if (!uuid) { + rc = -ENOMEM ; + goto out_free; + } + +ll_generate_random_uuid (uuidc); +class_uuid_unparse (uuidc, uuid); + +/* Start the MGC */ + rc =lustre_start_simple (mgcname,LUSTRE_MGC_NAME , + (char *)uuid->uuid,LUSTRE_MGS_OBDNAME , + niduuid,NULL ,NULL ); +kfree (uuid); +if (rc) + goto out_free; + +/* Add any failover MGS nids */ + i =1 ; +while (ptr && ((*ptr ==':' || +class_find_param (ptr,PARAM_MGSNODE , &ptr) ==0 ))) { +/* New failover node */ +sprintf (niduuid,"%s_%x" , mgcname, i); + j =0 ; +while (class_parse_nid_quiet (ptr, &nid, &ptr) ==0 ) { + rc =do_lcfg (mgcname, nid,LCFG_ADD_UUID , niduuid, +NULL ,NULL ,NULL ); +if (!rc) + ++j; +if (*ptr ==':' ) +break ; + } +if (j >0 ) { + rc =do_lcfg (mgcname,0 ,LCFG_ADD_CONN , + niduuid,NULL ,NULL ,NULL ); +if (!rc) + i++; + }else { +/* at ":/fsname" */ +break ; + } + } + lsi->lsi_lmd->lmd_mgs_failnodes = i; + + obd =class_name2obd (mgcname); +if (!obd) { +CERROR ("Can't find mgcobd %s\n" , mgcname); + rc = -ENOTCONN ; + goto out_free; + } + + rc =obd_set_info_async (NULL , obd->obd_self_export, +strlen (KEY_MGSSEC ),KEY_MGSSEC , +strlen (mgssec), mgssec,NULL ); +if (rc) + goto out_free; + +/* Keep a refcount of servers/clients who started with "mount", +* so we know when we can get rid of the mgc. +*/ +atomic_set (&obd->u.cli.cl_mgc_refcount,1 ); + +/* We connect to the MGS at setup, and don't disconnect until cleanup */ + data->ocd_connect_flags =OBD_CONNECT_VERSION |OBD_CONNECT_AT | +OBD_CONNECT_FULL20 |OBD_CONNECT_IMP_RECOV | +OBD_CONNECT_LVB_TYPE |OBD_CONNECT_BULK_MBITS ; + +#if OBD_OCD_VERSION (3 ,0 ,53 ,0 ) >LUSTRE_VERSION_CODE + data->ocd_connect_flags |=OBD_CONNECT_MNE_SWAB ; +#endif + +if (lmd_is_client (lsi->lsi_lmd) && + lsi->lsi_lmd->lmd_flags &LMD_FLG_NOIR ) + data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV ; + data->ocd_version =LUSTRE_VERSION_CODE ; + rc =obd_connect (NULL , &exp, obd, &obd->obd_uuid, data,NULL ); +if (rc) { +CERROR ("connect failed %d\n" , rc); + goto out; + } + + obd->u.cli.cl_mgc_mgsexp = exp; + +out: +/* Keep the mgc info in the sb. Note that many lsi's can point +* to the same mgc. +*/ + lsi->lsi_mgc = obd; +out_free: +mutex_unlock (&mgc_start_lock); + +kfree (data); +kfree (mgcname); +kfree (niduuid); +return rc; +} + +static int lustre_stop_mgc (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *obd; +char *niduuid =NULL , *ptr =NULL ; +int i, rc =0 , len =0 ; + +if (!lsi) +return -ENOENT ; + obd = lsi->lsi_mgc; +if (!obd) +return -ENOENT ; + lsi->lsi_mgc =NULL ; + +mutex_lock (&mgc_start_lock); +LASSERT (atomic_read (&obd->u.cli.cl_mgc_refcount) >0 ); +if (!atomic_dec_and_test (&obd->u.cli.cl_mgc_refcount)) { +/* This is not fatal, every client that stops +* will call in here. +*/ +CDEBUG (D_MOUNT ,"mgc still has %d references.\n" , +atomic_read (&obd->u.cli.cl_mgc_refcount)); + rc = -EBUSY ; + goto out; + } + +/* The MGC has no recoverable data in any case. +* force shutdown set in umount_begin +*/ + obd->obd_no_recov =1 ; + +if (obd->u.cli.cl_mgc_mgsexp) { +/* An error is not fatal, if we are unable to send the +* disconnect mgs ping evictor cleans up the export +*/ + rc =obd_disconnect (obd->u.cli.cl_mgc_mgsexp); +if (rc) +CDEBUG (D_MOUNT ,"disconnect failed %d\n" , rc); + } + +/* Save the obdname for cleaning the nid uuids, which are obdname_XX */ + len =strlen (obd->obd_name) +6 ; + niduuid =kzalloc (len,GFP_NOFS ); +if (niduuid) { +strcpy (niduuid, obd->obd_name); + ptr = niduuid +strlen (niduuid); + } + + rc =class_manual_cleanup (obd); +if (rc) + goto out; + +/* Clean the nid uuids */ +if (!niduuid) { + rc = -ENOMEM ; + goto out; + } + +for (i =0 ; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) { +sprintf (ptr,"_%x" , i); + rc =do_lcfg (LUSTRE_MGC_OBDNAME ,0 ,LCFG_DEL_UUID , + niduuid,NULL ,NULL ,NULL ); +if (rc) +CERROR ("del MDC UUID %s failed: rc = %d\n" , + niduuid, rc); + } +out: +kfree (niduuid); + +/* class_import_put will get rid of the additional connections */ +mutex_unlock (&mgc_start_lock); +return rc; +} + +/***************** lustre superblock **************/ + +static struct lustre_sb_info *lustre_init_lsi (struct super_block *sb) +{ +struct lustre_sb_info *lsi; + + lsi =kzalloc (sizeof (*lsi),GFP_NOFS ); +if (!lsi) +return NULL ; + lsi->lsi_lmd =kzalloc (sizeof (*lsi->lsi_lmd),GFP_NOFS ); +if (!lsi->lsi_lmd) { +kfree (lsi); +return NULL ; + } + + lsi->lsi_lmd->lmd_exclude_count =0 ; + lsi->lsi_lmd->lmd_recovery_time_soft =0 ; + lsi->lsi_lmd->lmd_recovery_time_hard =0 ; +s2lsi_nocast (sb) = lsi; +/* we take 1 extra ref for our setup */ +atomic_set (&lsi->lsi_mounts,1 ); + +/* Default umount style */ + lsi->lsi_flags =LSI_UMOUNT_FAILOVER ; + +return lsi; +} + +static int lustre_free_lsi (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); + +CDEBUG (D_MOUNT ,"Freeing lsi %p\n" , lsi); + +/* someone didn't call server_put_mount. */ +LASSERT (atomic_read (&lsi->lsi_mounts) ==0 ); + +if (lsi->lsi_lmd) { +kfree (lsi->lsi_lmd->lmd_dev); +kfree (lsi->lsi_lmd->lmd_profile); +kfree (lsi->lsi_lmd->lmd_fileset); +kfree (lsi->lsi_lmd->lmd_mgssec); +kfree (lsi->lsi_lmd->lmd_opts); +if (lsi->lsi_lmd->lmd_exclude_count) +kfree (lsi->lsi_lmd->lmd_exclude); +kfree (lsi->lsi_lmd->lmd_mgs); +kfree (lsi->lsi_lmd->lmd_osd_type); +kfree (lsi->lsi_lmd->lmd_params); + +kfree (lsi->lsi_lmd); + } + +LASSERT (!lsi->lsi_llsbi); +kfree (lsi); +s2lsi_nocast (sb) =NULL ; + +return 0 ; +} + +/* The lsi has one reference for every server that is using the disk - +* e.g. MDT, MGS, and potentially MGC +*/ +static int lustre_put_lsi (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); + +CDEBUG (D_MOUNT ,"put %p %d\n" , sb,atomic_read (&lsi->lsi_mounts)); +if (atomic_dec_and_test (&lsi->lsi_mounts)) { +lustre_free_lsi (sb); +return 1 ; + } +return 0 ; +} + +/*************** mount common between server and client ***************/ + +/* Common umount */ +int lustre_common_put_super (struct super_block *sb) +{ +int rc; + +CDEBUG (D_MOUNT ,"dropping sb %p\n" , sb); + +/* Drop a ref to the MGC */ + rc =lustre_stop_mgc (sb); +if (rc && (rc != -ENOENT )) { +if (rc != -EBUSY ) { +CERROR ("Can't stop MGC: %d\n" , rc); +return rc; + } +/* BUSY just means that there's some other obd that +* needs the mgc. Let him clean it up. +*/ +CDEBUG (D_MOUNT ,"MGC still in use\n" ); + } +/* Drop a ref to the mounted disk */ +lustre_put_lsi (sb); +return rc; +} + +static void lmd_print (struct lustre_mount_data *lmd) +{ +int i; + +PRINT_CMD (D_MOUNT ," mount data:\n" ); +if (lmd_is_client (lmd)) +PRINT_CMD (D_MOUNT ,"profile: %s\n" , lmd->lmd_profile); +PRINT_CMD (D_MOUNT ,"device: %s\n" , lmd->lmd_dev); +PRINT_CMD (D_MOUNT ,"flags: %x\n" , lmd->lmd_flags); + +if (lmd->lmd_opts) +PRINT_CMD (D_MOUNT ,"options: %s\n" , lmd->lmd_opts); + +if (lmd->lmd_recovery_time_soft) +PRINT_CMD (D_MOUNT ,"recovery time soft: %d\n" , + lmd->lmd_recovery_time_soft); + +if (lmd->lmd_recovery_time_hard) +PRINT_CMD (D_MOUNT ,"recovery time hard: %d\n" , + lmd->lmd_recovery_time_hard); + +for (i =0 ; i < lmd->lmd_exclude_count; i++) { +PRINT_CMD (D_MOUNT ,"exclude %d: OST%04x\n" , i, + lmd->lmd_exclude[i]); + } +} + +/* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */ +static int lmd_make_exclusion (struct lustre_mount_data *lmd,const char *ptr) +{ +const char *s1 = ptr, *s2; +__u32 index =0 , *exclude_list; +int rc =0 , devmax; + +/* The shortest an ost name can be is 8 chars: -OST0000. +* We don't actually know the fsname at this time, so in fact +* a user could specify any fsname. +*/ + devmax =strlen (ptr) /8 +1 ; + +/* temp storage until we figure out how many we have */ + exclude_list =kcalloc (devmax,sizeof (index),GFP_NOFS ); +if (!exclude_list) +return -ENOMEM ; + +/* we enter this fn pointing at the '=' */ +while (*s1 && *s1 !=' ' && *s1 !=',' ) { + s1++; + rc =server_name2index (s1, &index, &s2); +if (rc <0 ) { +CERROR ("Can't parse server name '%s': rc = %d\n" , + s1, rc); +break ; + } +if (rc ==LDD_F_SV_TYPE_OST ) + exclude_list[lmd->lmd_exclude_count++] = index; +else +CDEBUG (D_MOUNT ,"ignoring exclude %.*s: type = %#x\n" , + (uint)(s2 - s1), s1, rc); + s1 = s2; +/* now we are pointing at ':' (next exclude) +* or ',' (end of excludes) +*/ +if (lmd->lmd_exclude_count >= devmax) +break ; + } +if (rc >=0 )/* non-err */ + rc =0 ; + +if (lmd->lmd_exclude_count) { +/* permanent, freed in lustre_free_lsi */ + lmd->lmd_exclude =kcalloc (lmd->lmd_exclude_count, +sizeof (index),GFP_NOFS ); +if (lmd->lmd_exclude) { +memcpy (lmd->lmd_exclude, exclude_list, +sizeof (index) * lmd->lmd_exclude_count); + }else { + rc = -ENOMEM ; + lmd->lmd_exclude_count =0 ; + } + } +kfree (exclude_list); +return rc; +} + +static int lmd_parse_mgssec (struct lustre_mount_data *lmd,char *ptr) +{ +char *tail; +int length; + +kfree (lmd->lmd_mgssec); + lmd->lmd_mgssec =NULL ; + + tail =strchr (ptr,',' ); +if (!tail) + length =strlen (ptr); +else + length = tail - ptr; + + lmd->lmd_mgssec =kzalloc (length +1 ,GFP_NOFS ); +if (!lmd->lmd_mgssec) +return -ENOMEM ; + +memcpy (lmd->lmd_mgssec, ptr, length); + lmd->lmd_mgssec[length] ='\0' ; +return 0 ; +} + +static int lmd_parse_string (char **handle,char *ptr) +{ +char *tail; +int length; + +if (!handle || !ptr) +return -EINVAL ; + +kfree (*handle); + *handle =NULL ; + + tail =strchr (ptr,',' ); +if (!tail) + length =strlen (ptr); +else + length = tail - ptr; + + *handle =kzalloc (length +1 ,GFP_NOFS ); +if (!*handle) +return -ENOMEM ; + +memcpy (*handle, ptr, length); + (*handle)[length] ='\0' ; + +return 0 ; +} + +/* Collect multiple values for mgsnid specifiers */ +static int lmd_parse_mgs (struct lustre_mount_data *lmd,char **ptr) +{ +lnet_nid_t nid; +char *tail = *ptr; +char *mgsnid; +int length; +int oldlen =0 ; + +/* Find end of nidlist */ +while (class_parse_nid_quiet (tail, &nid, &tail) ==0 ) + ; + length = tail - *ptr; +if (length ==0 ) { +LCONSOLE_ERROR_MSG (0x159 ,"Can't parse NID '%s'\n" , *ptr); +return -EINVAL ; + } + +if (lmd->lmd_mgs) + oldlen =strlen (lmd->lmd_mgs) +1 ; + + mgsnid =kzalloc (oldlen + length +1 ,GFP_NOFS ); +if (!mgsnid) +return -ENOMEM ; + +if (lmd->lmd_mgs) { +/* Multiple mgsnid= are taken to mean failover locations */ +memcpy (mgsnid, lmd->lmd_mgs, oldlen); + mgsnid[oldlen -1 ] =':' ; +kfree (lmd->lmd_mgs); + } +memcpy (mgsnid + oldlen, *ptr, length); + mgsnid[oldlen + length] ='\0' ; + lmd->lmd_mgs = mgsnid; + *ptr = tail; + +return 0 ; +} + +/** +* Find the first delimiter (comma or colon) from the specified \a buf and +* make \a *endh point to the string starting with the delimiter. The commas +* in expression list [...] will be skipped. +* +* @buf a delimiter-separated string +* @endh a pointer to a pointer that will point to the string +* starting with the delimiter +* +* RETURNS true if delimiter is found, false if delimiter is not found +*/ +static bool lmd_find_delimiter (char *buf,char **endh) +{ +char *c = buf; +size_t pos; +bool found; + +if (!buf) +return false; +try_again: +if (*c ==',' || *c ==':' ) +return true; + + pos =strcspn (c,"[:,]" ); +if (!pos) +return false; + +/* Not a valid mount string */ +if (*c ==']' ) { +CWARN ("invalid mount string format\n" ); +return false; + } + + c += pos; +if (*c =='[' ) { + c =strchr (c,']' ); + +/* invalid mount string */ +if (!c) { +CWARN ("invalid mount string format\n" ); +return false; + } + c++; + goto try_again; + } + + found = *c !='\0' ; +if (found && endh) + *endh = c; + +return found; +} + +/** +* Find the first valid string delimited by comma or colon from the specified +* \a buf and parse it to see whether it's a valid nid list. If yes, \a *endh +* will point to the next string starting with the delimiter. +* +* \param[in] buf a delimiter-separated string +* \param[in] endh a pointer to a pointer that will point to the string +* starting with the delimiter +* +* \retval 0 if the string is a valid nid list +* \retval 1 if the string is not a valid nid list +*/ +static int lmd_parse_nidlist (char *buf,char **endh) +{ +struct list_head nidlist; +char *endp = buf; +int rc =0 ; +char tmp; + +if (!buf) +return 1 ; +while (*buf ==',' || *buf ==':' ) + buf++; +if (*buf ==' ' || *buf =='/' || *buf =='\0' ) +return 1 ; + +if (!lmd_find_delimiter (buf, &endp)) + endp = buf +strlen (buf); + + tmp = *endp; + *endp ='\0' ; + +INIT_LIST_HEAD (&nidlist); +if (cfs_parse_nidlist (buf,strlen (buf), &nidlist) <=0 ) + rc =1 ; +cfs_free_nidlist (&nidlist); + + *endp = tmp; +if (rc) +return rc; +if (endh) + *endh = endp; +return 0 ; +} + +/** Parse mount line options +* e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre +* dev is passed as device=uml1:/lustre by mount.lustre +*/ +static int lmd_parse (char *options,struct lustre_mount_data *lmd) +{ +char *s1, *s2, *devname =NULL ; +struct lustre_mount_data *raw = (struct lustre_mount_data *)options; +int rc =0 ; + +LASSERT (lmd); +if (!options) { +LCONSOLE_ERROR_MSG (0x162 ,"Missing mount data: check that /sbin/mount.lustre is installed.\n" ); +return -EINVAL ; + } + +/* Options should be a string - try to detect old lmd data */ +if ((raw->lmd_magic &0xffffff00 ) == (LMD_MAGIC &0xffffff00 )) { +LCONSOLE_ERROR_MSG (0x163 ,"You're using an old version of /sbin/mount.lustre. Please install version %s\n" , +LUSTRE_VERSION_STRING ); +return -EINVAL ; + } + lmd->lmd_magic =LMD_MAGIC ; + + lmd->lmd_params =kzalloc (LMD_PARAMS_MAXLEN ,GFP_NOFS ); +if (!lmd->lmd_params) +return -ENOMEM ; + lmd->lmd_params[0 ] ='\0' ; + +/* Set default flags here */ + + s1 = options; +while (*s1) { +int clear =0 ; +int time_min =OBD_RECOVERY_TIME_MIN ; +char *s3; + +/* Skip whitespace and extra commas */ +while (*s1 ==' ' || *s1 ==',' ) + s1++; + s3 = s1; + +/* Client options are parsed in ll_options: eg. flock, +* user_xattr, acl +*/ + +/* Parse non-ldiskfs options here. Rather than modifying +* ldiskfs, we just zero these out here +*/ +if (strncmp (s1,"abort_recov" ,11 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_ABORT_RECOV ; + clear++; + }else if (strncmp (s1,"recovery_time_soft=" ,19 ) ==0 ) { + lmd->lmd_recovery_time_soft =max_t (int, +simple_strtoul (s1 +19 ,NULL ,10 ), time_min); + clear++; + }else if (strncmp (s1,"recovery_time_hard=" ,19 ) ==0 ) { + lmd->lmd_recovery_time_hard =max_t (int, +simple_strtoul (s1 +19 ,NULL ,10 ), time_min); + clear++; + }else if (strncmp (s1,"noir" ,4 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOIR ;/* test purpose only. */ + clear++; + }else if (strncmp (s1,"nosvc" ,5 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOSVC ; + clear++; + }else if (strncmp (s1,"nomgs" ,5 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOMGS ; + clear++; + }else if (strncmp (s1,"noscrub" ,7 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOSCRUB ; + clear++; + }else if (strncmp (s1,PARAM_MGSNODE , +sizeof (PARAM_MGSNODE ) -1 ) ==0 ) { + s2 = s1 +sizeof (PARAM_MGSNODE ) -1 ; +/* Assume the next mount opt is the first +* invalid nid we get to. +*/ + rc =lmd_parse_mgs (lmd, &s2); +if (rc) + goto invalid; + clear++; + }else if (strncmp (s1,"writeconf" ,9 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_WRITECONF ; + clear++; + }else if (strncmp (s1,"update" ,6 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_UPDATE ; + clear++; + }else if (strncmp (s1,"virgin" ,6 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_VIRGIN ; + clear++; + }else if (strncmp (s1,"noprimnode" ,10 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NO_PRIMNODE ; + clear++; + }else if (strncmp (s1,"mgssec=" ,7 ) ==0 ) { + rc =lmd_parse_mgssec (lmd, s1 +7 ); +if (rc) + goto invalid; + s3 = s2; + clear++; +/* ost exclusion list */ + }else if (strncmp (s1,"exclude=" ,8 ) ==0 ) { + rc =lmd_make_exclusion (lmd, s1 +7 ); +if (rc) + goto invalid; + clear++; + }else if (strncmp (s1,"mgs" ,3 ) ==0 ) { +/* We are an MGS */ + lmd->lmd_flags |=LMD_FLG_MGS ; + clear++; + }else if (strncmp (s1,"svname=" ,7 ) ==0 ) { + rc =lmd_parse_string (&lmd->lmd_profile, s1 +7 ); +if (rc) + goto invalid; + clear++; + }else if (strncmp (s1,"param=" ,6 ) ==0 ) { +size_t length, params_length; +char *tail = s1; + +if (lmd_find_delimiter (s1 +6 , &tail)) { +char *param_str = tail +1 ; +int supplementary =1 ; + +while (!lmd_parse_nidlist (param_str, + ¶m_str)) + supplementary =0 ; + length = param_str - s1 - supplementary; + }else { + length =strlen (s1); + } + length -=6 ; + params_length =strlen (lmd->lmd_params); +if (params_length + length +1 >=LMD_PARAMS_MAXLEN ) +return -E2BIG ; +strncat (lmd->lmd_params, s1 +6 , length); + lmd->lmd_params[params_length + length] ='\0' ; +strlcat (lmd->lmd_params," " ,LMD_PARAMS_MAXLEN ); + s3 = s1 +6 + length; + clear++; + }else if (strncmp (s1,"osd=" ,4 ) ==0 ) { + rc =lmd_parse_string (&lmd->lmd_osd_type, s1 +4 ); +if (rc) + goto invalid; + clear++; + } +/* Linux 2.4 doesn't pass the device, so we stuck it at the +* end of the options. +*/ +else if (strncmp (s1,"device=" ,7 ) ==0 ) { + devname = s1 +7 ; +/* terminate options right before device. device +* must be the last one. +*/ + *s1 ='\0' ; +break ; + } + +/* Find next opt */ + s2 =strchr (s1,',' ); +if (!s2) { +if (clear) + *s1 ='\0' ; +break ; + } + s2++; +if (clear) +memmove (s1, s2,strlen (s2) +1 ); +else + s1 = s2; + } + +if (!devname) { +LCONSOLE_ERROR_MSG (0x164 ,"Can't find the device name (need mount option 'device=...')\n" ); + goto invalid; + } + + s1 =strstr (devname,":/" ); +if (s1) { + ++s1; + lmd->lmd_flags |=LMD_FLG_CLIENT ; +/* Remove leading /s from fsname */ +while (*++s1 =='/' ) + ; + s2 =strchrnul (s1,'/' ); +/* Freed in lustre_free_lsi */ + lmd->lmd_profile =kasprintf (GFP_KERNEL ,"%.*s-client" , + (int )(s2 - s1), s1); +if (!lmd->lmd_profile) +return -ENOMEM ; + + s1 = s2; + s2 = s1 +strlen (s1) -1 ; +/* Remove padding /s from fileset */ +while (*s2 =='/' ) + s2--; +if (s2 > s1) { + lmd->lmd_fileset =kstrndup (s1, s2 - s1 +1 , +GFP_KERNEL ); +if (!lmd->lmd_fileset) +return -ENOMEM ; + } + } + +/* Freed in lustre_free_lsi */ + lmd->lmd_dev =kstrdup (devname,GFP_KERNEL ); +if (!lmd->lmd_dev) +return -ENOMEM ; + +/* Save mount options */ + s1 = options +strlen (options) -1 ; +while (s1 >= options && (*s1 ==',' || *s1 ==' ' )) + *s1-- =0 ; +if (*options !=0 ) { +/* Freed in lustre_free_lsi */ + lmd->lmd_opts =kstrdup (options,GFP_KERNEL ); +if (!lmd->lmd_opts) +return -ENOMEM ; + } + +lmd_print (lmd); + lmd->lmd_magic =LMD_MAGIC ; + +return rc; + +invalid: +CERROR ("Bad mount options %s\n" , options); +return -EINVAL ; +} + +/** This is the entry point for the mount call into Lustre. +* This is called when a server or client is mounted, +* and this is where we start setting things up. +* @param data Mount options (e.g. -o flock,abort_recov) +*/ +static int lustre_fill_super (struct super_block *sb,void *lmd2_data,int silent) +{ +struct lustre_mount_data *lmd; +struct lustre_sb_info *lsi; +int rc; + +CDEBUG (D_MOUNT |D_VFSTRACE ,"VFS Op: sb %p\n" , sb); + + lsi =lustre_init_lsi (sb); +if (!lsi) +return -ENOMEM ; + lmd = lsi->lsi_lmd; + +/* +* Disable lockdep during mount, because mount locking patterns are +* `special'. +*/ +lockdep_off (); + +/* +* LU-639: the obd cleanup of last mount may not finish yet, wait here. +*/ +obd_zombie_barrier (); + +/* Figure out the lmd from the mount options */ +if (lmd_parse (lmd2_data, lmd)) { +lustre_put_lsi (sb); + rc = -EINVAL ; + goto out; + } + +if (lmd_is_client (lmd)) { +CDEBUG (D_MOUNT ,"Mounting client %s\n" , lmd->lmd_profile); + + rc =lustre_start_mgc (sb); +if (rc) { +lustre_common_put_super (sb); + goto out; + } +/* Connect and start */ + rc =ll_fill_super (sb); +/* l_f_s will call lustre_common_put_super on failure, otherwise +* l_f_s will have taken another reference to the module */ + }else { +CERROR ("This is client-side-only module, cannot handle server mount.\n" ); + rc = -EINVAL ; + } + +/* If error happens in fill_super() call, @lsi will be killed there. +* This is why we do not put it here. +*/ + goto out; +out: +if (rc) { +CERROR ("Unable to mount %s (%d)\n" , +s2lsi (sb) ? lmd->lmd_dev :"" , rc); + }else { +CDEBUG (D_SUPER ,"Mount %s complete\n" , + lmd->lmd_dev); + } +lockdep_on (); +return rc; +} + +/***************** FS registration ******************/ +static struct dentry *lustre_mount (struct file_system_type *fs_type,int flags, +const char *devname,void *data) +{ +return mount_nodev (fs_type, flags, data, lustre_fill_super); +} + +static void lustre_kill_super (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); + +if (lsi) +ll_kill_super (sb); + +kill_anon_super (sb); +} + +/** Register the "lustre" fs type +*/ +static struct file_system_type lustre_fs_type = { + .owner =THIS_MODULE , + .name ="lustre" , + .mount = lustre_mount, + .kill_sb = lustre_kill_super, + .fs_flags =FS_RENAME_DOES_D_MOVE , +}; +MODULE_ALIAS_FS ("lustre" ); + +int lustre_register_fs (void ) +{ +return register_filesystem (&lustre_fs_type); +} + +int lustre_unregister_fs (void ) +{ +return unregister_filesystem (&lustre_fs_type); +}drivers/staging/lustre/lustre/llite/super25.c +5
-3@@ -145,10 +145,11 @@ static int __init lustre_init(void)if (rc !=0 ) goto out_inode_fini_env; -lustre_register_super_ops (THIS_MODULE , ll_fill_super, ll_kill_super);lustre_register_client_process_config (ll_process_config); -return 0 ; + rc =lustre_register_fs (); + +return rc; out_inode_fini_env:cl_env_put (cl_inode_fini_env, &cl_inode_fini_refcheck);@@ -166,7 +167,8 @@ static int __init lustre_init(void) static void __exit lustre_exit(void) { -lustre_register_super_ops (NULL ,NULL ,NULL ); +lustre_unregister_fs (); +lustre_register_client_process_config (NULL );debugfs_remove (llite_root);drivers/staging/lustre/lustre/obdclass/Makefile +1
-1@@ -8,5 +8,5 @@ obdclass-y := module.o sysctl.o \ llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o debug.o \ genops.o uuid.o lprocfs_status.o lprocfs_counters.o \ lustre_handles.o lustre_peer.o statfs_pack.o linkea.o \ - obdo.o obd_config.o obd_mount.o lu_object.o lu_ref.o \ + obdo.o obd_config.o lu_object.o lu_ref.o \ cl_object.o cl_page.o cl_lock.o cl_io.o kernelcomm.odrivers/staging/lustre/lustre/obdclass/class_obd.c +0
-6@@ -510,18 +510,12 @@ static int __init obdclass_init(void)return err; err =llog_info_init (); -if (err) -return err; - - err =lustre_register_fs ();return err; }static void obdclass_exit (void ) { -lustre_unregister_fs (); -misc_deregister (&obd_psdev);llog_info_fini ();cl_global_fini ();drivers/staging/lustre/lustre/obdclass/obd_mount.c deleted +0
-1244@@ -1,1244 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* GPL HEADER START -* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 only, -* as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License version 2 for more details (a copy is included -* in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU General Public License -* version 2 along with this program; If not, see -* http://www.gnu.org/licenses/gpl-2.0.html -* -* GPL HEADER END -*/ -/* -* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. -* Use is subject to license terms. -* -* Copyright (c) 2011, 2015, Intel Corporation. -*/ -/* -* This file is part of Lustre, http://www.lustre.org/ -* Lustre is a trademark of Sun Microsystems, Inc. -* -* lustre/obdclass/obd_mount.c -* -* Client mount routines -* -* Author: Nathan Rutman <[email protected]> -*/ - -#define DEBUG_SUBSYSTEM S_CLASS -#define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */) -#define PRINT_CMD CDEBUG - -#include <linux/random.h> -#include <obd.h> -#include <obd_class.h> -#include <uapi/linux/lustre/lustre_idl.h> -#include <lustre_log.h> -#include <lustre_disk.h> -#include <uapi/linux/lustre/lustre_param.h> - -static DEFINE_SPINLOCK (client_lock); -static struct module *client_mod; -static int (*client_fill_super)(struct super_block *sb); -static void (*kill_super_cb)(struct super_block *sb); - -/**************** config llog ********************/ - -/** Get a config log from the MGS and process it. -* This func is called for both clients and servers. -* Continue to process new statements appended to the logs -* (whenever the config lock is revoked) until lustre_end_log -* is called. -* @param sb The superblock is used by the MGC to write to the local copy of -* the config log -* @param logname The name of the llog to replicate from the MGS -* @param cfg Since the same mgc may be used to follow multiple config logs -* (e.g. ost1, ost2, client), the config_llog_instance keeps the state for -* this log, and is added to the mgc's list of logs to follow. -*/ -int lustre_process_log (struct super_block *sb,char *logname, -struct config_llog_instance *cfg) -{ -struct lustre_cfg *lcfg; -struct lustre_cfg_bufs *bufs; -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *mgc = lsi->lsi_mgc; -int rc; - -LASSERT (mgc); -LASSERT (cfg); - - bufs =kzalloc (sizeof (*bufs),GFP_NOFS ); -if (!bufs) -return -ENOMEM ; - -/* mgc_process_config */ -lustre_cfg_bufs_reset (bufs, mgc->obd_name); -lustre_cfg_bufs_set_string (bufs,1 , logname); -lustre_cfg_bufs_set (bufs,2 , cfg,sizeof (*cfg)); -lustre_cfg_bufs_set (bufs,3 , &sb,sizeof (sb)); - lcfg =kzalloc (lustre_cfg_len (bufs->lcfg_bufcount, bufs->lcfg_buflen), -GFP_NOFS ); -if (!lcfg) { - rc = -ENOMEM ; - goto out; - } -lustre_cfg_init (lcfg,LCFG_LOG_START , bufs); - - rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); -kfree (lcfg); -out: -kfree (bufs); - -if (rc == -EINVAL ) -LCONSOLE_ERROR_MSG (0x15b ,"%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n" , - mgc->obd_name, logname, rc); - -else if (rc) -LCONSOLE_ERROR_MSG (0x15c ,"%s: The configuration from log '%s' failed (%d). This may be the result of communication errors between this node and the MGS, a bad configuration, or other errors. See the syslog for more information.\n" , - mgc->obd_name, logname, - rc); - -/* class_obd_list(); */ -return rc; -} -EXPORT_SYMBOL (lustre_process_log); - -/* Stop watching this config log for updates */ -int lustre_end_log (struct super_block *sb,char *logname, -struct config_llog_instance *cfg) -{ -struct lustre_cfg *lcfg; -struct lustre_cfg_bufs bufs; -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *mgc = lsi->lsi_mgc; -int rc; - -if (!mgc) -return -ENOENT ; - -/* mgc_process_config */ -lustre_cfg_bufs_reset (&bufs, mgc->obd_name); -lustre_cfg_bufs_set_string (&bufs,1 , logname); -if (cfg) -lustre_cfg_bufs_set (&bufs,2 , cfg,sizeof (*cfg)); - lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), -GFP_NOFS ); -if (!lcfg) -return -ENOMEM ; -lustre_cfg_init (lcfg,LCFG_LOG_END , &bufs); - - rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); -kfree (lcfg); -return rc; -} -EXPORT_SYMBOL (lustre_end_log); - -/**************** obd start *******************/ - -/** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from -* lctl (and do for echo cli/srv. -*/ -static int do_lcfg (char *cfgname,lnet_nid_t nid,int cmd, -char *s1,char *s2,char *s3,char *s4) -{ -struct lustre_cfg_bufs bufs; -struct lustre_cfg *lcfg =NULL ; -int rc; - -CDEBUG (D_TRACE ,"lcfg %s %#x %s %s %s %s\n" , cfgname, - cmd, s1, s2, s3, s4); - -lustre_cfg_bufs_reset (&bufs, cfgname); -if (s1) -lustre_cfg_bufs_set_string (&bufs,1 , s1); -if (s2) -lustre_cfg_bufs_set_string (&bufs,2 , s2); -if (s3) -lustre_cfg_bufs_set_string (&bufs,3 , s3); -if (s4) -lustre_cfg_bufs_set_string (&bufs,4 , s4); - - lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), -GFP_NOFS ); -if (!lcfg) -return -ENOMEM ; -lustre_cfg_init (lcfg, cmd, &bufs); - lcfg->lcfg_nid = nid; - rc =class_process_config (lcfg); -kfree (lcfg); -return rc; -} - -/** Call class_attach and class_setup. These methods in turn call -* obd type-specific methods. -*/ -static int lustre_start_simple (char *obdname,char *type,char *uuid, -char *s1,char *s2,char *s3,char *s4) -{ -int rc; - -CDEBUG (D_MOUNT ,"Starting obd %s (typ=%s)\n" , obdname, type); - - rc =do_lcfg (obdname,0 ,LCFG_ATTACH , type, uuid,NULL ,NULL ); -if (rc) { -CERROR ("%s attach error %d\n" , obdname, rc); -return rc; - } - rc =do_lcfg (obdname,0 ,LCFG_SETUP , s1, s2, s3, s4); -if (rc) { -CERROR ("%s setup error %d\n" , obdname, rc); -do_lcfg (obdname,0 ,LCFG_DETACH ,NULL ,NULL ,NULL ,NULL ); - } -return rc; -} - -static DEFINE_MUTEX (mgc_start_lock); - -/** Set up a mgc obd to process startup logs -* -* \param sb [in] super block of the mgc obd -* -* \retval 0 success, otherwise error code -*/ -int lustre_start_mgc (struct super_block *sb) -{ -struct obd_connect_data *data =NULL ; -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *obd; -struct obd_export *exp; -struct obd_uuid *uuid; -class_uuid_t uuidc; -lnet_nid_t nid; -char nidstr[LNET_NIDSTR_SIZE ]; -char *mgcname =NULL , *niduuid =NULL , *mgssec =NULL ; -char *ptr; -int rc =0 , i =0 , j; - -LASSERT (lsi->lsi_lmd); - -/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ - ptr = lsi->lsi_lmd->lmd_dev; -if (class_parse_nid (ptr, &nid, &ptr) ==0 ) - i++; -if (i ==0 ) { -CERROR ("No valid MGS nids found.\n" ); -return -EINVAL ; - } - -mutex_lock (&mgc_start_lock); - -libcfs_nid2str_r (nid, nidstr,sizeof (nidstr)); - mgcname =kasprintf (GFP_NOFS , -"%s%s" ,LUSTRE_MGC_OBDNAME , nidstr); - niduuid =kasprintf (GFP_NOFS ,"%s_%x" , mgcname,0 ); -if (!mgcname || !niduuid) { - rc = -ENOMEM ; - goto out_free; - } - - mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec :"" ; - - data =kzalloc (sizeof (*data),GFP_NOFS ); -if (!data) { - rc = -ENOMEM ; - goto out_free; - } - - obd =class_name2obd (mgcname); -if (obd && !obd->obd_stopping) { -int recov_bk; - - rc =obd_set_info_async (NULL , obd->obd_self_export, -strlen (KEY_MGSSEC ),KEY_MGSSEC , -strlen (mgssec), mgssec,NULL ); -if (rc) - goto out_free; - -/* Re-using an existing MGC */ -atomic_inc (&obd->u.cli.cl_mgc_refcount); - -/* IR compatibility check, only for clients */ -if (lmd_is_client (lsi->lsi_lmd)) { -int has_ir; -int vallen =sizeof (*data); -__u32 *flags = &lsi->lsi_lmd->lmd_flags; - - rc =obd_get_info (NULL , obd->obd_self_export, -strlen (KEY_CONN_DATA ),KEY_CONN_DATA , - &vallen, data); -LASSERT (rc ==0 ); - has_ir =OCD_HAS_FLAG (data,IMP_RECOV ); -if (has_ir ^ !(*flags &LMD_FLG_NOIR )) { -/* LMD_FLG_NOIR is for test purpose only */ -LCONSOLE_WARN ( -"Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n" , - has_ir ?"enabled" :"disabled" ); -if (has_ir) - *flags &= ~LMD_FLG_NOIR ; -else - *flags |=LMD_FLG_NOIR ; - } - } - - recov_bk =0 ; - -/* Try all connections, but only once (again). -* We don't want to block another target from starting -* (using its local copy of the log), but we do want to connect -* if at all possible. -*/ - recov_bk++; -CDEBUG (D_MOUNT ,"%s: Set MGC reconnect %d\n" , mgcname, - recov_bk); - rc =obd_set_info_async (NULL , obd->obd_self_export, -sizeof (KEY_INIT_RECOV_BACKUP ), -KEY_INIT_RECOV_BACKUP , -sizeof (recov_bk), &recov_bk,NULL ); - rc =0 ; - goto out; - } - -CDEBUG (D_MOUNT ,"Start MGC '%s'\n" , mgcname); - -/* Add the primary nids for the MGS */ - i =0 ; -/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ - ptr = lsi->lsi_lmd->lmd_dev; -while (class_parse_nid (ptr, &nid, &ptr) ==0 ) { - rc =do_lcfg (mgcname, nid, -LCFG_ADD_UUID , niduuid,NULL ,NULL ,NULL ); -if (!rc) - i++; -/* Stop at the first failover nid */ -if (*ptr ==':' ) -break ; - } -if (i ==0 ) { -CERROR ("No valid MGS nids found.\n" ); - rc = -EINVAL ; - goto out_free; - } - lsi->lsi_lmd->lmd_mgs_failnodes =1 ; - -/* Random uuid for MGC allows easier reconnects */ - uuid =kzalloc (sizeof (*uuid),GFP_NOFS ); -if (!uuid) { - rc = -ENOMEM ; - goto out_free; - } - -ll_generate_random_uuid (uuidc); -class_uuid_unparse (uuidc, uuid); - -/* Start the MGC */ - rc =lustre_start_simple (mgcname,LUSTRE_MGC_NAME , - (char *)uuid->uuid,LUSTRE_MGS_OBDNAME , - niduuid,NULL ,NULL ); -kfree (uuid); -if (rc) - goto out_free; - -/* Add any failover MGS nids */ - i =1 ; -while (ptr && ((*ptr ==':' || -class_find_param (ptr,PARAM_MGSNODE , &ptr) ==0 ))) { -/* New failover node */ -sprintf (niduuid,"%s_%x" , mgcname, i); - j =0 ; -while (class_parse_nid_quiet (ptr, &nid, &ptr) ==0 ) { - rc =do_lcfg (mgcname, nid,LCFG_ADD_UUID , niduuid, -NULL ,NULL ,NULL ); -if (!rc) - ++j; -if (*ptr ==':' ) -break ; - } -if (j >0 ) { - rc =do_lcfg (mgcname,0 ,LCFG_ADD_CONN , - niduuid,NULL ,NULL ,NULL ); -if (!rc) - i++; - }else { -/* at ":/fsname" */ -break ; - } - } - lsi->lsi_lmd->lmd_mgs_failnodes = i; - - obd =class_name2obd (mgcname); -if (!obd) { -CERROR ("Can't find mgcobd %s\n" , mgcname); - rc = -ENOTCONN ; - goto out_free; - } - - rc =obd_set_info_async (NULL , obd->obd_self_export, -strlen (KEY_MGSSEC ),KEY_MGSSEC , -strlen (mgssec), mgssec,NULL ); -if (rc) - goto out_free; - -/* Keep a refcount of servers/clients who started with "mount", -* so we know when we can get rid of the mgc. -*/ -atomic_set (&obd->u.cli.cl_mgc_refcount,1 ); - -/* We connect to the MGS at setup, and don't disconnect until cleanup */ - data->ocd_connect_flags =OBD_CONNECT_VERSION |OBD_CONNECT_AT | -OBD_CONNECT_FULL20 |OBD_CONNECT_IMP_RECOV | -OBD_CONNECT_LVB_TYPE |OBD_CONNECT_BULK_MBITS ; - -#if OBD_OCD_VERSION (3 ,0 ,53 ,0 ) >LUSTRE_VERSION_CODE - data->ocd_connect_flags |=OBD_CONNECT_MNE_SWAB ; -#endif - -if (lmd_is_client (lsi->lsi_lmd) && - lsi->lsi_lmd->lmd_flags &LMD_FLG_NOIR ) - data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV ; - data->ocd_version =LUSTRE_VERSION_CODE ; - rc =obd_connect (NULL , &exp, obd, &obd->obd_uuid, data,NULL ); -if (rc) { -CERROR ("connect failed %d\n" , rc); - goto out; - } - - obd->u.cli.cl_mgc_mgsexp = exp; - -out: -/* Keep the mgc info in the sb. Note that many lsi's can point -* to the same mgc. -*/ - lsi->lsi_mgc = obd; -out_free: -mutex_unlock (&mgc_start_lock); - -kfree (data); -kfree (mgcname); -kfree (niduuid); -return rc; -} - -static int lustre_stop_mgc (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *obd; -char *niduuid =NULL , *ptr =NULL ; -int i, rc =0 , len =0 ; - -if (!lsi) -return -ENOENT ; - obd = lsi->lsi_mgc; -if (!obd) -return -ENOENT ; - lsi->lsi_mgc =NULL ; - -mutex_lock (&mgc_start_lock); -LASSERT (atomic_read (&obd->u.cli.cl_mgc_refcount) >0 ); -if (!atomic_dec_and_test (&obd->u.cli.cl_mgc_refcount)) { -/* This is not fatal, every client that stops -* will call in here. -*/ -CDEBUG (D_MOUNT ,"mgc still has %d references.\n" , -atomic_read (&obd->u.cli.cl_mgc_refcount)); - rc = -EBUSY ; - goto out; - } - -/* The MGC has no recoverable data in any case. -* force shutdown set in umount_begin -*/ - obd->obd_no_recov =1 ; - -if (obd->u.cli.cl_mgc_mgsexp) { -/* An error is not fatal, if we are unable to send the -* disconnect mgs ping evictor cleans up the export -*/ - rc =obd_disconnect (obd->u.cli.cl_mgc_mgsexp); -if (rc) -CDEBUG (D_MOUNT ,"disconnect failed %d\n" , rc); - } - -/* Save the obdname for cleaning the nid uuids, which are obdname_XX */ - len =strlen (obd->obd_name) +6 ; - niduuid =kzalloc (len,GFP_NOFS ); -if (niduuid) { -strcpy (niduuid, obd->obd_name); - ptr = niduuid +strlen (niduuid); - } - - rc =class_manual_cleanup (obd); -if (rc) - goto out; - -/* Clean the nid uuids */ -if (!niduuid) { - rc = -ENOMEM ; - goto out; - } - -for (i =0 ; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) { -sprintf (ptr,"_%x" , i); - rc =do_lcfg (LUSTRE_MGC_OBDNAME ,0 ,LCFG_DEL_UUID , - niduuid,NULL ,NULL ,NULL ); -if (rc) -CERROR ("del MDC UUID %s failed: rc = %d\n" , - niduuid, rc); - } -out: -kfree (niduuid); - -/* class_import_put will get rid of the additional connections */ -mutex_unlock (&mgc_start_lock); -return rc; -} - -/***************** lustre superblock **************/ - -static struct lustre_sb_info *lustre_init_lsi (struct super_block *sb) -{ -struct lustre_sb_info *lsi; - - lsi =kzalloc (sizeof (*lsi),GFP_NOFS ); -if (!lsi) -return NULL ; - lsi->lsi_lmd =kzalloc (sizeof (*lsi->lsi_lmd),GFP_NOFS ); -if (!lsi->lsi_lmd) { -kfree (lsi); -return NULL ; - } - - lsi->lsi_lmd->lmd_exclude_count =0 ; - lsi->lsi_lmd->lmd_recovery_time_soft =0 ; - lsi->lsi_lmd->lmd_recovery_time_hard =0 ; -s2lsi_nocast (sb) = lsi; -/* we take 1 extra ref for our setup */ -atomic_set (&lsi->lsi_mounts,1 ); - -/* Default umount style */ - lsi->lsi_flags =LSI_UMOUNT_FAILOVER ; - -return lsi; -} - -static int lustre_free_lsi (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); - -CDEBUG (D_MOUNT ,"Freeing lsi %p\n" , lsi); - -/* someone didn't call server_put_mount. */ -LASSERT (atomic_read (&lsi->lsi_mounts) ==0 ); - -if (lsi->lsi_lmd) { -kfree (lsi->lsi_lmd->lmd_dev); -kfree (lsi->lsi_lmd->lmd_profile); -kfree (lsi->lsi_lmd->lmd_fileset); -kfree (lsi->lsi_lmd->lmd_mgssec); -kfree (lsi->lsi_lmd->lmd_opts); -if (lsi->lsi_lmd->lmd_exclude_count) -kfree (lsi->lsi_lmd->lmd_exclude); -kfree (lsi->lsi_lmd->lmd_mgs); -kfree (lsi->lsi_lmd->lmd_osd_type); -kfree (lsi->lsi_lmd->lmd_params); - -kfree (lsi->lsi_lmd); - } - -LASSERT (!lsi->lsi_llsbi); -kfree (lsi); -s2lsi_nocast (sb) =NULL ; - -return 0 ; -} - -/* The lsi has one reference for every server that is using the disk - -* e.g. MDT, MGS, and potentially MGC -*/ -static int lustre_put_lsi (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); - -CDEBUG (D_MOUNT ,"put %p %d\n" , sb,atomic_read (&lsi->lsi_mounts)); -if (atomic_dec_and_test (&lsi->lsi_mounts)) { -lustre_free_lsi (sb); -return 1 ; - } -return 0 ; -} - -/*************** mount common between server and client ***************/ - -/* Common umount */ -int lustre_common_put_super (struct super_block *sb) -{ -int rc; - -CDEBUG (D_MOUNT ,"dropping sb %p\n" , sb); - -/* Drop a ref to the MGC */ - rc =lustre_stop_mgc (sb); -if (rc && (rc != -ENOENT )) { -if (rc != -EBUSY ) { -CERROR ("Can't stop MGC: %d\n" , rc); -return rc; - } -/* BUSY just means that there's some other obd that -* needs the mgc. Let him clean it up. -*/ -CDEBUG (D_MOUNT ,"MGC still in use\n" ); - } -/* Drop a ref to the mounted disk */ -lustre_put_lsi (sb); -return rc; -} -EXPORT_SYMBOL (lustre_common_put_super); - -static void lmd_print (struct lustre_mount_data *lmd) -{ -int i; - -PRINT_CMD (D_MOUNT ," mount data:\n" ); -if (lmd_is_client (lmd)) -PRINT_CMD (D_MOUNT ,"profile: %s\n" , lmd->lmd_profile); -PRINT_CMD (D_MOUNT ,"device: %s\n" , lmd->lmd_dev); -PRINT_CMD (D_MOUNT ,"flags: %x\n" , lmd->lmd_flags); - -if (lmd->lmd_opts) -PRINT_CMD (D_MOUNT ,"options: %s\n" , lmd->lmd_opts); - -if (lmd->lmd_recovery_time_soft) -PRINT_CMD (D_MOUNT ,"recovery time soft: %d\n" , - lmd->lmd_recovery_time_soft); - -if (lmd->lmd_recovery_time_hard) -PRINT_CMD (D_MOUNT ,"recovery time hard: %d\n" , - lmd->lmd_recovery_time_hard); - -for (i =0 ; i < lmd->lmd_exclude_count; i++) { -PRINT_CMD (D_MOUNT ,"exclude %d: OST%04x\n" , i, - lmd->lmd_exclude[i]); - } -} - -/* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */ -static int lmd_make_exclusion (struct lustre_mount_data *lmd,const char *ptr) -{ -const char *s1 = ptr, *s2; -__u32 index =0 , *exclude_list; -int rc =0 , devmax; - -/* The shortest an ost name can be is 8 chars: -OST0000. -* We don't actually know the fsname at this time, so in fact -* a user could specify any fsname. -*/ - devmax =strlen (ptr) /8 +1 ; - -/* temp storage until we figure out how many we have */ - exclude_list =kcalloc (devmax,sizeof (index),GFP_NOFS ); -if (!exclude_list) -return -ENOMEM ; - -/* we enter this fn pointing at the '=' */ -while (*s1 && *s1 !=' ' && *s1 !=',' ) { - s1++; - rc =server_name2index (s1, &index, &s2); -if (rc <0 ) { -CERROR ("Can't parse server name '%s': rc = %d\n" , - s1, rc); -break ; - } -if (rc ==LDD_F_SV_TYPE_OST ) - exclude_list[lmd->lmd_exclude_count++] = index; -else -CDEBUG (D_MOUNT ,"ignoring exclude %.*s: type = %#x\n" , - (uint)(s2 - s1), s1, rc); - s1 = s2; -/* now we are pointing at ':' (next exclude) -* or ',' (end of excludes) -*/ -if (lmd->lmd_exclude_count >= devmax) -break ; - } -if (rc >=0 )/* non-err */ - rc =0 ; - -if (lmd->lmd_exclude_count) { -/* permanent, freed in lustre_free_lsi */ - lmd->lmd_exclude =kcalloc (lmd->lmd_exclude_count, -sizeof (index),GFP_NOFS ); -if (lmd->lmd_exclude) { -memcpy (lmd->lmd_exclude, exclude_list, -sizeof (index) * lmd->lmd_exclude_count); - }else { - rc = -ENOMEM ; - lmd->lmd_exclude_count =0 ; - } - } -kfree (exclude_list); -return rc; -} - -static int lmd_parse_mgssec (struct lustre_mount_data *lmd,char *ptr) -{ -char *tail; -int length; - -kfree (lmd->lmd_mgssec); - lmd->lmd_mgssec =NULL ; - - tail =strchr (ptr,',' ); -if (!tail) - length =strlen (ptr); -else - length = tail - ptr; - - lmd->lmd_mgssec =kzalloc (length +1 ,GFP_NOFS ); -if (!lmd->lmd_mgssec) -return -ENOMEM ; - -memcpy (lmd->lmd_mgssec, ptr, length); - lmd->lmd_mgssec[length] ='\0' ; -return 0 ; -} - -static int lmd_parse_string (char **handle,char *ptr) -{ -char *tail; -int length; - -if (!handle || !ptr) -return -EINVAL ; - -kfree (*handle); - *handle =NULL ; - - tail =strchr (ptr,',' ); -if (!tail) - length =strlen (ptr); -else - length = tail - ptr; - - *handle =kzalloc (length +1 ,GFP_NOFS ); -if (!*handle) -return -ENOMEM ; - -memcpy (*handle, ptr, length); - (*handle)[length] ='\0' ; - -return 0 ; -} - -/* Collect multiple values for mgsnid specifiers */ -static int lmd_parse_mgs (struct lustre_mount_data *lmd,char **ptr) -{ -lnet_nid_t nid; -char *tail = *ptr; -char *mgsnid; -int length; -int oldlen =0 ; - -/* Find end of nidlist */ -while (class_parse_nid_quiet (tail, &nid, &tail) ==0 ) - ; - length = tail - *ptr; -if (length ==0 ) { -LCONSOLE_ERROR_MSG (0x159 ,"Can't parse NID '%s'\n" , *ptr); -return -EINVAL ; - } - -if (lmd->lmd_mgs) - oldlen =strlen (lmd->lmd_mgs) +1 ; - - mgsnid =kzalloc (oldlen + length +1 ,GFP_NOFS ); -if (!mgsnid) -return -ENOMEM ; - -if (lmd->lmd_mgs) { -/* Multiple mgsnid= are taken to mean failover locations */ -memcpy (mgsnid, lmd->lmd_mgs, oldlen); - mgsnid[oldlen -1 ] =':' ; -kfree (lmd->lmd_mgs); - } -memcpy (mgsnid + oldlen, *ptr, length); - mgsnid[oldlen + length] ='\0' ; - lmd->lmd_mgs = mgsnid; - *ptr = tail; - -return 0 ; -} - -/** -* Find the first delimiter (comma or colon) from the specified \a buf and -* make \a *endh point to the string starting with the delimiter. The commas -* in expression list [...] will be skipped. -* -* @buf a delimiter-separated string -* @endh a pointer to a pointer that will point to the string -* starting with the delimiter -* -* RETURNS true if delimiter is found, false if delimiter is not found -*/ -static bool lmd_find_delimiter (char *buf,char **endh) -{ -char *c = buf; -size_t pos; -bool found; - -if (!buf) -return false; -try_again: -if (*c ==',' || *c ==':' ) -return true; - - pos =strcspn (c,"[:,]" ); -if (!pos) -return false; - -/* Not a valid mount string */ -if (*c ==']' ) { -CWARN ("invalid mount string format\n" ); -return false; - } - - c += pos; -if (*c =='[' ) { - c =strchr (c,']' ); - -/* invalid mount string */ -if (!c) { -CWARN ("invalid mount string format\n" ); -return false; - } - c++; - goto try_again; - } - - found = *c !='\0' ; -if (found && endh) - *endh = c; - -return found; -} - -/** -* Find the first valid string delimited by comma or colon from the specified -* \a buf and parse it to see whether it's a valid nid list. If yes, \a *endh -* will point to the next string starting with the delimiter. -* -* \param[in] buf a delimiter-separated string -* \param[in] endh a pointer to a pointer that will point to the string -* starting with the delimiter -* -* \retval 0 if the string is a valid nid list -* \retval 1 if the string is not a valid nid list -*/ -static int lmd_parse_nidlist (char *buf,char **endh) -{ -struct list_head nidlist; -char *endp = buf; -int rc =0 ; -char tmp; - -if (!buf) -return 1 ; -while (*buf ==',' || *buf ==':' ) - buf++; -if (*buf ==' ' || *buf =='/' || *buf =='\0' ) -return 1 ; - -if (!lmd_find_delimiter (buf, &endp)) - endp = buf +strlen (buf); - - tmp = *endp; - *endp ='\0' ; - -INIT_LIST_HEAD (&nidlist); -if (cfs_parse_nidlist (buf,strlen (buf), &nidlist) <=0 ) - rc =1 ; -cfs_free_nidlist (&nidlist); - - *endp = tmp; -if (rc) -return rc; -if (endh) - *endh = endp; -return 0 ; -} - -/** Parse mount line options -* e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre -* dev is passed as device=uml1:/lustre by mount.lustre -*/ -static int lmd_parse (char *options,struct lustre_mount_data *lmd) -{ -char *s1, *s2, *devname =NULL ; -struct lustre_mount_data *raw = (struct lustre_mount_data *)options; -int rc =0 ; - -LASSERT (lmd); -if (!options) { -LCONSOLE_ERROR_MSG (0x162 ,"Missing mount data: check that /sbin/mount.lustre is installed.\n" ); -return -EINVAL ; - } - -/* Options should be a string - try to detect old lmd data */ -if ((raw->lmd_magic &0xffffff00 ) == (LMD_MAGIC &0xffffff00 )) { -LCONSOLE_ERROR_MSG (0x163 ,"You're using an old version of /sbin/mount.lustre. Please install version %s\n" , -LUSTRE_VERSION_STRING ); -return -EINVAL ; - } - lmd->lmd_magic =LMD_MAGIC ; - - lmd->lmd_params =kzalloc (LMD_PARAMS_MAXLEN ,GFP_NOFS ); -if (!lmd->lmd_params) -return -ENOMEM ; - lmd->lmd_params[0 ] ='\0' ; - -/* Set default flags here */ - - s1 = options; -while (*s1) { -int clear =0 ; -int time_min =OBD_RECOVERY_TIME_MIN ; -char *s3; - -/* Skip whitespace and extra commas */ -while (*s1 ==' ' || *s1 ==',' ) - s1++; - s3 = s1; - -/* Client options are parsed in ll_options: eg. flock, -* user_xattr, acl -*/ - -/* Parse non-ldiskfs options here. Rather than modifying -* ldiskfs, we just zero these out here -*/ -if (strncmp (s1,"abort_recov" ,11 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_ABORT_RECOV ; - clear++; - }else if (strncmp (s1,"recovery_time_soft=" ,19 ) ==0 ) { - lmd->lmd_recovery_time_soft =max_t (int, -simple_strtoul (s1 +19 ,NULL ,10 ), time_min); - clear++; - }else if (strncmp (s1,"recovery_time_hard=" ,19 ) ==0 ) { - lmd->lmd_recovery_time_hard =max_t (int, -simple_strtoul (s1 +19 ,NULL ,10 ), time_min); - clear++; - }else if (strncmp (s1,"noir" ,4 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOIR ;/* test purpose only. */ - clear++; - }else if (strncmp (s1,"nosvc" ,5 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOSVC ; - clear++; - }else if (strncmp (s1,"nomgs" ,5 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOMGS ; - clear++; - }else if (strncmp (s1,"noscrub" ,7 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOSCRUB ; - clear++; - }else if (strncmp (s1,PARAM_MGSNODE , -sizeof (PARAM_MGSNODE ) -1 ) ==0 ) { - s2 = s1 +sizeof (PARAM_MGSNODE ) -1 ; -/* Assume the next mount opt is the first -* invalid nid we get to. -*/ - rc =lmd_parse_mgs (lmd, &s2); -if (rc) - goto invalid; - clear++; - }else if (strncmp (s1,"writeconf" ,9 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_WRITECONF ; - clear++; - }else if (strncmp (s1,"update" ,6 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_UPDATE ; - clear++; - }else if (strncmp (s1,"virgin" ,6 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_VIRGIN ; - clear++; - }else if (strncmp (s1,"noprimnode" ,10 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NO_PRIMNODE ; - clear++; - }else if (strncmp (s1,"mgssec=" ,7 ) ==0 ) { - rc =lmd_parse_mgssec (lmd, s1 +7 ); -if (rc) - goto invalid; - s3 = s2; - clear++; -/* ost exclusion list */ - }else if (strncmp (s1,"exclude=" ,8 ) ==0 ) { - rc =lmd_make_exclusion (lmd, s1 +7 ); -if (rc) - goto invalid; - clear++; - }else if (strncmp (s1,"mgs" ,3 ) ==0 ) { -/* We are an MGS */ - lmd->lmd_flags |=LMD_FLG_MGS ; - clear++; - }else if (strncmp (s1,"svname=" ,7 ) ==0 ) { - rc =lmd_parse_string (&lmd->lmd_profile, s1 +7 ); -if (rc) - goto invalid; - clear++; - }else if (strncmp (s1,"param=" ,6 ) ==0 ) { -size_t length, params_length; -char *tail = s1; - -if (lmd_find_delimiter (s1 +6 , &tail)) { -char *param_str = tail +1 ; -int supplementary =1 ; - -while (!lmd_parse_nidlist (param_str, - ¶m_str)) - supplementary =0 ; - length = param_str - s1 - supplementary; - }else { - length =strlen (s1); - } - length -=6 ; - params_length =strlen (lmd->lmd_params); -if (params_length + length +1 >=LMD_PARAMS_MAXLEN ) -return -E2BIG ; -strncat (lmd->lmd_params, s1 +6 , length); - lmd->lmd_params[params_length + length] ='\0' ; -strlcat (lmd->lmd_params," " ,LMD_PARAMS_MAXLEN ); - s3 = s1 +6 + length; - clear++; - }else if (strncmp (s1,"osd=" ,4 ) ==0 ) { - rc =lmd_parse_string (&lmd->lmd_osd_type, s1 +4 ); -if (rc) - goto invalid; - clear++; - } -/* Linux 2.4 doesn't pass the device, so we stuck it at the -* end of the options. -*/ -else if (strncmp (s1,"device=" ,7 ) ==0 ) { - devname = s1 +7 ; -/* terminate options right before device. device -* must be the last one. -*/ - *s1 ='\0' ; -break ; - } - -/* Find next opt */ - s2 =strchr (s1,',' ); -if (!s2) { -if (clear) - *s1 ='\0' ; -break ; - } - s2++; -if (clear) -memmove (s1, s2,strlen (s2) +1 ); -else - s1 = s2; - } - -if (!devname) { -LCONSOLE_ERROR_MSG (0x164 ,"Can't find the device name (need mount option 'device=...')\n" ); - goto invalid; - } - - s1 =strstr (devname,":/" ); -if (s1) { - ++s1; - lmd->lmd_flags |=LMD_FLG_CLIENT ; -/* Remove leading /s from fsname */ -while (*++s1 =='/' ) - ; - s2 =strchrnul (s1,'/' ); -/* Freed in lustre_free_lsi */ - lmd->lmd_profile =kasprintf (GFP_KERNEL ,"%.*s-client" , - (int )(s2 - s1), s1); -if (!lmd->lmd_profile) -return -ENOMEM ; - - s1 = s2; - s2 = s1 +strlen (s1) -1 ; -/* Remove padding /s from fileset */ -while (*s2 =='/' ) - s2--; -if (s2 > s1) { - lmd->lmd_fileset =kstrndup (s1, s2 - s1 +1 , -GFP_KERNEL ); -if (!lmd->lmd_fileset) -return -ENOMEM ; - } - } - -/* Freed in lustre_free_lsi */ - lmd->lmd_dev =kstrdup (devname,GFP_KERNEL ); -if (!lmd->lmd_dev) -return -ENOMEM ; - -/* Save mount options */ - s1 = options +strlen (options) -1 ; -while (s1 >= options && (*s1 ==',' || *s1 ==' ' )) - *s1-- =0 ; -if (*options !=0 ) { -/* Freed in lustre_free_lsi */ - lmd->lmd_opts =kstrdup (options,GFP_KERNEL ); -if (!lmd->lmd_opts) -return -ENOMEM ; - } - -lmd_print (lmd); - lmd->lmd_magic =LMD_MAGIC ; - -return rc; - -invalid: -CERROR ("Bad mount options %s\n" , options); -return -EINVAL ; -} - -/** This is the entry point for the mount call into Lustre. -* This is called when a server or client is mounted, -* and this is where we start setting things up. -* @param data Mount options (e.g. -o flock,abort_recov) -*/ -static int lustre_fill_super (struct super_block *sb,void *lmd2_data,int silent) -{ -struct lustre_mount_data *lmd; -struct lustre_sb_info *lsi; -int rc; - -CDEBUG (D_MOUNT |D_VFSTRACE ,"VFS Op: sb %p\n" , sb); - - lsi =lustre_init_lsi (sb); -if (!lsi) -return -ENOMEM ; - lmd = lsi->lsi_lmd; - -/* -* Disable lockdep during mount, because mount locking patterns are -* `special'. -*/ -lockdep_off (); - -/* -* LU-639: the obd cleanup of last mount may not finish yet, wait here. -*/ -obd_zombie_barrier (); - -/* Figure out the lmd from the mount options */ -if (lmd_parse (lmd2_data, lmd)) { -lustre_put_lsi (sb); - rc = -EINVAL ; - goto out; - } - -if (lmd_is_client (lmd)) { -bool have_client = false; -CDEBUG (D_MOUNT ,"Mounting client %s\n" , lmd->lmd_profile); -if (!client_fill_super) -request_module ("lustre" ); -spin_lock (&client_lock); -if (client_fill_super &&try_module_get (client_mod)) - have_client = true; -spin_unlock (&client_lock); -if (!have_client) { -LCONSOLE_ERROR_MSG (0x165 ,"Nothing registered for client mount! Is the 'lustre' module loaded?\n" ); -lustre_put_lsi (sb); - rc = -ENODEV ; - }else { - rc =lustre_start_mgc (sb); -if (rc) { -lustre_common_put_super (sb); - goto out; - } -/* Connect and start */ -/* (should always be ll_fill_super) */ - rc = (*client_fill_super)(sb); -/* c_f_s will call lustre_common_put_super on failure, otherwise -* c_f_s will have taken another reference to the module */ -module_put (client_mod); - } - }else { -CERROR ("This is client-side-only module, cannot handle server mount.\n" ); - rc = -EINVAL ; - } - -/* If error happens in fill_super() call, @lsi will be killed there. -* This is why we do not put it here. -*/ - goto out; -out: -if (rc) { -CERROR ("Unable to mount %s (%d)\n" , -s2lsi (sb) ? lmd->lmd_dev :"" , rc); - }else { -CDEBUG (D_SUPER ,"Mount %s complete\n" , - lmd->lmd_dev); - } -lockdep_on (); -return rc; -} - -/* We can't call ll_fill_super by name because it lives in a module that -* must be loaded after this one. -*/ -void lustre_register_super_ops (struct module *mod, -int (*cfs)(struct super_block *sb), -void (*ksc)(struct super_block *sb)) -{ -spin_lock (&client_lock); - client_mod = mod; - client_fill_super = cfs; - kill_super_cb = ksc; -spin_unlock (&client_lock); -} -EXPORT_SYMBOL (lustre_register_super_ops); - -/***************** FS registration ******************/ -static struct dentry *lustre_mount (struct file_system_type *fs_type,int flags, -const char *devname,void *data) -{ -return mount_nodev (fs_type, flags, data, lustre_fill_super); -} - -static void lustre_kill_super (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); - -if (kill_super_cb && lsi) - (*kill_super_cb)(sb); - -kill_anon_super (sb); -} - -/** Register the "lustre" fs type -*/ -static struct file_system_type lustre_fs_type = { - .owner =THIS_MODULE , - .name ="lustre" , - .mount = lustre_mount, - .kill_sb = lustre_kill_super, - .fs_flags =FS_RENAME_DOES_D_MOVE , -}; -MODULE_ALIAS_FS ("lustre" ); - -int lustre_register_fs (void ) -{ -return register_filesystem (&lustre_fs_type); -} - -int lustre_unregister_fs (void ) -{ -return unregister_filesystem (&lustre_fs_type); -}
PATCH 5/9 lustre: move filesystem mounting from obdclass to llite
Quoted 16 lines · James Simmons
Quoted 7 lines
All filesystem-api aspects of the lustre filesystem are in llite, except mounting which is in obdclass.
This is probably because the name filesystem type is/was used for mounting an lustre filesystem on the client, and for mounting a data-store on the server.
This is a confusion that is best discarded and forgotten.Quoted 8 lines
So move the mount handling into llite.
This removes that rather awkward requirment that obdclass needed to
request_module()the lustre module, and makeslustre_fill_super()significantly simpler.Several symbols don't need to be exported any more as they are now part of llite which is the only module that uses them.
Quoted 8 lines
Nak. The majority of this code is shared between both server and client code. Moving this directly to llite would make server code dependent on llite which is what is not desired. Things like
lustre_process_log()andlustre_end_log()have no client or server specific code and all nodes running lustre independent of the function of the node execute these code paths. Please seeobd_mount_server.cto see what functions are used.Do you mind if I take a stab at this ?
Sure, go for it.
I assume we agree that the actual mounting belongs in llite, but that there is other code in obd_mount.c which is not directly related to mounting, which is used by the server as well. I agree that such code needs to be left in obdclass.
Thanks,
NeilBrown
Quoted 2,576 lines
Quoted 2,576 lines
Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lustre/include/obd_class.h | 4 drivers/staging/lustre/lustre/llite/Makefile | 2 .../staging/lustre/lustre/llite/llite_internal.h | 3 drivers/staging/lustre/lustre/llite/mount.c | 1208 +++++++++++++++++++ drivers/staging/lustre/lustre/llite/super25.c | 8 drivers/staging/lustre/lustre/obdclass/Makefile | 2 drivers/staging/lustre/lustre/obdclass/class_obd.c | 6 drivers/staging/lustre/lustre/obdclass/obd_mount.c | 1244 -------------------- 8 files changed, 1218 insertions(+), 1259 deletions(-) create mode 100644 drivers/staging/lustre/lustre/llite/mount.c delete mode 100644 drivers/staging/lustre/lustre/obdclass/obd_mount.cdrivers/staging/lustre/lustre/include/obd_class.h +0
-4@@ -1556,10 +1556,6 @@ struct lwp_register_item {*/ extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); -/* obd_mount.c */ -int lustre_unregister_fs (void ); -int lustre_register_fs (void ); -/* sysctl.c */ int obd_sysctl_init (void );drivers/staging/lustre/lustre/llite/Makefile +1
-1@@ -3,7 +3,7 @@ ccflags-y += -I$(srctree)/drivers/staging/lustre/include ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LUSTRE_FS) += lustre.o -lustre-y := dcache.o dir.o file.o llite_lib.o llite_nfs.o \ +lustre-y := mount.o dcache.o dir.o file.o llite_lib.o llite_nfs.o \ rw.o rw26.o namei.o symlink.o llite_mmap.o range_lock.o \ xattr.o xattr_cache.o xattr_security.o \ super25.o statahead.o glimpse.o lcommon_cl.o lcommon_misc.o \drivers/staging/lustre/lustre/llite/llite_internal.h +3
-0@@ -1351,4 +1351,7 @@ void cl_inode_fini(struct inode *inode);__u64 cl_fid_build_ino (const struct lu_fid *fid,int api32);__u32 cl_fid_build_gen (const struct lu_fid *fid); +int lustre_unregister_fs (void ); +int lustre_register_fs (void ); +#endif /* LLITE_INTERNAL_H */ drivers/staging/lustre/lustre/llite/mount.c new file +1208
-0@@ -0,0 +1,1208 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* GPL HEADER START +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 only, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License version 2 for more details (a copy is included +* in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU General Public License +* version 2 along with this program; If not, see +* http://www.gnu.org/licenses/gpl-2.0.html +* +* GPL HEADER END +*/ +/* +* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. +* Use is subject to license terms. +* +* Copyright (c) 2011, 2015, Intel Corporation. +*/ +/* +* This file is part of Lustre, http://www.lustre.org/ +* Lustre is a trademark of Sun Microsystems, Inc. +* +* lustre/obdclass/obd_mount.c +* +* Client mount routines +* +* Author: Nathan Rutman <[email protected]> +*/ + +#define DEBUG_SUBSYSTEM S_CLASS +#define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */) +#define PRINT_CMD CDEBUG + +#include <linux/random.h> +#include <obd.h> +#include <obd_class.h> +#include <uapi/linux/lustre/lustre_idl.h> +#include <lustre_log.h> +#include <lustre_disk.h> +#include <uapi/linux/lustre/lustre_param.h> +#include <llite_internal.h> + +/**************** config llog ********************/ + +/** Get a config log from the MGS and process it. +* This func is called for both clients and servers. +* Continue to process new statements appended to the logs +* (whenever the config lock is revoked) until lustre_end_log +* is called. +* @param sb The superblock is used by the MGC to write to the local copy of +* the config log +* @param logname The name of the llog to replicate from the MGS +* @param cfg Since the same mgc may be used to follow multiple config logs +* (e.g. ost1, ost2, client), the config_llog_instance keeps the state for +* this log, and is added to the mgc's list of logs to follow. +*/ +int lustre_process_log (struct super_block *sb,char *logname, +struct config_llog_instance *cfg) +{ +struct lustre_cfg *lcfg; +struct lustre_cfg_bufs *bufs; +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *mgc = lsi->lsi_mgc; +int rc; + +LASSERT (mgc); +LASSERT (cfg); + + bufs =kzalloc (sizeof (*bufs),GFP_NOFS ); +if (!bufs) +return -ENOMEM ; + +/* mgc_process_config */ +lustre_cfg_bufs_reset (bufs, mgc->obd_name); +lustre_cfg_bufs_set_string (bufs,1 , logname); +lustre_cfg_bufs_set (bufs,2 , cfg,sizeof (*cfg)); +lustre_cfg_bufs_set (bufs,3 , &sb,sizeof (sb)); + lcfg =kzalloc (lustre_cfg_len (bufs->lcfg_bufcount, bufs->lcfg_buflen), +GFP_NOFS ); +if (!lcfg) { + rc = -ENOMEM ; + goto out; + } +lustre_cfg_init (lcfg,LCFG_LOG_START , bufs); + + rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); +kfree (lcfg); +out: +kfree (bufs); + +if (rc == -EINVAL ) +LCONSOLE_ERROR_MSG (0x15b ,"%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n" , + mgc->obd_name, logname, rc); + +else if (rc) +LCONSOLE_ERROR_MSG (0x15c ,"%s: The configuration from log '%s' failed (%d). This may be the result of communication errors between this node and the MGS, a bad configuration, or other errors. See the syslog for more information.\n" , + mgc->obd_name, logname, + rc); + +/* class_obd_list(); */ +return rc; +} + +/* Stop watching this config log for updates */ +int lustre_end_log (struct super_block *sb,char *logname, +struct config_llog_instance *cfg) +{ +struct lustre_cfg *lcfg; +struct lustre_cfg_bufs bufs; +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *mgc = lsi->lsi_mgc; +int rc; + +if (!mgc) +return -ENOENT ; + +/* mgc_process_config */ +lustre_cfg_bufs_reset (&bufs, mgc->obd_name); +lustre_cfg_bufs_set_string (&bufs,1 , logname); +if (cfg) +lustre_cfg_bufs_set (&bufs,2 , cfg,sizeof (*cfg)); + lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), +GFP_NOFS ); +if (!lcfg) +return -ENOMEM ; +lustre_cfg_init (lcfg,LCFG_LOG_END , &bufs); + + rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); +kfree (lcfg); +return rc; +} + +/**************** obd start *******************/ + +/** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from +* lctl (and do for echo cli/srv. +*/ +static int do_lcfg (char *cfgname,lnet_nid_t nid,int cmd, +char *s1,char *s2,char *s3,char *s4) +{ +struct lustre_cfg_bufs bufs; +struct lustre_cfg *lcfg =NULL ; +int rc; + +CDEBUG (D_TRACE ,"lcfg %s %#x %s %s %s %s\n" , cfgname, + cmd, s1, s2, s3, s4); + +lustre_cfg_bufs_reset (&bufs, cfgname); +if (s1) +lustre_cfg_bufs_set_string (&bufs,1 , s1); +if (s2) +lustre_cfg_bufs_set_string (&bufs,2 , s2); +if (s3) +lustre_cfg_bufs_set_string (&bufs,3 , s3); +if (s4) +lustre_cfg_bufs_set_string (&bufs,4 , s4); + + lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), +GFP_NOFS ); +if (!lcfg) +return -ENOMEM ; +lustre_cfg_init (lcfg, cmd, &bufs); + lcfg->lcfg_nid = nid; + rc =class_process_config (lcfg); +kfree (lcfg); +return rc; +} + +/** Call class_attach and class_setup. These methods in turn call +* obd type-specific methods. +*/ +static int lustre_start_simple (char *obdname,char *type,char *uuid, +char *s1,char *s2,char *s3,char *s4) +{ +int rc; + +CDEBUG (D_MOUNT ,"Starting obd %s (typ=%s)\n" , obdname, type); + + rc =do_lcfg (obdname,0 ,LCFG_ATTACH , type, uuid,NULL ,NULL ); +if (rc) { +CERROR ("%s attach error %d\n" , obdname, rc); +return rc; + } + rc =do_lcfg (obdname,0 ,LCFG_SETUP , s1, s2, s3, s4); +if (rc) { +CERROR ("%s setup error %d\n" , obdname, rc); +do_lcfg (obdname,0 ,LCFG_DETACH ,NULL ,NULL ,NULL ,NULL ); + } +return rc; +} + +static DEFINE_MUTEX (mgc_start_lock); + +/** Set up a mgc obd to process startup logs +* +* \param sb [in] super block of the mgc obd +* +* \retval 0 success, otherwise error code +*/ +int lustre_start_mgc (struct super_block *sb) +{ +struct obd_connect_data *data =NULL ; +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *obd; +struct obd_export *exp; +struct obd_uuid *uuid; +class_uuid_t uuidc; +lnet_nid_t nid; +char nidstr[LNET_NIDSTR_SIZE ]; +char *mgcname =NULL , *niduuid =NULL , *mgssec =NULL ; +char *ptr; +int rc =0 , i =0 , j; + +LASSERT (lsi->lsi_lmd); + +/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ + ptr = lsi->lsi_lmd->lmd_dev; +if (class_parse_nid (ptr, &nid, &ptr) ==0 ) + i++; +if (i ==0 ) { +CERROR ("No valid MGS nids found.\n" ); +return -EINVAL ; + } + +mutex_lock (&mgc_start_lock); + +libcfs_nid2str_r (nid, nidstr,sizeof (nidstr)); + mgcname =kasprintf (GFP_NOFS , +"%s%s" ,LUSTRE_MGC_OBDNAME , nidstr); + niduuid =kasprintf (GFP_NOFS ,"%s_%x" , mgcname,0 ); +if (!mgcname || !niduuid) { + rc = -ENOMEM ; + goto out_free; + } + + mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec :"" ; + + data =kzalloc (sizeof (*data),GFP_NOFS ); +if (!data) { + rc = -ENOMEM ; + goto out_free; + } + + obd =class_name2obd (mgcname); +if (obd && !obd->obd_stopping) { +int recov_bk; + + rc =obd_set_info_async (NULL , obd->obd_self_export, +strlen (KEY_MGSSEC ),KEY_MGSSEC , +strlen (mgssec), mgssec,NULL ); +if (rc) + goto out_free; + +/* Re-using an existing MGC */ +atomic_inc (&obd->u.cli.cl_mgc_refcount); + +/* IR compatibility check, only for clients */ +if (lmd_is_client (lsi->lsi_lmd)) { +int has_ir; +int vallen =sizeof (*data); +__u32 *flags = &lsi->lsi_lmd->lmd_flags; + + rc =obd_get_info (NULL , obd->obd_self_export, +strlen (KEY_CONN_DATA ),KEY_CONN_DATA , + &vallen, data); +LASSERT (rc ==0 ); + has_ir =OCD_HAS_FLAG (data,IMP_RECOV ); +if (has_ir ^ !(*flags &LMD_FLG_NOIR )) { +/* LMD_FLG_NOIR is for test purpose only */ +LCONSOLE_WARN ( +"Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n" , + has_ir ?"enabled" :"disabled" ); +if (has_ir) + *flags &= ~LMD_FLG_NOIR ; +else + *flags |=LMD_FLG_NOIR ; + } + } + + recov_bk =0 ; + +/* Try all connections, but only once (again). +* We don't want to block another target from starting +* (using its local copy of the log), but we do want to connect +* if at all possible. +*/ + recov_bk++; +CDEBUG (D_MOUNT ,"%s: Set MGC reconnect %d\n" , mgcname, + recov_bk); + rc =obd_set_info_async (NULL , obd->obd_self_export, +sizeof (KEY_INIT_RECOV_BACKUP ), +KEY_INIT_RECOV_BACKUP , +sizeof (recov_bk), &recov_bk,NULL ); + rc =0 ; + goto out; + } + +CDEBUG (D_MOUNT ,"Start MGC '%s'\n" , mgcname); + +/* Add the primary nids for the MGS */ + i =0 ; +/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ + ptr = lsi->lsi_lmd->lmd_dev; +while (class_parse_nid (ptr, &nid, &ptr) ==0 ) { + rc =do_lcfg (mgcname, nid, +LCFG_ADD_UUID , niduuid,NULL ,NULL ,NULL ); +if (!rc) + i++; +/* Stop at the first failover nid */ +if (*ptr ==':' ) +break ; + } +if (i ==0 ) { +CERROR ("No valid MGS nids found.\n" ); + rc = -EINVAL ; + goto out_free; + } + lsi->lsi_lmd->lmd_mgs_failnodes =1 ; + +/* Random uuid for MGC allows easier reconnects */ + uuid =kzalloc (sizeof (*uuid),GFP_NOFS ); +if (!uuid) { + rc = -ENOMEM ; + goto out_free; + } + +ll_generate_random_uuid (uuidc); +class_uuid_unparse (uuidc, uuid); + +/* Start the MGC */ + rc =lustre_start_simple (mgcname,LUSTRE_MGC_NAME , + (char *)uuid->uuid,LUSTRE_MGS_OBDNAME , + niduuid,NULL ,NULL ); +kfree (uuid); +if (rc) + goto out_free; + +/* Add any failover MGS nids */ + i =1 ; +while (ptr && ((*ptr ==':' || +class_find_param (ptr,PARAM_MGSNODE , &ptr) ==0 ))) { +/* New failover node */ +sprintf (niduuid,"%s_%x" , mgcname, i); + j =0 ; +while (class_parse_nid_quiet (ptr, &nid, &ptr) ==0 ) { + rc =do_lcfg (mgcname, nid,LCFG_ADD_UUID , niduuid, +NULL ,NULL ,NULL ); +if (!rc) + ++j; +if (*ptr ==':' ) +break ; + } +if (j >0 ) { + rc =do_lcfg (mgcname,0 ,LCFG_ADD_CONN , + niduuid,NULL ,NULL ,NULL ); +if (!rc) + i++; + }else { +/* at ":/fsname" */ +break ; + } + } + lsi->lsi_lmd->lmd_mgs_failnodes = i; + + obd =class_name2obd (mgcname); +if (!obd) { +CERROR ("Can't find mgcobd %s\n" , mgcname); + rc = -ENOTCONN ; + goto out_free; + } + + rc =obd_set_info_async (NULL , obd->obd_self_export, +strlen (KEY_MGSSEC ),KEY_MGSSEC , +strlen (mgssec), mgssec,NULL ); +if (rc) + goto out_free; + +/* Keep a refcount of servers/clients who started with "mount", +* so we know when we can get rid of the mgc. +*/ +atomic_set (&obd->u.cli.cl_mgc_refcount,1 ); + +/* We connect to the MGS at setup, and don't disconnect until cleanup */ + data->ocd_connect_flags =OBD_CONNECT_VERSION |OBD_CONNECT_AT | +OBD_CONNECT_FULL20 |OBD_CONNECT_IMP_RECOV | +OBD_CONNECT_LVB_TYPE |OBD_CONNECT_BULK_MBITS ; + +#if OBD_OCD_VERSION (3 ,0 ,53 ,0 ) >LUSTRE_VERSION_CODE + data->ocd_connect_flags |=OBD_CONNECT_MNE_SWAB ; +#endif + +if (lmd_is_client (lsi->lsi_lmd) && + lsi->lsi_lmd->lmd_flags &LMD_FLG_NOIR ) + data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV ; + data->ocd_version =LUSTRE_VERSION_CODE ; + rc =obd_connect (NULL , &exp, obd, &obd->obd_uuid, data,NULL ); +if (rc) { +CERROR ("connect failed %d\n" , rc); + goto out; + } + + obd->u.cli.cl_mgc_mgsexp = exp; + +out: +/* Keep the mgc info in the sb. Note that many lsi's can point +* to the same mgc. +*/ + lsi->lsi_mgc = obd; +out_free: +mutex_unlock (&mgc_start_lock); + +kfree (data); +kfree (mgcname); +kfree (niduuid); +return rc; +} + +static int lustre_stop_mgc (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); +struct obd_device *obd; +char *niduuid =NULL , *ptr =NULL ; +int i, rc =0 , len =0 ; + +if (!lsi) +return -ENOENT ; + obd = lsi->lsi_mgc; +if (!obd) +return -ENOENT ; + lsi->lsi_mgc =NULL ; + +mutex_lock (&mgc_start_lock); +LASSERT (atomic_read (&obd->u.cli.cl_mgc_refcount) >0 ); +if (!atomic_dec_and_test (&obd->u.cli.cl_mgc_refcount)) { +/* This is not fatal, every client that stops +* will call in here. +*/ +CDEBUG (D_MOUNT ,"mgc still has %d references.\n" , +atomic_read (&obd->u.cli.cl_mgc_refcount)); + rc = -EBUSY ; + goto out; + } + +/* The MGC has no recoverable data in any case. +* force shutdown set in umount_begin +*/ + obd->obd_no_recov =1 ; + +if (obd->u.cli.cl_mgc_mgsexp) { +/* An error is not fatal, if we are unable to send the +* disconnect mgs ping evictor cleans up the export +*/ + rc =obd_disconnect (obd->u.cli.cl_mgc_mgsexp); +if (rc) +CDEBUG (D_MOUNT ,"disconnect failed %d\n" , rc); + } + +/* Save the obdname for cleaning the nid uuids, which are obdname_XX */ + len =strlen (obd->obd_name) +6 ; + niduuid =kzalloc (len,GFP_NOFS ); +if (niduuid) { +strcpy (niduuid, obd->obd_name); + ptr = niduuid +strlen (niduuid); + } + + rc =class_manual_cleanup (obd); +if (rc) + goto out; + +/* Clean the nid uuids */ +if (!niduuid) { + rc = -ENOMEM ; + goto out; + } + +for (i =0 ; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) { +sprintf (ptr,"_%x" , i); + rc =do_lcfg (LUSTRE_MGC_OBDNAME ,0 ,LCFG_DEL_UUID , + niduuid,NULL ,NULL ,NULL ); +if (rc) +CERROR ("del MDC UUID %s failed: rc = %d\n" , + niduuid, rc); + } +out: +kfree (niduuid); + +/* class_import_put will get rid of the additional connections */ +mutex_unlock (&mgc_start_lock); +return rc; +} + +/***************** lustre superblock **************/ + +static struct lustre_sb_info *lustre_init_lsi (struct super_block *sb) +{ +struct lustre_sb_info *lsi; + + lsi =kzalloc (sizeof (*lsi),GFP_NOFS ); +if (!lsi) +return NULL ; + lsi->lsi_lmd =kzalloc (sizeof (*lsi->lsi_lmd),GFP_NOFS ); +if (!lsi->lsi_lmd) { +kfree (lsi); +return NULL ; + } + + lsi->lsi_lmd->lmd_exclude_count =0 ; + lsi->lsi_lmd->lmd_recovery_time_soft =0 ; + lsi->lsi_lmd->lmd_recovery_time_hard =0 ; +s2lsi_nocast (sb) = lsi; +/* we take 1 extra ref for our setup */ +atomic_set (&lsi->lsi_mounts,1 ); + +/* Default umount style */ + lsi->lsi_flags =LSI_UMOUNT_FAILOVER ; + +return lsi; +} + +static int lustre_free_lsi (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); + +CDEBUG (D_MOUNT ,"Freeing lsi %p\n" , lsi); + +/* someone didn't call server_put_mount. */ +LASSERT (atomic_read (&lsi->lsi_mounts) ==0 ); + +if (lsi->lsi_lmd) { +kfree (lsi->lsi_lmd->lmd_dev); +kfree (lsi->lsi_lmd->lmd_profile); +kfree (lsi->lsi_lmd->lmd_fileset); +kfree (lsi->lsi_lmd->lmd_mgssec); +kfree (lsi->lsi_lmd->lmd_opts); +if (lsi->lsi_lmd->lmd_exclude_count) +kfree (lsi->lsi_lmd->lmd_exclude); +kfree (lsi->lsi_lmd->lmd_mgs); +kfree (lsi->lsi_lmd->lmd_osd_type); +kfree (lsi->lsi_lmd->lmd_params); + +kfree (lsi->lsi_lmd); + } + +LASSERT (!lsi->lsi_llsbi); +kfree (lsi); +s2lsi_nocast (sb) =NULL ; + +return 0 ; +} + +/* The lsi has one reference for every server that is using the disk - +* e.g. MDT, MGS, and potentially MGC +*/ +static int lustre_put_lsi (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); + +CDEBUG (D_MOUNT ,"put %p %d\n" , sb,atomic_read (&lsi->lsi_mounts)); +if (atomic_dec_and_test (&lsi->lsi_mounts)) { +lustre_free_lsi (sb); +return 1 ; + } +return 0 ; +} + +/*************** mount common between server and client ***************/ + +/* Common umount */ +int lustre_common_put_super (struct super_block *sb) +{ +int rc; + +CDEBUG (D_MOUNT ,"dropping sb %p\n" , sb); + +/* Drop a ref to the MGC */ + rc =lustre_stop_mgc (sb); +if (rc && (rc != -ENOENT )) { +if (rc != -EBUSY ) { +CERROR ("Can't stop MGC: %d\n" , rc); +return rc; + } +/* BUSY just means that there's some other obd that +* needs the mgc. Let him clean it up. +*/ +CDEBUG (D_MOUNT ,"MGC still in use\n" ); + } +/* Drop a ref to the mounted disk */ +lustre_put_lsi (sb); +return rc; +} + +static void lmd_print (struct lustre_mount_data *lmd) +{ +int i; + +PRINT_CMD (D_MOUNT ," mount data:\n" ); +if (lmd_is_client (lmd)) +PRINT_CMD (D_MOUNT ,"profile: %s\n" , lmd->lmd_profile); +PRINT_CMD (D_MOUNT ,"device: %s\n" , lmd->lmd_dev); +PRINT_CMD (D_MOUNT ,"flags: %x\n" , lmd->lmd_flags); + +if (lmd->lmd_opts) +PRINT_CMD (D_MOUNT ,"options: %s\n" , lmd->lmd_opts); + +if (lmd->lmd_recovery_time_soft) +PRINT_CMD (D_MOUNT ,"recovery time soft: %d\n" , + lmd->lmd_recovery_time_soft); + +if (lmd->lmd_recovery_time_hard) +PRINT_CMD (D_MOUNT ,"recovery time hard: %d\n" , + lmd->lmd_recovery_time_hard); + +for (i =0 ; i < lmd->lmd_exclude_count; i++) { +PRINT_CMD (D_MOUNT ,"exclude %d: OST%04x\n" , i, + lmd->lmd_exclude[i]); + } +} + +/* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */ +static int lmd_make_exclusion (struct lustre_mount_data *lmd,const char *ptr) +{ +const char *s1 = ptr, *s2; +__u32 index =0 , *exclude_list; +int rc =0 , devmax; + +/* The shortest an ost name can be is 8 chars: -OST0000. +* We don't actually know the fsname at this time, so in fact +* a user could specify any fsname. +*/ + devmax =strlen (ptr) /8 +1 ; + +/* temp storage until we figure out how many we have */ + exclude_list =kcalloc (devmax,sizeof (index),GFP_NOFS ); +if (!exclude_list) +return -ENOMEM ; + +/* we enter this fn pointing at the '=' */ +while (*s1 && *s1 !=' ' && *s1 !=',' ) { + s1++; + rc =server_name2index (s1, &index, &s2); +if (rc <0 ) { +CERROR ("Can't parse server name '%s': rc = %d\n" , + s1, rc); +break ; + } +if (rc ==LDD_F_SV_TYPE_OST ) + exclude_list[lmd->lmd_exclude_count++] = index; +else +CDEBUG (D_MOUNT ,"ignoring exclude %.*s: type = %#x\n" , + (uint)(s2 - s1), s1, rc); + s1 = s2; +/* now we are pointing at ':' (next exclude) +* or ',' (end of excludes) +*/ +if (lmd->lmd_exclude_count >= devmax) +break ; + } +if (rc >=0 )/* non-err */ + rc =0 ; + +if (lmd->lmd_exclude_count) { +/* permanent, freed in lustre_free_lsi */ + lmd->lmd_exclude =kcalloc (lmd->lmd_exclude_count, +sizeof (index),GFP_NOFS ); +if (lmd->lmd_exclude) { +memcpy (lmd->lmd_exclude, exclude_list, +sizeof (index) * lmd->lmd_exclude_count); + }else { + rc = -ENOMEM ; + lmd->lmd_exclude_count =0 ; + } + } +kfree (exclude_list); +return rc; +} + +static int lmd_parse_mgssec (struct lustre_mount_data *lmd,char *ptr) +{ +char *tail; +int length; + +kfree (lmd->lmd_mgssec); + lmd->lmd_mgssec =NULL ; + + tail =strchr (ptr,',' ); +if (!tail) + length =strlen (ptr); +else + length = tail - ptr; + + lmd->lmd_mgssec =kzalloc (length +1 ,GFP_NOFS ); +if (!lmd->lmd_mgssec) +return -ENOMEM ; + +memcpy (lmd->lmd_mgssec, ptr, length); + lmd->lmd_mgssec[length] ='\0' ; +return 0 ; +} + +static int lmd_parse_string (char **handle,char *ptr) +{ +char *tail; +int length; + +if (!handle || !ptr) +return -EINVAL ; + +kfree (*handle); + *handle =NULL ; + + tail =strchr (ptr,',' ); +if (!tail) + length =strlen (ptr); +else + length = tail - ptr; + + *handle =kzalloc (length +1 ,GFP_NOFS ); +if (!*handle) +return -ENOMEM ; + +memcpy (*handle, ptr, length); + (*handle)[length] ='\0' ; + +return 0 ; +} + +/* Collect multiple values for mgsnid specifiers */ +static int lmd_parse_mgs (struct lustre_mount_data *lmd,char **ptr) +{ +lnet_nid_t nid; +char *tail = *ptr; +char *mgsnid; +int length; +int oldlen =0 ; + +/* Find end of nidlist */ +while (class_parse_nid_quiet (tail, &nid, &tail) ==0 ) + ; + length = tail - *ptr; +if (length ==0 ) { +LCONSOLE_ERROR_MSG (0x159 ,"Can't parse NID '%s'\n" , *ptr); +return -EINVAL ; + } + +if (lmd->lmd_mgs) + oldlen =strlen (lmd->lmd_mgs) +1 ; + + mgsnid =kzalloc (oldlen + length +1 ,GFP_NOFS ); +if (!mgsnid) +return -ENOMEM ; + +if (lmd->lmd_mgs) { +/* Multiple mgsnid= are taken to mean failover locations */ +memcpy (mgsnid, lmd->lmd_mgs, oldlen); + mgsnid[oldlen -1 ] =':' ; +kfree (lmd->lmd_mgs); + } +memcpy (mgsnid + oldlen, *ptr, length); + mgsnid[oldlen + length] ='\0' ; + lmd->lmd_mgs = mgsnid; + *ptr = tail; + +return 0 ; +} + +/** +* Find the first delimiter (comma or colon) from the specified \a buf and +* make \a *endh point to the string starting with the delimiter. The commas +* in expression list [...] will be skipped. +* +* @buf a delimiter-separated string +* @endh a pointer to a pointer that will point to the string +* starting with the delimiter +* +* RETURNS true if delimiter is found, false if delimiter is not found +*/ +static bool lmd_find_delimiter (char *buf,char **endh) +{ +char *c = buf; +size_t pos; +bool found; + +if (!buf) +return false; +try_again: +if (*c ==',' || *c ==':' ) +return true; + + pos =strcspn (c,"[:,]" ); +if (!pos) +return false; + +/* Not a valid mount string */ +if (*c ==']' ) { +CWARN ("invalid mount string format\n" ); +return false; + } + + c += pos; +if (*c =='[' ) { + c =strchr (c,']' ); + +/* invalid mount string */ +if (!c) { +CWARN ("invalid mount string format\n" ); +return false; + } + c++; + goto try_again; + } + + found = *c !='\0' ; +if (found && endh) + *endh = c; + +return found; +} + +/** +* Find the first valid string delimited by comma or colon from the specified +* \a buf and parse it to see whether it's a valid nid list. If yes, \a *endh +* will point to the next string starting with the delimiter. +* +* \param[in] buf a delimiter-separated string +* \param[in] endh a pointer to a pointer that will point to the string +* starting with the delimiter +* +* \retval 0 if the string is a valid nid list +* \retval 1 if the string is not a valid nid list +*/ +static int lmd_parse_nidlist (char *buf,char **endh) +{ +struct list_head nidlist; +char *endp = buf; +int rc =0 ; +char tmp; + +if (!buf) +return 1 ; +while (*buf ==',' || *buf ==':' ) + buf++; +if (*buf ==' ' || *buf =='/' || *buf =='\0' ) +return 1 ; + +if (!lmd_find_delimiter (buf, &endp)) + endp = buf +strlen (buf); + + tmp = *endp; + *endp ='\0' ; + +INIT_LIST_HEAD (&nidlist); +if (cfs_parse_nidlist (buf,strlen (buf), &nidlist) <=0 ) + rc =1 ; +cfs_free_nidlist (&nidlist); + + *endp = tmp; +if (rc) +return rc; +if (endh) + *endh = endp; +return 0 ; +} + +/** Parse mount line options +* e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre +* dev is passed as device=uml1:/lustre by mount.lustre +*/ +static int lmd_parse (char *options,struct lustre_mount_data *lmd) +{ +char *s1, *s2, *devname =NULL ; +struct lustre_mount_data *raw = (struct lustre_mount_data *)options; +int rc =0 ; + +LASSERT (lmd); +if (!options) { +LCONSOLE_ERROR_MSG (0x162 ,"Missing mount data: check that /sbin/mount.lustre is installed.\n" ); +return -EINVAL ; + } + +/* Options should be a string - try to detect old lmd data */ +if ((raw->lmd_magic &0xffffff00 ) == (LMD_MAGIC &0xffffff00 )) { +LCONSOLE_ERROR_MSG (0x163 ,"You're using an old version of /sbin/mount.lustre. Please install version %s\n" , +LUSTRE_VERSION_STRING ); +return -EINVAL ; + } + lmd->lmd_magic =LMD_MAGIC ; + + lmd->lmd_params =kzalloc (LMD_PARAMS_MAXLEN ,GFP_NOFS ); +if (!lmd->lmd_params) +return -ENOMEM ; + lmd->lmd_params[0 ] ='\0' ; + +/* Set default flags here */ + + s1 = options; +while (*s1) { +int clear =0 ; +int time_min =OBD_RECOVERY_TIME_MIN ; +char *s3; + +/* Skip whitespace and extra commas */ +while (*s1 ==' ' || *s1 ==',' ) + s1++; + s3 = s1; + +/* Client options are parsed in ll_options: eg. flock, +* user_xattr, acl +*/ + +/* Parse non-ldiskfs options here. Rather than modifying +* ldiskfs, we just zero these out here +*/ +if (strncmp (s1,"abort_recov" ,11 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_ABORT_RECOV ; + clear++; + }else if (strncmp (s1,"recovery_time_soft=" ,19 ) ==0 ) { + lmd->lmd_recovery_time_soft =max_t (int, +simple_strtoul (s1 +19 ,NULL ,10 ), time_min); + clear++; + }else if (strncmp (s1,"recovery_time_hard=" ,19 ) ==0 ) { + lmd->lmd_recovery_time_hard =max_t (int, +simple_strtoul (s1 +19 ,NULL ,10 ), time_min); + clear++; + }else if (strncmp (s1,"noir" ,4 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOIR ;/* test purpose only. */ + clear++; + }else if (strncmp (s1,"nosvc" ,5 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOSVC ; + clear++; + }else if (strncmp (s1,"nomgs" ,5 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOMGS ; + clear++; + }else if (strncmp (s1,"noscrub" ,7 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NOSCRUB ; + clear++; + }else if (strncmp (s1,PARAM_MGSNODE , +sizeof (PARAM_MGSNODE ) -1 ) ==0 ) { + s2 = s1 +sizeof (PARAM_MGSNODE ) -1 ; +/* Assume the next mount opt is the first +* invalid nid we get to. +*/ + rc =lmd_parse_mgs (lmd, &s2); +if (rc) + goto invalid; + clear++; + }else if (strncmp (s1,"writeconf" ,9 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_WRITECONF ; + clear++; + }else if (strncmp (s1,"update" ,6 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_UPDATE ; + clear++; + }else if (strncmp (s1,"virgin" ,6 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_VIRGIN ; + clear++; + }else if (strncmp (s1,"noprimnode" ,10 ) ==0 ) { + lmd->lmd_flags |=LMD_FLG_NO_PRIMNODE ; + clear++; + }else if (strncmp (s1,"mgssec=" ,7 ) ==0 ) { + rc =lmd_parse_mgssec (lmd, s1 +7 ); +if (rc) + goto invalid; + s3 = s2; + clear++; +/* ost exclusion list */ + }else if (strncmp (s1,"exclude=" ,8 ) ==0 ) { + rc =lmd_make_exclusion (lmd, s1 +7 ); +if (rc) + goto invalid; + clear++; + }else if (strncmp (s1,"mgs" ,3 ) ==0 ) { +/* We are an MGS */ + lmd->lmd_flags |=LMD_FLG_MGS ; + clear++; + }else if (strncmp (s1,"svname=" ,7 ) ==0 ) { + rc =lmd_parse_string (&lmd->lmd_profile, s1 +7 ); +if (rc) + goto invalid; + clear++; + }else if (strncmp (s1,"param=" ,6 ) ==0 ) { +size_t length, params_length; +char *tail = s1; + +if (lmd_find_delimiter (s1 +6 , &tail)) { +char *param_str = tail +1 ; +int supplementary =1 ; + +while (!lmd_parse_nidlist (param_str, + ¶m_str)) + supplementary =0 ; + length = param_str - s1 - supplementary; + }else { + length =strlen (s1); + } + length -=6 ; + params_length =strlen (lmd->lmd_params); +if (params_length + length +1 >=LMD_PARAMS_MAXLEN ) +return -E2BIG ; +strncat (lmd->lmd_params, s1 +6 , length); + lmd->lmd_params[params_length + length] ='\0' ; +strlcat (lmd->lmd_params," " ,LMD_PARAMS_MAXLEN ); + s3 = s1 +6 + length; + clear++; + }else if (strncmp (s1,"osd=" ,4 ) ==0 ) { + rc =lmd_parse_string (&lmd->lmd_osd_type, s1 +4 ); +if (rc) + goto invalid; + clear++; + } +/* Linux 2.4 doesn't pass the device, so we stuck it at the +* end of the options. +*/ +else if (strncmp (s1,"device=" ,7 ) ==0 ) { + devname = s1 +7 ; +/* terminate options right before device. device +* must be the last one. +*/ + *s1 ='\0' ; +break ; + } + +/* Find next opt */ + s2 =strchr (s1,',' ); +if (!s2) { +if (clear) + *s1 ='\0' ; +break ; + } + s2++; +if (clear) +memmove (s1, s2,strlen (s2) +1 ); +else + s1 = s2; + } + +if (!devname) { +LCONSOLE_ERROR_MSG (0x164 ,"Can't find the device name (need mount option 'device=...')\n" ); + goto invalid; + } + + s1 =strstr (devname,":/" ); +if (s1) { + ++s1; + lmd->lmd_flags |=LMD_FLG_CLIENT ; +/* Remove leading /s from fsname */ +while (*++s1 =='/' ) + ; + s2 =strchrnul (s1,'/' ); +/* Freed in lustre_free_lsi */ + lmd->lmd_profile =kasprintf (GFP_KERNEL ,"%.*s-client" , + (int )(s2 - s1), s1); +if (!lmd->lmd_profile) +return -ENOMEM ; + + s1 = s2; + s2 = s1 +strlen (s1) -1 ; +/* Remove padding /s from fileset */ +while (*s2 =='/' ) + s2--; +if (s2 > s1) { + lmd->lmd_fileset =kstrndup (s1, s2 - s1 +1 , +GFP_KERNEL ); +if (!lmd->lmd_fileset) +return -ENOMEM ; + } + } + +/* Freed in lustre_free_lsi */ + lmd->lmd_dev =kstrdup (devname,GFP_KERNEL ); +if (!lmd->lmd_dev) +return -ENOMEM ; + +/* Save mount options */ + s1 = options +strlen (options) -1 ; +while (s1 >= options && (*s1 ==',' || *s1 ==' ' )) + *s1-- =0 ; +if (*options !=0 ) { +/* Freed in lustre_free_lsi */ + lmd->lmd_opts =kstrdup (options,GFP_KERNEL ); +if (!lmd->lmd_opts) +return -ENOMEM ; + } + +lmd_print (lmd); + lmd->lmd_magic =LMD_MAGIC ; + +return rc; + +invalid: +CERROR ("Bad mount options %s\n" , options); +return -EINVAL ; +} + +/** This is the entry point for the mount call into Lustre. +* This is called when a server or client is mounted, +* and this is where we start setting things up. +* @param data Mount options (e.g. -o flock,abort_recov) +*/ +static int lustre_fill_super (struct super_block *sb,void *lmd2_data,int silent) +{ +struct lustre_mount_data *lmd; +struct lustre_sb_info *lsi; +int rc; + +CDEBUG (D_MOUNT |D_VFSTRACE ,"VFS Op: sb %p\n" , sb); + + lsi =lustre_init_lsi (sb); +if (!lsi) +return -ENOMEM ; + lmd = lsi->lsi_lmd; + +/* +* Disable lockdep during mount, because mount locking patterns are +* `special'. +*/ +lockdep_off (); + +/* +* LU-639: the obd cleanup of last mount may not finish yet, wait here. +*/ +obd_zombie_barrier (); + +/* Figure out the lmd from the mount options */ +if (lmd_parse (lmd2_data, lmd)) { +lustre_put_lsi (sb); + rc = -EINVAL ; + goto out; + } + +if (lmd_is_client (lmd)) { +CDEBUG (D_MOUNT ,"Mounting client %s\n" , lmd->lmd_profile); + + rc =lustre_start_mgc (sb); +if (rc) { +lustre_common_put_super (sb); + goto out; + } +/* Connect and start */ + rc =ll_fill_super (sb); +/* l_f_s will call lustre_common_put_super on failure, otherwise +* l_f_s will have taken another reference to the module */ + }else { +CERROR ("This is client-side-only module, cannot handle server mount.\n" ); + rc = -EINVAL ; + } + +/* If error happens in fill_super() call, @lsi will be killed there. +* This is why we do not put it here. +*/ + goto out; +out: +if (rc) { +CERROR ("Unable to mount %s (%d)\n" , +s2lsi (sb) ? lmd->lmd_dev :"" , rc); + }else { +CDEBUG (D_SUPER ,"Mount %s complete\n" , + lmd->lmd_dev); + } +lockdep_on (); +return rc; +} + +/***************** FS registration ******************/ +static struct dentry *lustre_mount (struct file_system_type *fs_type,int flags, +const char *devname,void *data) +{ +return mount_nodev (fs_type, flags, data, lustre_fill_super); +} + +static void lustre_kill_super (struct super_block *sb) +{ +struct lustre_sb_info *lsi =s2lsi (sb); + +if (lsi) +ll_kill_super (sb); + +kill_anon_super (sb); +} + +/** Register the "lustre" fs type +*/ +static struct file_system_type lustre_fs_type = { + .owner =THIS_MODULE , + .name ="lustre" , + .mount = lustre_mount, + .kill_sb = lustre_kill_super, + .fs_flags =FS_RENAME_DOES_D_MOVE , +}; +MODULE_ALIAS_FS ("lustre" ); + +int lustre_register_fs (void ) +{ +return register_filesystem (&lustre_fs_type); +} + +int lustre_unregister_fs (void ) +{ +return unregister_filesystem (&lustre_fs_type); +}drivers/staging/lustre/lustre/llite/super25.c +5
-3@@ -145,10 +145,11 @@ static int __init lustre_init(void)if (rc !=0 ) goto out_inode_fini_env; -lustre_register_super_ops (THIS_MODULE , ll_fill_super, ll_kill_super);lustre_register_client_process_config (ll_process_config); -return 0 ; + rc =lustre_register_fs (); + +return rc; out_inode_fini_env:cl_env_put (cl_inode_fini_env, &cl_inode_fini_refcheck);@@ -166,7 +167,8 @@ static int __init lustre_init(void) static void __exit lustre_exit(void) { -lustre_register_super_ops (NULL ,NULL ,NULL ); +lustre_unregister_fs (); +lustre_register_client_process_config (NULL );debugfs_remove (llite_root);drivers/staging/lustre/lustre/obdclass/Makefile +1
-1@@ -8,5 +8,5 @@ obdclass-y := module.o sysctl.o \ llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o debug.o \ genops.o uuid.o lprocfs_status.o lprocfs_counters.o \ lustre_handles.o lustre_peer.o statfs_pack.o linkea.o \ - obdo.o obd_config.o obd_mount.o lu_object.o lu_ref.o \ + obdo.o obd_config.o lu_object.o lu_ref.o \ cl_object.o cl_page.o cl_lock.o cl_io.o kernelcomm.odrivers/staging/lustre/lustre/obdclass/class_obd.c +0
-6@@ -510,18 +510,12 @@ static int __init obdclass_init(void)return err; err =llog_info_init (); -if (err) -return err; - - err =lustre_register_fs ();return err; }static void obdclass_exit (void ) { -lustre_unregister_fs (); -misc_deregister (&obd_psdev);llog_info_fini ();cl_global_fini ();drivers/staging/lustre/lustre/obdclass/obd_mount.c deleted +0
-1239@@ -1,1244 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* GPL HEADER START -* -* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 only, -* as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License version 2 for more details (a copy is included -* in the LICENSE file that accompanied this code). -* -* You should have received a copy of the GNU General Public License -* version 2 along with this program; If not, see -* http://www.gnu.org/licenses/gpl-2.0.html -* -* GPL HEADER END -*/ -/* -* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. -* Use is subject to license terms. -* -* Copyright (c) 2011, 2015, Intel Corporation. -*/ -/* -* This file is part of Lustre, http://www.lustre.org/ -* Lustre is a trademark of Sun Microsystems, Inc. -* -* lustre/obdclass/obd_mount.c -* -* Client mount routines -* -* Author: Nathan Rutman <[email protected]> -*/ - -#define DEBUG_SUBSYSTEM S_CLASS -#define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */) -#define PRINT_CMD CDEBUG - -#include <linux/random.h> -#include <obd.h> -#include <obd_class.h> -#include <uapi/linux/lustre/lustre_idl.h> -#include <lustre_log.h> -#include <lustre_disk.h> -#include <uapi/linux/lustre/lustre_param.h> - -static DEFINE_SPINLOCK (client_lock); -static struct module *client_mod; -static int (*client_fill_super)(struct super_block *sb); -static void (*kill_super_cb)(struct super_block *sb); - -/**************** config llog ********************/ - -/** Get a config log from the MGS and process it. -* This func is called for both clients and servers. -* Continue to process new statements appended to the logs -* (whenever the config lock is revoked) until lustre_end_log -* is called. -* @param sb The superblock is used by the MGC to write to the local copy of -* the config log -* @param logname The name of the llog to replicate from the MGS -* @param cfg Since the same mgc may be used to follow multiple config logs -* (e.g. ost1, ost2, client), the config_llog_instance keeps the state for -* this log, and is added to the mgc's list of logs to follow. -*/ -int lustre_process_log (struct super_block *sb,char *logname, -struct config_llog_instance *cfg) -{ -struct lustre_cfg *lcfg; -struct lustre_cfg_bufs *bufs; -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *mgc = lsi->lsi_mgc; -int rc; - -LASSERT (mgc); -LASSERT (cfg); - - bufs =kzalloc (sizeof (*bufs),GFP_NOFS ); -if (!bufs) -return -ENOMEM ; - -/* mgc_process_config */ -lustre_cfg_bufs_reset (bufs, mgc->obd_name); -lustre_cfg_bufs_set_string (bufs,1 , logname); -lustre_cfg_bufs_set (bufs,2 , cfg,sizeof (*cfg)); -lustre_cfg_bufs_set (bufs,3 , &sb,sizeof (sb)); - lcfg =kzalloc (lustre_cfg_len (bufs->lcfg_bufcount, bufs->lcfg_buflen), -GFP_NOFS ); -if (!lcfg) { - rc = -ENOMEM ; - goto out; - } -lustre_cfg_init (lcfg,LCFG_LOG_START , bufs); - - rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); -kfree (lcfg); -out: -kfree (bufs); - -if (rc == -EINVAL ) -LCONSOLE_ERROR_MSG (0x15b ,"%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n" , - mgc->obd_name, logname, rc); - -else if (rc) -LCONSOLE_ERROR_MSG (0x15c ,"%s: The configuration from log '%s' failed (%d). This may be the result of communication errors between this node and the MGS, a bad configuration, or other errors. See the syslog for more information.\n" , - mgc->obd_name, logname, - rc); - -/* class_obd_list(); */ -return rc; -} -EXPORT_SYMBOL (lustre_process_log); - -/* Stop watching this config log for updates */ -int lustre_end_log (struct super_block *sb,char *logname, -struct config_llog_instance *cfg) -{ -struct lustre_cfg *lcfg; -struct lustre_cfg_bufs bufs; -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *mgc = lsi->lsi_mgc; -int rc; - -if (!mgc) -return -ENOENT ; - -/* mgc_process_config */ -lustre_cfg_bufs_reset (&bufs, mgc->obd_name); -lustre_cfg_bufs_set_string (&bufs,1 , logname); -if (cfg) -lustre_cfg_bufs_set (&bufs,2 , cfg,sizeof (*cfg)); - lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), -GFP_NOFS ); -if (!lcfg) -return -ENOMEM ; -lustre_cfg_init (lcfg,LCFG_LOG_END , &bufs); - - rc =obd_process_config (mgc,sizeof (*lcfg), lcfg); -kfree (lcfg); -return rc; -} -EXPORT_SYMBOL (lustre_end_log); - -/**************** obd start *******************/ - -/** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from -* lctl (and do for echo cli/srv. -*/ -static int do_lcfg (char *cfgname,lnet_nid_t nid,int cmd, -char *s1,char *s2,char *s3,char *s4) -{ -struct lustre_cfg_bufs bufs; -struct lustre_cfg *lcfg =NULL ; -int rc; - -CDEBUG (D_TRACE ,"lcfg %s %#x %s %s %s %s\n" , cfgname, - cmd, s1, s2, s3, s4); - -lustre_cfg_bufs_reset (&bufs, cfgname); -if (s1) -lustre_cfg_bufs_set_string (&bufs,1 , s1); -if (s2) -lustre_cfg_bufs_set_string (&bufs,2 , s2); -if (s3) -lustre_cfg_bufs_set_string (&bufs,3 , s3); -if (s4) -lustre_cfg_bufs_set_string (&bufs,4 , s4); - - lcfg =kzalloc (lustre_cfg_len (bufs.lcfg_bufcount, bufs.lcfg_buflen), -GFP_NOFS ); -if (!lcfg) -return -ENOMEM ; -lustre_cfg_init (lcfg, cmd, &bufs); - lcfg->lcfg_nid = nid; - rc =class_process_config (lcfg); -kfree (lcfg); -return rc; -} - -/** Call class_attach and class_setup. These methods in turn call -* obd type-specific methods. -*/ -static int lustre_start_simple (char *obdname,char *type,char *uuid, -char *s1,char *s2,char *s3,char *s4) -{ -int rc; - -CDEBUG (D_MOUNT ,"Starting obd %s (typ=%s)\n" , obdname, type); - - rc =do_lcfg (obdname,0 ,LCFG_ATTACH , type, uuid,NULL ,NULL ); -if (rc) { -CERROR ("%s attach error %d\n" , obdname, rc); -return rc; - } - rc =do_lcfg (obdname,0 ,LCFG_SETUP , s1, s2, s3, s4); -if (rc) { -CERROR ("%s setup error %d\n" , obdname, rc); -do_lcfg (obdname,0 ,LCFG_DETACH ,NULL ,NULL ,NULL ,NULL ); - } -return rc; -} - -static DEFINE_MUTEX (mgc_start_lock); - -/** Set up a mgc obd to process startup logs -* -* \param sb [in] super block of the mgc obd -* -* \retval 0 success, otherwise error code -*/ -int lustre_start_mgc (struct super_block *sb) -{ -struct obd_connect_data *data =NULL ; -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *obd; -struct obd_export *exp; -struct obd_uuid *uuid; -class_uuid_t uuidc; -lnet_nid_t nid; -char nidstr[LNET_NIDSTR_SIZE ]; -char *mgcname =NULL , *niduuid =NULL , *mgssec =NULL ; -char *ptr; -int rc =0 , i =0 , j; - -LASSERT (lsi->lsi_lmd); - -/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ - ptr = lsi->lsi_lmd->lmd_dev; -if (class_parse_nid (ptr, &nid, &ptr) ==0 ) - i++; -if (i ==0 ) { -CERROR ("No valid MGS nids found.\n" ); -return -EINVAL ; - } - -mutex_lock (&mgc_start_lock); - -libcfs_nid2str_r (nid, nidstr,sizeof (nidstr)); - mgcname =kasprintf (GFP_NOFS , -"%s%s" ,LUSTRE_MGC_OBDNAME , nidstr); - niduuid =kasprintf (GFP_NOFS ,"%s_%x" , mgcname,0 ); -if (!mgcname || !niduuid) { - rc = -ENOMEM ; - goto out_free; - } - - mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec :"" ; - - data =kzalloc (sizeof (*data),GFP_NOFS ); -if (!data) { - rc = -ENOMEM ; - goto out_free; - } - - obd =class_name2obd (mgcname); -if (obd && !obd->obd_stopping) { -int recov_bk; - - rc =obd_set_info_async (NULL , obd->obd_self_export, -strlen (KEY_MGSSEC ),KEY_MGSSEC , -strlen (mgssec), mgssec,NULL ); -if (rc) - goto out_free; - -/* Re-using an existing MGC */ -atomic_inc (&obd->u.cli.cl_mgc_refcount); - -/* IR compatibility check, only for clients */ -if (lmd_is_client (lsi->lsi_lmd)) { -int has_ir; -int vallen =sizeof (*data); -__u32 *flags = &lsi->lsi_lmd->lmd_flags; - - rc =obd_get_info (NULL , obd->obd_self_export, -strlen (KEY_CONN_DATA ),KEY_CONN_DATA , - &vallen, data); -LASSERT (rc ==0 ); - has_ir =OCD_HAS_FLAG (data,IMP_RECOV ); -if (has_ir ^ !(*flags &LMD_FLG_NOIR )) { -/* LMD_FLG_NOIR is for test purpose only */ -LCONSOLE_WARN ( -"Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n" , - has_ir ?"enabled" :"disabled" ); -if (has_ir) - *flags &= ~LMD_FLG_NOIR ; -else - *flags |=LMD_FLG_NOIR ; - } - } - - recov_bk =0 ; - -/* Try all connections, but only once (again). -* We don't want to block another target from starting -* (using its local copy of the log), but we do want to connect -* if at all possible. -*/ - recov_bk++; -CDEBUG (D_MOUNT ,"%s: Set MGC reconnect %d\n" , mgcname, - recov_bk); - rc =obd_set_info_async (NULL , obd->obd_self_export, -sizeof (KEY_INIT_RECOV_BACKUP ), -KEY_INIT_RECOV_BACKUP , -sizeof (recov_bk), &recov_bk,NULL ); - rc =0 ; - goto out; - } - -CDEBUG (D_MOUNT ,"Start MGC '%s'\n" , mgcname); - -/* Add the primary nids for the MGS */ - i =0 ; -/* Use nids from mount line: uml1,1 at elan:uml2,2 at elan:/lustre */ - ptr = lsi->lsi_lmd->lmd_dev; -while (class_parse_nid (ptr, &nid, &ptr) ==0 ) { - rc =do_lcfg (mgcname, nid, -LCFG_ADD_UUID , niduuid,NULL ,NULL ,NULL ); -if (!rc) - i++; -/* Stop at the first failover nid */ -if (*ptr ==':' ) -break ; - } -if (i ==0 ) { -CERROR ("No valid MGS nids found.\n" ); - rc = -EINVAL ; - goto out_free; - } - lsi->lsi_lmd->lmd_mgs_failnodes =1 ; - -/* Random uuid for MGC allows easier reconnects */ - uuid =kzalloc (sizeof (*uuid),GFP_NOFS ); -if (!uuid) { - rc = -ENOMEM ; - goto out_free; - } - -ll_generate_random_uuid (uuidc); -class_uuid_unparse (uuidc, uuid); - -/* Start the MGC */ - rc =lustre_start_simple (mgcname,LUSTRE_MGC_NAME , - (char *)uuid->uuid,LUSTRE_MGS_OBDNAME , - niduuid,NULL ,NULL ); -kfree (uuid); -if (rc) - goto out_free; - -/* Add any failover MGS nids */ - i =1 ; -while (ptr && ((*ptr ==':' || -class_find_param (ptr,PARAM_MGSNODE , &ptr) ==0 ))) { -/* New failover node */ -sprintf (niduuid,"%s_%x" , mgcname, i); - j =0 ; -while (class_parse_nid_quiet (ptr, &nid, &ptr) ==0 ) { - rc =do_lcfg (mgcname, nid,LCFG_ADD_UUID , niduuid, -NULL ,NULL ,NULL ); -if (!rc) - ++j; -if (*ptr ==':' ) -break ; - } -if (j >0 ) { - rc =do_lcfg (mgcname,0 ,LCFG_ADD_CONN , - niduuid,NULL ,NULL ,NULL ); -if (!rc) - i++; - }else { -/* at ":/fsname" */ -break ; - } - } - lsi->lsi_lmd->lmd_mgs_failnodes = i; - - obd =class_name2obd (mgcname); -if (!obd) { -CERROR ("Can't find mgcobd %s\n" , mgcname); - rc = -ENOTCONN ; - goto out_free; - } - - rc =obd_set_info_async (NULL , obd->obd_self_export, -strlen (KEY_MGSSEC ),KEY_MGSSEC , -strlen (mgssec), mgssec,NULL ); -if (rc) - goto out_free; - -/* Keep a refcount of servers/clients who started with "mount", -* so we know when we can get rid of the mgc. -*/ -atomic_set (&obd->u.cli.cl_mgc_refcount,1 ); - -/* We connect to the MGS at setup, and don't disconnect until cleanup */ - data->ocd_connect_flags =OBD_CONNECT_VERSION |OBD_CONNECT_AT | -OBD_CONNECT_FULL20 |OBD_CONNECT_IMP_RECOV | -OBD_CONNECT_LVB_TYPE |OBD_CONNECT_BULK_MBITS ; - -#if OBD_OCD_VERSION (3 ,0 ,53 ,0 ) >LUSTRE_VERSION_CODE - data->ocd_connect_flags |=OBD_CONNECT_MNE_SWAB ; -#endif - -if (lmd_is_client (lsi->lsi_lmd) && - lsi->lsi_lmd->lmd_flags &LMD_FLG_NOIR ) - data->ocd_connect_flags &= ~OBD_CONNECT_IMP_RECOV ; - data->ocd_version =LUSTRE_VERSION_CODE ; - rc =obd_connect (NULL , &exp, obd, &obd->obd_uuid, data,NULL ); -if (rc) { -CERROR ("connect failed %d\n" , rc); - goto out; - } - - obd->u.cli.cl_mgc_mgsexp = exp; - -out: -/* Keep the mgc info in the sb. Note that many lsi's can point -* to the same mgc. -*/ - lsi->lsi_mgc = obd; -out_free: -mutex_unlock (&mgc_start_lock); - -kfree (data); -kfree (mgcname); -kfree (niduuid); -return rc; -} - -static int lustre_stop_mgc (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); -struct obd_device *obd; -char *niduuid =NULL , *ptr =NULL ; -int i, rc =0 , len =0 ; - -if (!lsi) -return -ENOENT ; - obd = lsi->lsi_mgc; -if (!obd) -return -ENOENT ; - lsi->lsi_mgc =NULL ; - -mutex_lock (&mgc_start_lock); -LASSERT (atomic_read (&obd->u.cli.cl_mgc_refcount) >0 ); -if (!atomic_dec_and_test (&obd->u.cli.cl_mgc_refcount)) { -/* This is not fatal, every client that stops -* will call in here. -*/ -CDEBUG (D_MOUNT ,"mgc still has %d references.\n" , -atomic_read (&obd->u.cli.cl_mgc_refcount)); - rc = -EBUSY ; - goto out; - } - -/* The MGC has no recoverable data in any case. -* force shutdown set in umount_begin -*/ - obd->obd_no_recov =1 ; - -if (obd->u.cli.cl_mgc_mgsexp) { -/* An error is not fatal, if we are unable to send the -* disconnect mgs ping evictor cleans up the export -*/ - rc =obd_disconnect (obd->u.cli.cl_mgc_mgsexp); -if (rc) -CDEBUG (D_MOUNT ,"disconnect failed %d\n" , rc); - } - -/* Save the obdname for cleaning the nid uuids, which are obdname_XX */ - len =strlen (obd->obd_name) +6 ; - niduuid =kzalloc (len,GFP_NOFS ); -if (niduuid) { -strcpy (niduuid, obd->obd_name); - ptr = niduuid +strlen (niduuid); - } - - rc =class_manual_cleanup (obd); -if (rc) - goto out; - -/* Clean the nid uuids */ -if (!niduuid) { - rc = -ENOMEM ; - goto out; - } - -for (i =0 ; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) { -sprintf (ptr,"_%x" , i); - rc =do_lcfg (LUSTRE_MGC_OBDNAME ,0 ,LCFG_DEL_UUID , - niduuid,NULL ,NULL ,NULL ); -if (rc) -CERROR ("del MDC UUID %s failed: rc = %d\n" , - niduuid, rc); - } -out: -kfree (niduuid); - -/* class_import_put will get rid of the additional connections */ -mutex_unlock (&mgc_start_lock); -return rc; -} - -/***************** lustre superblock **************/ - -static struct lustre_sb_info *lustre_init_lsi (struct super_block *sb) -{ -struct lustre_sb_info *lsi; - - lsi =kzalloc (sizeof (*lsi),GFP_NOFS ); -if (!lsi) -return NULL ; - lsi->lsi_lmd =kzalloc (sizeof (*lsi->lsi_lmd),GFP_NOFS ); -if (!lsi->lsi_lmd) { -kfree (lsi); -return NULL ; - } - - lsi->lsi_lmd->lmd_exclude_count =0 ; - lsi->lsi_lmd->lmd_recovery_time_soft =0 ; - lsi->lsi_lmd->lmd_recovery_time_hard =0 ; -s2lsi_nocast (sb) = lsi; -/* we take 1 extra ref for our setup */ -atomic_set (&lsi->lsi_mounts,1 ); - -/* Default umount style */ - lsi->lsi_flags =LSI_UMOUNT_FAILOVER ; - -return lsi; -} - -static int lustre_free_lsi (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); - -CDEBUG (D_MOUNT ,"Freeing lsi %p\n" , lsi); - -/* someone didn't call server_put_mount. */ -LASSERT (atomic_read (&lsi->lsi_mounts) ==0 ); - -if (lsi->lsi_lmd) { -kfree (lsi->lsi_lmd->lmd_dev); -kfree (lsi->lsi_lmd->lmd_profile); -kfree (lsi->lsi_lmd->lmd_fileset); -kfree (lsi->lsi_lmd->lmd_mgssec); -kfree (lsi->lsi_lmd->lmd_opts); -if (lsi->lsi_lmd->lmd_exclude_count) -kfree (lsi->lsi_lmd->lmd_exclude); -kfree (lsi->lsi_lmd->lmd_mgs); -kfree (lsi->lsi_lmd->lmd_osd_type); -kfree (lsi->lsi_lmd->lmd_params); - -kfree (lsi->lsi_lmd); - } - -LASSERT (!lsi->lsi_llsbi); -kfree (lsi); -s2lsi_nocast (sb) =NULL ; - -return 0 ; -} - -/* The lsi has one reference for every server that is using the disk - -* e.g. MDT, MGS, and potentially MGC -*/ -static int lustre_put_lsi (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); - -CDEBUG (D_MOUNT ,"put %p %d\n" , sb,atomic_read (&lsi->lsi_mounts)); -if (atomic_dec_and_test (&lsi->lsi_mounts)) { -lustre_free_lsi (sb); -return 1 ; - } -return 0 ; -} - -/*************** mount common between server and client ***************/ - -/* Common umount */ -int lustre_common_put_super (struct super_block *sb) -{ -int rc; - -CDEBUG (D_MOUNT ,"dropping sb %p\n" , sb); - -/* Drop a ref to the MGC */ - rc =lustre_stop_mgc (sb); -if (rc && (rc != -ENOENT )) { -if (rc != -EBUSY ) { -CERROR ("Can't stop MGC: %d\n" , rc); -return rc; - } -/* BUSY just means that there's some other obd that -* needs the mgc. Let him clean it up. -*/ -CDEBUG (D_MOUNT ,"MGC still in use\n" ); - } -/* Drop a ref to the mounted disk */ -lustre_put_lsi (sb); -return rc; -} -EXPORT_SYMBOL (lustre_common_put_super); - -static void lmd_print (struct lustre_mount_data *lmd) -{ -int i; - -PRINT_CMD (D_MOUNT ," mount data:\n" ); -if (lmd_is_client (lmd)) -PRINT_CMD (D_MOUNT ,"profile: %s\n" , lmd->lmd_profile); -PRINT_CMD (D_MOUNT ,"device: %s\n" , lmd->lmd_dev); -PRINT_CMD (D_MOUNT ,"flags: %x\n" , lmd->lmd_flags); - -if (lmd->lmd_opts) -PRINT_CMD (D_MOUNT ,"options: %s\n" , lmd->lmd_opts); - -if (lmd->lmd_recovery_time_soft) -PRINT_CMD (D_MOUNT ,"recovery time soft: %d\n" , - lmd->lmd_recovery_time_soft); - -if (lmd->lmd_recovery_time_hard) -PRINT_CMD (D_MOUNT ,"recovery time hard: %d\n" , - lmd->lmd_recovery_time_hard); - -for (i =0 ; i < lmd->lmd_exclude_count; i++) { -PRINT_CMD (D_MOUNT ,"exclude %d: OST%04x\n" , i, - lmd->lmd_exclude[i]); - } -} - -/* mount -v -o exclude=lustre-OST0001:lustre-OST0002 -t lustre ... */ -static int lmd_make_exclusion (struct lustre_mount_data *lmd,const char *ptr) -{ -const char *s1 = ptr, *s2; -__u32 index =0 , *exclude_list; -int rc =0 , devmax; - -/* The shortest an ost name can be is 8 chars: -OST0000. -* We don't actually know the fsname at this time, so in fact -* a user could specify any fsname. -*/ - devmax =strlen (ptr) /8 +1 ; - -/* temp storage until we figure out how many we have */ - exclude_list =kcalloc (devmax,sizeof (index),GFP_NOFS ); -if (!exclude_list) -return -ENOMEM ; - -/* we enter this fn pointing at the '=' */ -while (*s1 && *s1 !=' ' && *s1 !=',' ) { - s1++; - rc =server_name2index (s1, &index, &s2); -if (rc <0 ) { -CERROR ("Can't parse server name '%s': rc = %d\n" , - s1, rc); -break ; - } -if (rc ==LDD_F_SV_TYPE_OST ) - exclude_list[lmd->lmd_exclude_count++] = index; -else -CDEBUG (D_MOUNT ,"ignoring exclude %.*s: type = %#x\n" , - (uint)(s2 - s1), s1, rc); - s1 = s2; -/* now we are pointing at ':' (next exclude) -* or ',' (end of excludes) -*/ -if (lmd->lmd_exclude_count >= devmax) -break ; - } -if (rc >=0 )/* non-err */ - rc =0 ; - -if (lmd->lmd_exclude_count) { -/* permanent, freed in lustre_free_lsi */ - lmd->lmd_exclude =kcalloc (lmd->lmd_exclude_count, -sizeof (index),GFP_NOFS ); -if (lmd->lmd_exclude) { -memcpy (lmd->lmd_exclude, exclude_list, -sizeof (index) * lmd->lmd_exclude_count); - }else { - rc = -ENOMEM ; - lmd->lmd_exclude_count =0 ; - } - } -kfree (exclude_list); -return rc; -} - -static int lmd_parse_mgssec (struct lustre_mount_data *lmd,char *ptr) -{ -char *tail; -int length; - -kfree (lmd->lmd_mgssec); - lmd->lmd_mgssec =NULL ; - - tail =strchr (ptr,',' ); -if (!tail) - length =strlen (ptr); -else - length = tail - ptr; - - lmd->lmd_mgssec =kzalloc (length +1 ,GFP_NOFS ); -if (!lmd->lmd_mgssec) -return -ENOMEM ; - -memcpy (lmd->lmd_mgssec, ptr, length); - lmd->lmd_mgssec[length] ='\0' ; -return 0 ; -} - -static int lmd_parse_string (char **handle,char *ptr) -{ -char *tail; -int length; - -if (!handle || !ptr) -return -EINVAL ; - -kfree (*handle); - *handle =NULL ; - - tail =strchr (ptr,',' ); -if (!tail) - length =strlen (ptr); -else - length = tail - ptr; - - *handle =kzalloc (length +1 ,GFP_NOFS ); -if (!*handle) -return -ENOMEM ; - -memcpy (*handle, ptr, length); - (*handle)[length] ='\0' ; - -return 0 ; -} - -/* Collect multiple values for mgsnid specifiers */ -static int lmd_parse_mgs (struct lustre_mount_data *lmd,char **ptr) -{ -lnet_nid_t nid; -char *tail = *ptr; -char *mgsnid; -int length; -int oldlen =0 ; - -/* Find end of nidlist */ -while (class_parse_nid_quiet (tail, &nid, &tail) ==0 ) - ; - length = tail - *ptr; -if (length ==0 ) { -LCONSOLE_ERROR_MSG (0x159 ,"Can't parse NID '%s'\n" , *ptr); -return -EINVAL ; - } - -if (lmd->lmd_mgs) - oldlen =strlen (lmd->lmd_mgs) +1 ; - - mgsnid =kzalloc (oldlen + length +1 ,GFP_NOFS ); -if (!mgsnid) -return -ENOMEM ; - -if (lmd->lmd_mgs) { -/* Multiple mgsnid= are taken to mean failover locations */ -memcpy (mgsnid, lmd->lmd_mgs, oldlen); - mgsnid[oldlen -1 ] =':' ; -kfree (lmd->lmd_mgs); - } -memcpy (mgsnid + oldlen, *ptr, length); - mgsnid[oldlen + length] ='\0' ; - lmd->lmd_mgs = mgsnid; - *ptr = tail; - -return 0 ; -} - -/** -* Find the first delimiter (comma or colon) from the specified \a buf and -* make \a *endh point to the string starting with the delimiter. The commas -* in expression list [...] will be skipped. -* -* @buf a delimiter-separated string -* @endh a pointer to a pointer that will point to the string -* starting with the delimiter -* -* RETURNS true if delimiter is found, false if delimiter is not found -*/ -static bool lmd_find_delimiter (char *buf,char **endh) -{ -char *c = buf; -size_t pos; -bool found; - -if (!buf) -return false; -try_again: -if (*c ==',' || *c ==':' ) -return true; - - pos =strcspn (c,"[:,]" ); -if (!pos) -return false; - -/* Not a valid mount string */ -if (*c ==']' ) { -CWARN ("invalid mount string format\n" ); -return false; - } - - c += pos; -if (*c =='[' ) { - c =strchr (c,']' ); - -/* invalid mount string */ -if (!c) { -CWARN ("invalid mount string format\n" ); -return false; - } - c++; - goto try_again; - } - - found = *c !='\0' ; -if (found && endh) - *endh = c; - -return found; -} - -/** -* Find the first valid string delimited by comma or colon from the specified -* \a buf and parse it to see whether it's a valid nid list. If yes, \a *endh -* will point to the next string starting with the delimiter. -* -* \param[in] buf a delimiter-separated string -* \param[in] endh a pointer to a pointer that will point to the string -* starting with the delimiter -* -* \retval 0 if the string is a valid nid list -* \retval 1 if the string is not a valid nid list -*/ -static int lmd_parse_nidlist (char *buf,char **endh) -{ -struct list_head nidlist; -char *endp = buf; -int rc =0 ; -char tmp; - -if (!buf) -return 1 ; -while (*buf ==',' || *buf ==':' ) - buf++; -if (*buf ==' ' || *buf =='/' || *buf =='\0' ) -return 1 ; - -if (!lmd_find_delimiter (buf, &endp)) - endp = buf +strlen (buf); - - tmp = *endp; - *endp ='\0' ; - -INIT_LIST_HEAD (&nidlist); -if (cfs_parse_nidlist (buf,strlen (buf), &nidlist) <=0 ) - rc =1 ; -cfs_free_nidlist (&nidlist); - - *endp = tmp; -if (rc) -return rc; -if (endh) - *endh = endp; -return 0 ; -} - -/** Parse mount line options -* e.g. mount -v -t lustre -o abort_recov uml1:uml2:/lustre-client /mnt/lustre -* dev is passed as device=uml1:/lustre by mount.lustre -*/ -static int lmd_parse (char *options,struct lustre_mount_data *lmd) -{ -char *s1, *s2, *devname =NULL ; -struct lustre_mount_data *raw = (struct lustre_mount_data *)options; -int rc =0 ; - -LASSERT (lmd); -if (!options) { -LCONSOLE_ERROR_MSG (0x162 ,"Missing mount data: check that /sbin/mount.lustre is installed.\n" ); -return -EINVAL ; - } - -/* Options should be a string - try to detect old lmd data */ -if ((raw->lmd_magic &0xffffff00 ) == (LMD_MAGIC &0xffffff00 )) { -LCONSOLE_ERROR_MSG (0x163 ,"You're using an old version of /sbin/mount.lustre. Please install version %s\n" , -LUSTRE_VERSION_STRING ); -return -EINVAL ; - } - lmd->lmd_magic =LMD_MAGIC ; - - lmd->lmd_params =kzalloc (LMD_PARAMS_MAXLEN ,GFP_NOFS ); -if (!lmd->lmd_params) -return -ENOMEM ; - lmd->lmd_params[0 ] ='\0' ; - -/* Set default flags here */ - - s1 = options; -while (*s1) { -int clear =0 ; -int time_min =OBD_RECOVERY_TIME_MIN ; -char *s3; - -/* Skip whitespace and extra commas */ -while (*s1 ==' ' || *s1 ==',' ) - s1++; - s3 = s1; - -/* Client options are parsed in ll_options: eg. flock, -* user_xattr, acl -*/ - -/* Parse non-ldiskfs options here. Rather than modifying -* ldiskfs, we just zero these out here -*/ -if (strncmp (s1,"abort_recov" ,11 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_ABORT_RECOV ; - clear++; - }else if (strncmp (s1,"recovery_time_soft=" ,19 ) ==0 ) { - lmd->lmd_recovery_time_soft =max_t (int, -simple_strtoul (s1 +19 ,NULL ,10 ), time_min); - clear++; - }else if (strncmp (s1,"recovery_time_hard=" ,19 ) ==0 ) { - lmd->lmd_recovery_time_hard =max_t (int, -simple_strtoul (s1 +19 ,NULL ,10 ), time_min); - clear++; - }else if (strncmp (s1,"noir" ,4 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOIR ;/* test purpose only. */ - clear++; - }else if (strncmp (s1,"nosvc" ,5 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOSVC ; - clear++; - }else if (strncmp (s1,"nomgs" ,5 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOMGS ; - clear++; - }else if (strncmp (s1,"noscrub" ,7 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NOSCRUB ; - clear++; - }else if (strncmp (s1,PARAM_MGSNODE , -sizeof (PARAM_MGSNODE ) -1 ) ==0 ) { - s2 = s1 +sizeof (PARAM_MGSNODE ) -1 ; -/* Assume the next mount opt is the first -* invalid nid we get to. -*/ - rc =lmd_parse_mgs (lmd, &s2); -if (rc) - goto invalid; - clear++; - }else if (strncmp (s1,"writeconf" ,9 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_WRITECONF ; - clear++; - }else if (strncmp (s1,"update" ,6 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_UPDATE ; - clear++; - }else if (strncmp (s1,"virgin" ,6 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_VIRGIN ; - clear++; - }else if (strncmp (s1,"noprimnode" ,10 ) ==0 ) { - lmd->lmd_flags |=LMD_FLG_NO_PRIMNODE ; - clear++; - }else if (strncmp (s1,"mgssec=" ,7 ) ==0 ) { - rc =lmd_parse_mgssec (lmd, s1 +7 ); -if (rc) - goto invalid; - s3 = s2; - clear++; -/* ost exclusion list */ - }else if (strncmp (s1,"exclude=" ,8 ) ==0 ) { - rc =lmd_make_exclusion (lmd, s1 +7 ); -if (rc) - goto invalid; - clear++; - }else if (strncmp (s1,"mgs" ,3 ) ==0 ) { -/* We are an MGS */ - lmd->lmd_flags |=LMD_FLG_MGS ; - clear++; - }else if (strncmp (s1,"svname=" ,7 ) ==0 ) { - rc =lmd_parse_string (&lmd->lmd_profile, s1 +7 ); -if (rc) - goto invalid; - clear++; - }else if (strncmp (s1,"param=" ,6 ) ==0 ) { -size_t length, params_length; -char *tail = s1; - -if (lmd_find_delimiter (s1 +6 , &tail)) { -char *param_str = tail +1 ; -int supplementary =1 ; - -while (!lmd_parse_nidlist (param_str, - ¶m_str)) - supplementary =0 ; - length = param_str - s1 - supplementary; - }else { - length =strlen (s1); - } - length -=6 ; - params_length =strlen (lmd->lmd_params); -if (params_length + length +1 >=LMD_PARAMS_MAXLEN ) -return -E2BIG ; -strncat (lmd->lmd_params, s1 +6 , length); - lmd->lmd_params[params_length + length] ='\0' ; -strlcat (lmd->lmd_params," " ,LMD_PARAMS_MAXLEN ); - s3 = s1 +6 + length; - clear++; - }else if (strncmp (s1,"osd=" ,4 ) ==0 ) { - rc =lmd_parse_string (&lmd->lmd_osd_type, s1 +4 ); -if (rc) - goto invalid; - clear++; - } -/* Linux 2.4 doesn't pass the device, so we stuck it at the -* end of the options. -*/ -else if (strncmp (s1,"device=" ,7 ) ==0 ) { - devname = s1 +7 ; -/* terminate options right before device. device -* must be the last one. -*/ - *s1 ='\0' ; -break ; - } - -/* Find next opt */ - s2 =strchr (s1,',' ); -if (!s2) { -if (clear) - *s1 ='\0' ; -break ; - } - s2++; -if (clear) -memmove (s1, s2,strlen (s2) +1 ); -else - s1 = s2; - } - -if (!devname) { -LCONSOLE_ERROR_MSG (0x164 ,"Can't find the device name (need mount option 'device=...')\n" ); - goto invalid; - } - - s1 =strstr (devname,":/" ); -if (s1) { - ++s1; - lmd->lmd_flags |=LMD_FLG_CLIENT ; -/* Remove leading /s from fsname */ -while (*++s1 =='/' ) - ; - s2 =strchrnul (s1,'/' ); -/* Freed in lustre_free_lsi */ - lmd->lmd_profile =kasprintf (GFP_KERNEL ,"%.*s-client" , - (int )(s2 - s1), s1); -if (!lmd->lmd_profile) -return -ENOMEM ; - - s1 = s2; - s2 = s1 +strlen (s1) -1 ; -/* Remove padding /s from fileset */ -while (*s2 =='/' ) - s2--; -if (s2 > s1) { - lmd->lmd_fileset =kstrndup (s1, s2 - s1 +1 , -GFP_KERNEL ); -if (!lmd->lmd_fileset) -return -ENOMEM ; - } - } - -/* Freed in lustre_free_lsi */ - lmd->lmd_dev =kstrdup (devname,GFP_KERNEL ); -if (!lmd->lmd_dev) -return -ENOMEM ; - -/* Save mount options */ - s1 = options +strlen (options) -1 ; -while (s1 >= options && (*s1 ==',' || *s1 ==' ' )) - *s1-- =0 ; -if (*options !=0 ) { -/* Freed in lustre_free_lsi */ - lmd->lmd_opts =kstrdup (options,GFP_KERNEL ); -if (!lmd->lmd_opts) -return -ENOMEM ; - } - -lmd_print (lmd); - lmd->lmd_magic =LMD_MAGIC ; - -return rc; - -invalid: -CERROR ("Bad mount options %s\n" , options); -return -EINVAL ; -} - -/** This is the entry point for the mount call into Lustre. -* This is called when a server or client is mounted, -* and this is where we start setting things up. -* @param data Mount options (e.g. -o flock,abort_recov) -*/ -static int lustre_fill_super (struct super_block *sb,void *lmd2_data,int silent) -{ -struct lustre_mount_data *lmd; -struct lustre_sb_info *lsi; -int rc; - -CDEBUG (D_MOUNT |D_VFSTRACE ,"VFS Op: sb %p\n" , sb); - - lsi =lustre_init_lsi (sb); -if (!lsi) -return -ENOMEM ; - lmd = lsi->lsi_lmd; - -/* -* Disable lockdep during mount, because mount locking patterns are -* `special'. -*/ -lockdep_off (); - -/* -* LU-639: the obd cleanup of last mount may not finish yet, wait here. -*/ -obd_zombie_barrier (); - -/* Figure out the lmd from the mount options */ -if (lmd_parse (lmd2_data, lmd)) { -lustre_put_lsi (sb); - rc = -EINVAL ; - goto out; - } - -if (lmd_is_client (lmd)) { -bool have_client = false; -CDEBUG (D_MOUNT ,"Mounting client %s\n" , lmd->lmd_profile); -if (!client_fill_super) -request_module ("lustre" ); -spin_lock (&client_lock); -if (client_fill_super &&try_module_get (client_mod)) - have_client = true; -spin_unlock (&client_lock); -if (!have_client) { -LCONSOLE_ERROR_MSG (0x165 ,"Nothing registered for client mount! Is the 'lustre' module loaded?\n" ); -lustre_put_lsi (sb); - rc = -ENODEV ; - }else { - rc =lustre_start_mgc (sb); -if (rc) { -lustre_common_put_super (sb); - goto out; - } -/* Connect and start */ -/* (should always be ll_fill_super) */ - rc = (*client_fill_super)(sb); -/* c_f_s will call lustre_common_put_super on failure, otherwise -* c_f_s will have taken another reference to the module */ -module_put (client_mod); - } - }else { -CERROR ("This is client-side-only module, cannot handle server mount.\n" ); - rc = -EINVAL ; - } - -/* If error happens in fill_super() call, @lsi will be killed there. -* This is why we do not put it here. -*/ - goto out; -out: -if (rc) { -CERROR ("Unable to mount %s (%d)\n" , -s2lsi (sb) ? lmd->lmd_dev :"" , rc); - }else { -CDEBUG (D_SUPER ,"Mount %s complete\n" , - lmd->lmd_dev); - } -lockdep_on (); -return rc; -} - -/* We can't call ll_fill_super by name because it lives in a module that -* must be loaded after this one. -*/ -void lustre_register_super_ops (struct module *mod, -int (*cfs)(struct super_block *sb), -void (*ksc)(struct super_block *sb)) -{ -spin_lock (&client_lock); - client_mod = mod; - client_fill_super = cfs; - kill_super_cb = ksc; -spin_unlock (&client_lock); -} -EXPORT_SYMBOL (lustre_register_super_ops); - -/***************** FS registration ******************/ -static struct dentry *lustre_mount (struct file_system_type *fs_type,int flags, -const char *devname,void *data) -{ -return mount_nodev (fs_type, flags, data, lustre_fill_super); -} - -static void lustre_kill_super (struct super_block *sb) -{ -struct lustre_sb_info *lsi =s2lsi (sb); - -if (kill_super_cb && lsi) - (*kill_super_cb)(sb); - -kill_anon_super (sb); -} - -/** Register the "lustre" fs type -*/ -static struct file_system_type lustre_fs_type = { - .owner =THIS_MODULE , - .name ="lustre" , - .mount = lustre_mount, - .kill_sb = lustre_kill_super, - .fs_flags =FS_RENAME_DOES_D_MOVE , -}; -MODULE_ALIAS_FS ("lustre" ); - -int lustre_register_fs (void ) -{ -return register_filesystem (&lustre_fs_type); -}
Quoted 8 lines
drivers/staging/lustre/lustre/obdclass/obd_mount.c line 1244
Quoted 8 lines
drivers/staging/lustre/lustre/obdclass/obd_mount.c deleted +0
-5- -int lustre_unregister_fs (void ) -{ -return unregister_filesystem (&lustre_fs_type); -}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180730/a947e71e/attachment-0001.sig>
PATCH 6/9 lustre: hold ptlrpc active for lustre_start_mgc()
In reply to NeilBrownCommit 26f7a294e5ec ("staging: lustre: ptlrpc: move thread creation out of module initialization") move ptlrpc initialization out of module_init() and into explicit ptlrpc_inc_ref() calls. This was added in ll_fill_super with a put_ref in ll_put_super(). Unfortunately this means lustre_fill_super calls lustre_start_mgc() without first activating ptlrpc.
So move the inc/put ref calls to lustre_fill_super() and lustre_common_put_super() respectively.
--- drivers/staging/lustre/lustre/llite/llite_lib.c | 17 +++-------------- drivers/staging/lustre/lustre/llite/mount.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 16 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +3 -14
@@ -911,15 +911,9 @@ int ll_fill_super(struct super_block *sb)CDEBUG (D_VFSTRACE ,"VFS Op: sb %p\n" , sb); - err =ptlrpc_inc_ref (); -if (err) -return err; - cfg =kzalloc (sizeof (*cfg),GFP_NOFS ); -if (!cfg) { - err = -ENOMEM ; - goto out_put; - } +if (!cfg) +return -ENOMEM ;try_module_get (THIS_MODULE );
@@ -929,8 +923,7 @@ int ll_fill_super(struct super_block *sb)if (!sbi) {module_put (THIS_MODULE );kfree (cfg); - err = -ENOMEM ; - goto out_put; +return -ENOMEM ; } err =ll_options (lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
@@ -997,9 +990,6 @@ int ll_fill_super(struct super_block *sb)LCONSOLE_WARN ("Mounted %s\n" , profilenm);kfree (cfg); -out_put: -if (err) -ptlrpc_dec_ref ();return err; }/* ll_fill_super */
@@ -1071,7 +1061,6 @@ void ll_put_super(struct super_block *sb)module_put (THIS_MODULE ); -ptlrpc_dec_ref (); }/* client_put_super */ struct inode *ll_inode_from_resource_lock (struct ldlm_lock *lock)
drivers/staging/lustre/lustre/llite/mount.c +8 -2
@@ -596,6 +596,7 @@ int lustre_common_put_super(struct super_block *sb) }/* Drop a ref to the mounted disk */ lustre_put_lsi (sb); +ptlrpc_dec_ref ();return rc; }
@@ -1131,16 +1132,19 @@ static int lustre_fill_super(struct super_block *sb, void *lmd2_data, int silent/* Figure out the lmd from the mount options */ if (lmd_parse (lmd2_data, lmd)) { -lustre_put_lsi (sb); rc = -EINVAL ; - goto out; + goto out_put_lsi; }if (lmd_is_client (lmd)) {CDEBUG (D_MOUNT ,"Mounting client %s\n" , lmd->lmd_profile); + rc =ptlrpc_inc_ref (); +if (rc) + goto out_put_lsi; rc =lustre_start_mgc (sb);if (rc) { +/* This will put_lsi and ptlrpc_dec_ref() */ lustre_common_put_super (sb); goto out; }
@@ -1157,6 +1161,8 @@ static int lustre_fill_super(struct super_block *sb, void *lmd2_data, int silent* This is why we do not put it here. */ goto out; +out_put_lsi: +lustre_put_lsi (sb); out:if (rc) { CERROR("Unable to mount %s (%d)\n",
PATCH 7/9 lustre: ll_fill_super() must put sb on all failure paths.
In reply to NeilBrownlustre_fill_super() has comment saying:
/* * l_f_s will call lustre_common_put_super on failure, otherwise * l_f_s will have taken another reference to the module */
But this is not the case - ENOMEM error do not result in a 'put'. So add appropriate calls to lustre_common_put_super().
--- drivers/staging/lustre/lustre/llite/llite_lib.c | 5 ++++- drivers/staging/lustre/lustre/llite/mount.c | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +4 -1
@@ -912,8 +912,10 @@ int ll_fill_super(struct super_block *sb)CDEBUG (D_VFSTRACE ,"VFS Op: sb %p\n" , sb); cfg =kzalloc (sizeof (*cfg),GFP_NOFS ); -if (!cfg) +if (!cfg) { +lustre_common_put_super (sb);return -ENOMEM ; + }try_module_get (THIS_MODULE );
@@ -923,6 +925,7 @@ int ll_fill_super(struct super_block *sb)if (!sbi) {module_put (THIS_MODULE );kfree (cfg); +lustre_common_put_super (sb);return -ENOMEM ; }
drivers/staging/lustre/lustre/llite/mount.c +4 -2
@@ -1150,8 +1150,10 @@ static int lustre_fill_super(struct super_block *sb, void *lmd2_data, int silent }/* Connect and start */ rc =ll_fill_super (sb); -/* l_f_s will call lustre_common_put_super on failure, otherwise -* l_f_s will have taken another reference to the module */ +/* +* l_f_s will call lustre_common_put_super on failure, otherwise +* l_f_s will have taken another reference to the module +*/ }else {CERROR ("This is client-side-only module, cannot handle server mount.\n" ); rc = -EINVAL ;
PATCH 8/9 lustre: ensure libcfs is set up for ioctls.
In reply to NeilBrownlibcfs only allocated various buffers when libcfs_setup() is called.
This should be called before any significant libcfs related activity. However it isn't called by libcfs_ioctl(). So if the first thing that happens is an ioctl, tracing can cause NULL pointer dereferences.
--- drivers/staging/lustre/lnet/libcfs/module.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/lustre/lnet/libcfs/module.c +3 -0
@@ -206,6 +206,9 @@ static int libcfs_ioctl(unsigned long cmd, void __user *uparam)struct libcfs_ioctl_hdr *hdr;int err; + err =libcfs_setup (); +if (err) +return err;/* 'cmd' and permissions get checked in our arch-specific caller */ err =libcfs_ioctl_getdata (&hdr, uparam);if (err) {
PATCH 8/9 lustre: ensure libcfs is set up for ioctls.
Quoted 7 lines
libcfs only allocated various buffers when
libcfs_setup()is called.
This should be called before any significant libcfs related activity. However it isn't called bylibcfs_ioctl(). So if the first thing that happens is an ioctl, tracing can cause NULL pointer dereferences.
Quoted 23 lines
Fixes 64bf0b1a079d ("staging: lustre: refactor libcfs initialization.")Signed-off-by NeilBrown <[email protected]>--- drivers/staging/lustre/lnet/libcfs/module.c | 3 +++ 1 file changed, 3 insertions(+)drivers/staging/lustre/lnet/libcfs/module.c +3
-0@@ -206,6 +206,9 @@ static int libcfs_ioctl(unsigned long cmd, void __user *uparam)struct libcfs_ioctl_hdr *hdr;int err; + err =libcfs_setup (); +if (err) +return err;/* 'cmd' and permissions get checked in our arch-specific caller */ err =libcfs_ioctl_getdata (&hdr, uparam);if (err) {
PATCH 9/9 lustre: lnet: discard LNET_LOCK()
In reply to NeilBrownThis macro, and LNET_UNLOCK() are rarely used, don't add clarify, and make greping for lock usage harder. So discard macro and just the lnet_net_{un,}lock() like everyone else.
--- .../staging/lustre/include/linux/lnet/lib-lnet.h | 3 --- .../lustre/lnet/klnds/socklnd/socklnd_proto.c | 8 ++++---- drivers/staging/lustre/lnet/selftest/rpc.c | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +0 -3
@@ -177,9 +177,6 @@ lnet_net_lock_current(void)return cpt; } -#define LNET_LOCK () lnet_net_lock(LNET_LOCK_EX) -#define LNET_UNLOCK () lnet_net_unlock(LNET_LOCK_EX) -#define lnet_ptl_lock (ptl) spin_lock(&(ptl)->ptl_lock)#define lnet_ptl_unlock (ptl) spin_unlock(&(ptl)->ptl_lock)#define lnet_eq_wait_lock () spin_lock(&the_lnet.ln_eq_wait_lock)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c +4 -4
@@ -485,7 +485,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)if (the_lnet.ln_testprotocompat) {/* single-shot proto check */ -LNET_LOCK (); +lnet_net_lock (LNET_LOCK_EX );if (the_lnet.ln_testprotocompat &1 ) { hmv->version_major++;/* just different! */ the_lnet.ln_testprotocompat &= ~1 ;
@@ -494,7 +494,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello) hmv->magic =LNET_PROTO_MAGIC ; the_lnet.ln_testprotocompat &= ~2 ; } -LNET_UNLOCK (); +lnet_net_unlock (LNET_LOCK_EX ); } hdr->src_nid =cpu_to_le64 (hello->kshm_src_nid);
@@ -542,12 +542,12 @@ ksocknal_send_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello)if (the_lnet.ln_testprotocompat) {/* single-shot proto check */ -LNET_LOCK (); +lnet_net_lock (LNET_LOCK_EX );if (the_lnet.ln_testprotocompat &1 ) { hello->kshm_version++;/* just different! */ the_lnet.ln_testprotocompat &= ~1 ; } -LNET_UNLOCK (); +lnet_net_unlock (LNET_LOCK_EX ); } rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
drivers/staging/lustre/lnet/selftest/rpc.c +1 -1
@@ -1399,7 +1399,7 @@ srpc_send_reply(struct srpc_server_rpc *rpc)return rc; } -/* when in kernel always called with LNET_LOCK() held, and in thread context */ +/* when in kernel always called with lnet_net_lock() held, and in thread context */ static void srpc_lnet_ev_handler (struct lnet_event *ev) {
PATCH 9/9 lustre: lnet: discard LNET_LOCK()
Quoted 5 lines
This macro, and
LNET_UNLOCK()are rarely used, don't add clarify, and make greping for lock usage harder. So discard macro and just the lnet_net_{un,}lock() like everyone else.
Quoted 74 lines
Signed-off-by NeilBrown <[email protected]>--- .../staging/lustre/include/linux/lnet/lib-lnet.h | 3 --- .../lustre/lnet/klnds/socklnd/socklnd_proto.c | 8 ++++---- drivers/staging/lustre/lnet/selftest/rpc.c | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-)drivers/staging/lustre/include/linux/lnet/lib-lnet.h +0
-3@@ -177,9 +177,6 @@ lnet_net_lock_current(void)return cpt; } -#define LNET_LOCK () lnet_net_lock(LNET_LOCK_EX) -#define LNET_UNLOCK () lnet_net_unlock(LNET_LOCK_EX) -#define lnet_ptl_lock (ptl) spin_lock(&(ptl)->ptl_lock)#define lnet_ptl_unlock (ptl) spin_unlock(&(ptl)->ptl_lock)#define lnet_eq_wait_lock () spin_lock(&the_lnet.ln_eq_wait_lock)drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c +4
-4@@ -485,7 +485,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)if (the_lnet.ln_testprotocompat) {/* single-shot proto check */ -LNET_LOCK (); +lnet_net_lock (LNET_LOCK_EX );if (the_lnet.ln_testprotocompat &1 ) { hmv->version_major++;/* just different! */ the_lnet.ln_testprotocompat &= ~1 ;@@ -494,7 +494,7 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello) hmv->magic =LNET_PROTO_MAGIC ; the_lnet.ln_testprotocompat &= ~2 ; } -LNET_UNLOCK (); +lnet_net_unlock (LNET_LOCK_EX ); } hdr->src_nid =cpu_to_le64 (hello->kshm_src_nid);@@ -542,12 +542,12 @@ ksocknal_send_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello)if (the_lnet.ln_testprotocompat) {/* single-shot proto check */ -LNET_LOCK (); +lnet_net_lock (LNET_LOCK_EX );if (the_lnet.ln_testprotocompat &1 ) { hello->kshm_version++;/* just different! */ the_lnet.ln_testprotocompat &= ~1 ; } -LNET_UNLOCK (); +lnet_net_unlock (LNET_LOCK_EX ); } rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),drivers/staging/lustre/lnet/selftest/rpc.c +1
-1@@ -1399,7 +1399,7 @@ srpc_send_reply(struct srpc_server_rpc *rpc)return rc; } -/* when in kernel always called with LNET_LOCK() held, and in thread context */ +/* when in kernel always called with lnet_net_lock() held, and in thread context */ static void srpc_lnet_ev_handler (struct lnet_event *ev) {