cifsfs.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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 mmap, 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. .splice_read = generic_file_splice_read,
  674. #ifdef CONFIG_CIFS_POSIX
  675. .unlocked_ioctl = cifs_ioctl,
  676. #endif /* CONFIG_CIFS_POSIX */
  677. .llseek = cifs_llseek,
  678. #ifdef CONFIG_CIFS_EXPERIMENTAL
  679. .setlease = cifs_setlease,
  680. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  681. };
  682. const struct file_operations cifs_file_nobrl_ops = {
  683. .read = do_sync_read,
  684. .write = do_sync_write,
  685. .aio_read = generic_file_aio_read,
  686. .aio_write = cifs_file_aio_write,
  687. .open = cifs_open,
  688. .release = cifs_close,
  689. .fsync = cifs_fsync,
  690. .flush = cifs_flush,
  691. .mmap = cifs_file_mmap,
  692. .splice_read = generic_file_splice_read,
  693. .llseek = cifs_llseek,
  694. #ifdef CONFIG_CIFS_POSIX
  695. .unlocked_ioctl = cifs_ioctl,
  696. #endif /* CONFIG_CIFS_POSIX */
  697. #ifdef CONFIG_CIFS_EXPERIMENTAL
  698. .setlease = cifs_setlease,
  699. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  700. };
  701. const struct file_operations cifs_file_direct_nobrl_ops = {
  702. /* no mmap, no aio, no readv -
  703. BB reevaluate whether they can be done with directio, no cache */
  704. .read = cifs_user_read,
  705. .write = cifs_user_write,
  706. .open = cifs_open,
  707. .release = cifs_close,
  708. .fsync = cifs_fsync,
  709. .flush = cifs_flush,
  710. .splice_read = generic_file_splice_read,
  711. #ifdef CONFIG_CIFS_POSIX
  712. .unlocked_ioctl = cifs_ioctl,
  713. #endif /* CONFIG_CIFS_POSIX */
  714. .llseek = cifs_llseek,
  715. #ifdef CONFIG_CIFS_EXPERIMENTAL
  716. .setlease = cifs_setlease,
  717. #endif /* CONFIG_CIFS_EXPERIMENTAL */
  718. };
  719. const struct file_operations cifs_dir_ops = {
  720. .readdir = cifs_readdir,
  721. .release = cifs_closedir,
  722. .read = generic_read_dir,
  723. .unlocked_ioctl = cifs_ioctl,
  724. .llseek = generic_file_llseek,
  725. };
  726. static void
  727. cifs_init_once(void *inode)
  728. {
  729. struct cifsInodeInfo *cifsi = inode;
  730. inode_init_once(&cifsi->vfs_inode);
  731. INIT_LIST_HEAD(&cifsi->lockList);
  732. }
  733. static int
  734. cifs_init_inodecache(void)
  735. {
  736. cifs_inode_cachep = kmem_cache_create("cifs_inode_cache",
  737. sizeof(struct cifsInodeInfo),
  738. 0, (SLAB_RECLAIM_ACCOUNT|
  739. SLAB_MEM_SPREAD),
  740. cifs_init_once);
  741. if (cifs_inode_cachep == NULL)
  742. return -ENOMEM;
  743. return 0;
  744. }
  745. static void
  746. cifs_destroy_inodecache(void)
  747. {
  748. kmem_cache_destroy(cifs_inode_cachep);
  749. }
  750. static int
  751. cifs_init_request_bufs(void)
  752. {
  753. if (CIFSMaxBufSize < 8192) {
  754. /* Buffer size can not be smaller than 2 * PATH_MAX since maximum
  755. Unicode path name has to fit in any SMB/CIFS path based frames */
  756. CIFSMaxBufSize = 8192;
  757. } else if (CIFSMaxBufSize > 1024*127) {
  758. CIFSMaxBufSize = 1024 * 127;
  759. } else {
  760. CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
  761. }
  762. /* cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
  763. cifs_req_cachep = kmem_cache_create("cifs_request",
  764. CIFSMaxBufSize +
  765. MAX_CIFS_HDR_SIZE, 0,
  766. SLAB_HWCACHE_ALIGN, NULL);
  767. if (cifs_req_cachep == NULL)
  768. return -ENOMEM;
  769. if (cifs_min_rcv < 1)
  770. cifs_min_rcv = 1;
  771. else if (cifs_min_rcv > 64) {
  772. cifs_min_rcv = 64;
  773. cERROR(1, ("cifs_min_rcv set to maximum (64)"));
  774. }
  775. cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
  776. cifs_req_cachep);
  777. if (cifs_req_poolp == NULL) {
  778. kmem_cache_destroy(cifs_req_cachep);
  779. return -ENOMEM;
  780. }
  781. /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
  782. almost all handle based requests (but not write response, nor is it
  783. sufficient for path based requests). A smaller size would have
  784. been more efficient (compacting multiple slab items on one 4k page)
  785. for the case in which debug was on, but this larger size allows
  786. more SMBs to use small buffer alloc and is still much more
  787. efficient to alloc 1 per page off the slab compared to 17K (5page)
  788. alloc of large cifs buffers even when page debugging is on */
  789. cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
  790. MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
  791. NULL);
  792. if (cifs_sm_req_cachep == NULL) {
  793. mempool_destroy(cifs_req_poolp);
  794. kmem_cache_destroy(cifs_req_cachep);
  795. return -ENOMEM;
  796. }
  797. if (cifs_min_small < 2)
  798. cifs_min_small = 2;
  799. else if (cifs_min_small > 256) {
  800. cifs_min_small = 256;
  801. cFYI(1, ("cifs_min_small set to maximum (256)"));
  802. }
  803. cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
  804. cifs_sm_req_cachep);
  805. if (cifs_sm_req_poolp == NULL) {
  806. mempool_destroy(cifs_req_poolp);
  807. kmem_cache_destroy(cifs_req_cachep);
  808. kmem_cache_destroy(cifs_sm_req_cachep);
  809. return -ENOMEM;
  810. }
  811. return 0;
  812. }
  813. static void
  814. cifs_destroy_request_bufs(void)
  815. {
  816. mempool_destroy(cifs_req_poolp);
  817. kmem_cache_destroy(cifs_req_cachep);
  818. mempool_destroy(cifs_sm_req_poolp);
  819. kmem_cache_destroy(cifs_sm_req_cachep);
  820. }
  821. static int
  822. cifs_init_mids(void)
  823. {
  824. cifs_mid_cachep = kmem_cache_create("cifs_mpx_ids",
  825. sizeof(struct mid_q_entry), 0,
  826. SLAB_HWCACHE_ALIGN, NULL);
  827. if (cifs_mid_cachep == NULL)
  828. return -ENOMEM;
  829. /* 3 is a reasonable minimum number of simultaneous operations */
  830. cifs_mid_poolp = mempool_create_slab_pool(3, cifs_mid_cachep);
  831. if (cifs_mid_poolp == NULL) {
  832. kmem_cache_destroy(cifs_mid_cachep);
  833. return -ENOMEM;
  834. }
  835. cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
  836. sizeof(struct oplock_q_entry), 0,
  837. SLAB_HWCACHE_ALIGN, NULL);
  838. if (cifs_oplock_cachep == NULL) {
  839. mempool_destroy(cifs_mid_poolp);
  840. kmem_cache_destroy(cifs_mid_cachep);
  841. return -ENOMEM;
  842. }
  843. return 0;
  844. }
  845. static void
  846. cifs_destroy_mids(void)
  847. {
  848. mempool_destroy(cifs_mid_poolp);
  849. kmem_cache_destroy(cifs_mid_cachep);
  850. kmem_cache_destroy(cifs_oplock_cachep);
  851. }
  852. static int __init
  853. init_cifs(void)
  854. {
  855. int rc = 0;
  856. cifs_proc_init();
  857. INIT_LIST_HEAD(&cifs_tcp_ses_list);
  858. #ifdef CONFIG_CIFS_EXPERIMENTAL
  859. INIT_LIST_HEAD(&GlobalDnotifyReqList);
  860. INIT_LIST_HEAD(&GlobalDnotifyRsp_Q);
  861. #endif
  862. /*
  863. * Initialize Global counters
  864. */
  865. atomic_set(&sesInfoAllocCount, 0);
  866. atomic_set(&tconInfoAllocCount, 0);
  867. atomic_set(&tcpSesAllocCount, 0);
  868. atomic_set(&tcpSesReconnectCount, 0);
  869. atomic_set(&tconInfoReconnectCount, 0);
  870. atomic_set(&bufAllocCount, 0);
  871. atomic_set(&smBufAllocCount, 0);
  872. #ifdef CONFIG_CIFS_STATS2
  873. atomic_set(&totBufAllocCount, 0);
  874. atomic_set(&totSmBufAllocCount, 0);
  875. #endif /* CONFIG_CIFS_STATS2 */
  876. atomic_set(&midCount, 0);
  877. GlobalCurrentXid = 0;
  878. GlobalTotalActiveXid = 0;
  879. GlobalMaxActiveXid = 0;
  880. memset(Local_System_Name, 0, 15);
  881. rwlock_init(&GlobalSMBSeslock);
  882. rwlock_init(&cifs_tcp_ses_lock);
  883. spin_lock_init(&GlobalMid_Lock);
  884. if (cifs_max_pending < 2) {
  885. cifs_max_pending = 2;
  886. cFYI(1, ("cifs_max_pending set to min of 2"));
  887. } else if (cifs_max_pending > 256) {
  888. cifs_max_pending = 256;
  889. cFYI(1, ("cifs_max_pending set to max of 256"));
  890. }
  891. rc = cifs_init_inodecache();
  892. if (rc)
  893. goto out_clean_proc;
  894. rc = cifs_init_mids();
  895. if (rc)
  896. goto out_destroy_inodecache;
  897. rc = cifs_init_request_bufs();
  898. if (rc)
  899. goto out_destroy_mids;
  900. rc = register_filesystem(&cifs_fs_type);
  901. if (rc)
  902. goto out_destroy_request_bufs;
  903. #ifdef CONFIG_CIFS_UPCALL
  904. rc = register_key_type(&cifs_spnego_key_type);
  905. if (rc)
  906. goto out_unregister_filesystem;
  907. #endif
  908. #ifdef CONFIG_CIFS_DFS_UPCALL
  909. rc = register_key_type(&key_type_dns_resolver);
  910. if (rc)
  911. goto out_unregister_key_type;
  912. #endif
  913. rc = slow_work_register_user();
  914. if (rc)
  915. goto out_unregister_resolver_key;
  916. return 0;
  917. out_unregister_resolver_key:
  918. #ifdef CONFIG_CIFS_DFS_UPCALL
  919. unregister_key_type(&key_type_dns_resolver);
  920. out_unregister_key_type:
  921. #endif
  922. #ifdef CONFIG_CIFS_UPCALL
  923. unregister_key_type(&cifs_spnego_key_type);
  924. out_unregister_filesystem:
  925. #endif
  926. unregister_filesystem(&cifs_fs_type);
  927. out_destroy_request_bufs:
  928. cifs_destroy_request_bufs();
  929. out_destroy_mids:
  930. cifs_destroy_mids();
  931. out_destroy_inodecache:
  932. cifs_destroy_inodecache();
  933. out_clean_proc:
  934. cifs_proc_clean();
  935. return rc;
  936. }
  937. static void __exit
  938. exit_cifs(void)
  939. {
  940. cFYI(DBG2, ("exit_cifs"));
  941. cifs_proc_clean();
  942. #ifdef CONFIG_CIFS_DFS_UPCALL
  943. cifs_dfs_release_automount_timer();
  944. unregister_key_type(&key_type_dns_resolver);
  945. #endif
  946. #ifdef CONFIG_CIFS_UPCALL
  947. unregister_key_type(&cifs_spnego_key_type);
  948. #endif
  949. unregister_filesystem(&cifs_fs_type);
  950. cifs_destroy_inodecache();
  951. cifs_destroy_mids();
  952. cifs_destroy_request_bufs();
  953. }
  954. MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
  955. MODULE_LICENSE("GPL"); /* combination of LGPL + GPL source behaves as GPL */
  956. MODULE_DESCRIPTION
  957. ("VFS to access servers complying with the SNIA CIFS Specification "
  958. "e.g. Samba and Windows");
  959. MODULE_VERSION(CIFS_VERSION);
  960. module_init(init_cifs)
  961. module_exit(exit_cifs)