cifsfs.c 32 KB

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