cifsfs.c 34 KB

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