smb2ops.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  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 <linux/falloc.h>
  22. #include "cifsglob.h"
  23. #include "smb2pdu.h"
  24. #include "smb2proto.h"
  25. #include "cifsproto.h"
  26. #include "cifs_debug.h"
  27. #include "cifs_unicode.h"
  28. #include "smb2status.h"
  29. #include "smb2glob.h"
  30. static int
  31. change_conf(struct TCP_Server_Info *server)
  32. {
  33. server->credits += server->echo_credits + server->oplock_credits;
  34. server->oplock_credits = server->echo_credits = 0;
  35. switch (server->credits) {
  36. case 0:
  37. return -1;
  38. case 1:
  39. server->echoes = false;
  40. server->oplocks = false;
  41. cifs_dbg(VFS, "disabling echoes and oplocks\n");
  42. break;
  43. case 2:
  44. server->echoes = true;
  45. server->oplocks = false;
  46. server->echo_credits = 1;
  47. cifs_dbg(FYI, "disabling oplocks\n");
  48. break;
  49. default:
  50. server->echoes = true;
  51. server->oplocks = true;
  52. server->echo_credits = 1;
  53. server->oplock_credits = 1;
  54. }
  55. server->credits -= server->echo_credits + server->oplock_credits;
  56. return 0;
  57. }
  58. static void
  59. smb2_add_credits(struct TCP_Server_Info *server, const unsigned int add,
  60. const int optype)
  61. {
  62. int *val, rc = 0;
  63. spin_lock(&server->req_lock);
  64. val = server->ops->get_credits_field(server, optype);
  65. *val += add;
  66. server->in_flight--;
  67. if (server->in_flight == 0 && (optype & CIFS_OP_MASK) != CIFS_NEG_OP)
  68. rc = change_conf(server);
  69. /*
  70. * Sometimes server returns 0 credits on oplock break ack - we need to
  71. * rebalance credits in this case.
  72. */
  73. else if (server->in_flight > 0 && server->oplock_credits == 0 &&
  74. server->oplocks) {
  75. if (server->credits > 1) {
  76. server->credits--;
  77. server->oplock_credits++;
  78. }
  79. }
  80. spin_unlock(&server->req_lock);
  81. wake_up(&server->request_q);
  82. if (rc)
  83. cifs_reconnect(server);
  84. }
  85. static void
  86. smb2_set_credits(struct TCP_Server_Info *server, const int val)
  87. {
  88. spin_lock(&server->req_lock);
  89. server->credits = val;
  90. spin_unlock(&server->req_lock);
  91. }
  92. static int *
  93. smb2_get_credits_field(struct TCP_Server_Info *server, const int optype)
  94. {
  95. switch (optype) {
  96. case CIFS_ECHO_OP:
  97. return &server->echo_credits;
  98. case CIFS_OBREAK_OP:
  99. return &server->oplock_credits;
  100. default:
  101. return &server->credits;
  102. }
  103. }
  104. static unsigned int
  105. smb2_get_credits(struct mid_q_entry *mid)
  106. {
  107. return le16_to_cpu(((struct smb2_hdr *)mid->resp_buf)->CreditRequest);
  108. }
  109. static int
  110. smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
  111. unsigned int *num, unsigned int *credits)
  112. {
  113. int rc = 0;
  114. unsigned int scredits;
  115. spin_lock(&server->req_lock);
  116. while (1) {
  117. if (server->credits <= 0) {
  118. spin_unlock(&server->req_lock);
  119. cifs_num_waiters_inc(server);
  120. rc = wait_event_killable(server->request_q,
  121. has_credits(server, &server->credits));
  122. cifs_num_waiters_dec(server);
  123. if (rc)
  124. return rc;
  125. spin_lock(&server->req_lock);
  126. } else {
  127. if (server->tcpStatus == CifsExiting) {
  128. spin_unlock(&server->req_lock);
  129. return -ENOENT;
  130. }
  131. scredits = server->credits;
  132. /* can deadlock with reopen */
  133. if (scredits == 1) {
  134. *num = SMB2_MAX_BUFFER_SIZE;
  135. *credits = 0;
  136. break;
  137. }
  138. /* leave one credit for a possible reopen */
  139. scredits--;
  140. *num = min_t(unsigned int, size,
  141. scredits * SMB2_MAX_BUFFER_SIZE);
  142. *credits = DIV_ROUND_UP(*num, SMB2_MAX_BUFFER_SIZE);
  143. server->credits -= *credits;
  144. server->in_flight++;
  145. break;
  146. }
  147. }
  148. spin_unlock(&server->req_lock);
  149. return rc;
  150. }
  151. static __u64
  152. smb2_get_next_mid(struct TCP_Server_Info *server)
  153. {
  154. __u64 mid;
  155. /* for SMB2 we need the current value */
  156. spin_lock(&GlobalMid_Lock);
  157. mid = server->CurrentMid++;
  158. spin_unlock(&GlobalMid_Lock);
  159. return mid;
  160. }
  161. static struct mid_q_entry *
  162. smb2_find_mid(struct TCP_Server_Info *server, char *buf)
  163. {
  164. struct mid_q_entry *mid;
  165. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  166. __u64 wire_mid = le64_to_cpu(hdr->MessageId);
  167. spin_lock(&GlobalMid_Lock);
  168. list_for_each_entry(mid, &server->pending_mid_q, qhead) {
  169. if ((mid->mid == wire_mid) &&
  170. (mid->mid_state == MID_REQUEST_SUBMITTED) &&
  171. (mid->command == hdr->Command)) {
  172. spin_unlock(&GlobalMid_Lock);
  173. return mid;
  174. }
  175. }
  176. spin_unlock(&GlobalMid_Lock);
  177. return NULL;
  178. }
  179. static void
  180. smb2_dump_detail(void *buf)
  181. {
  182. #ifdef CONFIG_CIFS_DEBUG2
  183. struct smb2_hdr *smb = (struct smb2_hdr *)buf;
  184. cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Mid: %llu Pid: %d\n",
  185. smb->Command, smb->Status, smb->Flags, smb->MessageId,
  186. smb->ProcessId);
  187. cifs_dbg(VFS, "smb buf %p len %u\n", smb, smb2_calc_size(smb));
  188. #endif
  189. }
  190. static bool
  191. smb2_need_neg(struct TCP_Server_Info *server)
  192. {
  193. return server->max_read == 0;
  194. }
  195. static int
  196. smb2_negotiate(const unsigned int xid, struct cifs_ses *ses)
  197. {
  198. int rc;
  199. ses->server->CurrentMid = 0;
  200. rc = SMB2_negotiate(xid, ses);
  201. /* BB we probably don't need to retry with modern servers */
  202. if (rc == -EAGAIN)
  203. rc = -EHOSTDOWN;
  204. return rc;
  205. }
  206. static unsigned int
  207. smb2_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  208. {
  209. struct TCP_Server_Info *server = tcon->ses->server;
  210. unsigned int wsize;
  211. /* start with specified wsize, or default */
  212. wsize = volume_info->wsize ? volume_info->wsize : CIFS_DEFAULT_IOSIZE;
  213. wsize = min_t(unsigned int, wsize, server->max_write);
  214. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  215. wsize = min_t(unsigned int, wsize, SMB2_MAX_BUFFER_SIZE);
  216. return wsize;
  217. }
  218. static unsigned int
  219. smb2_negotiate_rsize(struct cifs_tcon *tcon, struct smb_vol *volume_info)
  220. {
  221. struct TCP_Server_Info *server = tcon->ses->server;
  222. unsigned int rsize;
  223. /* start with specified rsize, or default */
  224. rsize = volume_info->rsize ? volume_info->rsize : CIFS_DEFAULT_IOSIZE;
  225. rsize = min_t(unsigned int, rsize, server->max_read);
  226. if (!(server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
  227. rsize = min_t(unsigned int, rsize, SMB2_MAX_BUFFER_SIZE);
  228. return rsize;
  229. }
  230. #ifdef CONFIG_CIFS_STATS2
  231. static int
  232. SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
  233. {
  234. int rc;
  235. unsigned int ret_data_len = 0;
  236. struct network_interface_info_ioctl_rsp *out_buf;
  237. rc = SMB2_ioctl(xid, tcon, NO_FILE_ID, NO_FILE_ID,
  238. FSCTL_QUERY_NETWORK_INTERFACE_INFO, true /* is_fsctl */,
  239. NULL /* no data input */, 0 /* no data input */,
  240. (char **)&out_buf, &ret_data_len);
  241. if (rc != 0)
  242. cifs_dbg(VFS, "error %d on ioctl to get interface list\n", rc);
  243. else if (ret_data_len < sizeof(struct network_interface_info_ioctl_rsp)) {
  244. cifs_dbg(VFS, "server returned bad net interface info buf\n");
  245. rc = -EINVAL;
  246. } else {
  247. /* Dump info on first interface */
  248. cifs_dbg(FYI, "Adapter Capability 0x%x\t",
  249. le32_to_cpu(out_buf->Capability));
  250. cifs_dbg(FYI, "Link Speed %lld\n",
  251. le64_to_cpu(out_buf->LinkSpeed));
  252. }
  253. return rc;
  254. }
  255. #endif /* STATS2 */
  256. static void
  257. smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  258. {
  259. int rc;
  260. __le16 srch_path = 0; /* Null - open root of share */
  261. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  262. struct cifs_open_parms oparms;
  263. struct cifs_fid fid;
  264. oparms.tcon = tcon;
  265. oparms.desired_access = FILE_READ_ATTRIBUTES;
  266. oparms.disposition = FILE_OPEN;
  267. oparms.create_options = 0;
  268. oparms.fid = &fid;
  269. oparms.reconnect = false;
  270. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  271. if (rc)
  272. return;
  273. #ifdef CONFIG_CIFS_STATS2
  274. SMB3_request_interfaces(xid, tcon);
  275. #endif /* STATS2 */
  276. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  277. FS_ATTRIBUTE_INFORMATION);
  278. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  279. FS_DEVICE_INFORMATION);
  280. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  281. FS_SECTOR_SIZE_INFORMATION); /* SMB3 specific */
  282. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  283. return;
  284. }
  285. static void
  286. smb2_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon)
  287. {
  288. int rc;
  289. __le16 srch_path = 0; /* Null - open root of share */
  290. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  291. struct cifs_open_parms oparms;
  292. struct cifs_fid fid;
  293. oparms.tcon = tcon;
  294. oparms.desired_access = FILE_READ_ATTRIBUTES;
  295. oparms.disposition = FILE_OPEN;
  296. oparms.create_options = 0;
  297. oparms.fid = &fid;
  298. oparms.reconnect = false;
  299. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  300. if (rc)
  301. return;
  302. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  303. FS_ATTRIBUTE_INFORMATION);
  304. SMB2_QFS_attr(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  305. FS_DEVICE_INFORMATION);
  306. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  307. return;
  308. }
  309. static int
  310. smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
  311. struct cifs_sb_info *cifs_sb, const char *full_path)
  312. {
  313. int rc;
  314. __le16 *utf16_path;
  315. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  316. struct cifs_open_parms oparms;
  317. struct cifs_fid fid;
  318. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  319. if (!utf16_path)
  320. return -ENOMEM;
  321. oparms.tcon = tcon;
  322. oparms.desired_access = FILE_READ_ATTRIBUTES;
  323. oparms.disposition = FILE_OPEN;
  324. oparms.create_options = 0;
  325. oparms.fid = &fid;
  326. oparms.reconnect = false;
  327. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  328. if (rc) {
  329. kfree(utf16_path);
  330. return rc;
  331. }
  332. rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  333. kfree(utf16_path);
  334. return rc;
  335. }
  336. static int
  337. smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
  338. struct cifs_sb_info *cifs_sb, const char *full_path,
  339. u64 *uniqueid, FILE_ALL_INFO *data)
  340. {
  341. *uniqueid = le64_to_cpu(data->IndexNumber);
  342. return 0;
  343. }
  344. static int
  345. smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
  346. struct cifs_fid *fid, FILE_ALL_INFO *data)
  347. {
  348. int rc;
  349. struct smb2_file_all_info *smb2_data;
  350. smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
  351. GFP_KERNEL);
  352. if (smb2_data == NULL)
  353. return -ENOMEM;
  354. rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
  355. smb2_data);
  356. if (!rc)
  357. move_smb2_info_to_cifs(data, smb2_data);
  358. kfree(smb2_data);
  359. return rc;
  360. }
  361. static bool
  362. smb2_can_echo(struct TCP_Server_Info *server)
  363. {
  364. return server->echoes;
  365. }
  366. static void
  367. smb2_clear_stats(struct cifs_tcon *tcon)
  368. {
  369. #ifdef CONFIG_CIFS_STATS
  370. int i;
  371. for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
  372. atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
  373. atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
  374. }
  375. #endif
  376. }
  377. static void
  378. smb2_dump_share_caps(struct seq_file *m, struct cifs_tcon *tcon)
  379. {
  380. seq_puts(m, "\n\tShare Capabilities:");
  381. if (tcon->capabilities & SMB2_SHARE_CAP_DFS)
  382. seq_puts(m, " DFS,");
  383. if (tcon->capabilities & SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY)
  384. seq_puts(m, " CONTINUOUS AVAILABILITY,");
  385. if (tcon->capabilities & SMB2_SHARE_CAP_SCALEOUT)
  386. seq_puts(m, " SCALEOUT,");
  387. if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER)
  388. seq_puts(m, " CLUSTER,");
  389. if (tcon->capabilities & SMB2_SHARE_CAP_ASYMMETRIC)
  390. seq_puts(m, " ASYMMETRIC,");
  391. if (tcon->capabilities == 0)
  392. seq_puts(m, " None");
  393. if (tcon->ss_flags & SSINFO_FLAGS_ALIGNED_DEVICE)
  394. seq_puts(m, " Aligned,");
  395. if (tcon->ss_flags & SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE)
  396. seq_puts(m, " Partition Aligned,");
  397. if (tcon->ss_flags & SSINFO_FLAGS_NO_SEEK_PENALTY)
  398. seq_puts(m, " SSD,");
  399. if (tcon->ss_flags & SSINFO_FLAGS_TRIM_ENABLED)
  400. seq_puts(m, " TRIM-support,");
  401. seq_printf(m, "\tShare Flags: 0x%x", tcon->share_flags);
  402. if (tcon->perf_sector_size)
  403. seq_printf(m, "\tOptimal sector size: 0x%x",
  404. tcon->perf_sector_size);
  405. }
  406. static void
  407. smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
  408. {
  409. #ifdef CONFIG_CIFS_STATS
  410. atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
  411. atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
  412. seq_printf(m, "\nNegotiates: %d sent %d failed",
  413. atomic_read(&sent[SMB2_NEGOTIATE_HE]),
  414. atomic_read(&failed[SMB2_NEGOTIATE_HE]));
  415. seq_printf(m, "\nSessionSetups: %d sent %d failed",
  416. atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
  417. atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
  418. seq_printf(m, "\nLogoffs: %d sent %d failed",
  419. atomic_read(&sent[SMB2_LOGOFF_HE]),
  420. atomic_read(&failed[SMB2_LOGOFF_HE]));
  421. seq_printf(m, "\nTreeConnects: %d sent %d failed",
  422. atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
  423. atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
  424. seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
  425. atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
  426. atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
  427. seq_printf(m, "\nCreates: %d sent %d failed",
  428. atomic_read(&sent[SMB2_CREATE_HE]),
  429. atomic_read(&failed[SMB2_CREATE_HE]));
  430. seq_printf(m, "\nCloses: %d sent %d failed",
  431. atomic_read(&sent[SMB2_CLOSE_HE]),
  432. atomic_read(&failed[SMB2_CLOSE_HE]));
  433. seq_printf(m, "\nFlushes: %d sent %d failed",
  434. atomic_read(&sent[SMB2_FLUSH_HE]),
  435. atomic_read(&failed[SMB2_FLUSH_HE]));
  436. seq_printf(m, "\nReads: %d sent %d failed",
  437. atomic_read(&sent[SMB2_READ_HE]),
  438. atomic_read(&failed[SMB2_READ_HE]));
  439. seq_printf(m, "\nWrites: %d sent %d failed",
  440. atomic_read(&sent[SMB2_WRITE_HE]),
  441. atomic_read(&failed[SMB2_WRITE_HE]));
  442. seq_printf(m, "\nLocks: %d sent %d failed",
  443. atomic_read(&sent[SMB2_LOCK_HE]),
  444. atomic_read(&failed[SMB2_LOCK_HE]));
  445. seq_printf(m, "\nIOCTLs: %d sent %d failed",
  446. atomic_read(&sent[SMB2_IOCTL_HE]),
  447. atomic_read(&failed[SMB2_IOCTL_HE]));
  448. seq_printf(m, "\nCancels: %d sent %d failed",
  449. atomic_read(&sent[SMB2_CANCEL_HE]),
  450. atomic_read(&failed[SMB2_CANCEL_HE]));
  451. seq_printf(m, "\nEchos: %d sent %d failed",
  452. atomic_read(&sent[SMB2_ECHO_HE]),
  453. atomic_read(&failed[SMB2_ECHO_HE]));
  454. seq_printf(m, "\nQueryDirectories: %d sent %d failed",
  455. atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
  456. atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
  457. seq_printf(m, "\nChangeNotifies: %d sent %d failed",
  458. atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
  459. atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
  460. seq_printf(m, "\nQueryInfos: %d sent %d failed",
  461. atomic_read(&sent[SMB2_QUERY_INFO_HE]),
  462. atomic_read(&failed[SMB2_QUERY_INFO_HE]));
  463. seq_printf(m, "\nSetInfos: %d sent %d failed",
  464. atomic_read(&sent[SMB2_SET_INFO_HE]),
  465. atomic_read(&failed[SMB2_SET_INFO_HE]));
  466. seq_printf(m, "\nOplockBreaks: %d sent %d failed",
  467. atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
  468. atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
  469. #endif
  470. }
  471. static void
  472. smb2_set_fid(struct cifsFileInfo *cfile, struct cifs_fid *fid, __u32 oplock)
  473. {
  474. struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
  475. struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
  476. cfile->fid.persistent_fid = fid->persistent_fid;
  477. cfile->fid.volatile_fid = fid->volatile_fid;
  478. server->ops->set_oplock_level(cinode, oplock, fid->epoch,
  479. &fid->purge_cache);
  480. cinode->can_cache_brlcks = CIFS_CACHE_WRITE(cinode);
  481. }
  482. static void
  483. smb2_close_file(const unsigned int xid, struct cifs_tcon *tcon,
  484. struct cifs_fid *fid)
  485. {
  486. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  487. }
  488. static int
  489. SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,
  490. u64 persistent_fid, u64 volatile_fid,
  491. struct copychunk_ioctl *pcchunk)
  492. {
  493. int rc;
  494. unsigned int ret_data_len;
  495. struct resume_key_req *res_key;
  496. rc = SMB2_ioctl(xid, tcon, persistent_fid, volatile_fid,
  497. FSCTL_SRV_REQUEST_RESUME_KEY, true /* is_fsctl */,
  498. NULL, 0 /* no input */,
  499. (char **)&res_key, &ret_data_len);
  500. if (rc) {
  501. cifs_dbg(VFS, "refcpy ioctl error %d getting resume key\n", rc);
  502. goto req_res_key_exit;
  503. }
  504. if (ret_data_len < sizeof(struct resume_key_req)) {
  505. cifs_dbg(VFS, "Invalid refcopy resume key length\n");
  506. rc = -EINVAL;
  507. goto req_res_key_exit;
  508. }
  509. memcpy(pcchunk->SourceKey, res_key->ResumeKey, COPY_CHUNK_RES_KEY_SIZE);
  510. req_res_key_exit:
  511. kfree(res_key);
  512. return rc;
  513. }
  514. static int
  515. smb2_clone_range(const unsigned int xid,
  516. struct cifsFileInfo *srcfile,
  517. struct cifsFileInfo *trgtfile, u64 src_off,
  518. u64 len, u64 dest_off)
  519. {
  520. int rc;
  521. unsigned int ret_data_len;
  522. struct copychunk_ioctl *pcchunk;
  523. struct copychunk_ioctl_rsp *retbuf = NULL;
  524. struct cifs_tcon *tcon;
  525. int chunks_copied = 0;
  526. bool chunk_sizes_updated = false;
  527. pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL);
  528. if (pcchunk == NULL)
  529. return -ENOMEM;
  530. cifs_dbg(FYI, "in smb2_clone_range - about to call request res key\n");
  531. /* Request a key from the server to identify the source of the copy */
  532. rc = SMB2_request_res_key(xid, tlink_tcon(srcfile->tlink),
  533. srcfile->fid.persistent_fid,
  534. srcfile->fid.volatile_fid, pcchunk);
  535. /* Note: request_res_key sets res_key null only if rc !=0 */
  536. if (rc)
  537. goto cchunk_out;
  538. /* For now array only one chunk long, will make more flexible later */
  539. pcchunk->ChunkCount = cpu_to_le32(1);
  540. pcchunk->Reserved = 0;
  541. pcchunk->Reserved2 = 0;
  542. tcon = tlink_tcon(trgtfile->tlink);
  543. while (len > 0) {
  544. pcchunk->SourceOffset = cpu_to_le64(src_off);
  545. pcchunk->TargetOffset = cpu_to_le64(dest_off);
  546. pcchunk->Length =
  547. cpu_to_le32(min_t(u32, len, tcon->max_bytes_chunk));
  548. /* Request server copy to target from src identified by key */
  549. rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,
  550. trgtfile->fid.volatile_fid, FSCTL_SRV_COPYCHUNK_WRITE,
  551. true /* is_fsctl */, (char *)pcchunk,
  552. sizeof(struct copychunk_ioctl), (char **)&retbuf,
  553. &ret_data_len);
  554. if (rc == 0) {
  555. if (ret_data_len !=
  556. sizeof(struct copychunk_ioctl_rsp)) {
  557. cifs_dbg(VFS, "invalid cchunk response size\n");
  558. rc = -EIO;
  559. goto cchunk_out;
  560. }
  561. if (retbuf->TotalBytesWritten == 0) {
  562. cifs_dbg(FYI, "no bytes copied\n");
  563. rc = -EIO;
  564. goto cchunk_out;
  565. }
  566. /*
  567. * Check if server claimed to write more than we asked
  568. */
  569. if (le32_to_cpu(retbuf->TotalBytesWritten) >
  570. le32_to_cpu(pcchunk->Length)) {
  571. cifs_dbg(VFS, "invalid copy chunk response\n");
  572. rc = -EIO;
  573. goto cchunk_out;
  574. }
  575. if (le32_to_cpu(retbuf->ChunksWritten) != 1) {
  576. cifs_dbg(VFS, "invalid num chunks written\n");
  577. rc = -EIO;
  578. goto cchunk_out;
  579. }
  580. chunks_copied++;
  581. src_off += le32_to_cpu(retbuf->TotalBytesWritten);
  582. dest_off += le32_to_cpu(retbuf->TotalBytesWritten);
  583. len -= le32_to_cpu(retbuf->TotalBytesWritten);
  584. cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
  585. le32_to_cpu(retbuf->ChunksWritten),
  586. le32_to_cpu(retbuf->ChunkBytesWritten),
  587. le32_to_cpu(retbuf->TotalBytesWritten));
  588. } else if (rc == -EINVAL) {
  589. if (ret_data_len != sizeof(struct copychunk_ioctl_rsp))
  590. goto cchunk_out;
  591. cifs_dbg(FYI, "MaxChunks %d BytesChunk %d MaxCopy %d\n",
  592. le32_to_cpu(retbuf->ChunksWritten),
  593. le32_to_cpu(retbuf->ChunkBytesWritten),
  594. le32_to_cpu(retbuf->TotalBytesWritten));
  595. /*
  596. * Check if this is the first request using these sizes,
  597. * (ie check if copy succeed once with original sizes
  598. * and check if the server gave us different sizes after
  599. * we already updated max sizes on previous request).
  600. * if not then why is the server returning an error now
  601. */
  602. if ((chunks_copied != 0) || chunk_sizes_updated)
  603. goto cchunk_out;
  604. /* Check that server is not asking us to grow size */
  605. if (le32_to_cpu(retbuf->ChunkBytesWritten) <
  606. tcon->max_bytes_chunk)
  607. tcon->max_bytes_chunk =
  608. le32_to_cpu(retbuf->ChunkBytesWritten);
  609. else
  610. goto cchunk_out; /* server gave us bogus size */
  611. /* No need to change MaxChunks since already set to 1 */
  612. chunk_sizes_updated = true;
  613. } else
  614. goto cchunk_out;
  615. }
  616. cchunk_out:
  617. kfree(pcchunk);
  618. return rc;
  619. }
  620. static int
  621. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  622. struct cifs_fid *fid)
  623. {
  624. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  625. }
  626. static unsigned int
  627. smb2_read_data_offset(char *buf)
  628. {
  629. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  630. return rsp->DataOffset;
  631. }
  632. static unsigned int
  633. smb2_read_data_length(char *buf)
  634. {
  635. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  636. return le32_to_cpu(rsp->DataLength);
  637. }
  638. static int
  639. smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
  640. struct cifs_io_parms *parms, unsigned int *bytes_read,
  641. char **buf, int *buf_type)
  642. {
  643. parms->persistent_fid = pfid->persistent_fid;
  644. parms->volatile_fid = pfid->volatile_fid;
  645. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  646. }
  647. static int
  648. smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
  649. struct cifs_io_parms *parms, unsigned int *written,
  650. struct kvec *iov, unsigned long nr_segs)
  651. {
  652. parms->persistent_fid = pfid->persistent_fid;
  653. parms->volatile_fid = pfid->volatile_fid;
  654. return SMB2_write(xid, parms, written, iov, nr_segs);
  655. }
  656. /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
  657. static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
  658. struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
  659. {
  660. struct cifsInodeInfo *cifsi;
  661. int rc;
  662. cifsi = CIFS_I(inode);
  663. /* if file already sparse don't bother setting sparse again */
  664. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
  665. return true; /* already sparse */
  666. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
  667. return true; /* already not sparse */
  668. /*
  669. * Can't check for sparse support on share the usual way via the
  670. * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
  671. * since Samba server doesn't set the flag on the share, yet
  672. * supports the set sparse FSCTL and returns sparse correctly
  673. * in the file attributes. If we fail setting sparse though we
  674. * mark that server does not support sparse files for this share
  675. * to avoid repeatedly sending the unsupported fsctl to server
  676. * if the file is repeatedly extended.
  677. */
  678. if (tcon->broken_sparse_sup)
  679. return false;
  680. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  681. cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
  682. true /* is_fctl */, &setsparse, 1, NULL, NULL);
  683. if (rc) {
  684. tcon->broken_sparse_sup = true;
  685. cifs_dbg(FYI, "set sparse rc = %d\n", rc);
  686. return false;
  687. }
  688. if (setsparse)
  689. cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
  690. else
  691. cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
  692. return true;
  693. }
  694. static int
  695. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  696. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  697. {
  698. __le64 eof = cpu_to_le64(size);
  699. struct inode *inode;
  700. /*
  701. * If extending file more than one page make sparse. Many Linux fs
  702. * make files sparse by default when extending via ftruncate
  703. */
  704. inode = d_inode(cfile->dentry);
  705. if (!set_alloc && (size > inode->i_size + 8192)) {
  706. __u8 set_sparse = 1;
  707. /* whether set sparse succeeds or not, extend the file */
  708. smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
  709. }
  710. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  711. cfile->fid.volatile_fid, cfile->pid, &eof, false);
  712. }
  713. static int
  714. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  715. struct cifsFileInfo *cfile)
  716. {
  717. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  718. cfile->fid.volatile_fid);
  719. }
  720. static int
  721. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  722. const char *path, struct cifs_sb_info *cifs_sb,
  723. struct cifs_fid *fid, __u16 search_flags,
  724. struct cifs_search_info *srch_inf)
  725. {
  726. __le16 *utf16_path;
  727. int rc;
  728. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  729. struct cifs_open_parms oparms;
  730. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  731. if (!utf16_path)
  732. return -ENOMEM;
  733. oparms.tcon = tcon;
  734. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  735. oparms.disposition = FILE_OPEN;
  736. oparms.create_options = 0;
  737. oparms.fid = fid;
  738. oparms.reconnect = false;
  739. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  740. kfree(utf16_path);
  741. if (rc) {
  742. cifs_dbg(VFS, "open dir failed\n");
  743. return rc;
  744. }
  745. srch_inf->entries_in_buffer = 0;
  746. srch_inf->index_of_last_entry = 0;
  747. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  748. fid->volatile_fid, 0, srch_inf);
  749. if (rc) {
  750. cifs_dbg(VFS, "query directory failed\n");
  751. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  752. }
  753. return rc;
  754. }
  755. static int
  756. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  757. struct cifs_fid *fid, __u16 search_flags,
  758. struct cifs_search_info *srch_inf)
  759. {
  760. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  761. fid->volatile_fid, 0, srch_inf);
  762. }
  763. static int
  764. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  765. struct cifs_fid *fid)
  766. {
  767. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  768. }
  769. /*
  770. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  771. * the number of credits and return true. Otherwise - return false.
  772. */
  773. static bool
  774. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  775. {
  776. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  777. if (hdr->Status != STATUS_PENDING)
  778. return false;
  779. if (!length) {
  780. spin_lock(&server->req_lock);
  781. server->credits += le16_to_cpu(hdr->CreditRequest);
  782. spin_unlock(&server->req_lock);
  783. wake_up(&server->request_q);
  784. }
  785. return true;
  786. }
  787. static int
  788. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  789. struct cifsInodeInfo *cinode)
  790. {
  791. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  792. return SMB2_lease_break(0, tcon, cinode->lease_key,
  793. smb2_get_lease_state(cinode));
  794. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  795. fid->volatile_fid,
  796. CIFS_CACHE_READ(cinode) ? 1 : 0);
  797. }
  798. static int
  799. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  800. struct kstatfs *buf)
  801. {
  802. int rc;
  803. __le16 srch_path = 0; /* Null - open root of share */
  804. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  805. struct cifs_open_parms oparms;
  806. struct cifs_fid fid;
  807. oparms.tcon = tcon;
  808. oparms.desired_access = FILE_READ_ATTRIBUTES;
  809. oparms.disposition = FILE_OPEN;
  810. oparms.create_options = 0;
  811. oparms.fid = &fid;
  812. oparms.reconnect = false;
  813. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  814. if (rc)
  815. return rc;
  816. buf->f_type = SMB2_MAGIC_NUMBER;
  817. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  818. buf);
  819. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  820. return rc;
  821. }
  822. static bool
  823. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  824. {
  825. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  826. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  827. }
  828. static int
  829. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  830. __u64 length, __u32 type, int lock, int unlock, bool wait)
  831. {
  832. if (unlock && !lock)
  833. type = SMB2_LOCKFLAG_UNLOCK;
  834. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  835. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  836. current->tgid, length, offset, type, wait);
  837. }
  838. static void
  839. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  840. {
  841. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  842. }
  843. static void
  844. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  845. {
  846. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  847. }
  848. static void
  849. smb2_new_lease_key(struct cifs_fid *fid)
  850. {
  851. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  852. }
  853. static int
  854. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  855. const char *full_path, char **target_path,
  856. struct cifs_sb_info *cifs_sb)
  857. {
  858. int rc;
  859. __le16 *utf16_path;
  860. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  861. struct cifs_open_parms oparms;
  862. struct cifs_fid fid;
  863. struct smb2_err_rsp *err_buf = NULL;
  864. struct smb2_symlink_err_rsp *symlink;
  865. unsigned int sub_len, sub_offset;
  866. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  867. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  868. if (!utf16_path)
  869. return -ENOMEM;
  870. oparms.tcon = tcon;
  871. oparms.desired_access = FILE_READ_ATTRIBUTES;
  872. oparms.disposition = FILE_OPEN;
  873. oparms.create_options = 0;
  874. oparms.fid = &fid;
  875. oparms.reconnect = false;
  876. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  877. if (!rc || !err_buf) {
  878. kfree(utf16_path);
  879. return -ENOENT;
  880. }
  881. /* open must fail on symlink - reset rc */
  882. rc = 0;
  883. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  884. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  885. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  886. *target_path = cifs_strndup_from_utf16(
  887. (char *)symlink->PathBuffer + sub_offset,
  888. sub_len, true, cifs_sb->local_nls);
  889. if (!(*target_path)) {
  890. kfree(utf16_path);
  891. return -ENOMEM;
  892. }
  893. convert_delimiter(*target_path, '/');
  894. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  895. kfree(utf16_path);
  896. return rc;
  897. }
  898. static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
  899. loff_t offset, loff_t len, bool keep_size)
  900. {
  901. struct inode *inode;
  902. struct cifsInodeInfo *cifsi;
  903. struct cifsFileInfo *cfile = file->private_data;
  904. struct file_zero_data_information fsctl_buf;
  905. long rc;
  906. unsigned int xid;
  907. xid = get_xid();
  908. inode = d_inode(cfile->dentry);
  909. cifsi = CIFS_I(inode);
  910. /* if file not oplocked can't be sure whether asking to extend size */
  911. if (!CIFS_CACHE_READ(cifsi))
  912. if (keep_size == false)
  913. return -EOPNOTSUPP;
  914. /*
  915. * Must check if file sparse since fallocate -z (zero range) assumes
  916. * non-sparse allocation
  917. */
  918. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
  919. return -EOPNOTSUPP;
  920. /*
  921. * need to make sure we are not asked to extend the file since the SMB3
  922. * fsctl does not change the file size. In the future we could change
  923. * this to zero the first part of the range then set the file size
  924. * which for a non sparse file would zero the newly extended range
  925. */
  926. if (keep_size == false)
  927. if (i_size_read(inode) < offset + len)
  928. return -EOPNOTSUPP;
  929. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  930. fsctl_buf.FileOffset = cpu_to_le64(offset);
  931. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  932. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  933. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  934. true /* is_fctl */, (char *)&fsctl_buf,
  935. sizeof(struct file_zero_data_information), NULL, NULL);
  936. free_xid(xid);
  937. return rc;
  938. }
  939. static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
  940. loff_t offset, loff_t len)
  941. {
  942. struct inode *inode;
  943. struct cifsInodeInfo *cifsi;
  944. struct cifsFileInfo *cfile = file->private_data;
  945. struct file_zero_data_information fsctl_buf;
  946. long rc;
  947. unsigned int xid;
  948. __u8 set_sparse = 1;
  949. xid = get_xid();
  950. inode = d_inode(cfile->dentry);
  951. cifsi = CIFS_I(inode);
  952. /* Need to make file sparse, if not already, before freeing range. */
  953. /* Consider adding equivalent for compressed since it could also work */
  954. if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
  955. return -EOPNOTSUPP;
  956. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  957. fsctl_buf.FileOffset = cpu_to_le64(offset);
  958. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  959. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  960. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  961. true /* is_fctl */, (char *)&fsctl_buf,
  962. sizeof(struct file_zero_data_information), NULL, NULL);
  963. free_xid(xid);
  964. return rc;
  965. }
  966. static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
  967. loff_t off, loff_t len, bool keep_size)
  968. {
  969. struct inode *inode;
  970. struct cifsInodeInfo *cifsi;
  971. struct cifsFileInfo *cfile = file->private_data;
  972. long rc = -EOPNOTSUPP;
  973. unsigned int xid;
  974. xid = get_xid();
  975. inode = d_inode(cfile->dentry);
  976. cifsi = CIFS_I(inode);
  977. /* if file not oplocked can't be sure whether asking to extend size */
  978. if (!CIFS_CACHE_READ(cifsi))
  979. if (keep_size == false)
  980. return -EOPNOTSUPP;
  981. /*
  982. * Files are non-sparse by default so falloc may be a no-op
  983. * Must check if file sparse. If not sparse, and not extending
  984. * then no need to do anything since file already allocated
  985. */
  986. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
  987. if (keep_size == true)
  988. return 0;
  989. /* check if extending file */
  990. else if (i_size_read(inode) >= off + len)
  991. /* not extending file and already not sparse */
  992. return 0;
  993. /* BB: in future add else clause to extend file */
  994. else
  995. return -EOPNOTSUPP;
  996. }
  997. if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
  998. /*
  999. * Check if falloc starts within first few pages of file
  1000. * and ends within a few pages of the end of file to
  1001. * ensure that most of file is being forced to be
  1002. * fallocated now. If so then setting whole file sparse
  1003. * ie potentially making a few extra pages at the beginning
  1004. * or end of the file non-sparse via set_sparse is harmless.
  1005. */
  1006. if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
  1007. return -EOPNOTSUPP;
  1008. rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
  1009. }
  1010. /* BB: else ... in future add code to extend file and set sparse */
  1011. free_xid(xid);
  1012. return rc;
  1013. }
  1014. static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
  1015. loff_t off, loff_t len)
  1016. {
  1017. /* KEEP_SIZE already checked for by do_fallocate */
  1018. if (mode & FALLOC_FL_PUNCH_HOLE)
  1019. return smb3_punch_hole(file, tcon, off, len);
  1020. else if (mode & FALLOC_FL_ZERO_RANGE) {
  1021. if (mode & FALLOC_FL_KEEP_SIZE)
  1022. return smb3_zero_range(file, tcon, off, len, true);
  1023. return smb3_zero_range(file, tcon, off, len, false);
  1024. } else if (mode == FALLOC_FL_KEEP_SIZE)
  1025. return smb3_simple_falloc(file, tcon, off, len, true);
  1026. else if (mode == 0)
  1027. return smb3_simple_falloc(file, tcon, off, len, false);
  1028. return -EOPNOTSUPP;
  1029. }
  1030. static void
  1031. smb2_downgrade_oplock(struct TCP_Server_Info *server,
  1032. struct cifsInodeInfo *cinode, bool set_level2)
  1033. {
  1034. if (set_level2)
  1035. server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
  1036. 0, NULL);
  1037. else
  1038. server->ops->set_oplock_level(cinode, 0, 0, NULL);
  1039. }
  1040. static void
  1041. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1042. unsigned int epoch, bool *purge_cache)
  1043. {
  1044. oplock &= 0xFF;
  1045. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1046. return;
  1047. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  1048. cinode->oplock = CIFS_CACHE_RHW_FLG;
  1049. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  1050. &cinode->vfs_inode);
  1051. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  1052. cinode->oplock = CIFS_CACHE_RW_FLG;
  1053. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  1054. &cinode->vfs_inode);
  1055. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  1056. cinode->oplock = CIFS_CACHE_READ_FLG;
  1057. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  1058. &cinode->vfs_inode);
  1059. } else
  1060. cinode->oplock = 0;
  1061. }
  1062. static void
  1063. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1064. unsigned int epoch, bool *purge_cache)
  1065. {
  1066. char message[5] = {0};
  1067. oplock &= 0xFF;
  1068. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1069. return;
  1070. cinode->oplock = 0;
  1071. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  1072. cinode->oplock |= CIFS_CACHE_READ_FLG;
  1073. strcat(message, "R");
  1074. }
  1075. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  1076. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  1077. strcat(message, "H");
  1078. }
  1079. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  1080. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  1081. strcat(message, "W");
  1082. }
  1083. if (!cinode->oplock)
  1084. strcat(message, "None");
  1085. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  1086. &cinode->vfs_inode);
  1087. }
  1088. static void
  1089. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1090. unsigned int epoch, bool *purge_cache)
  1091. {
  1092. unsigned int old_oplock = cinode->oplock;
  1093. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  1094. if (purge_cache) {
  1095. *purge_cache = false;
  1096. if (old_oplock == CIFS_CACHE_READ_FLG) {
  1097. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  1098. (epoch - cinode->epoch > 0))
  1099. *purge_cache = true;
  1100. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1101. (epoch - cinode->epoch > 1))
  1102. *purge_cache = true;
  1103. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1104. (epoch - cinode->epoch > 1))
  1105. *purge_cache = true;
  1106. else if (cinode->oplock == 0 &&
  1107. (epoch - cinode->epoch > 0))
  1108. *purge_cache = true;
  1109. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  1110. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1111. (epoch - cinode->epoch > 0))
  1112. *purge_cache = true;
  1113. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1114. (epoch - cinode->epoch > 1))
  1115. *purge_cache = true;
  1116. }
  1117. cinode->epoch = epoch;
  1118. }
  1119. }
  1120. static bool
  1121. smb2_is_read_op(__u32 oplock)
  1122. {
  1123. return oplock == SMB2_OPLOCK_LEVEL_II;
  1124. }
  1125. static bool
  1126. smb21_is_read_op(__u32 oplock)
  1127. {
  1128. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  1129. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  1130. }
  1131. static __le32
  1132. map_oplock_to_lease(u8 oplock)
  1133. {
  1134. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  1135. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  1136. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  1137. return SMB2_LEASE_READ_CACHING;
  1138. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  1139. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  1140. SMB2_LEASE_WRITE_CACHING;
  1141. return 0;
  1142. }
  1143. static char *
  1144. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  1145. {
  1146. struct create_lease *buf;
  1147. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  1148. if (!buf)
  1149. return NULL;
  1150. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1151. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1152. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1153. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1154. (struct create_lease, lcontext));
  1155. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  1156. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1157. (struct create_lease, Name));
  1158. buf->ccontext.NameLength = cpu_to_le16(4);
  1159. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1160. buf->Name[0] = 'R';
  1161. buf->Name[1] = 'q';
  1162. buf->Name[2] = 'L';
  1163. buf->Name[3] = 's';
  1164. return (char *)buf;
  1165. }
  1166. static char *
  1167. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  1168. {
  1169. struct create_lease_v2 *buf;
  1170. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  1171. if (!buf)
  1172. return NULL;
  1173. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1174. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1175. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1176. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1177. (struct create_lease_v2, lcontext));
  1178. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  1179. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1180. (struct create_lease_v2, Name));
  1181. buf->ccontext.NameLength = cpu_to_le16(4);
  1182. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1183. buf->Name[0] = 'R';
  1184. buf->Name[1] = 'q';
  1185. buf->Name[2] = 'L';
  1186. buf->Name[3] = 's';
  1187. return (char *)buf;
  1188. }
  1189. static __u8
  1190. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  1191. {
  1192. struct create_lease *lc = (struct create_lease *)buf;
  1193. *epoch = 0; /* not used */
  1194. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1195. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1196. return le32_to_cpu(lc->lcontext.LeaseState);
  1197. }
  1198. static __u8
  1199. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  1200. {
  1201. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  1202. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  1203. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1204. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1205. return le32_to_cpu(lc->lcontext.LeaseState);
  1206. }
  1207. static unsigned int
  1208. smb2_wp_retry_size(struct inode *inode)
  1209. {
  1210. return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
  1211. SMB2_MAX_BUFFER_SIZE);
  1212. }
  1213. static bool
  1214. smb2_dir_needs_close(struct cifsFileInfo *cfile)
  1215. {
  1216. return !cfile->invalidHandle;
  1217. }
  1218. struct smb_version_operations smb20_operations = {
  1219. .compare_fids = smb2_compare_fids,
  1220. .setup_request = smb2_setup_request,
  1221. .setup_async_request = smb2_setup_async_request,
  1222. .check_receive = smb2_check_receive,
  1223. .add_credits = smb2_add_credits,
  1224. .set_credits = smb2_set_credits,
  1225. .get_credits_field = smb2_get_credits_field,
  1226. .get_credits = smb2_get_credits,
  1227. .wait_mtu_credits = cifs_wait_mtu_credits,
  1228. .get_next_mid = smb2_get_next_mid,
  1229. .read_data_offset = smb2_read_data_offset,
  1230. .read_data_length = smb2_read_data_length,
  1231. .map_error = map_smb2_to_linux_error,
  1232. .find_mid = smb2_find_mid,
  1233. .check_message = smb2_check_message,
  1234. .dump_detail = smb2_dump_detail,
  1235. .clear_stats = smb2_clear_stats,
  1236. .print_stats = smb2_print_stats,
  1237. .is_oplock_break = smb2_is_valid_oplock_break,
  1238. .downgrade_oplock = smb2_downgrade_oplock,
  1239. .need_neg = smb2_need_neg,
  1240. .negotiate = smb2_negotiate,
  1241. .negotiate_wsize = smb2_negotiate_wsize,
  1242. .negotiate_rsize = smb2_negotiate_rsize,
  1243. .sess_setup = SMB2_sess_setup,
  1244. .logoff = SMB2_logoff,
  1245. .tree_connect = SMB2_tcon,
  1246. .tree_disconnect = SMB2_tdis,
  1247. .qfs_tcon = smb2_qfs_tcon,
  1248. .is_path_accessible = smb2_is_path_accessible,
  1249. .can_echo = smb2_can_echo,
  1250. .echo = SMB2_echo,
  1251. .query_path_info = smb2_query_path_info,
  1252. .get_srv_inum = smb2_get_srv_inum,
  1253. .query_file_info = smb2_query_file_info,
  1254. .set_path_size = smb2_set_path_size,
  1255. .set_file_size = smb2_set_file_size,
  1256. .set_file_info = smb2_set_file_info,
  1257. .set_compression = smb2_set_compression,
  1258. .mkdir = smb2_mkdir,
  1259. .mkdir_setinfo = smb2_mkdir_setinfo,
  1260. .rmdir = smb2_rmdir,
  1261. .unlink = smb2_unlink,
  1262. .rename = smb2_rename_path,
  1263. .create_hardlink = smb2_create_hardlink,
  1264. .query_symlink = smb2_query_symlink,
  1265. .open = smb2_open_file,
  1266. .set_fid = smb2_set_fid,
  1267. .close = smb2_close_file,
  1268. .flush = smb2_flush_file,
  1269. .async_readv = smb2_async_readv,
  1270. .async_writev = smb2_async_writev,
  1271. .sync_read = smb2_sync_read,
  1272. .sync_write = smb2_sync_write,
  1273. .query_dir_first = smb2_query_dir_first,
  1274. .query_dir_next = smb2_query_dir_next,
  1275. .close_dir = smb2_close_dir,
  1276. .calc_smb_size = smb2_calc_size,
  1277. .is_status_pending = smb2_is_status_pending,
  1278. .oplock_response = smb2_oplock_response,
  1279. .queryfs = smb2_queryfs,
  1280. .mand_lock = smb2_mand_lock,
  1281. .mand_unlock_range = smb2_unlock_range,
  1282. .push_mand_locks = smb2_push_mandatory_locks,
  1283. .get_lease_key = smb2_get_lease_key,
  1284. .set_lease_key = smb2_set_lease_key,
  1285. .new_lease_key = smb2_new_lease_key,
  1286. .calc_signature = smb2_calc_signature,
  1287. .is_read_op = smb2_is_read_op,
  1288. .set_oplock_level = smb2_set_oplock_level,
  1289. .create_lease_buf = smb2_create_lease_buf,
  1290. .parse_lease_buf = smb2_parse_lease_buf,
  1291. .clone_range = smb2_clone_range,
  1292. .wp_retry_size = smb2_wp_retry_size,
  1293. .dir_needs_close = smb2_dir_needs_close,
  1294. };
  1295. struct smb_version_operations smb21_operations = {
  1296. .compare_fids = smb2_compare_fids,
  1297. .setup_request = smb2_setup_request,
  1298. .setup_async_request = smb2_setup_async_request,
  1299. .check_receive = smb2_check_receive,
  1300. .add_credits = smb2_add_credits,
  1301. .set_credits = smb2_set_credits,
  1302. .get_credits_field = smb2_get_credits_field,
  1303. .get_credits = smb2_get_credits,
  1304. .wait_mtu_credits = smb2_wait_mtu_credits,
  1305. .get_next_mid = smb2_get_next_mid,
  1306. .read_data_offset = smb2_read_data_offset,
  1307. .read_data_length = smb2_read_data_length,
  1308. .map_error = map_smb2_to_linux_error,
  1309. .find_mid = smb2_find_mid,
  1310. .check_message = smb2_check_message,
  1311. .dump_detail = smb2_dump_detail,
  1312. .clear_stats = smb2_clear_stats,
  1313. .print_stats = smb2_print_stats,
  1314. .is_oplock_break = smb2_is_valid_oplock_break,
  1315. .downgrade_oplock = smb2_downgrade_oplock,
  1316. .need_neg = smb2_need_neg,
  1317. .negotiate = smb2_negotiate,
  1318. .negotiate_wsize = smb2_negotiate_wsize,
  1319. .negotiate_rsize = smb2_negotiate_rsize,
  1320. .sess_setup = SMB2_sess_setup,
  1321. .logoff = SMB2_logoff,
  1322. .tree_connect = SMB2_tcon,
  1323. .tree_disconnect = SMB2_tdis,
  1324. .qfs_tcon = smb2_qfs_tcon,
  1325. .is_path_accessible = smb2_is_path_accessible,
  1326. .can_echo = smb2_can_echo,
  1327. .echo = SMB2_echo,
  1328. .query_path_info = smb2_query_path_info,
  1329. .get_srv_inum = smb2_get_srv_inum,
  1330. .query_file_info = smb2_query_file_info,
  1331. .set_path_size = smb2_set_path_size,
  1332. .set_file_size = smb2_set_file_size,
  1333. .set_file_info = smb2_set_file_info,
  1334. .set_compression = smb2_set_compression,
  1335. .mkdir = smb2_mkdir,
  1336. .mkdir_setinfo = smb2_mkdir_setinfo,
  1337. .rmdir = smb2_rmdir,
  1338. .unlink = smb2_unlink,
  1339. .rename = smb2_rename_path,
  1340. .create_hardlink = smb2_create_hardlink,
  1341. .query_symlink = smb2_query_symlink,
  1342. .query_mf_symlink = smb3_query_mf_symlink,
  1343. .create_mf_symlink = smb3_create_mf_symlink,
  1344. .open = smb2_open_file,
  1345. .set_fid = smb2_set_fid,
  1346. .close = smb2_close_file,
  1347. .flush = smb2_flush_file,
  1348. .async_readv = smb2_async_readv,
  1349. .async_writev = smb2_async_writev,
  1350. .sync_read = smb2_sync_read,
  1351. .sync_write = smb2_sync_write,
  1352. .query_dir_first = smb2_query_dir_first,
  1353. .query_dir_next = smb2_query_dir_next,
  1354. .close_dir = smb2_close_dir,
  1355. .calc_smb_size = smb2_calc_size,
  1356. .is_status_pending = smb2_is_status_pending,
  1357. .oplock_response = smb2_oplock_response,
  1358. .queryfs = smb2_queryfs,
  1359. .mand_lock = smb2_mand_lock,
  1360. .mand_unlock_range = smb2_unlock_range,
  1361. .push_mand_locks = smb2_push_mandatory_locks,
  1362. .get_lease_key = smb2_get_lease_key,
  1363. .set_lease_key = smb2_set_lease_key,
  1364. .new_lease_key = smb2_new_lease_key,
  1365. .calc_signature = smb2_calc_signature,
  1366. .is_read_op = smb21_is_read_op,
  1367. .set_oplock_level = smb21_set_oplock_level,
  1368. .create_lease_buf = smb2_create_lease_buf,
  1369. .parse_lease_buf = smb2_parse_lease_buf,
  1370. .clone_range = smb2_clone_range,
  1371. .wp_retry_size = smb2_wp_retry_size,
  1372. .dir_needs_close = smb2_dir_needs_close,
  1373. };
  1374. struct smb_version_operations smb30_operations = {
  1375. .compare_fids = smb2_compare_fids,
  1376. .setup_request = smb2_setup_request,
  1377. .setup_async_request = smb2_setup_async_request,
  1378. .check_receive = smb2_check_receive,
  1379. .add_credits = smb2_add_credits,
  1380. .set_credits = smb2_set_credits,
  1381. .get_credits_field = smb2_get_credits_field,
  1382. .get_credits = smb2_get_credits,
  1383. .wait_mtu_credits = smb2_wait_mtu_credits,
  1384. .get_next_mid = smb2_get_next_mid,
  1385. .read_data_offset = smb2_read_data_offset,
  1386. .read_data_length = smb2_read_data_length,
  1387. .map_error = map_smb2_to_linux_error,
  1388. .find_mid = smb2_find_mid,
  1389. .check_message = smb2_check_message,
  1390. .dump_detail = smb2_dump_detail,
  1391. .clear_stats = smb2_clear_stats,
  1392. .print_stats = smb2_print_stats,
  1393. .dump_share_caps = smb2_dump_share_caps,
  1394. .is_oplock_break = smb2_is_valid_oplock_break,
  1395. .downgrade_oplock = smb2_downgrade_oplock,
  1396. .need_neg = smb2_need_neg,
  1397. .negotiate = smb2_negotiate,
  1398. .negotiate_wsize = smb2_negotiate_wsize,
  1399. .negotiate_rsize = smb2_negotiate_rsize,
  1400. .sess_setup = SMB2_sess_setup,
  1401. .logoff = SMB2_logoff,
  1402. .tree_connect = SMB2_tcon,
  1403. .tree_disconnect = SMB2_tdis,
  1404. .qfs_tcon = smb3_qfs_tcon,
  1405. .is_path_accessible = smb2_is_path_accessible,
  1406. .can_echo = smb2_can_echo,
  1407. .echo = SMB2_echo,
  1408. .query_path_info = smb2_query_path_info,
  1409. .get_srv_inum = smb2_get_srv_inum,
  1410. .query_file_info = smb2_query_file_info,
  1411. .set_path_size = smb2_set_path_size,
  1412. .set_file_size = smb2_set_file_size,
  1413. .set_file_info = smb2_set_file_info,
  1414. .set_compression = smb2_set_compression,
  1415. .mkdir = smb2_mkdir,
  1416. .mkdir_setinfo = smb2_mkdir_setinfo,
  1417. .rmdir = smb2_rmdir,
  1418. .unlink = smb2_unlink,
  1419. .rename = smb2_rename_path,
  1420. .create_hardlink = smb2_create_hardlink,
  1421. .query_symlink = smb2_query_symlink,
  1422. .query_mf_symlink = smb3_query_mf_symlink,
  1423. .create_mf_symlink = smb3_create_mf_symlink,
  1424. .open = smb2_open_file,
  1425. .set_fid = smb2_set_fid,
  1426. .close = smb2_close_file,
  1427. .flush = smb2_flush_file,
  1428. .async_readv = smb2_async_readv,
  1429. .async_writev = smb2_async_writev,
  1430. .sync_read = smb2_sync_read,
  1431. .sync_write = smb2_sync_write,
  1432. .query_dir_first = smb2_query_dir_first,
  1433. .query_dir_next = smb2_query_dir_next,
  1434. .close_dir = smb2_close_dir,
  1435. .calc_smb_size = smb2_calc_size,
  1436. .is_status_pending = smb2_is_status_pending,
  1437. .oplock_response = smb2_oplock_response,
  1438. .queryfs = smb2_queryfs,
  1439. .mand_lock = smb2_mand_lock,
  1440. .mand_unlock_range = smb2_unlock_range,
  1441. .push_mand_locks = smb2_push_mandatory_locks,
  1442. .get_lease_key = smb2_get_lease_key,
  1443. .set_lease_key = smb2_set_lease_key,
  1444. .new_lease_key = smb2_new_lease_key,
  1445. .generate_signingkey = generate_smb3signingkey,
  1446. .calc_signature = smb3_calc_signature,
  1447. .is_read_op = smb21_is_read_op,
  1448. .set_oplock_level = smb3_set_oplock_level,
  1449. .create_lease_buf = smb3_create_lease_buf,
  1450. .parse_lease_buf = smb3_parse_lease_buf,
  1451. .clone_range = smb2_clone_range,
  1452. .validate_negotiate = smb3_validate_negotiate,
  1453. .wp_retry_size = smb2_wp_retry_size,
  1454. .dir_needs_close = smb2_dir_needs_close,
  1455. .fallocate = smb3_fallocate,
  1456. };
  1457. struct smb_version_values smb20_values = {
  1458. .version_string = SMB20_VERSION_STRING,
  1459. .protocol_id = SMB20_PROT_ID,
  1460. .req_capabilities = 0, /* MBZ */
  1461. .large_lock_type = 0,
  1462. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1463. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1464. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1465. .header_size = sizeof(struct smb2_hdr),
  1466. .max_header_size = MAX_SMB2_HDR_SIZE,
  1467. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1468. .lock_cmd = SMB2_LOCK,
  1469. .cap_unix = 0,
  1470. .cap_nt_find = SMB2_NT_FIND,
  1471. .cap_large_files = SMB2_LARGE_FILES,
  1472. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1473. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1474. .create_lease_size = sizeof(struct create_lease),
  1475. };
  1476. struct smb_version_values smb21_values = {
  1477. .version_string = SMB21_VERSION_STRING,
  1478. .protocol_id = SMB21_PROT_ID,
  1479. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  1480. .large_lock_type = 0,
  1481. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1482. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1483. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1484. .header_size = sizeof(struct smb2_hdr),
  1485. .max_header_size = MAX_SMB2_HDR_SIZE,
  1486. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1487. .lock_cmd = SMB2_LOCK,
  1488. .cap_unix = 0,
  1489. .cap_nt_find = SMB2_NT_FIND,
  1490. .cap_large_files = SMB2_LARGE_FILES,
  1491. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1492. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1493. .create_lease_size = sizeof(struct create_lease),
  1494. };
  1495. struct smb_version_values smb30_values = {
  1496. .version_string = SMB30_VERSION_STRING,
  1497. .protocol_id = SMB30_PROT_ID,
  1498. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1499. .large_lock_type = 0,
  1500. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1501. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1502. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1503. .header_size = sizeof(struct smb2_hdr),
  1504. .max_header_size = MAX_SMB2_HDR_SIZE,
  1505. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1506. .lock_cmd = SMB2_LOCK,
  1507. .cap_unix = 0,
  1508. .cap_nt_find = SMB2_NT_FIND,
  1509. .cap_large_files = SMB2_LARGE_FILES,
  1510. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1511. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1512. .create_lease_size = sizeof(struct create_lease_v2),
  1513. };
  1514. struct smb_version_values smb302_values = {
  1515. .version_string = SMB302_VERSION_STRING,
  1516. .protocol_id = SMB302_PROT_ID,
  1517. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1518. .large_lock_type = 0,
  1519. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1520. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1521. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1522. .header_size = sizeof(struct smb2_hdr),
  1523. .max_header_size = MAX_SMB2_HDR_SIZE,
  1524. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1525. .lock_cmd = SMB2_LOCK,
  1526. .cap_unix = 0,
  1527. .cap_nt_find = SMB2_NT_FIND,
  1528. .cap_large_files = SMB2_LARGE_FILES,
  1529. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1530. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1531. .create_lease_size = sizeof(struct create_lease_v2),
  1532. };