cifsfs.c 28 KB

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