cifsfs.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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 "cifsfs.h"
  37. #include "cifspdu.h"
  38. #define DECLARE_GLOBALS_HERE
  39. #include "cifsglob.h"
  40. #include "cifsproto.h"
  41. #include "cifs_debug.h"
  42. #include "cifs_fs_sb.h"
  43. #include <linux/mm.h>
  44. #include <linux/key-type.h>
  45. #include "dns_resolve.h"
  46. #include "cifs_spnego.h"
  47. #define CIFS_MAGIC_NUMBER 0xFF534D42 /* the first four bytes of SMB PDUs */
  48. #ifdef CONFIG_CIFS_QUOTA
  49. static struct quotactl_ops cifs_quotactl_ops;
  50. #endif /* QUOTA */
  51. int cifsFYI = 0;
  52. int cifsERROR = 1;
  53. int traceSMB = 0;
  54. unsigned int oplockEnabled = 1;
  55. unsigned int experimEnabled = 0;
  56. unsigned int linuxExtEnabled = 1;
  57. unsigned int lookupCacheEnabled = 1;
  58. unsigned int multiuser_mount = 0;
  59. unsigned int extended_security = CIFSSEC_DEF;
  60. /* unsigned int ntlmv2_support = 0; */
  61. unsigned int sign_CIFS_PDUs = 1;
  62. extern struct task_struct *oplockThread; /* remove sparse warning */
  63. struct task_struct *oplockThread = NULL;
  64. /* extern struct task_struct * dnotifyThread; remove sparse warning */
  65. #ifdef CONFIG_CIFS_EXPERIMENTAL
  66. static struct task_struct *dnotifyThread = NULL;
  67. #endif
  68. static const struct super_operations cifs_super_ops;
  69. unsigned int CIFSMaxBufSize = CIFS_MAX_MSGSIZE;
  70. module_param(CIFSMaxBufSize, int, 0);
  71. MODULE_PARM_DESC(CIFSMaxBufSize, "Network buffer size (not including header). "
  72. "Default: 16384 Range: 8192 to 130048");
  73. unsigned int cifs_min_rcv = CIFS_MIN_RCV_POOL;
  74. module_param(cifs_min_rcv, int, 0);
  75. MODULE_PARM_DESC(cifs_min_rcv, "Network buffers in pool. Default: 4 Range: "
  76. "1 to 64");
  77. unsigned int cifs_min_small = 30;
  78. module_param(cifs_min_small, int, 0);
  79. MODULE_PARM_DESC(cifs_min_small, "Small network buffers in pool. Default: 30 "
  80. "Range: 2 to 256");
  81. unsigned int cifs_max_pending = CIFS_MAX_REQ;
  82. module_param(cifs_max_pending, int, 0);
  83. MODULE_PARM_DESC(cifs_max_pending, "Simultaneous requests to server. "
  84. "Default: 50 Range: 2 to 256");
  85. extern mempool_t *cifs_sm_req_poolp;
  86. extern mempool_t *cifs_req_poolp;
  87. extern mempool_t *cifs_mid_poolp;
  88. extern struct kmem_cache *cifs_oplock_cachep;
  89. static int
  90. cifs_read_super(struct super_block *sb, void *data,
  91. const char *devname, int silent)
  92. {
  93. struct inode *inode;
  94. struct cifs_sb_info *cifs_sb;
  95. int rc = 0;
  96. /* BB should we make this contingent on mount parm? */
  97. sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
  98. sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
  99. cifs_sb = CIFS_SB(sb);
  100. if (cifs_sb == NULL)
  101. return -ENOMEM;
  102. #ifdef CONFIG_CIFS_DFS_UPCALL
  103. /* copy mount params to sb for use in submounts */
  104. /* BB: should we move this after the mount so we
  105. * do not have to do the copy on failed mounts?
  106. * BB: May be it is better to do simple copy before
  107. * complex operation (mount), and in case of fail
  108. * just exit instead of doing mount and attempting
  109. * undo it if this copy fails?*/
  110. if (data) {
  111. int len = strlen(data);
  112. cifs_sb->mountdata = kzalloc(len + 1, GFP_KERNEL);
  113. if (cifs_sb->mountdata == NULL) {
  114. kfree(sb->s_fs_info);
  115. sb->s_fs_info = NULL;
  116. return -ENOMEM;
  117. }
  118. strncpy(cifs_sb->mountdata, data, len + 1);
  119. cifs_sb->mountdata[len] = '\0';
  120. }
  121. #endif
  122. rc = cifs_mount(sb, cifs_sb, data, devname);
  123. if (rc) {
  124. if (!silent)
  125. cERROR(1,
  126. ("cifs_mount failed w/return code = %d", rc));
  127. goto out_mount_failed;
  128. }
  129. sb->s_magic = CIFS_MAGIC_NUMBER;
  130. sb->s_op = &cifs_super_ops;
  131. /* if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
  132. sb->s_blocksize =
  133. cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
  134. #ifdef CONFIG_CIFS_QUOTA
  135. sb->s_qcop = &cifs_quotactl_ops;
  136. #endif
  137. sb->s_blocksize = CIFS_MAX_MSGSIZE;
  138. sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
  139. inode = cifs_iget(sb, ROOT_I);
  140. if (IS_ERR(inode)) {
  141. rc = PTR_ERR(inode);
  142. inode = NULL;
  143. goto out_no_root;
  144. }
  145. sb->s_root = d_alloc_root(inode);
  146. if (!sb->s_root) {
  147. rc = -ENOMEM;
  148. goto out_no_root;
  149. }
  150. #ifdef CONFIG_CIFS_EXPERIMENTAL
  151. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
  152. cFYI(1, ("export ops supported"));
  153. sb->s_export_op = &cifs_export_ops;
  154. }
  155. #endif /* EXPERIMENTAL */
  156. return 0;
  157. out_no_root:
  158. cERROR(1, ("cifs_read_super: get root inode failed"));
  159. if (inode)
  160. iput(inode);
  161. cifs_umount(sb, cifs_sb);
  162. out_mount_failed:
  163. if (cifs_sb) {
  164. #ifdef CONFIG_CIFS_DFS_UPCALL
  165. if (cifs_sb->mountdata) {
  166. kfree(cifs_sb->mountdata);
  167. cifs_sb->mountdata = NULL;
  168. }
  169. #endif
  170. if (cifs_sb->local_nls)
  171. unload_nls(cifs_sb->local_nls);
  172. kfree(cifs_sb);
  173. }
  174. return rc;
  175. }
  176. static void
  177. cifs_put_super(struct super_block *sb)
  178. {
  179. int rc = 0;
  180. struct cifs_sb_info *cifs_sb;
  181. cFYI(1, ("In cifs_put_super"));
  182. cifs_sb = CIFS_SB(sb);
  183. if (cifs_sb == NULL) {
  184. cFYI(1, ("Empty cifs superblock info passed to unmount"));
  185. return;
  186. }
  187. rc = cifs_umount(sb, cifs_sb);
  188. if (rc)
  189. cERROR(1, ("cifs_umount failed with return code %d", rc));
  190. #ifdef CONFIG_CIFS_DFS_UPCALL
  191. if (cifs_sb->mountdata) {
  192. kfree(cifs_sb->mountdata);
  193. cifs_sb->mountdata = NULL;
  194. }
  195. #endif
  196. unload_nls(cifs_sb->local_nls);
  197. kfree(cifs_sb);
  198. return;
  199. }
  200. static int
  201. cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
  202. {
  203. struct super_block *sb = dentry->d_sb;
  204. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  205. struct cifsTconInfo *tcon = cifs_sb->tcon;
  206. int rc = -EOPNOTSUPP;
  207. int xid;
  208. xid = GetXid();
  209. buf->f_type = CIFS_MAGIC_NUMBER;
  210. /*
  211. * PATH_MAX may be too long - it would presumably be total path,
  212. * but note that some servers (includinng Samba 3) have a shorter
  213. * maximum path.
  214. *
  215. * Instead could get the real value via SMB_QUERY_FS_ATTRIBUTE_INFO.
  216. */
  217. buf->f_namelen = PATH_MAX;
  218. buf->f_files = 0; /* undefined */
  219. buf->f_ffree = 0; /* unlimited */
  220. /*
  221. * We could add a second check for a QFS Unix capability bit
  222. */
  223. if ((tcon->ses->capabilities & CAP_UNIX) &&
  224. (CIFS_POSIX_EXTENSIONS & le64_to_cpu(tcon->fsUnixInfo.Capability)))
  225. rc = CIFSSMBQFSPosixInfo(xid, tcon, buf);
  226. /*
  227. * Only need to call the old QFSInfo if failed on newer one,
  228. * e.g. by OS/2.
  229. **/
  230. if (rc && (tcon->ses->capabilities & CAP_NT_SMBS))
  231. rc = CIFSSMBQFSInfo(xid, tcon, buf);
  232. /*
  233. * Some old Windows servers also do not support level 103, retry with
  234. * older level one if old server failed the previous call or we
  235. * bypassed it because we detected that this was an older LANMAN sess
  236. */
  237. if (rc)
  238. rc = SMBOldQFSInfo(xid, tcon, buf);
  239. FreeXid(xid);
  240. return 0;
  241. }
  242. static int cifs_permission(struct inode *inode, int mask)
  243. {
  244. struct cifs_sb_info *cifs_sb;
  245. cifs_sb = CIFS_SB(inode->i_sb);
  246. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
  247. if ((mask & MAY_EXEC) && !execute_ok(inode))
  248. return -EACCES;
  249. else
  250. return 0;
  251. } else /* file mode might have been restricted at mount time
  252. on the client (above and beyond ACL on servers) for
  253. servers which do not support setting and viewing mode bits,
  254. so allowing client to check permissions is useful */
  255. return generic_permission(inode, mask, NULL);
  256. }
  257. static struct kmem_cache *cifs_inode_cachep;
  258. static struct kmem_cache *cifs_req_cachep;
  259. static struct kmem_cache *cifs_mid_cachep;
  260. struct kmem_cache *cifs_oplock_cachep;
  261. static struct kmem_cache *cifs_sm_req_cachep;
  262. mempool_t *cifs_sm_req_poolp;
  263. mempool_t *cifs_req_poolp;
  264. mempool_t *cifs_mid_poolp;
  265. static struct inode *
  266. cifs_alloc_inode(struct super_block *sb)
  267. {
  268. struct cifsInodeInfo *cifs_inode;
  269. cifs_inode = kmem_cache_alloc(cifs_inode_cachep, GFP_KERNEL);
  270. if (!cifs_inode)
  271. return NULL;
  272. cifs_inode->cifsAttrs = 0x20; /* default */
  273. atomic_set(&cifs_inode->inUse, 0);
  274. cifs_inode->time = 0;
  275. cifs_inode->write_behind_rc = 0;
  276. /* Until the file is open and we have gotten oplock
  277. info back from the server, can not assume caching of
  278. file data or metadata */
  279. cifs_inode->clientCanCacheRead = false;
  280. cifs_inode->clientCanCacheAll = false;
  281. cifs_inode->delete_pending = false;
  282. cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
  283. /* Can not set i_flags here - they get immediately overwritten
  284. to zero by the VFS */
  285. /* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
  286. INIT_LIST_HEAD(&cifs_inode->openFileList);
  287. return &cifs_inode->vfs_inode;
  288. }
  289. static void
  290. cifs_destroy_inode(struct inode *inode)
  291. {
  292. kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
  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 vfsmount *m)
  301. {
  302. struct cifs_sb_info *cifs_sb;
  303. struct cifsTconInfo *tcon;
  304. struct TCP_Server_Info *server;
  305. cifs_sb = CIFS_SB(m->mnt_sb);
  306. if (cifs_sb) {
  307. tcon = cifs_sb->tcon;
  308. if (tcon) {
  309. /* BB add prepath to mount options displayed */
  310. seq_printf(s, ",unc=%s", cifs_sb->tcon->treeName);
  311. if (tcon->ses) {
  312. if (tcon->ses->userName)
  313. seq_printf(s, ",username=%s",
  314. tcon->ses->userName);
  315. if (tcon->ses->domainName)
  316. seq_printf(s, ",domain=%s",
  317. tcon->ses->domainName);
  318. server = tcon->ses->server;
  319. if (server) {
  320. seq_printf(s, ",addr=");
  321. switch (server->addr.sockAddr6.
  322. sin6_family) {
  323. case AF_INET6:
  324. seq_printf(s, NIP6_FMT,
  325. NIP6(server->addr.sockAddr6.sin6_addr));
  326. break;
  327. case AF_INET:
  328. seq_printf(s, NIPQUAD_FMT,
  329. NIPQUAD(server->addr.sockAddr.sin_addr.s_addr));
  330. break;
  331. }
  332. }
  333. }
  334. if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) ||
  335. !(tcon->unix_ext))
  336. seq_printf(s, ",uid=%d", cifs_sb->mnt_uid);
  337. if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
  338. !(tcon->unix_ext))
  339. seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
  340. if (!tcon->unix_ext) {
  341. seq_printf(s, ",file_mode=0%o,dir_mode=0%o",
  342. cifs_sb->mnt_file_mode,
  343. cifs_sb->mnt_dir_mode);
  344. }
  345. if (tcon->seal)
  346. seq_printf(s, ",seal");
  347. if (tcon->nocase)
  348. seq_printf(s, ",nocase");
  349. if (tcon->retry)
  350. seq_printf(s, ",hard");
  351. }
  352. if (cifs_sb->prepath)
  353. seq_printf(s, ",prepath=%s", cifs_sb->prepath);
  354. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
  355. seq_printf(s, ",posixpaths");
  356. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
  357. seq_printf(s, ",setuids");
  358. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
  359. seq_printf(s, ",serverino");
  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 (m->mnt_sb->s_flags & MS_POSIXACL)
  375. seq_printf(s, ",acl");
  376. seq_printf(s, ",rsize=%d", cifs_sb->rsize);
  377. seq_printf(s, ",wsize=%d", cifs_sb->wsize);
  378. }
  379. return 0;
  380. }
  381. #ifdef CONFIG_CIFS_QUOTA
  382. int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid,
  383. struct fs_disk_quota *pdquota)
  384. {
  385. int xid;
  386. int rc = 0;
  387. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  388. struct cifsTconInfo *pTcon;
  389. if (cifs_sb)
  390. pTcon = cifs_sb->tcon;
  391. else
  392. return -EIO;
  393. xid = GetXid();
  394. if (pTcon) {
  395. cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
  396. } else {
  397. rc = -EIO;
  398. }
  399. FreeXid(xid);
  400. return rc;
  401. }
  402. int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid,
  403. struct fs_disk_quota *pdquota)
  404. {
  405. int xid;
  406. int rc = 0;
  407. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  408. struct cifsTconInfo *pTcon;
  409. if (cifs_sb)
  410. pTcon = cifs_sb->tcon;
  411. else
  412. return -EIO;
  413. xid = GetXid();
  414. if (pTcon) {
  415. cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
  416. } else {
  417. rc = -EIO;
  418. }
  419. FreeXid(xid);
  420. return rc;
  421. }
  422. int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation)
  423. {
  424. int xid;
  425. int rc = 0;
  426. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  427. struct cifsTconInfo *pTcon;
  428. if (cifs_sb)
  429. pTcon = cifs_sb->tcon;
  430. else
  431. return -EIO;
  432. xid = GetXid();
  433. if (pTcon) {
  434. cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation));
  435. } else {
  436. rc = -EIO;
  437. }
  438. FreeXid(xid);
  439. return rc;
  440. }
  441. int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
  442. {
  443. int xid;
  444. int rc = 0;
  445. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  446. struct cifsTconInfo *pTcon;
  447. if (cifs_sb) {
  448. pTcon = cifs_sb->tcon;
  449. } else {
  450. return -EIO;
  451. }
  452. xid = GetXid();
  453. if (pTcon) {
  454. cFYI(1, ("pqstats %p", qstats));
  455. } else {
  456. rc = -EIO;
  457. }
  458. FreeXid(xid);
  459. return rc;
  460. }
  461. static struct quotactl_ops cifs_quotactl_ops = {
  462. .set_xquota = cifs_xquota_set,
  463. .get_xquota = cifs_xquota_get,
  464. .set_xstate = cifs_xstate_set,
  465. .get_xstate = cifs_xstate_get,
  466. };
  467. #endif
  468. static void cifs_umount_begin(struct super_block *sb)
  469. {
  470. struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
  471. struct cifsTconInfo *tcon;
  472. if (cifs_sb == NULL)
  473. return;
  474. tcon = cifs_sb->tcon;
  475. if (tcon == NULL)
  476. return;
  477. read_lock(&cifs_tcp_ses_lock);
  478. if (tcon->tc_count == 1)
  479. tcon->tidStatus = CifsExiting;
  480. read_unlock(&cifs_tcp_ses_lock);
  481. /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
  482. /* cancel_notify_requests(tcon); */
  483. if (tcon->ses && tcon->ses->server) {
  484. cFYI(1, ("wake up tasks now - umount begin not complete"));
  485. wake_up_all(&tcon->ses->server->request_q);
  486. wake_up_all(&tcon->ses->server->response_q);
  487. msleep(1); /* yield */
  488. /* we have to kick the requests once more */
  489. wake_up_all(&tcon->ses->server->response_q);
  490. msleep(1);
  491. }
  492. /* BB FIXME - finish add checks for tidStatus BB */
  493. return;
  494. }
  495. #ifdef CONFIG_CIFS_STATS2
  496. static int cifs_show_stats(struct seq_file *s, struct vfsmount *mnt)
  497. {
  498. /* BB FIXME */
  499. return 0;
  500. }
  501. #endif
  502. static int cifs_remount(struct super_block *sb, int *flags, char *data)
  503. {
  504. *flags |= MS_NODIRATIME;
  505. return 0;
  506. }
  507. static const struct super_operations cifs_super_ops = {
  508. .put_super = cifs_put_super,
  509. .statfs = cifs_statfs,
  510. .alloc_inode = cifs_alloc_inode,
  511. .destroy_inode = cifs_destroy_inode,
  512. /* .drop_inode = generic_delete_inode,
  513. .delete_inode = cifs_delete_inode, */ /* Do not need above two
  514. functions unless later we add lazy close of inodes or unless the
  515. kernel forgets to call us with the same number of releases (closes)
  516. as opens */
  517. .show_options = cifs_show_options,
  518. .umount_begin = cifs_umount_begin,
  519. .remount_fs = cifs_remount,
  520. #ifdef CONFIG_CIFS_STATS2
  521. .show_stats = cifs_show_stats,
  522. #endif
  523. };
  524. static int
  525. cifs_get_sb(struct file_system_type *fs_type,
  526. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  527. {
  528. int rc;
  529. struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
  530. cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
  531. if (IS_ERR(sb))
  532. return PTR_ERR(sb);
  533. sb->s_flags = flags;
  534. rc = cifs_read_super(sb, data, dev_name, flags & MS_SILENT ? 1 : 0);
  535. if (rc) {
  536. up_write(&sb->s_umount);
  537. deactivate_super(sb);
  538. return rc;
  539. }
  540. sb->s_flags |= MS_ACTIVE;
  541. return simple_set_mnt(mnt, sb);
  542. }
  543. static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
  544. unsigned long nr_segs, loff_t pos)
  545. {
  546. struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
  547. ssize_t written;
  548. written = generic_file_aio_write(iocb, iov, nr_segs, pos);
  549. if (!CIFS_I(inode)->clientCanCacheAll)
  550. filemap_fdatawrite(inode->i_mapping);
  551. return written;
  552. }
  553. static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
  554. {
  555. /* origin == SEEK_END => we must revalidate the cached file length */
  556. if (origin == SEEK_END) {
  557. int retval;
  558. /* some applications poll for the file length in this strange
  559. way so we must seek to end on non-oplocked files by
  560. setting the revalidate time to zero */
  561. CIFS_I(file->f_path.dentry->d_inode)->time = 0;
  562. retval = cifs_revalidate(file->f_path.dentry);
  563. if (retval < 0)
  564. return (loff_t)retval;
  565. }
  566. return generic_file_llseek_unlocked(file, offset, origin);
  567. }
  568. #ifdef CONFIG_CIFS_EXPERIMENTAL
  569. static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
  570. {
  571. /* note that this is called by vfs setlease with the BKL held
  572. although I doubt that BKL is needed here in cifs */
  573. struct inode *inode = file->f_path.dentry->d_inode;
  574. if (!(S_ISREG(inode->i_mode)))
  575. return -EINVAL;
  576. /* check if file is oplocked */
  577. if (((arg == F_RDLCK) &&
  578. (CIFS_I(inode)->clientCanCacheRead)) ||
  579. ((arg == F_WRLCK) &&
  580. (CIFS_I(inode)->clientCanCacheAll)))
  581. return generic_setlease(file, arg, lease);
  582. else if (CIFS_SB(inode->i_sb)->tcon->local_lease &&
  583. !CIFS_I(inode)->clientCanCacheRead)
  584. /* If the server claims to support oplock on this
  585. file, then we still need to check oplock even
  586. if the local_lease mount option is set, but there
  587. are servers which do not support oplock for which
  588. this mount option may be useful if the user
  589. knows that the file won't be changed on the server
  590. by anyone else */
  591. return generic_setlease(file, arg, lease);
  592. else
  593. return -EAGAIN;
  594. }
  595. #endif
  596. struct file_system_type cifs_fs_type = {
  597. .owner = THIS_MODULE,
  598. .name = "cifs",
  599. .get_sb = cifs_get_sb,
  600. .kill_sb = kill_anon_super,
  601. /* .fs_flags */
  602. };
  603. const struct inode_operations cifs_dir_inode_ops = {
  604. .create = cifs_create,
  605. .lookup = cifs_lookup,
  606. .getattr = cifs_getattr,
  607. .unlink = cifs_unlink,
  608. .link = cifs_hardlink,
  609. .mkdir = cifs_mkdir,
  610. .rmdir = cifs_rmdir,
  611. .rename = cifs_rename,
  612. .permission = cifs_permission,
  613. /* revalidate:cifs_revalidate, */
  614. .setattr = cifs_setattr,
  615. .symlink = cifs_symlink,
  616. .mknod = cifs_mknod,
  617. #ifdef CONFIG_CIFS_XATTR
  618. .setxattr = cifs_setxattr,
  619. .getxattr = cifs_getxattr,
  620. .listxattr = cifs_listxattr,
  621. .removexattr = cifs_removexattr,
  622. #endif
  623. };
  624. const struct inode_operations cifs_file_inode_ops = {
  625. /* revalidate:cifs_revalidate, */
  626. .setattr = cifs_setattr,
  627. .getattr = cifs_getattr, /* do we need this anymore? */
  628. .rename = cifs_rename,
  629. .permission = cifs_permission,
  630. #ifdef CONFIG_CIFS_XATTR
  631. .setxattr = cifs_setxattr,
  632. .getxattr = cifs_getxattr,
  633. .listxattr = cifs_listxattr,
  634. .removexattr = cifs_removexattr,
  635. #endif
  636. };
  637. const struct inode_operations cifs_symlink_inode_ops = {
  638. .readlink = generic_readlink,
  639. .follow_link = cifs_follow_link,
  640. .put_link = cifs_put_link,
  641. .permission = cifs_permission,
  642. /* BB add the following two eventually */
  643. /* revalidate: cifs_revalidate,
  644. setattr: cifs_notify_change, *//* BB do we need notify change */
  645. #ifdef CONFIG_CIFS_XATTR
  646. .setxattr = cifs_setxattr,
  647. .getxattr = cifs_getxattr,
  648. .listxattr = cifs_listxattr,
  649. .removexattr = cifs_removexattr,
  650. #endif
  651. };
  652. const struct file_operations cifs_file_ops = {
  653. .read = do_sync_read,
  654. .write = do_sync_write,
  655. .aio_read = generic_file_aio_read,
  656. .aio_write = cifs_file_aio_write,
  657. .open = cifs_open,
  658. .release = cifs_close,
  659. .lock = cifs_lock,
  660. .fsync = cifs_fsync,
  661. .flush = cifs_flush,
  662. .mmap = cifs_file_mmap,
  663. .splice_read = generic_file_splice_read,
  664. .llseek = cifs_llseek,
  665. #ifdef CONFIG_CIFS_POSIX
  666. .unlocked_ioctl = cifs_ioctl,
  667. #endif /* CONFIG_CIFS_POSIX */
  668. #ifdef CONFIG_CIFS_EXPERIMENTAL
  669. .dir_notify = cifs_dir_notify,
  670. .setlease = cifs_setlease,
  671. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  672. };
  673. const struct file_operations cifs_file_direct_ops = {
  674. /* no mmap, no aio, no readv -
  675. BB reevaluate whether they can be done with directio, no cache */
  676. .read = cifs_user_read,
  677. .write = cifs_user_write,
  678. .open = cifs_open,
  679. .release = cifs_close,
  680. .lock = cifs_lock,
  681. .fsync = cifs_fsync,
  682. .flush = cifs_flush,
  683. .splice_read = generic_file_splice_read,
  684. #ifdef CONFIG_CIFS_POSIX
  685. .unlocked_ioctl = cifs_ioctl,
  686. #endif /* CONFIG_CIFS_POSIX */
  687. .llseek = cifs_llseek,
  688. #ifdef CONFIG_CIFS_EXPERIMENTAL
  689. .dir_notify = cifs_dir_notify,
  690. .setlease = cifs_setlease,
  691. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  692. };
  693. const struct file_operations cifs_file_nobrl_ops = {
  694. .read = do_sync_read,
  695. .write = do_sync_write,
  696. .aio_read = generic_file_aio_read,
  697. .aio_write = cifs_file_aio_write,
  698. .open = cifs_open,
  699. .release = cifs_close,
  700. .fsync = cifs_fsync,
  701. .flush = cifs_flush,
  702. .mmap = cifs_file_mmap,
  703. .splice_read = generic_file_splice_read,
  704. .llseek = cifs_llseek,
  705. #ifdef CONFIG_CIFS_POSIX
  706. .unlocked_ioctl = cifs_ioctl,
  707. #endif /* CONFIG_CIFS_POSIX */
  708. #ifdef CONFIG_CIFS_EXPERIMENTAL
  709. .dir_notify = cifs_dir_notify,
  710. .setlease = cifs_setlease,
  711. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  712. };
  713. const struct file_operations cifs_file_direct_nobrl_ops = {
  714. /* no mmap, no aio, no readv -
  715. BB reevaluate whether they can be done with directio, no cache */
  716. .read = cifs_user_read,
  717. .write = cifs_user_write,
  718. .open = cifs_open,
  719. .release = cifs_close,
  720. .fsync = cifs_fsync,
  721. .flush = cifs_flush,
  722. .splice_read = generic_file_splice_read,
  723. #ifdef CONFIG_CIFS_POSIX
  724. .unlocked_ioctl = cifs_ioctl,
  725. #endif /* CONFIG_CIFS_POSIX */
  726. .llseek = cifs_llseek,
  727. #ifdef CONFIG_CIFS_EXPERIMENTAL
  728. .dir_notify = cifs_dir_notify,
  729. .setlease = cifs_setlease,
  730. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  731. };
  732. const struct file_operations cifs_dir_ops = {
  733. .readdir = cifs_readdir,
  734. .release = cifs_closedir,
  735. .read = generic_read_dir,
  736. #ifdef CONFIG_CIFS_EXPERIMENTAL
  737. .dir_notify = cifs_dir_notify,
  738. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  739. .unlocked_ioctl = cifs_ioctl,
  740. .llseek = generic_file_llseek,
  741. };
  742. static void
  743. cifs_init_once(void *inode)
  744. {
  745. struct cifsInodeInfo *cifsi = inode;
  746. inode_init_once(&cifsi->vfs_inode);
  747. INIT_LIST_HEAD(&cifsi->lockList);
  748. }
  749. static int
  750. cifs_init_inodecache(void)
  751. {
  752. cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
  753. sizeof(struct cifsInodeInfo),
  754. 0, (SLAB_RECLAIM_ACCOUNT|
  755. SLAB_MEM_SPREAD),
  756. cifs_init_once);
  757. if (cifs_inode_cachep == NULL)
  758. return -ENOMEM;
  759. return 0;
  760. }
  761. static void
  762. cifs_destroy_inodecache(void)
  763. {
  764. kmem_cache_destroy(cifs_inode_cachep);
  765. }
  766. static int
  767. cifs_init_request_bufs(void)
  768. {
  769. if (CIFSMaxBufSize < 8192) {
  770. /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
  771. Unicode path name has to fit in any SMB/CIFS path based frames */
  772. CIFSMaxBufSize = 8192;
  773. } else if (CIFSMaxBufSize > 1024*127) {
  774. CIFSMaxBufSize = 1024 * 127;
  775. } else {
  776. CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
  777. }
  778. /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
  779. cifs_req_cachep = kmem_cache_create("cifs_request",
  780. CIFSMaxBufSize +
  781. MAX_CIFS_HDR_SIZE, 0,
  782. SLAB_HWCACHE_ALIGN, NULL);
  783. if (cifs_req_cachep == NULL)
  784. return -ENOMEM;
  785. if (cifs_min_rcv < 1)
  786. cifs_min_rcv = 1;
  787. else if (cifs_min_rcv > 64) {
  788. cifs_min_rcv = 64;
  789. cERROR(1, ("cifs_min_rcv set to maximum (64)"));
  790. }
  791. cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
  792. cifs_req_cachep);
  793. if (cifs_req_poolp == NULL) {
  794. kmem_cache_destroy(cifs_req_cachep);
  795. return -ENOMEM;
  796. }
  797. /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
  798. almost all handle based requests (but not write response, nor is it
  799. sufficient for path based requests). A smaller size would have
  800. been more efficient (compacting multiple slab items on one 4k page)
  801. for the case in which debug was on, but this larger size allows
  802. more SMBs to use small buffer alloc and is still much more
  803. efficient to alloc 1 per page off the slab compared to 17K (5page)
  804. alloc of large cifs buffers even when page debugging is on */
  805. cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
  806. MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
  807. NULL);
  808. if (cifs_sm_req_cachep == NULL) {
  809. mempool_destroy(cifs_req_poolp);
  810. kmem_cache_destroy(cifs_req_cachep);
  811. return -ENOMEM;
  812. }
  813. if (cifs_min_small < 2)
  814. cifs_min_small = 2;
  815. else if (cifs_min_small > 256) {
  816. cifs_min_small = 256;
  817. cFYI(1, ("cifs_min_small set to maximum (256)"));
  818. }
  819. cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
  820. cifs_sm_req_cachep);
  821. if (cifs_sm_req_poolp == NULL) {
  822. mempool_destroy(cifs_req_poolp);
  823. kmem_cache_destroy(cifs_req_cachep);
  824. kmem_cache_destroy(cifs_sm_req_cachep);
  825. return -ENOMEM;
  826. }
  827. return 0;
  828. }
  829. static void
  830. cifs_destroy_request_bufs(void)
  831. {
  832. mempool_destroy(cifs_req_poolp);
  833. kmem_cache_destroy(cifs_req_cachep);
  834. mempool_destroy(cifs_sm_req_poolp);
  835. kmem_cache_destroy(cifs_sm_req_cachep);
  836. }
  837. static int
  838. cifs_init_mids(void)
  839. {
  840. cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
  841. sizeof(struct mid_q_entry), 0,
  842. SLAB_HWCACHE_ALIGN, NULL);
  843. if (cifs_mid_cachep == NULL)
  844. return -ENOMEM;
  845. /* 3 is a reasonable minimum number of simultaneous operations */
  846. cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
  847. if (cifs_mid_poolp == NULL) {
  848. kmem_cache_destroy(cifs_mid_cachep);
  849. return -ENOMEM;
  850. }
  851. cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
  852. sizeof(struct oplock_q_entry), 0,
  853. SLAB_HWCACHE_ALIGN, NULL);
  854. if (cifs_oplock_cachep == NULL) {
  855. mempool_destroy(cifs_mid_poolp);
  856. kmem_cache_destroy(cifs_mid_cachep);
  857. return -ENOMEM;
  858. }
  859. return 0;
  860. }
  861. static void
  862. cifs_destroy_mids(void)
  863. {
  864. mempool_destroy(cifs_mid_poolp);
  865. kmem_cache_destroy(cifs_mid_cachep);
  866. kmem_cache_destroy(cifs_oplock_cachep);
  867. }
  868. static int cifs_oplock_thread(void *dummyarg)
  869. {
  870. struct oplock_q_entry *oplock_item;
  871. struct cifsTconInfo *pTcon;
  872. struct inode *inode;
  873. __u16 netfid;
  874. int rc, waitrc = 0;
  875. set_freezable();
  876. do {
  877. if (try_to_freeze())
  878. continue;
  879. spin_lock(&GlobalMid_Lock);
  880. if (list_empty(&GlobalOplock_Q)) {
  881. spin_unlock(&GlobalMid_Lock);
  882. set_current_state(TASK_INTERRUPTIBLE);
  883. schedule_timeout(39*HZ);
  884. } else {
  885. oplock_item = list_entry(GlobalOplock_Q.next,
  886. struct oplock_q_entry, qhead);
  887. cFYI(1, ("found oplock item to write out"));
  888. pTcon = oplock_item->tcon;
  889. inode = oplock_item->pinode;
  890. netfid = oplock_item->netfid;
  891. spin_unlock(&GlobalMid_Lock);
  892. DeleteOplockQEntry(oplock_item);
  893. /* can not grab inode sem here since it would
  894. deadlock when oplock received on delete
  895. since vfs_unlink holds the i_mutex across
  896. the call */
  897. /* mutex_lock(&inode->i_mutex);*/
  898. if (S_ISREG(inode->i_mode)) {
  899. #ifdef CONFIG_CIFS_EXPERIMENTAL
  900. if (CIFS_I(inode)->clientCanCacheAll == 0)
  901. break_lease(inode, FMODE_READ);
  902. else if (CIFS_I(inode)->clientCanCacheRead == 0)
  903. break_lease(inode, FMODE_WRITE);
  904. #endif
  905. rc = filemap_fdatawrite(inode->i_mapping);
  906. if (CIFS_I(inode)->clientCanCacheRead == 0) {
  907. waitrc = filemap_fdatawait(
  908. inode->i_mapping);
  909. invalidate_remote_inode(inode);
  910. }
  911. if (rc == 0)
  912. rc = waitrc;
  913. } else
  914. rc = 0;
  915. /* mutex_unlock(&inode->i_mutex);*/
  916. if (rc)
  917. CIFS_I(inode)->write_behind_rc = rc;
  918. cFYI(1, ("Oplock flush inode %p rc %d",
  919. inode, rc));
  920. /* releasing stale oplock after recent reconnect
  921. of smb session using a now incorrect file
  922. handle is not a data integrity issue but do
  923. not bother sending an oplock release if session
  924. to server still is disconnected since oplock
  925. already released by the server in that case */
  926. if (!pTcon->need_reconnect) {
  927. rc = CIFSSMBLock(0, pTcon, netfid,
  928. 0 /* len */ , 0 /* offset */, 0,
  929. 0, LOCKING_ANDX_OPLOCK_RELEASE,
  930. false /* wait flag */);
  931. cFYI(1, ("Oplock release rc = %d", rc));
  932. }
  933. set_current_state(TASK_INTERRUPTIBLE);
  934. schedule_timeout(1); /* yield in case q were corrupt */
  935. }
  936. } while (!kthread_should_stop());
  937. return 0;
  938. }
  939. #ifdef CONFIG_CIFS_EXPERIMENTAL
  940. static int cifs_dnotify_thread(void *dummyarg)
  941. {
  942. struct list_head *tmp;
  943. struct TCP_Server_Info *server;
  944. do {
  945. if (try_to_freeze())
  946. continue;
  947. set_current_state(TASK_INTERRUPTIBLE);
  948. schedule_timeout(15*HZ);
  949. /* check if any stuck requests that need
  950. to be woken up and wakeq so the
  951. thread can wake up and error out */
  952. read_lock(&cifs_tcp_ses_lock);
  953. list_for_each(tmp, &cifs_tcp_ses_list) {
  954. server = list_entry(tmp, struct TCP_Server_Info,
  955. tcp_ses_list);
  956. if (atomic_read(&server->inFlight))
  957. wake_up_all(&server->response_q);
  958. }
  959. read_unlock(&cifs_tcp_ses_lock);
  960. } while (!kthread_should_stop());
  961. return 0;
  962. }
  963. #endif
  964. static int __init
  965. init_cifs(void)
  966. {
  967. int rc = 0;
  968. cifs_proc_init();
  969. INIT_LIST_HEAD(&cifs_tcp_ses_list);
  970. INIT_LIST_HEAD(&GlobalOplock_Q);
  971. #ifdef CONFIG_CIFS_EXPERIMENTAL
  972. INIT_LIST_HEAD(&GlobalDnotifyReqList);
  973. INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
  974. #endif
  975. /*
  976. * Initialize Global counters
  977. */
  978. atomic_set(&sesInfoAllocCount, 0);
  979. atomic_set(&tconInfoAllocCount, 0);
  980. atomic_set(&tcpSesAllocCount, 0);
  981. atomic_set(&tcpSesReconnectCount, 0);
  982. atomic_set(&tconInfoReconnectCount, 0);
  983. atomic_set(&bufAllocCount, 0);
  984. atomic_set(&smBufAllocCount, 0);
  985. #ifdef CONFIG_CIFS_STATS2
  986. atomic_set(&totBufAllocCount, 0);
  987. atomic_set(&totSmBufAllocCount, 0);
  988. #endif /* CONFIG_CIFS_STATS2 */
  989. atomic_set(&midCount, 0);
  990. GlobalCurrentXid = 0;
  991. GlobalTotalActiveXid = 0;
  992. GlobalMaxActiveXid = 0;
  993. memset(Local_System_Name, 0, 15);
  994. rwlock_init(&GlobalSMBSeslock);
  995. rwlock_init(&cifs_tcp_ses_lock);
  996. spin_lock_init(&GlobalMid_Lock);
  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 > 256) {
  1001. cifs_max_pending = 256;
  1002. cFYI(1, ("cifs_max_pending set to max of 256"));
  1003. }
  1004. rc = cifs_init_inodecache();
  1005. if (rc)
  1006. goto out_clean_proc;
  1007. rc = cifs_init_mids();
  1008. if (rc)
  1009. goto out_destroy_inodecache;
  1010. rc = cifs_init_request_bufs();
  1011. if (rc)
  1012. goto out_destroy_mids;
  1013. rc = register_filesystem(&cifs_fs_type);
  1014. if (rc)
  1015. goto out_destroy_request_bufs;
  1016. #ifdef CONFIG_CIFS_UPCALL
  1017. rc = register_key_type(&cifs_spnego_key_type);
  1018. if (rc)
  1019. goto out_unregister_filesystem;
  1020. #endif
  1021. #ifdef CONFIG_CIFS_DFS_UPCALL
  1022. rc = register_key_type(&key_type_dns_resolver);
  1023. if (rc)
  1024. goto out_unregister_key_type;
  1025. #endif
  1026. oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
  1027. if (IS_ERR(oplockThread)) {
  1028. rc = PTR_ERR(oplockThread);
  1029. cERROR(1, ("error %d create oplock thread", rc));
  1030. goto out_unregister_dfs_key_type;
  1031. }
  1032. #ifdef CONFIG_CIFS_EXPERIMENTAL
  1033. dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");
  1034. if (IS_ERR(dnotifyThread)) {
  1035. rc = PTR_ERR(dnotifyThread);
  1036. cERROR(1, ("error %d create dnotify thread", rc));
  1037. goto out_stop_oplock_thread;
  1038. }
  1039. #endif
  1040. return 0;
  1041. #ifdef CONFIG_CIFS_EXPERIMENTAL
  1042. out_stop_oplock_thread:
  1043. #endif
  1044. kthread_stop(oplockThread);
  1045. out_unregister_dfs_key_type:
  1046. #ifdef CONFIG_CIFS_DFS_UPCALL
  1047. unregister_key_type(&key_type_dns_resolver);
  1048. out_unregister_key_type:
  1049. #endif
  1050. #ifdef CONFIG_CIFS_UPCALL
  1051. unregister_key_type(&cifs_spnego_key_type);
  1052. out_unregister_filesystem:
  1053. #endif
  1054. unregister_filesystem(&cifs_fs_type);
  1055. out_destroy_request_bufs:
  1056. cifs_destroy_request_bufs();
  1057. out_destroy_mids:
  1058. cifs_destroy_mids();
  1059. out_destroy_inodecache:
  1060. cifs_destroy_inodecache();
  1061. out_clean_proc:
  1062. cifs_proc_clean();
  1063. return rc;
  1064. }
  1065. static void __exit
  1066. exit_cifs(void)
  1067. {
  1068. cFYI(DBG2, ("exit_cifs"));
  1069. cifs_proc_clean();
  1070. #ifdef CONFIG_CIFS_DFS_UPCALL
  1071. cifs_dfs_release_automount_timer();
  1072. unregister_key_type(&key_type_dns_resolver);
  1073. #endif
  1074. #ifdef CONFIG_CIFS_UPCALL
  1075. unregister_key_type(&cifs_spnego_key_type);
  1076. #endif
  1077. unregister_filesystem(&cifs_fs_type);
  1078. cifs_destroy_inodecache();
  1079. cifs_destroy_mids();
  1080. cifs_destroy_request_bufs();
  1081. #ifdef CONFIG_CIFS_EXPERIMENTAL
  1082. kthread_stop(dnotifyThread);
  1083. #endif
  1084. kthread_stop(oplockThread);
  1085. }
  1086. MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
  1087. MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
  1088. MODULE_DESCRIPTION
  1089. ("VFS to access servers complying with the SNIA CIFS Specification "
  1090. "e.g. Samba and Windows");
  1091. MODULE_VERSION(CIFS_VERSION);
  1092. module_init(init_cifs)
  1093. module_exit(exit_cifs)