cifsfs.c 33 KB

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