cifsfs.c 29 KB

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