cifsfs.c 28 KB

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