cifsfs.c 34 KB

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