cifsfs.c 32 KB

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