cifsfs.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  1. /*
  2. * fs/cifs/cifsfs.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2008
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  7. * Common Internet FileSystem (CIFS) client
  8. *
  9. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published
  11. * by the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /* Note that BB means BUGBUG (ie something to fix eventually) */
  24. #include <linux/module.h>
  25. #include <linux/fs.h>
  26. #include <linux/mount.h>
  27. #include <linux/slab.h>
  28. #include <linux/init.h>
  29. #include <linux/list.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/vfs.h>
  32. #include <linux/mempool.h>
  33. #include <linux/delay.h>
  34. #include <linux/kthread.h>
  35. #include <linux/freezer.h>
  36. #include <linux/namei.h>
  37. #include <net/ipv6.h>
  38. #include "cifsfs.h"
  39. #include "cifspdu.h"
  40. #define DECLARE_GLOBALS_HERE
  41. #include "cifsglob.h"
  42. #include "cifsproto.h"
  43. #include "cifs_debug.h"
  44. #include "cifs_fs_sb.h"
  45. #include <linux/mm.h>
  46. #include <linux/key-type.h>
  47. #include "cifs_spnego.h"
  48. #include "fscache.h"
  49. #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
  50. int cifsFYI = 0;
  51. int cifsERROR = 1;
  52. int traceSMB = 0;
  53. bool enable_oplocks = true;
  54. unsigned int linuxExtEnabled = 1;
  55. unsigned int lookupCacheEnabled = 1;
  56. unsigned int multiuser_mount = 0;
  57. unsigned int global_secflags = CIFSSEC_DEF;
  58. /* unsigned int ntlmv2_support = 0; */
  59. unsigned int sign_CIFS_PDUs = 1;
  60. static const struct super_operations cifs_super_ops;
  61. unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
  62. module_param(CIFSMaxBufSize, int, 0);
  63. MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
  64. "Default: 16384 Range: 8192 to 130048");
  65. unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
  66. module_param(cifs_min_rcv, int, 0);
  67. MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
  68. "1 to 64");
  69. unsigned int cifs_min_small = 30;
  70. module_param(cifs_min_small, int, 0);
  71. MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
  72. "Range: 2 to 256");
  73. unsigned int cifs_max_pending = CIFS_MAX_REQ;
  74. module_param(cifs_max_pending, int, 0444);
  75. MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
  76. "Default: 32767 Range: 2 to 32767.");
  77. module_param(enable_oplocks, bool, 0644);
  78. MODULE_PARM_DESC(enable_oplocks, "Enable or disable oplocks (bool). Default:"
  79. "y/Y/1");
  80. extern mempool_t *cifs_sm_req_poolp;
  81. extern mempool_t *cifs_req_poolp;
  82. extern mempool_t *cifs_mid_poolp;
  83. struct workqueue_struct *cifsiod_wq;
  84. /*
  85. * Bumps refcount for cifs super block.
  86. * Note that it should be only called if a referece to VFS super block is
  87. * already held, e.g. in open-type syscalls context. Otherwise it can race with
  88. * atomic_dec_and_test in deactivate_locked_super.
  89. */
  90. void
  91. cifs_sb_active(struct super_block *sb)
  92. {
  93. struct cifs_sb_info *server = CIFS_SB(sb);
  94. if (atomic_inc_return(&server->active) == 1)
  95. atomic_inc(&sb->s_active);
  96. }
  97. void
  98. cifs_sb_deactive(struct super_block *sb)
  99. {
  100. struct cifs_sb_info *server = CIFS_SB(sb);
  101. if (atomic_dec_and_test(&server->active))
  102. deactivate_super(sb);
  103. }
  104. static int
  105. cifs_read_super(struct super_block *sb)
  106. {
  107. struct inode *inode;
  108. struct cifs_sb_info *cifs_sb;
  109. int rc = 0;
  110. cifs_sb = CIFS_SB(sb);
  111. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIXACL)
  112. sb->s_flags |= MS_POSIXACL;
  113. if (cifs_sb_master_tcon(cifs_sb)->ses->capabilities & CAP_LARGE_FILES)
  114. sb->s_maxbytes = MAX_LFS_FILESIZE;
  115. else
  116. sb->s_maxbytes = MAX_NON_LFS;
  117. /* BB FIXME fix time_gran to be larger for LANMAN sessions */
  118. sb->s_time_gran = 100;
  119. sb->s_magic = CIFS_MAGIC_NUMBER;
  120. sb->s_op = &cifs_super_ops;
  121. sb->s_bdi = &cifs_sb->bdi;
  122. sb->s_blocksize = CIFS_MAX_MSGSIZE;
  123. sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
  124. inode = cifs_root_iget(sb);
  125. if (IS_ERR(inode)) {
  126. rc = PTR_ERR(inode);
  127. goto out_no_root;
  128. }
  129. sb->s_root = d_make_root(inode);
  130. if (!sb->s_root) {
  131. rc = -ENOMEM;
  132. goto out_no_root;
  133. }
  134. /* do that *after* d_alloc_root() - we want NULL ->d_op for root here */
  135. if (cifs_sb_master_tcon(cifs_sb)->nocase)
  136. sb->s_d_op = &cifs_ci_dentry_ops;
  137. else
  138. sb->s_d_op = &cifs_dentry_ops;
  139. #ifdef CONFIG_CIFS_NFSD_EXPORT
  140. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
  141. cFYI(1, "export ops supported");
  142. sb->s_export_op = &cifs_export_ops;
  143. }
  144. #endif /* CONFIG_CIFS_NFSD_EXPORT */
  145. return 0;
  146. out_no_root:
  147. cERROR(1, "cifs_read_super: get root inode failed");
  148. return rc;
  149. }
  150. static void cifs_kill_sb(struct super_block *sb)
  151. {
  152. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  153. kill_anon_super(sb);
  154. cifs_umount(cifs_sb);
  155. }
  156. static int
  157. cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
  158. {
  159. struct super_block *sb = dentry->d_sb;
  160. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  161. struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
  162. int rc = -EOPNOTSUPP;
  163. int xid;
  164. xid = GetXid();
  165. buf->f_type = CIFS_MAGIC_NUMBER;
  166. /*
  167. * PATH_MAX may be too long - it would presumably be total path,
  168. * but note that some servers (includinng Samba 3) have a shorter
  169. * maximum path.
  170. *
  171. * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
  172. */
  173. buf->f_namelen = PATH_MAX;
  174. buf->f_files = 0; /* undefined */
  175. buf->f_ffree = 0; /* unlimited */
  176. /*
  177. * We could add a second check for a QFS Unix capability bit
  178. */
  179. if ((tcon->ses->capabilities & CAP_UNIX) &&
  180. (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
  181. rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
  182. /*
  183. * Only need to call the old QFSInfo if failed on newer one,
  184. * e.g. by OS/2.
  185. **/
  186. if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
  187. rc = CIFSSMBQFSInfo(xid, tcon, buf);
  188. /*
  189. * Some old Windows servers also do not support level 103, retry with
  190. * older level one if old server failed the previous call or we
  191. * bypassed it because we detected that this was an older LANMAN sess
  192. */
  193. if (rc)
  194. rc = SMBOldQFSInfo(xid, tcon, buf);
  195. FreeXid(xid);
  196. return 0;
  197. }
  198. static int cifs_permission(struct inode *inode, int mask)
  199. {
  200. struct cifs_sb_info *cifs_sb;
  201. cifs_sb = CIFS_SB(inode->i_sb);
  202. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
  203. if ((mask & MAY_EXEC) && !execute_ok(inode))
  204. return -EACCES;
  205. else
  206. return 0;
  207. } else /* file mode might have been restricted at mount time
  208. on the client (above and beyond ACL on servers) for
  209. servers which do not support setting and viewing mode bits,
  210. so allowing client to check permissions is useful */
  211. return generic_permission(inode, mask);
  212. }
  213. static struct kmem_cache *cifs_inode_cachep;
  214. static struct kmem_cache *cifs_req_cachep;
  215. static struct kmem_cache *cifs_mid_cachep;
  216. static struct kmem_cache *cifs_sm_req_cachep;
  217. mempool_t *cifs_sm_req_poolp;
  218. mempool_t *cifs_req_poolp;
  219. mempool_t *cifs_mid_poolp;
  220. static struct inode *
  221. cifs_alloc_inode(struct super_block *sb)
  222. {
  223. struct cifsInodeInfo *cifs_inode;
  224. cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
  225. if (!cifs_inode)
  226. return NULL;
  227. cifs_inode->cifsAttrs = 0x20; /* default */
  228. cifs_inode->time = 0;
  229. /* Until the file is open and we have gotten oplock
  230. info back from the server, can not assume caching of
  231. file data or metadata */
  232. cifs_set_oplock_level(cifs_inode, 0);
  233. cifs_inode->delete_pending = false;
  234. cifs_inode->invalid_mapping = false;
  235. cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
  236. cifs_inode->server_eof = 0;
  237. cifs_inode->uniqueid = 0;
  238. cifs_inode->createtime = 0;
  239. /* Can not set i_flags here - they get immediately overwritten
  240. to zero by the VFS */
  241. /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
  242. INIT_LIST_HEAD(&cifs_inode->openFileList);
  243. return &cifs_inode->vfs_inode;
  244. }
  245. static void cifs_i_callback(struct rcu_head *head)
  246. {
  247. struct inode *inode = container_of(head, struct inode, i_rcu);
  248. kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
  249. }
  250. static void
  251. cifs_destroy_inode(struct inode *inode)
  252. {
  253. call_rcu(&inode->i_rcu, cifs_i_callback);
  254. }
  255. static void
  256. cifs_evict_inode(struct inode *inode)
  257. {
  258. truncate_inode_pages(&inode->i_data, 0);
  259. end_writeback(inode);
  260. cifs_fscache_release_inode_cookie(inode);
  261. }
  262. static void
  263. cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
  264. {
  265. struct sockaddr_in *sa = (struct sockaddr_in *) &server->dstaddr;
  266. struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) &server->dstaddr;
  267. seq_printf(s, ",addr=");
  268. switch (server->dstaddr.ss_family) {
  269. case AF_INET:
  270. seq_printf(s, "%pI4", &sa->sin_addr.s_addr);
  271. break;
  272. case AF_INET6:
  273. seq_printf(s, "%pI6", &sa6->sin6_addr.s6_addr);
  274. if (sa6->sin6_scope_id)
  275. seq_printf(s, "%%%u", sa6->sin6_scope_id);
  276. break;
  277. default:
  278. seq_printf(s, "(unknown)");
  279. }
  280. }
  281. static void
  282. cifs_show_security(struct seq_file *s, struct TCP_Server_Info *server)
  283. {
  284. seq_printf(s, ",sec=");
  285. switch (server->secType) {
  286. case LANMAN:
  287. seq_printf(s, "lanman");
  288. break;
  289. case NTLMv2:
  290. seq_printf(s, "ntlmv2");
  291. break;
  292. case NTLM:
  293. seq_printf(s, "ntlm");
  294. break;
  295. case Kerberos:
  296. seq_printf(s, "krb5");
  297. break;
  298. case RawNTLMSSP:
  299. seq_printf(s, "ntlmssp");
  300. break;
  301. default:
  302. /* shouldn't ever happen */
  303. seq_printf(s, "unknown");
  304. break;
  305. }
  306. if (server->sec_mode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  307. seq_printf(s, "i");
  308. }
  309. /*
  310. * cifs_show_options() is for displaying mount options in /proc/mounts.
  311. * Not all settable options are displayed but most of the important
  312. * ones are.
  313. */
  314. static int
  315. cifs_show_options(struct seq_file *s, struct dentry *root)
  316. {
  317. struct cifs_sb_info *cifs_sb = CIFS_SB(root->d_sb);
  318. struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
  319. struct sockaddr *srcaddr;
  320. srcaddr = (struct sockaddr *)&tcon->ses->server->srcaddr;
  321. cifs_show_security(s, tcon->ses->server);
  322. seq_printf(s, ",unc=%s", tcon->treeName);
  323. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER)
  324. seq_printf(s, ",multiuser");
  325. else if (tcon->ses->user_name)
  326. seq_show_option(s, "username", tcon->ses->user_name);
  327. if (tcon->ses->domainName)
  328. seq_show_option(s, "domain", tcon->ses->domainName);
  329. if (srcaddr->sa_family != AF_UNSPEC) {
  330. struct sockaddr_in *saddr4;
  331. struct sockaddr_in6 *saddr6;
  332. saddr4 = (struct sockaddr_in *)srcaddr;
  333. saddr6 = (struct sockaddr_in6 *)srcaddr;
  334. if (srcaddr->sa_family == AF_INET6)
  335. seq_printf(s, ",srcaddr=%pI6c",
  336. &saddr6->sin6_addr);
  337. else if (srcaddr->sa_family == AF_INET)
  338. seq_printf(s, ",srcaddr=%pI4",
  339. &saddr4->sin_addr.s_addr);
  340. else
  341. seq_printf(s, ",srcaddr=BAD-AF:%i",
  342. (int)(srcaddr->sa_family));
  343. }
  344. seq_printf(s, ",uid=%u", cifs_sb->mnt_uid);
  345. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
  346. seq_printf(s, ",forceuid");
  347. else
  348. seq_printf(s, ",noforceuid");
  349. seq_printf(s, ",gid=%u", cifs_sb->mnt_gid);
  350. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)
  351. seq_printf(s, ",forcegid");
  352. else
  353. seq_printf(s, ",noforcegid");
  354. cifs_show_address(s, tcon->ses->server);
  355. if (!tcon->unix_ext)
  356. seq_printf(s, ",file_mode=0%ho,dir_mode=0%ho",
  357. cifs_sb->mnt_file_mode,
  358. cifs_sb->mnt_dir_mode);
  359. if (tcon->seal)
  360. seq_printf(s, ",seal");
  361. if (tcon->nocase)
  362. seq_printf(s, ",nocase");
  363. if (tcon->retry)
  364. seq_printf(s, ",hard");
  365. if (tcon->unix_ext)
  366. seq_printf(s, ",unix");
  367. else
  368. seq_printf(s, ",nounix");
  369. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
  370. seq_printf(s, ",posixpaths");
  371. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
  372. seq_printf(s, ",setuids");
  373. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
  374. seq_printf(s, ",serverino");
  375. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
  376. seq_printf(s, ",rwpidforward");
  377. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
  378. seq_printf(s, ",forcemand");
  379. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
  380. seq_printf(s, ",directio");
  381. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
  382. seq_printf(s, ",nouser_xattr");
  383. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR)
  384. seq_printf(s, ",mapchars");
  385. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
  386. seq_printf(s, ",sfu");
  387. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
  388. seq_printf(s, ",nobrl");
  389. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL)
  390. seq_printf(s, ",cifsacl");
  391. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
  392. seq_printf(s, ",dynperm");
  393. if (root->d_sb->s_flags & MS_POSIXACL)
  394. seq_printf(s, ",acl");
  395. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
  396. seq_printf(s, ",mfsymlinks");
  397. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_FSCACHE)
  398. seq_printf(s, ",fsc");
  399. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)
  400. seq_printf(s, ",nostrictsync");
  401. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
  402. seq_printf(s, ",noperm");
  403. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
  404. seq_printf(s, ",strictcache");
  405. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPUID)
  406. seq_printf(s, ",backupuid=%u", cifs_sb->mnt_backupuid);
  407. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_BACKUPGID)
  408. seq_printf(s, ",backupgid=%u", cifs_sb->mnt_backupgid);
  409. seq_printf(s, ",rsize=%u", cifs_sb->rsize);
  410. seq_printf(s, ",wsize=%u", cifs_sb->wsize);
  411. /* convert actimeo and display it in seconds */
  412. seq_printf(s, ",actimeo=%lu", cifs_sb->actimeo / HZ);
  413. return 0;
  414. }
  415. static void cifs_umount_begin(struct super_block *sb)
  416. {
  417. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  418. struct cifs_tcon *tcon;
  419. if (cifs_sb == NULL)
  420. return;
  421. tcon = cifs_sb_master_tcon(cifs_sb);
  422. spin_lock(&cifs_tcp_ses_lock);
  423. if ((tcon->tc_count > 1) || (tcon->tidStatus == CifsExiting)) {
  424. /* we have other mounts to same share or we have
  425. already tried to force umount this and woken up
  426. all waiting network requests, nothing to do */
  427. spin_unlock(&cifs_tcp_ses_lock);
  428. return;
  429. } else if (tcon->tc_count == 1)
  430. tcon->tidStatus = CifsExiting;
  431. spin_unlock(&cifs_tcp_ses_lock);
  432. /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
  433. /* cancel_notify_requests(tcon); */
  434. if (tcon->ses && tcon->ses->server) {
  435. cFYI(1, "wake up tasks now - umount begin not complete");
  436. wake_up_all(&tcon->ses->server->request_q);
  437. wake_up_all(&tcon->ses->server->response_q);
  438. msleep(1); /* yield */
  439. /* we have to kick the requests once more */
  440. wake_up_all(&tcon->ses->server->response_q);
  441. msleep(1);
  442. }
  443. return;
  444. }
  445. #ifdef CONFIG_CIFS_STATS2
  446. static int cifs_show_stats(struct seq_file *s, struct dentry *root)
  447. {
  448. /* BB FIXME */
  449. return 0;
  450. }
  451. #endif
  452. static int cifs_remount(struct super_block *sb, int *flags, char *data)
  453. {
  454. sync_filesystem(sb);
  455. *flags |= MS_NODIRATIME;
  456. return 0;
  457. }
  458. static int cifs_drop_inode(struct inode *inode)
  459. {
  460. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  461. /* no serverino => unconditional eviction */
  462. return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
  463. generic_drop_inode(inode);
  464. }
  465. static const struct super_operations cifs_super_ops = {
  466. .statfs = cifs_statfs,
  467. .alloc_inode = cifs_alloc_inode,
  468. .destroy_inode = cifs_destroy_inode,
  469. .drop_inode = cifs_drop_inode,
  470. .evict_inode = cifs_evict_inode,
  471. /* .delete_inode = cifs_delete_inode, */ /* Do not need above
  472. function unless later we add lazy close of inodes or unless the
  473. kernel forgets to call us with the same number of releases (closes)
  474. as opens */
  475. .show_options = cifs_show_options,
  476. .umount_begin = cifs_umount_begin,
  477. .remount_fs = cifs_remount,
  478. #ifdef CONFIG_CIFS_STATS2
  479. .show_stats = cifs_show_stats,
  480. #endif
  481. };
  482. /*
  483. * Get root dentry from superblock according to prefix path mount option.
  484. * Return dentry with refcount + 1 on success and NULL otherwise.
  485. */
  486. static struct dentry *
  487. cifs_get_root(struct smb_vol *vol, struct super_block *sb)
  488. {
  489. struct dentry *dentry;
  490. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  491. char *full_path = NULL;
  492. char *s, *p;
  493. char sep;
  494. full_path = cifs_build_path_to_root(vol, cifs_sb,
  495. cifs_sb_master_tcon(cifs_sb));
  496. if (full_path == NULL)
  497. return ERR_PTR(-ENOMEM);
  498. cFYI(1, "Get root dentry for %s", full_path);
  499. sep = CIFS_DIR_SEP(cifs_sb);
  500. dentry = dget(sb->s_root);
  501. p = s = full_path;
  502. do {
  503. struct inode *dir = dentry->d_inode;
  504. struct dentry *child;
  505. if (!dir) {
  506. dput(dentry);
  507. dentry = ERR_PTR(-ENOENT);
  508. break;
  509. }
  510. if (!S_ISDIR(dir->i_mode)) {
  511. dput(dentry);
  512. dentry = ERR_PTR(-ENOTDIR);
  513. break;
  514. }
  515. /* skip separators */
  516. while (*s == sep)
  517. s++;
  518. if (!*s)
  519. break;
  520. p = s++;
  521. /* next separator */
  522. while (*s && *s != sep)
  523. s++;
  524. mutex_lock(&dir->i_mutex);
  525. child = lookup_one_len(p, dentry, s - p);
  526. mutex_unlock(&dir->i_mutex);
  527. dput(dentry);
  528. dentry = child;
  529. } while (!IS_ERR(dentry));
  530. kfree(full_path);
  531. return dentry;
  532. }
  533. static int cifs_set_super(struct super_block *sb, void *data)
  534. {
  535. struct cifs_mnt_data *mnt_data = data;
  536. sb->s_fs_info = mnt_data->cifs_sb;
  537. return set_anon_super(sb, NULL);
  538. }
  539. static struct dentry *
  540. cifs_do_mount(struct file_system_type *fs_type,
  541. int flags, const char *dev_name, void *data)
  542. {
  543. int rc;
  544. struct super_block *sb;
  545. struct cifs_sb_info *cifs_sb;
  546. struct smb_vol *volume_info;
  547. struct cifs_mnt_data mnt_data;
  548. struct dentry *root;
  549. cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
  550. volume_info = cifs_get_volume_info((char *)data, dev_name);
  551. if (IS_ERR(volume_info))
  552. return ERR_CAST(volume_info);
  553. cifs_sb = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
  554. if (cifs_sb == NULL) {
  555. root = ERR_PTR(-ENOMEM);
  556. goto out_nls;
  557. }
  558. cifs_sb->mountdata = kstrndup(data, PAGE_SIZE, GFP_KERNEL);
  559. if (cifs_sb->mountdata == NULL) {
  560. root = ERR_PTR(-ENOMEM);
  561. goto out_cifs_sb;
  562. }
  563. cifs_setup_cifs_sb(volume_info, cifs_sb);
  564. rc = cifs_mount(cifs_sb, volume_info);
  565. if (rc) {
  566. if (!(flags & MS_SILENT))
  567. cERROR(1, "cifs_mount failed w/return code = %d", rc);
  568. root = ERR_PTR(rc);
  569. goto out_mountdata;
  570. }
  571. mnt_data.vol = volume_info;
  572. mnt_data.cifs_sb = cifs_sb;
  573. mnt_data.flags = flags;
  574. /* BB should we make this contingent on mount parm? */
  575. flags |= MS_NODIRATIME | MS_NOATIME;
  576. sb = sget(fs_type, cifs_match_super, cifs_set_super, flags, &mnt_data);
  577. if (IS_ERR(sb)) {
  578. root = ERR_CAST(sb);
  579. cifs_umount(cifs_sb);
  580. goto out;
  581. }
  582. if (sb->s_root) {
  583. cFYI(1, "Use existing superblock");
  584. cifs_umount(cifs_sb);
  585. } else {
  586. rc = cifs_read_super(sb);
  587. if (rc) {
  588. root = ERR_PTR(rc);
  589. goto out_super;
  590. }
  591. sb->s_flags |= MS_ACTIVE;
  592. }
  593. root = cifs_get_root(volume_info, sb);
  594. if (IS_ERR(root))
  595. goto out_super;
  596. cFYI(1, "dentry root is: %p", root);
  597. goto out;
  598. out_super:
  599. deactivate_locked_super(sb);
  600. out:
  601. cifs_cleanup_volume_info(volume_info);
  602. return root;
  603. out_mountdata:
  604. kfree(cifs_sb->mountdata);
  605. out_cifs_sb:
  606. kfree(cifs_sb);
  607. out_nls:
  608. unload_nls(volume_info->local_nls);
  609. goto out;
  610. }
  611. static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
  612. unsigned long nr_segs, loff_t pos)
  613. {
  614. struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
  615. ssize_t written;
  616. int rc;
  617. written = generic_file_aio_write(iocb, iov, nr_segs, pos);
  618. if (CIFS_I(inode)->clientCanCacheAll)
  619. return written;
  620. rc = filemap_fdatawrite(inode->i_mapping);
  621. if (rc)
  622. cFYI(1, "cifs_file_aio_write: %d rc on %p inode", rc, inode);
  623. return written;
  624. }
  625. static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
  626. {
  627. /*
  628. * origin == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate
  629. * the cached file length
  630. */
  631. if (origin != SEEK_SET && origin != SEEK_CUR) {
  632. int rc;
  633. struct inode *inode = file->f_path.dentry->d_inode;
  634. /*
  635. * We need to be sure that all dirty pages are written and the
  636. * server has the newest file length.
  637. */
  638. if (!CIFS_I(inode)->clientCanCacheRead && inode->i_mapping &&
  639. inode->i_mapping->nrpages != 0) {
  640. rc = filemap_fdatawait(inode->i_mapping);
  641. if (rc) {
  642. mapping_set_error(inode->i_mapping, rc);
  643. return rc;
  644. }
  645. }
  646. /*
  647. * Some applications poll for the file length in this strange
  648. * way so we must seek to end on non-oplocked files by
  649. * setting the revalidate time to zero.
  650. */
  651. CIFS_I(inode)->time = 0;
  652. rc = cifs_revalidate_file_attr(file);
  653. if (rc < 0)
  654. return (loff_t)rc;
  655. }
  656. return generic_file_llseek(file, offset, origin);
  657. }
  658. static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
  659. {
  660. /* note that this is called by vfs setlease with lock_flocks held
  661. to protect *lease from going away */
  662. struct inode *inode = file->f_path.dentry->d_inode;
  663. struct cifsFileInfo *cfile = file->private_data;
  664. if (!(S_ISREG(inode->i_mode)))
  665. return -EINVAL;
  666. /* check if file is oplocked */
  667. if (((arg == F_RDLCK) &&
  668. (CIFS_I(inode)->clientCanCacheRead)) ||
  669. ((arg == F_WRLCK) &&
  670. (CIFS_I(inode)->clientCanCacheAll)))
  671. return generic_setlease(file, arg, lease);
  672. else if (tlink_tcon(cfile->tlink)->local_lease &&
  673. !CIFS_I(inode)->clientCanCacheRead)
  674. /* If the server claims to support oplock on this
  675. file, then we still need to check oplock even
  676. if the local_lease mount option is set, but there
  677. are servers which do not support oplock for which
  678. this mount option may be useful if the user
  679. knows that the file won't be changed on the server
  680. by anyone else */
  681. return generic_setlease(file, arg, lease);
  682. else
  683. return -EAGAIN;
  684. }
  685. struct file_system_type cifs_fs_type = {
  686. .owner = THIS_MODULE,
  687. .name = "cifs",
  688. .mount = cifs_do_mount,
  689. .kill_sb = cifs_kill_sb,
  690. /* .fs_flags */
  691. };
  692. const struct inode_operations cifs_dir_inode_ops = {
  693. .create = cifs_create,
  694. .lookup = cifs_lookup,
  695. .getattr = cifs_getattr,
  696. .unlink = cifs_unlink,
  697. .link = cifs_hardlink,
  698. .mkdir = cifs_mkdir,
  699. .rmdir = cifs_rmdir,
  700. .rename = cifs_rename,
  701. .permission = cifs_permission,
  702. /* revalidate:cifs_revalidate, */
  703. .setattr = cifs_setattr,
  704. .symlink = cifs_symlink,
  705. .mknod = cifs_mknod,
  706. #ifdef CONFIG_CIFS_XATTR
  707. .setxattr = cifs_setxattr,
  708. .getxattr = cifs_getxattr,
  709. .listxattr = cifs_listxattr,
  710. .removexattr = cifs_removexattr,
  711. #endif
  712. };
  713. const struct inode_operations cifs_file_inode_ops = {
  714. /* revalidate:cifs_revalidate, */
  715. .setattr = cifs_setattr,
  716. .getattr = cifs_getattr, /* do we need this anymore? */
  717. .rename = cifs_rename,
  718. .permission = cifs_permission,
  719. #ifdef CONFIG_CIFS_XATTR
  720. .setxattr = cifs_setxattr,
  721. .getxattr = cifs_getxattr,
  722. .listxattr = cifs_listxattr,
  723. .removexattr = cifs_removexattr,
  724. #endif
  725. };
  726. const struct inode_operations cifs_symlink_inode_ops = {
  727. .readlink = generic_readlink,
  728. .follow_link = cifs_follow_link,
  729. .put_link = cifs_put_link,
  730. .permission = cifs_permission,
  731. /* BB add the following two eventually */
  732. /* revalidate: cifs_revalidate,
  733. setattr: cifs_notify_change, *//* BB do we need notify change */
  734. #ifdef CONFIG_CIFS_XATTR
  735. .setxattr = cifs_setxattr,
  736. .getxattr = cifs_getxattr,
  737. .listxattr = cifs_listxattr,
  738. .removexattr = cifs_removexattr,
  739. #endif
  740. };
  741. const struct file_operations cifs_file_ops = {
  742. .read = do_sync_read,
  743. .write = do_sync_write,
  744. .aio_read = generic_file_aio_read,
  745. .aio_write = cifs_file_aio_write,
  746. .open = cifs_open,
  747. .release = cifs_close,
  748. .lock = cifs_lock,
  749. .fsync = cifs_fsync,
  750. .flush = cifs_flush,
  751. .mmap = cifs_file_mmap,
  752. .splice_read = generic_file_splice_read,
  753. .llseek = cifs_llseek,
  754. #ifdef CONFIG_CIFS_POSIX
  755. .unlocked_ioctl = cifs_ioctl,
  756. #endif /* CONFIG_CIFS_POSIX */
  757. .setlease = cifs_setlease,
  758. };
  759. const struct file_operations cifs_file_strict_ops = {
  760. .read = do_sync_read,
  761. .write = do_sync_write,
  762. .aio_read = cifs_strict_readv,
  763. .aio_write = cifs_strict_writev,
  764. .open = cifs_open,
  765. .release = cifs_close,
  766. .lock = cifs_lock,
  767. .fsync = cifs_strict_fsync,
  768. .flush = cifs_flush,
  769. .mmap = cifs_file_strict_mmap,
  770. .splice_read = generic_file_splice_read,
  771. .llseek = cifs_llseek,
  772. #ifdef CONFIG_CIFS_POSIX
  773. .unlocked_ioctl = cifs_ioctl,
  774. #endif /* CONFIG_CIFS_POSIX */
  775. .setlease = cifs_setlease,
  776. };
  777. const struct file_operations cifs_file_direct_ops = {
  778. /* BB reevaluate whether they can be done with directio, no cache */
  779. .read = do_sync_read,
  780. .write = do_sync_write,
  781. .aio_read = cifs_user_readv,
  782. .aio_write = cifs_user_writev,
  783. .open = cifs_open,
  784. .release = cifs_close,
  785. .lock = cifs_lock,
  786. .fsync = cifs_fsync,
  787. .flush = cifs_flush,
  788. .mmap = cifs_file_mmap,
  789. .splice_read = generic_file_splice_read,
  790. #ifdef CONFIG_CIFS_POSIX
  791. .unlocked_ioctl = cifs_ioctl,
  792. #endif /* CONFIG_CIFS_POSIX */
  793. .llseek = cifs_llseek,
  794. .setlease = cifs_setlease,
  795. };
  796. const struct file_operations cifs_file_nobrl_ops = {
  797. .read = do_sync_read,
  798. .write = do_sync_write,
  799. .aio_read = generic_file_aio_read,
  800. .aio_write = cifs_file_aio_write,
  801. .open = cifs_open,
  802. .release = cifs_close,
  803. .fsync = cifs_fsync,
  804. .flush = cifs_flush,
  805. .mmap = cifs_file_mmap,
  806. .splice_read = generic_file_splice_read,
  807. .llseek = cifs_llseek,
  808. #ifdef CONFIG_CIFS_POSIX
  809. .unlocked_ioctl = cifs_ioctl,
  810. #endif /* CONFIG_CIFS_POSIX */
  811. .setlease = cifs_setlease,
  812. };
  813. const struct file_operations cifs_file_strict_nobrl_ops = {
  814. .read = do_sync_read,
  815. .write = do_sync_write,
  816. .aio_read = cifs_strict_readv,
  817. .aio_write = cifs_strict_writev,
  818. .open = cifs_open,
  819. .release = cifs_close,
  820. .fsync = cifs_strict_fsync,
  821. .flush = cifs_flush,
  822. .mmap = cifs_file_strict_mmap,
  823. .splice_read = generic_file_splice_read,
  824. .llseek = cifs_llseek,
  825. #ifdef CONFIG_CIFS_POSIX
  826. .unlocked_ioctl = cifs_ioctl,
  827. #endif /* CONFIG_CIFS_POSIX */
  828. .setlease = cifs_setlease,
  829. };
  830. const struct file_operations cifs_file_direct_nobrl_ops = {
  831. /* BB reevaluate whether they can be done with directio, no cache */
  832. .read = do_sync_read,
  833. .write = do_sync_write,
  834. .aio_read = cifs_user_readv,
  835. .aio_write = cifs_user_writev,
  836. .open = cifs_open,
  837. .release = cifs_close,
  838. .fsync = cifs_fsync,
  839. .flush = cifs_flush,
  840. .mmap = cifs_file_mmap,
  841. .splice_read = generic_file_splice_read,
  842. #ifdef CONFIG_CIFS_POSIX
  843. .unlocked_ioctl = cifs_ioctl,
  844. #endif /* CONFIG_CIFS_POSIX */
  845. .llseek = cifs_llseek,
  846. .setlease = cifs_setlease,
  847. };
  848. const struct file_operations cifs_dir_ops = {
  849. .readdir = cifs_readdir,
  850. .release = cifs_closedir,
  851. .read = generic_read_dir,
  852. .unlocked_ioctl = cifs_ioctl,
  853. .llseek = generic_file_llseek,
  854. };
  855. static void
  856. cifs_init_once(void *inode)
  857. {
  858. struct cifsInodeInfo *cifsi = inode;
  859. inode_init_once(&cifsi->vfs_inode);
  860. INIT_LIST_HEAD(&cifsi->llist);
  861. mutex_init(&cifsi->lock_mutex);
  862. }
  863. static int
  864. cifs_init_inodecache(void)
  865. {
  866. cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
  867. sizeof(struct cifsInodeInfo),
  868. 0, (SLAB_RECLAIM_ACCOUNT|
  869. SLAB_MEM_SPREAD),
  870. cifs_init_once);
  871. if (cifs_inode_cachep == NULL)
  872. return -ENOMEM;
  873. return 0;
  874. }
  875. static void
  876. cifs_destroy_inodecache(void)
  877. {
  878. /*
  879. * Make sure all delayed rcu free inodes are flushed before we
  880. * destroy cache.
  881. */
  882. rcu_barrier();
  883. kmem_cache_destroy(cifs_inode_cachep);
  884. }
  885. static int
  886. cifs_init_request_bufs(void)
  887. {
  888. if (CIFSMaxBufSize < 8192) {
  889. /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
  890. Unicode path name has to fit in any SMB/CIFS path based frames */
  891. CIFSMaxBufSize = 8192;
  892. } else if (CIFSMaxBufSize > 1024*127) {
  893. CIFSMaxBufSize = 1024 * 127;
  894. } else {
  895. CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
  896. }
  897. /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
  898. cifs_req_cachep = kmem_cache_create("cifs_request",
  899. CIFSMaxBufSize +
  900. MAX_CIFS_HDR_SIZE, 0,
  901. SLAB_HWCACHE_ALIGN, NULL);
  902. if (cifs_req_cachep == NULL)
  903. return -ENOMEM;
  904. if (cifs_min_rcv < 1)
  905. cifs_min_rcv = 1;
  906. else if (cifs_min_rcv > 64) {
  907. cifs_min_rcv = 64;
  908. cERROR(1, "cifs_min_rcv set to maximum (64)");
  909. }
  910. cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
  911. cifs_req_cachep);
  912. if (cifs_req_poolp == NULL) {
  913. kmem_cache_destroy(cifs_req_cachep);
  914. return -ENOMEM;
  915. }
  916. /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
  917. almost all handle based requests (but not write response, nor is it
  918. sufficient for path based requests). A smaller size would have
  919. been more efficient (compacting multiple slab items on one 4k page)
  920. for the case in which debug was on, but this larger size allows
  921. more SMBs to use small buffer alloc and is still much more
  922. efficient to alloc 1 per page off the slab compared to 17K (5page)
  923. alloc of large cifs buffers even when page debugging is on */
  924. cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
  925. MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
  926. NULL);
  927. if (cifs_sm_req_cachep == NULL) {
  928. mempool_destroy(cifs_req_poolp);
  929. kmem_cache_destroy(cifs_req_cachep);
  930. return -ENOMEM;
  931. }
  932. if (cifs_min_small < 2)
  933. cifs_min_small = 2;
  934. else if (cifs_min_small > 256) {
  935. cifs_min_small = 256;
  936. cFYI(1, "cifs_min_small set to maximum (256)");
  937. }
  938. cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
  939. cifs_sm_req_cachep);
  940. if (cifs_sm_req_poolp == NULL) {
  941. mempool_destroy(cifs_req_poolp);
  942. kmem_cache_destroy(cifs_req_cachep);
  943. kmem_cache_destroy(cifs_sm_req_cachep);
  944. return -ENOMEM;
  945. }
  946. return 0;
  947. }
  948. static void
  949. cifs_destroy_request_bufs(void)
  950. {
  951. mempool_destroy(cifs_req_poolp);
  952. kmem_cache_destroy(cifs_req_cachep);
  953. mempool_destroy(cifs_sm_req_poolp);
  954. kmem_cache_destroy(cifs_sm_req_cachep);
  955. }
  956. static int
  957. cifs_init_mids(void)
  958. {
  959. cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
  960. sizeof(struct mid_q_entry), 0,
  961. SLAB_HWCACHE_ALIGN, NULL);
  962. if (cifs_mid_cachep == NULL)
  963. return -ENOMEM;
  964. /* 3 is a reasonable minimum number of simultaneous operations */
  965. cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
  966. if (cifs_mid_poolp == NULL) {
  967. kmem_cache_destroy(cifs_mid_cachep);
  968. return -ENOMEM;
  969. }
  970. return 0;
  971. }
  972. static void
  973. cifs_destroy_mids(void)
  974. {
  975. mempool_destroy(cifs_mid_poolp);
  976. kmem_cache_destroy(cifs_mid_cachep);
  977. }
  978. static int __init
  979. init_cifs(void)
  980. {
  981. int rc = 0;
  982. cifs_proc_init();
  983. INIT_LIST_HEAD(&cifs_tcp_ses_list);
  984. #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
  985. INIT_LIST_HEAD(&GlobalDnotifyReqList);
  986. INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
  987. #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
  988. /*
  989. * Initialize Global counters
  990. */
  991. atomic_set(&sesInfoAllocCount, 0);
  992. atomic_set(&tconInfoAllocCount, 0);
  993. atomic_set(&tcpSesAllocCount, 0);
  994. atomic_set(&tcpSesReconnectCount, 0);
  995. atomic_set(&tconInfoReconnectCount, 0);
  996. atomic_set(&bufAllocCount, 0);
  997. atomic_set(&smBufAllocCount, 0);
  998. #ifdef CONFIG_CIFS_STATS2
  999. atomic_set(&totBufAllocCount, 0);
  1000. atomic_set(&totSmBufAllocCount, 0);
  1001. #endif /* CONFIG_CIFS_STATS2 */
  1002. atomic_set(&midCount, 0);
  1003. GlobalCurrentXid = 0;
  1004. GlobalTotalActiveXid = 0;
  1005. GlobalMaxActiveXid = 0;
  1006. spin_lock_init(&cifs_tcp_ses_lock);
  1007. spin_lock_init(&cifs_file_list_lock);
  1008. spin_lock_init(&GlobalMid_Lock);
  1009. if (cifs_max_pending < 2) {
  1010. cifs_max_pending = 2;
  1011. cFYI(1, "cifs_max_pending set to min of 2");
  1012. } else if (cifs_max_pending > CIFS_MAX_REQ) {
  1013. cifs_max_pending = CIFS_MAX_REQ;
  1014. cFYI(1, "cifs_max_pending set to max of %u", CIFS_MAX_REQ);
  1015. }
  1016. cifsiod_wq = alloc_workqueue("cifsiod", WQ_FREEZABLE|WQ_MEM_RECLAIM, 0);
  1017. if (!cifsiod_wq) {
  1018. rc = -ENOMEM;
  1019. goto out_clean_proc;
  1020. }
  1021. rc = cifs_fscache_register();
  1022. if (rc)
  1023. goto out_destroy_wq;
  1024. rc = cifs_init_inodecache();
  1025. if (rc)
  1026. goto out_unreg_fscache;
  1027. rc = cifs_init_mids();
  1028. if (rc)
  1029. goto out_destroy_inodecache;
  1030. rc = cifs_init_request_bufs();
  1031. if (rc)
  1032. goto out_destroy_mids;
  1033. #ifdef CONFIG_CIFS_UPCALL
  1034. rc = register_key_type(&cifs_spnego_key_type);
  1035. if (rc)
  1036. goto out_destroy_request_bufs;
  1037. #endif /* CONFIG_CIFS_UPCALL */
  1038. #ifdef CONFIG_CIFS_ACL
  1039. rc = init_cifs_idmap();
  1040. if (rc)
  1041. goto out_register_key_type;
  1042. #endif /* CONFIG_CIFS_ACL */
  1043. rc = register_filesystem(&cifs_fs_type);
  1044. if (rc)
  1045. goto out_init_cifs_idmap;
  1046. return 0;
  1047. out_init_cifs_idmap:
  1048. #ifdef CONFIG_CIFS_ACL
  1049. exit_cifs_idmap();
  1050. out_register_key_type:
  1051. #endif
  1052. #ifdef CONFIG_CIFS_UPCALL
  1053. unregister_key_type(&cifs_spnego_key_type);
  1054. out_destroy_request_bufs:
  1055. #endif
  1056. cifs_destroy_request_bufs();
  1057. out_destroy_mids:
  1058. cifs_destroy_mids();
  1059. out_destroy_inodecache:
  1060. cifs_destroy_inodecache();
  1061. out_unreg_fscache:
  1062. cifs_fscache_unregister();
  1063. out_destroy_wq:
  1064. destroy_workqueue(cifsiod_wq);
  1065. out_clean_proc:
  1066. cifs_proc_clean();
  1067. return rc;
  1068. }
  1069. static void __exit
  1070. exit_cifs(void)
  1071. {
  1072. cFYI(DBG2, "exit_cifs");
  1073. unregister_filesystem(&cifs_fs_type);
  1074. cifs_dfs_release_automount_timer();
  1075. #ifdef CONFIG_CIFS_ACL
  1076. cifs_destroy_idmaptrees();
  1077. exit_cifs_idmap();
  1078. #endif
  1079. #ifdef CONFIG_CIFS_UPCALL
  1080. unregister_key_type(&cifs_spnego_key_type);
  1081. #endif
  1082. cifs_destroy_request_bufs();
  1083. cifs_destroy_mids();
  1084. cifs_destroy_inodecache();
  1085. cifs_fscache_unregister();
  1086. destroy_workqueue(cifsiod_wq);
  1087. cifs_proc_clean();
  1088. }
  1089. MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
  1090. MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
  1091. MODULE_DESCRIPTION
  1092. ("VFS to access servers complying with the SNIA CIFS Specification "
  1093. "e.g. Samba and Windows");
  1094. MODULE_VERSION(CIFS_VERSION);
  1095. module_init(init_cifs)
  1096. module_exit(exit_cifs)