cifsfs.c 33 KB

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