cifsfs.c 33 KB

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