cifsfs.c 33 KB

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