smb2ops.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /*
  2. * SMB2 version specific operations
  3. *
  4. * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License v2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/pagemap.h>
  20. #include <linux/vfs.h>
  21. #include "cifsglob.h"
  22. #include "smb2pdu.h"
  23. #include "smb2proto.h"
  24. #include "cifsproto.h"
  25. #include "cifs_debug.h"
  26. #include "smb2status.h"
  27. #include "smb2glob.h"
  28. static int
  29. change_conf(struct TCP_Server_Info *server)
  30. {
  31. server->credits += server->echo_credits + server->oplock_credits;
  32. server->oplock_credits = server->echo_credits = 0;
  33. switch (server->credits) {
  34. case 0:
  35. return -1;
  36. case 1:
  37. server->echoes = false;
  38. server->oplocks = false;
  39. cifs_dbg(VFS, "disabling echoes and oplocks\n");
  40. break;
  41. case 2:
  42. server->echoes = true;
  43. server->oplocks = false;
  44. server->echo_credits = 1;
  45. cifs_dbg(FYI, "disabling oplocks\n");
  46. break;
  47. default:
  48. server->echoes = true;
  49. server->oplocks = true;
  50. server->echo_credits = 1;
  51. server->oplock_credits = 1;
  52. }
  53. server->credits -= server->echo_credits + server->oplock_credits;
  54. return 0;
  55. }
  56. static void
  57. smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
  58. const int optype)
  59. {
  60. int *val, rc = 0;
  61. spin_lock(&server->req_lock);
  62. val = server->ops->get_credits_field(server, optype);
  63. *val += add;
  64. server->in_flight--;
  65. if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
  66. rc = change_conf(server);
  67. /*
  68. * Sometimes server returns 0 credits on oplock break ack - we need to
  69. * rebalance credits in this case.
  70. */
  71. else if (server->in_flight > 0 && server->oplock_credits == 0 &&
  72. server->oplocks) {
  73. if (server->credits > 1) {
  74. server->credits--;
  75. server->oplock_credits++;
  76. }
  77. }
  78. spin_unlock(&server->req_lock);
  79. wake_up(&server->request_q);
  80. if (rc)
  81. cifs_reconnect(server);
  82. }
  83. static void
  84. smb2_set_credits(struct TCP_Server_Info *server, const int val)
  85. {
  86. spin_lock(&server->req_lock);
  87. server->credits = val;
  88. spin_unlock(&server->req_lock);
  89. }
  90. static int *
  91. smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
  92. {
  93. switch (optype) {
  94. case CIFS_ECHO_OP:
  95. return &server->echo_credits;
  96. case CIFS_OBREAK_OP:
  97. return &server->oplock_credits;
  98. default:
  99. return &server->credits;
  100. }
  101. }
  102. static unsigned int
  103. smb2_get_credits(struct mid_q_entry *mid)
  104. {
  105. return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
  106. }
  107. static __u64
  108. smb2_get_next_mid(struct TCP_Server_Info *server)
  109. {
  110. __u64 mid;
  111. /* for SMB2 we need the current value */
  112. spin_lock(&GlobalMid_Lock);
  113. mid = server->CurrentMid++;
  114. spin_unlock(&GlobalMid_Lock);
  115. return mid;
  116. }
  117. static struct mid_q_entry *
  118. smb2_find_mid(struct TCP_Server_Info *server, char *buf)
  119. {
  120. struct mid_q_entry *mid;
  121. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  122. spin_lock(&GlobalMid_Lock);
  123. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  124. if ((mid->mid == hdr->MessageId) &&
  125. (mid->mid_state == MID_REQUEST_SUBMITTED) &&
  126. (mid->command == hdr->Command)) {
  127. spin_unlock(&GlobalMid_Lock);
  128. return mid;
  129. }
  130. }
  131. spin_unlock(&GlobalMid_Lock);
  132. return NULL;
  133. }
  134. static void
  135. smb2_dump_detail(void *buf)
  136. {
  137. #ifdef CONFIG_CIFS_DEBUG2
  138. struct smb2_hdr *smb = (struct smb2_hdr *)buf;
  139. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
  140. smb->Command, smb->Status, smb->Flags, smb->MessageId,
  141. smb->ProcessId);
  142. cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
  143. #endif
  144. }
  145. static bool
  146. smb2_need_neg(struct TCP_Server_Info *server)
  147. {
  148. return server->max_read == 0;
  149. }
  150. static int
  151. smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
  152. {
  153. int rc;
  154. ses->server->CurrentMid = 0;
  155. rc = SMB2_negotiate(xid, ses);
  156. /* BB we probably don't need to retry with modern servers */
  157. if (rc == -EAGAIN)
  158. rc = -EHOSTDOWN;
  159. return rc;
  160. }
  161. static unsigned int
  162. smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  163. {
  164. struct TCP_Server_Info *server = tcon->ses->server;
  165. unsigned int wsize;
  166. /* start with specified wsize, or default */
  167. wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
  168. wsize = min_t(unsigned int, wsize, server->max_write);
  169. /*
  170. * limit write size to 2 ** 16, because we don't support multicredit
  171. * requests now.
  172. */
  173. wsize = min_t(unsigned int, wsize, 2 << 15);
  174. return wsize;
  175. }
  176. static unsigned int
  177. smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  178. {
  179. struct TCP_Server_Info *server = tcon->ses->server;
  180. unsigned int rsize;
  181. /* start with specified rsize, or default */
  182. rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
  183. rsize = min_t(unsigned int, rsize, server->max_read);
  184. /*
  185. * limit write size to 2 ** 16, because we don't support multicredit
  186. * requests now.
  187. */
  188. rsize = min_t(unsigned int, rsize, 2 << 15);
  189. return rsize;
  190. }
  191. static int
  192. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  193. struct cifs_sb_info *cifs_sb, const char *full_path)
  194. {
  195. int rc;
  196. __u64 persistent_fid, volatile_fid;
  197. __le16 *utf16_path;
  198. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  199. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  200. if (!utf16_path)
  201. return -ENOMEM;
  202. rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
  203. FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL);
  204. if (rc) {
  205. kfree(utf16_path);
  206. return rc;
  207. }
  208. rc = SMB2_close(xid, tcon, persistent_fid, volatile_fid);
  209. kfree(utf16_path);
  210. return rc;
  211. }
  212. static int
  213. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  214. struct cifs_sb_info *cifs_sb, const char *full_path,
  215. u64 *uniqueid, FILE_ALL_INFO *data)
  216. {
  217. *uniqueid = le64_to_cpu(data->IndexNumber);
  218. return 0;
  219. }
  220. static int
  221. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  222. struct cifs_fid *fid, FILE_ALL_INFO *data)
  223. {
  224. int rc;
  225. struct smb2_file_all_info *smb2_data;
  226. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2,
  227. GFP_KERNEL);
  228. if (smb2_data == NULL)
  229. return -ENOMEM;
  230. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  231. smb2_data);
  232. if (!rc)
  233. move_smb2_info_to_cifs(data, smb2_data);
  234. kfree(smb2_data);
  235. return rc;
  236. }
  237. static bool
  238. smb2_can_echo(struct TCP_Server_Info *server)
  239. {
  240. return server->echoes;
  241. }
  242. static void
  243. smb2_clear_stats(struct cifs_tcon *tcon)
  244. {
  245. #ifdef CONFIG_CIFS_STATS
  246. int i;
  247. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  248. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  249. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  250. }
  251. #endif
  252. }
  253. static void
  254. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  255. {
  256. seq_puts(m, "\n\tShare Capabilities:");
  257. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  258. seq_puts(m, " DFS,");
  259. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  260. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  261. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  262. seq_puts(m, " SCALEOUT,");
  263. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  264. seq_puts(m, " CLUSTER,");
  265. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  266. seq_puts(m, " ASYMMETRIC,");
  267. if (tcon->capabilities == 0)
  268. seq_puts(m, " None");
  269. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  270. }
  271. static void
  272. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  273. {
  274. #ifdef CONFIG_CIFS_STATS
  275. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  276. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  277. seq_printf(m, "\nNegotiates: %d sent %d failed",
  278. atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  279. atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  280. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  281. atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  282. atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  283. #define SMB2LOGOFF 0x0002 /* trivial request/resp */
  284. seq_printf(m, "\nLogoffs: %d sent %d failed",
  285. atomic_read(&sent[SMB2_LOGOFF_HE]),
  286. atomic_read(&failed[SMB2_LOGOFF_HE]));
  287. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  288. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  289. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  290. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  291. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  292. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  293. seq_printf(m, "\nCreates: %d sent %d failed",
  294. atomic_read(&sent[SMB2_CREATE_HE]),
  295. atomic_read(&failed[SMB2_CREATE_HE]));
  296. seq_printf(m, "\nCloses: %d sent %d failed",
  297. atomic_read(&sent[SMB2_CLOSE_HE]),
  298. atomic_read(&failed[SMB2_CLOSE_HE]));
  299. seq_printf(m, "\nFlushes: %d sent %d failed",
  300. atomic_read(&sent[SMB2_FLUSH_HE]),
  301. atomic_read(&failed[SMB2_FLUSH_HE]));
  302. seq_printf(m, "\nReads: %d sent %d failed",
  303. atomic_read(&sent[SMB2_READ_HE]),
  304. atomic_read(&failed[SMB2_READ_HE]));
  305. seq_printf(m, "\nWrites: %d sent %d failed",
  306. atomic_read(&sent[SMB2_WRITE_HE]),
  307. atomic_read(&failed[SMB2_WRITE_HE]));
  308. seq_printf(m, "\nLocks: %d sent %d failed",
  309. atomic_read(&sent[SMB2_LOCK_HE]),
  310. atomic_read(&failed[SMB2_LOCK_HE]));
  311. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  312. atomic_read(&sent[SMB2_IOCTL_HE]),
  313. atomic_read(&failed[SMB2_IOCTL_HE]));
  314. seq_printf(m, "\nCancels: %d sent %d failed",
  315. atomic_read(&sent[SMB2_CANCEL_HE]),
  316. atomic_read(&failed[SMB2_CANCEL_HE]));
  317. seq_printf(m, "\nEchos: %d sent %d failed",
  318. atomic_read(&sent[SMB2_ECHO_HE]),
  319. atomic_read(&failed[SMB2_ECHO_HE]));
  320. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  321. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  322. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  323. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  324. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  325. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  326. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  327. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  328. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  329. seq_printf(m, "\nSetInfos: %d sent %d failed",
  330. atomic_read(&sent[SMB2_SET_INFO_HE]),
  331. atomic_read(&failed[SMB2_SET_INFO_HE]));
  332. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  333. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  334. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  335. #endif
  336. }
  337. static void
  338. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  339. {
  340. struct cifsInodeInfo *cinode = CIFS_I(cfile->dentry->d_inode);
  341. cfile->fid.persistent_fid = fid->persistent_fid;
  342. cfile->fid.volatile_fid = fid->volatile_fid;
  343. smb2_set_oplock_level(cinode, oplock);
  344. cinode->can_cache_brlcks = cinode->clientCanCacheAll;
  345. }
  346. static void
  347. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  348. struct cifs_fid *fid)
  349. {
  350. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  351. }
  352. static int
  353. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  354. struct cifs_fid *fid)
  355. {
  356. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  357. }
  358. static unsigned int
  359. smb2_read_data_offset(char *buf)
  360. {
  361. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  362. return rsp->DataOffset;
  363. }
  364. static unsigned int
  365. smb2_read_data_length(char *buf)
  366. {
  367. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  368. return le32_to_cpu(rsp->DataLength);
  369. }
  370. static int
  371. smb2_sync_read(const unsigned int xid, struct cifsFileInfo *cfile,
  372. struct cifs_io_parms *parms, unsigned int *bytes_read,
  373. char **buf, int *buf_type)
  374. {
  375. parms->persistent_fid = cfile->fid.persistent_fid;
  376. parms->volatile_fid = cfile->fid.volatile_fid;
  377. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  378. }
  379. static int
  380. smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
  381. struct cifs_io_parms *parms, unsigned int *written,
  382. struct kvec *iov, unsigned long nr_segs)
  383. {
  384. parms->persistent_fid = cfile->fid.persistent_fid;
  385. parms->volatile_fid = cfile->fid.volatile_fid;
  386. return SMB2_write(xid, parms, written, iov, nr_segs);
  387. }
  388. static int
  389. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  390. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  391. {
  392. __le64 eof = cpu_to_le64(size);
  393. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  394. cfile->fid.volatile_fid, cfile->pid, &eof);
  395. }
  396. static int
  397. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  398. const char *path, struct cifs_sb_info *cifs_sb,
  399. struct cifs_fid *fid, __u16 search_flags,
  400. struct cifs_search_info *srch_inf)
  401. {
  402. __le16 *utf16_path;
  403. int rc;
  404. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  405. __u64 persistent_fid, volatile_fid;
  406. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  407. if (!utf16_path)
  408. return -ENOMEM;
  409. rc = SMB2_open(xid, tcon, utf16_path, &persistent_fid, &volatile_fid,
  410. FILE_READ_ATTRIBUTES | FILE_READ_DATA, FILE_OPEN, 0, 0,
  411. &oplock, NULL);
  412. kfree(utf16_path);
  413. if (rc) {
  414. cifs_dbg(VFS, "open dir failed\n");
  415. return rc;
  416. }
  417. srch_inf->entries_in_buffer = 0;
  418. srch_inf->index_of_last_entry = 0;
  419. fid->persistent_fid = persistent_fid;
  420. fid->volatile_fid = volatile_fid;
  421. rc = SMB2_query_directory(xid, tcon, persistent_fid, volatile_fid, 0,
  422. srch_inf);
  423. if (rc) {
  424. cifs_dbg(VFS, "query directory failed\n");
  425. SMB2_close(xid, tcon, persistent_fid, volatile_fid);
  426. }
  427. return rc;
  428. }
  429. static int
  430. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  431. struct cifs_fid *fid, __u16 search_flags,
  432. struct cifs_search_info *srch_inf)
  433. {
  434. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  435. fid->volatile_fid, 0, srch_inf);
  436. }
  437. static int
  438. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  439. struct cifs_fid *fid)
  440. {
  441. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  442. }
  443. /*
  444. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  445. * the number of credits and return true. Otherwise - return false.
  446. */
  447. static bool
  448. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  449. {
  450. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  451. if (hdr->Status != STATUS_PENDING)
  452. return false;
  453. if (!length) {
  454. spin_lock(&server->req_lock);
  455. server->credits += le16_to_cpu(hdr->CreditRequest);
  456. spin_unlock(&server->req_lock);
  457. wake_up(&server->request_q);
  458. }
  459. return true;
  460. }
  461. static int
  462. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  463. struct cifsInodeInfo *cinode)
  464. {
  465. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  466. return SMB2_lease_break(0, tcon, cinode->lease_key,
  467. smb2_get_lease_state(cinode));
  468. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  469. fid->volatile_fid,
  470. cinode->clientCanCacheRead ? 1 : 0);
  471. }
  472. static int
  473. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  474. struct kstatfs *buf)
  475. {
  476. int rc;
  477. u64 persistent_fid, volatile_fid;
  478. __le16 srch_path = 0; /* Null - open root of share */
  479. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  480. rc = SMB2_open(xid, tcon, &srch_path, &persistent_fid, &volatile_fid,
  481. FILE_READ_ATTRIBUTES, FILE_OPEN, 0, 0, &oplock, NULL);
  482. if (rc)
  483. return rc;
  484. buf->f_type = SMB2_MAGIC_NUMBER;
  485. rc = SMB2_QFS_info(xid, tcon, persistent_fid, volatile_fid, buf);
  486. SMB2_close(xid, tcon, persistent_fid, volatile_fid);
  487. return rc;
  488. }
  489. static bool
  490. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  491. {
  492. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  493. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  494. }
  495. static int
  496. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  497. __u64 length, __u32 type, int lock, int unlock, bool wait)
  498. {
  499. if (unlock && !lock)
  500. type = SMB2_LOCKFLAG_UNLOCK;
  501. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  502. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  503. current->tgid, length, offset, type, wait);
  504. }
  505. static void
  506. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  507. {
  508. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  509. }
  510. static void
  511. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  512. {
  513. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  514. }
  515. static void
  516. smb2_new_lease_key(struct cifs_fid *fid)
  517. {
  518. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  519. }
  520. struct smb_version_operations smb21_operations = {
  521. .compare_fids = smb2_compare_fids,
  522. .setup_request = smb2_setup_request,
  523. .setup_async_request = smb2_setup_async_request,
  524. .check_receive = smb2_check_receive,
  525. .add_credits = smb2_add_credits,
  526. .set_credits = smb2_set_credits,
  527. .get_credits_field = smb2_get_credits_field,
  528. .get_credits = smb2_get_credits,
  529. .get_next_mid = smb2_get_next_mid,
  530. .read_data_offset = smb2_read_data_offset,
  531. .read_data_length = smb2_read_data_length,
  532. .map_error = map_smb2_to_linux_error,
  533. .find_mid = smb2_find_mid,
  534. .check_message = smb2_check_message,
  535. .dump_detail = smb2_dump_detail,
  536. .clear_stats = smb2_clear_stats,
  537. .print_stats = smb2_print_stats,
  538. .is_oplock_break = smb2_is_valid_oplock_break,
  539. .need_neg = smb2_need_neg,
  540. .negotiate = smb2_negotiate,
  541. .negotiate_wsize = smb2_negotiate_wsize,
  542. .negotiate_rsize = smb2_negotiate_rsize,
  543. .sess_setup = SMB2_sess_setup,
  544. .logoff = SMB2_logoff,
  545. .tree_connect = SMB2_tcon,
  546. .tree_disconnect = SMB2_tdis,
  547. .is_path_accessible = smb2_is_path_accessible,
  548. .can_echo = smb2_can_echo,
  549. .echo = SMB2_echo,
  550. .query_path_info = smb2_query_path_info,
  551. .get_srv_inum = smb2_get_srv_inum,
  552. .query_file_info = smb2_query_file_info,
  553. .set_path_size = smb2_set_path_size,
  554. .set_file_size = smb2_set_file_size,
  555. .set_file_info = smb2_set_file_info,
  556. .mkdir = smb2_mkdir,
  557. .mkdir_setinfo = smb2_mkdir_setinfo,
  558. .rmdir = smb2_rmdir,
  559. .unlink = smb2_unlink,
  560. .rename = smb2_rename_path,
  561. .create_hardlink = smb2_create_hardlink,
  562. .open = smb2_open_file,
  563. .set_fid = smb2_set_fid,
  564. .close = smb2_close_file,
  565. .flush = smb2_flush_file,
  566. .async_readv = smb2_async_readv,
  567. .async_writev = smb2_async_writev,
  568. .sync_read = smb2_sync_read,
  569. .sync_write = smb2_sync_write,
  570. .query_dir_first = smb2_query_dir_first,
  571. .query_dir_next = smb2_query_dir_next,
  572. .close_dir = smb2_close_dir,
  573. .calc_smb_size = smb2_calc_size,
  574. .is_status_pending = smb2_is_status_pending,
  575. .oplock_response = smb2_oplock_response,
  576. .queryfs = smb2_queryfs,
  577. .mand_lock = smb2_mand_lock,
  578. .mand_unlock_range = smb2_unlock_range,
  579. .push_mand_locks = smb2_push_mandatory_locks,
  580. .get_lease_key = smb2_get_lease_key,
  581. .set_lease_key = smb2_set_lease_key,
  582. .new_lease_key = smb2_new_lease_key,
  583. .calc_signature = smb2_calc_signature,
  584. };
  585. struct smb_version_operations smb30_operations = {
  586. .compare_fids = smb2_compare_fids,
  587. .setup_request = smb2_setup_request,
  588. .setup_async_request = smb2_setup_async_request,
  589. .check_receive = smb2_check_receive,
  590. .add_credits = smb2_add_credits,
  591. .set_credits = smb2_set_credits,
  592. .get_credits_field = smb2_get_credits_field,
  593. .get_credits = smb2_get_credits,
  594. .get_next_mid = smb2_get_next_mid,
  595. .read_data_offset = smb2_read_data_offset,
  596. .read_data_length = smb2_read_data_length,
  597. .map_error = map_smb2_to_linux_error,
  598. .find_mid = smb2_find_mid,
  599. .check_message = smb2_check_message,
  600. .dump_detail = smb2_dump_detail,
  601. .clear_stats = smb2_clear_stats,
  602. .print_stats = smb2_print_stats,
  603. .dump_share_caps = smb2_dump_share_caps,
  604. .is_oplock_break = smb2_is_valid_oplock_break,
  605. .need_neg = smb2_need_neg,
  606. .negotiate = smb2_negotiate,
  607. .negotiate_wsize = smb2_negotiate_wsize,
  608. .negotiate_rsize = smb2_negotiate_rsize,
  609. .sess_setup = SMB2_sess_setup,
  610. .logoff = SMB2_logoff,
  611. .tree_connect = SMB2_tcon,
  612. .tree_disconnect = SMB2_tdis,
  613. .is_path_accessible = smb2_is_path_accessible,
  614. .can_echo = smb2_can_echo,
  615. .echo = SMB2_echo,
  616. .query_path_info = smb2_query_path_info,
  617. .get_srv_inum = smb2_get_srv_inum,
  618. .query_file_info = smb2_query_file_info,
  619. .set_path_size = smb2_set_path_size,
  620. .set_file_size = smb2_set_file_size,
  621. .set_file_info = smb2_set_file_info,
  622. .mkdir = smb2_mkdir,
  623. .mkdir_setinfo = smb2_mkdir_setinfo,
  624. .rmdir = smb2_rmdir,
  625. .unlink = smb2_unlink,
  626. .rename = smb2_rename_path,
  627. .create_hardlink = smb2_create_hardlink,
  628. .open = smb2_open_file,
  629. .set_fid = smb2_set_fid,
  630. .close = smb2_close_file,
  631. .flush = smb2_flush_file,
  632. .async_readv = smb2_async_readv,
  633. .async_writev = smb2_async_writev,
  634. .sync_read = smb2_sync_read,
  635. .sync_write = smb2_sync_write,
  636. .query_dir_first = smb2_query_dir_first,
  637. .query_dir_next = smb2_query_dir_next,
  638. .close_dir = smb2_close_dir,
  639. .calc_smb_size = smb2_calc_size,
  640. .is_status_pending = smb2_is_status_pending,
  641. .oplock_response = smb2_oplock_response,
  642. .queryfs = smb2_queryfs,
  643. .mand_lock = smb2_mand_lock,
  644. .mand_unlock_range = smb2_unlock_range,
  645. .push_mand_locks = smb2_push_mandatory_locks,
  646. .get_lease_key = smb2_get_lease_key,
  647. .set_lease_key = smb2_set_lease_key,
  648. .new_lease_key = smb2_new_lease_key,
  649. .calc_signature = smb3_calc_signature,
  650. };
  651. struct smb_version_values smb20_values = {
  652. .version_string = SMB20_VERSION_STRING,
  653. .protocol_id = SMB20_PROT_ID,
  654. .req_capabilities = 0, /* MBZ */
  655. .large_lock_type = 0,
  656. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  657. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  658. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  659. .header_size = sizeof(struct smb2_hdr),
  660. .max_header_size = MAX_SMB2_HDR_SIZE,
  661. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  662. .lock_cmd = SMB2_LOCK,
  663. .cap_unix = 0,
  664. .cap_nt_find = SMB2_NT_FIND,
  665. .cap_large_files = SMB2_LARGE_FILES,
  666. .oplock_read = SMB2_OPLOCK_LEVEL_II,
  667. };
  668. struct smb_version_values smb21_values = {
  669. .version_string = SMB21_VERSION_STRING,
  670. .protocol_id = SMB21_PROT_ID,
  671. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  672. .large_lock_type = 0,
  673. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  674. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  675. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  676. .header_size = sizeof(struct smb2_hdr),
  677. .max_header_size = MAX_SMB2_HDR_SIZE,
  678. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  679. .lock_cmd = SMB2_LOCK,
  680. .cap_unix = 0,
  681. .cap_nt_find = SMB2_NT_FIND,
  682. .cap_large_files = SMB2_LARGE_FILES,
  683. .oplock_read = SMB2_OPLOCK_LEVEL_II,
  684. };
  685. struct smb_version_values smb30_values = {
  686. .version_string = SMB30_VERSION_STRING,
  687. .protocol_id = SMB30_PROT_ID,
  688. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  689. .large_lock_type = 0,
  690. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  691. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  692. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  693. .header_size = sizeof(struct smb2_hdr),
  694. .max_header_size = MAX_SMB2_HDR_SIZE,
  695. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  696. .lock_cmd = SMB2_LOCK,
  697. .cap_unix = 0,
  698. .cap_nt_find = SMB2_NT_FIND,
  699. .cap_large_files = SMB2_LARGE_FILES,
  700. .oplock_read = SMB2_OPLOCK_LEVEL_II,
  701. };
  702. struct smb_version_values smb302_values = {
  703. .version_string = SMB302_VERSION_STRING,
  704. .protocol_id = SMB302_PROT_ID,
  705. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  706. .large_lock_type = 0,
  707. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  708. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  709. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  710. .header_size = sizeof(struct smb2_hdr),
  711. .max_header_size = MAX_SMB2_HDR_SIZE,
  712. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  713. .lock_cmd = SMB2_LOCK,
  714. .cap_unix = 0,
  715. .cap_nt_find = SMB2_NT_FIND,
  716. .cap_large_files = SMB2_LARGE_FILES,
  717. .oplock_read = SMB2_OPLOCK_LEVEL_II,
  718. };