cifsfs.c 32 KB

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