smb2ops.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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(cfile->dentry->d_inode);
  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. }
  614. }
  615. cchunk_out:
  616. kfree(pcchunk);
  617. return rc;
  618. }
  619. static int
  620. smb2_flush_file(const unsigned int xid, struct cifs_tcon *tcon,
  621. struct cifs_fid *fid)
  622. {
  623. return SMB2_flush(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  624. }
  625. static unsigned int
  626. smb2_read_data_offset(char *buf)
  627. {
  628. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  629. return rsp->DataOffset;
  630. }
  631. static unsigned int
  632. smb2_read_data_length(char *buf)
  633. {
  634. struct smb2_read_rsp *rsp = (struct smb2_read_rsp *)buf;
  635. return le32_to_cpu(rsp->DataLength);
  636. }
  637. static int
  638. smb2_sync_read(const unsigned int xid, struct cifs_fid *pfid,
  639. struct cifs_io_parms *parms, unsigned int *bytes_read,
  640. char **buf, int *buf_type)
  641. {
  642. parms->persistent_fid = pfid->persistent_fid;
  643. parms->volatile_fid = pfid->volatile_fid;
  644. return SMB2_read(xid, parms, bytes_read, buf, buf_type);
  645. }
  646. static int
  647. smb2_sync_write(const unsigned int xid, struct cifs_fid *pfid,
  648. struct cifs_io_parms *parms, unsigned int *written,
  649. struct kvec *iov, unsigned long nr_segs)
  650. {
  651. parms->persistent_fid = pfid->persistent_fid;
  652. parms->volatile_fid = pfid->volatile_fid;
  653. return SMB2_write(xid, parms, written, iov, nr_segs);
  654. }
  655. /* Set or clear the SPARSE_FILE attribute based on value passed in setsparse */
  656. static bool smb2_set_sparse(const unsigned int xid, struct cifs_tcon *tcon,
  657. struct cifsFileInfo *cfile, struct inode *inode, __u8 setsparse)
  658. {
  659. struct cifsInodeInfo *cifsi;
  660. int rc;
  661. cifsi = CIFS_I(inode);
  662. /* if file already sparse don't bother setting sparse again */
  663. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && setsparse)
  664. return true; /* already sparse */
  665. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) && !setsparse)
  666. return true; /* already not sparse */
  667. /*
  668. * Can't check for sparse support on share the usual way via the
  669. * FS attribute info (FILE_SUPPORTS_SPARSE_FILES) on the share
  670. * since Samba server doesn't set the flag on the share, yet
  671. * supports the set sparse FSCTL and returns sparse correctly
  672. * in the file attributes. If we fail setting sparse though we
  673. * mark that server does not support sparse files for this share
  674. * to avoid repeatedly sending the unsupported fsctl to server
  675. * if the file is repeatedly extended.
  676. */
  677. if (tcon->broken_sparse_sup)
  678. return false;
  679. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  680. cfile->fid.volatile_fid, FSCTL_SET_SPARSE,
  681. true /* is_fctl */, &setsparse, 1, NULL, NULL);
  682. if (rc) {
  683. tcon->broken_sparse_sup = true;
  684. cifs_dbg(FYI, "set sparse rc = %d\n", rc);
  685. return false;
  686. }
  687. if (setsparse)
  688. cifsi->cifsAttrs |= FILE_ATTRIBUTE_SPARSE_FILE;
  689. else
  690. cifsi->cifsAttrs &= (~FILE_ATTRIBUTE_SPARSE_FILE);
  691. return true;
  692. }
  693. static int
  694. smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
  695. struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
  696. {
  697. __le64 eof = cpu_to_le64(size);
  698. struct inode *inode;
  699. /*
  700. * If extending file more than one page make sparse. Many Linux fs
  701. * make files sparse by default when extending via ftruncate
  702. */
  703. inode = cfile->dentry->d_inode;
  704. if (!set_alloc && (size > inode->i_size + 8192)) {
  705. __u8 set_sparse = 1;
  706. /* whether set sparse succeeds or not, extend the file */
  707. smb2_set_sparse(xid, tcon, cfile, inode, set_sparse);
  708. }
  709. return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
  710. cfile->fid.volatile_fid, cfile->pid, &eof, false);
  711. }
  712. static int
  713. smb2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
  714. struct cifsFileInfo *cfile)
  715. {
  716. return SMB2_set_compression(xid, tcon, cfile->fid.persistent_fid,
  717. cfile->fid.volatile_fid);
  718. }
  719. static int
  720. smb2_query_dir_first(const unsigned int xid, struct cifs_tcon *tcon,
  721. const char *path, struct cifs_sb_info *cifs_sb,
  722. struct cifs_fid *fid, __u16 search_flags,
  723. struct cifs_search_info *srch_inf)
  724. {
  725. __le16 *utf16_path;
  726. int rc;
  727. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  728. struct cifs_open_parms oparms;
  729. utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
  730. if (!utf16_path)
  731. return -ENOMEM;
  732. oparms.tcon = tcon;
  733. oparms.desired_access = FILE_READ_ATTRIBUTES | FILE_READ_DATA;
  734. oparms.disposition = FILE_OPEN;
  735. oparms.create_options = 0;
  736. oparms.fid = fid;
  737. oparms.reconnect = false;
  738. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL);
  739. kfree(utf16_path);
  740. if (rc) {
  741. cifs_dbg(VFS, "open dir failed\n");
  742. return rc;
  743. }
  744. srch_inf->entries_in_buffer = 0;
  745. srch_inf->index_of_last_entry = 0;
  746. rc = SMB2_query_directory(xid, tcon, fid->persistent_fid,
  747. fid->volatile_fid, 0, srch_inf);
  748. if (rc) {
  749. cifs_dbg(VFS, "query directory failed\n");
  750. SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  751. }
  752. return rc;
  753. }
  754. static int
  755. smb2_query_dir_next(const unsigned int xid, struct cifs_tcon *tcon,
  756. struct cifs_fid *fid, __u16 search_flags,
  757. struct cifs_search_info *srch_inf)
  758. {
  759. return SMB2_query_directory(xid, tcon, fid->persistent_fid,
  760. fid->volatile_fid, 0, srch_inf);
  761. }
  762. static int
  763. smb2_close_dir(const unsigned int xid, struct cifs_tcon *tcon,
  764. struct cifs_fid *fid)
  765. {
  766. return SMB2_close(xid, tcon, fid->persistent_fid, fid->volatile_fid);
  767. }
  768. /*
  769. * If we negotiate SMB2 protocol and get STATUS_PENDING - update
  770. * the number of credits and return true. Otherwise - return false.
  771. */
  772. static bool
  773. smb2_is_status_pending(char *buf, struct TCP_Server_Info *server, int length)
  774. {
  775. struct smb2_hdr *hdr = (struct smb2_hdr *)buf;
  776. if (hdr->Status != STATUS_PENDING)
  777. return false;
  778. if (!length) {
  779. spin_lock(&server->req_lock);
  780. server->credits += le16_to_cpu(hdr->CreditRequest);
  781. spin_unlock(&server->req_lock);
  782. wake_up(&server->request_q);
  783. }
  784. return true;
  785. }
  786. static int
  787. smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
  788. struct cifsInodeInfo *cinode)
  789. {
  790. if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING)
  791. return SMB2_lease_break(0, tcon, cinode->lease_key,
  792. smb2_get_lease_state(cinode));
  793. return SMB2_oplock_break(0, tcon, fid->persistent_fid,
  794. fid->volatile_fid,
  795. CIFS_CACHE_READ(cinode) ? 1 : 0);
  796. }
  797. static int
  798. smb2_queryfs(const unsigned int xid, struct cifs_tcon *tcon,
  799. struct kstatfs *buf)
  800. {
  801. int rc;
  802. __le16 srch_path = 0; /* Null - open root of share */
  803. u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  804. struct cifs_open_parms oparms;
  805. struct cifs_fid fid;
  806. oparms.tcon = tcon;
  807. oparms.desired_access = FILE_READ_ATTRIBUTES;
  808. oparms.disposition = FILE_OPEN;
  809. oparms.create_options = 0;
  810. oparms.fid = &fid;
  811. oparms.reconnect = false;
  812. rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL);
  813. if (rc)
  814. return rc;
  815. buf->f_type = SMB2_MAGIC_NUMBER;
  816. rc = SMB2_QFS_info(xid, tcon, fid.persistent_fid, fid.volatile_fid,
  817. buf);
  818. SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
  819. return rc;
  820. }
  821. static bool
  822. smb2_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  823. {
  824. return ob1->fid.persistent_fid == ob2->fid.persistent_fid &&
  825. ob1->fid.volatile_fid == ob2->fid.volatile_fid;
  826. }
  827. static int
  828. smb2_mand_lock(const unsigned int xid, struct cifsFileInfo *cfile, __u64 offset,
  829. __u64 length, __u32 type, int lock, int unlock, bool wait)
  830. {
  831. if (unlock && !lock)
  832. type = SMB2_LOCKFLAG_UNLOCK;
  833. return SMB2_lock(xid, tlink_tcon(cfile->tlink),
  834. cfile->fid.persistent_fid, cfile->fid.volatile_fid,
  835. current->tgid, length, offset, type, wait);
  836. }
  837. static void
  838. smb2_get_lease_key(struct inode *inode, struct cifs_fid *fid)
  839. {
  840. memcpy(fid->lease_key, CIFS_I(inode)->lease_key, SMB2_LEASE_KEY_SIZE);
  841. }
  842. static void
  843. smb2_set_lease_key(struct inode *inode, struct cifs_fid *fid)
  844. {
  845. memcpy(CIFS_I(inode)->lease_key, fid->lease_key, SMB2_LEASE_KEY_SIZE);
  846. }
  847. static void
  848. smb2_new_lease_key(struct cifs_fid *fid)
  849. {
  850. get_random_bytes(fid->lease_key, SMB2_LEASE_KEY_SIZE);
  851. }
  852. static int
  853. smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
  854. const char *full_path, char **target_path,
  855. struct cifs_sb_info *cifs_sb)
  856. {
  857. int rc;
  858. __le16 *utf16_path;
  859. __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
  860. struct cifs_open_parms oparms;
  861. struct cifs_fid fid;
  862. struct smb2_err_rsp *err_buf = NULL;
  863. struct smb2_symlink_err_rsp *symlink;
  864. unsigned int sub_len, sub_offset;
  865. cifs_dbg(FYI, "%s: path: %s\n", __func__, full_path);
  866. utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
  867. if (!utf16_path)
  868. return -ENOMEM;
  869. oparms.tcon = tcon;
  870. oparms.desired_access = FILE_READ_ATTRIBUTES;
  871. oparms.disposition = FILE_OPEN;
  872. oparms.create_options = 0;
  873. oparms.fid = &fid;
  874. oparms.reconnect = false;
  875. rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, &err_buf);
  876. if (!rc || !err_buf) {
  877. kfree(utf16_path);
  878. return -ENOENT;
  879. }
  880. /* open must fail on symlink - reset rc */
  881. rc = 0;
  882. symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
  883. sub_len = le16_to_cpu(symlink->SubstituteNameLength);
  884. sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
  885. *target_path = cifs_strndup_from_utf16(
  886. (char *)symlink->PathBuffer + sub_offset,
  887. sub_len, true, cifs_sb->local_nls);
  888. if (!(*target_path)) {
  889. kfree(utf16_path);
  890. return -ENOMEM;
  891. }
  892. convert_delimiter(*target_path, '/');
  893. cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
  894. kfree(utf16_path);
  895. return rc;
  896. }
  897. static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
  898. loff_t offset, loff_t len, bool keep_size)
  899. {
  900. struct inode *inode;
  901. struct cifsInodeInfo *cifsi;
  902. struct cifsFileInfo *cfile = file->private_data;
  903. struct file_zero_data_information fsctl_buf;
  904. long rc;
  905. unsigned int xid;
  906. xid = get_xid();
  907. inode = cfile->dentry->d_inode;
  908. cifsi = CIFS_I(inode);
  909. /* if file not oplocked can't be sure whether asking to extend size */
  910. if (!CIFS_CACHE_READ(cifsi))
  911. if (keep_size == false)
  912. return -EOPNOTSUPP;
  913. /*
  914. * Must check if file sparse since fallocate -z (zero range) assumes
  915. * non-sparse allocation
  916. */
  917. if (!(cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE))
  918. return -EOPNOTSUPP;
  919. /*
  920. * need to make sure we are not asked to extend the file since the SMB3
  921. * fsctl does not change the file size. In the future we could change
  922. * this to zero the first part of the range then set the file size
  923. * which for a non sparse file would zero the newly extended range
  924. */
  925. if (keep_size == false)
  926. if (i_size_read(inode) < offset + len)
  927. return -EOPNOTSUPP;
  928. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  929. fsctl_buf.FileOffset = cpu_to_le64(offset);
  930. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  931. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  932. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  933. true /* is_fctl */, (char *)&fsctl_buf,
  934. sizeof(struct file_zero_data_information), NULL, NULL);
  935. free_xid(xid);
  936. return rc;
  937. }
  938. static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
  939. loff_t offset, loff_t len)
  940. {
  941. struct inode *inode;
  942. struct cifsInodeInfo *cifsi;
  943. struct cifsFileInfo *cfile = file->private_data;
  944. struct file_zero_data_information fsctl_buf;
  945. long rc;
  946. unsigned int xid;
  947. __u8 set_sparse = 1;
  948. xid = get_xid();
  949. inode = cfile->dentry->d_inode;
  950. cifsi = CIFS_I(inode);
  951. /* Need to make file sparse, if not already, before freeing range. */
  952. /* Consider adding equivalent for compressed since it could also work */
  953. if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse))
  954. return -EOPNOTSUPP;
  955. cifs_dbg(FYI, "offset %lld len %lld", offset, len);
  956. fsctl_buf.FileOffset = cpu_to_le64(offset);
  957. fsctl_buf.BeyondFinalZero = cpu_to_le64(offset + len);
  958. rc = SMB2_ioctl(xid, tcon, cfile->fid.persistent_fid,
  959. cfile->fid.volatile_fid, FSCTL_SET_ZERO_DATA,
  960. true /* is_fctl */, (char *)&fsctl_buf,
  961. sizeof(struct file_zero_data_information), NULL, NULL);
  962. free_xid(xid);
  963. return rc;
  964. }
  965. static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
  966. loff_t off, loff_t len, bool keep_size)
  967. {
  968. struct inode *inode;
  969. struct cifsInodeInfo *cifsi;
  970. struct cifsFileInfo *cfile = file->private_data;
  971. long rc = -EOPNOTSUPP;
  972. unsigned int xid;
  973. xid = get_xid();
  974. inode = cfile->dentry->d_inode;
  975. cifsi = CIFS_I(inode);
  976. /* if file not oplocked can't be sure whether asking to extend size */
  977. if (!CIFS_CACHE_READ(cifsi))
  978. if (keep_size == false)
  979. return -EOPNOTSUPP;
  980. /*
  981. * Files are non-sparse by default so falloc may be a no-op
  982. * Must check if file sparse. If not sparse, and not extending
  983. * then no need to do anything since file already allocated
  984. */
  985. if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0) {
  986. if (keep_size == true)
  987. return 0;
  988. /* check if extending file */
  989. else if (i_size_read(inode) >= off + len)
  990. /* not extending file and already not sparse */
  991. return 0;
  992. /* BB: in future add else clause to extend file */
  993. else
  994. return -EOPNOTSUPP;
  995. }
  996. if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
  997. /*
  998. * Check if falloc starts within first few pages of file
  999. * and ends within a few pages of the end of file to
  1000. * ensure that most of file is being forced to be
  1001. * fallocated now. If so then setting whole file sparse
  1002. * ie potentially making a few extra pages at the beginning
  1003. * or end of the file non-sparse via set_sparse is harmless.
  1004. */
  1005. if ((off > 8192) || (off + len + 8192 < i_size_read(inode)))
  1006. return -EOPNOTSUPP;
  1007. rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
  1008. }
  1009. /* BB: else ... in future add code to extend file and set sparse */
  1010. free_xid(xid);
  1011. return rc;
  1012. }
  1013. static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
  1014. loff_t off, loff_t len)
  1015. {
  1016. /* KEEP_SIZE already checked for by do_fallocate */
  1017. if (mode & FALLOC_FL_PUNCH_HOLE)
  1018. return smb3_punch_hole(file, tcon, off, len);
  1019. else if (mode & FALLOC_FL_ZERO_RANGE) {
  1020. if (mode & FALLOC_FL_KEEP_SIZE)
  1021. return smb3_zero_range(file, tcon, off, len, true);
  1022. return smb3_zero_range(file, tcon, off, len, false);
  1023. } else if (mode == FALLOC_FL_KEEP_SIZE)
  1024. return smb3_simple_falloc(file, tcon, off, len, true);
  1025. else if (mode == 0)
  1026. return smb3_simple_falloc(file, tcon, off, len, false);
  1027. return -EOPNOTSUPP;
  1028. }
  1029. static void
  1030. smb2_downgrade_oplock(struct TCP_Server_Info *server,
  1031. struct cifsInodeInfo *cinode, bool set_level2)
  1032. {
  1033. if (set_level2)
  1034. server->ops->set_oplock_level(cinode, SMB2_OPLOCK_LEVEL_II,
  1035. 0, NULL);
  1036. else
  1037. server->ops->set_oplock_level(cinode, 0, 0, NULL);
  1038. }
  1039. static void
  1040. smb2_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1041. unsigned int epoch, bool *purge_cache)
  1042. {
  1043. oplock &= 0xFF;
  1044. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1045. return;
  1046. if (oplock == SMB2_OPLOCK_LEVEL_BATCH) {
  1047. cinode->oplock = CIFS_CACHE_RHW_FLG;
  1048. cifs_dbg(FYI, "Batch Oplock granted on inode %p\n",
  1049. &cinode->vfs_inode);
  1050. } else if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) {
  1051. cinode->oplock = CIFS_CACHE_RW_FLG;
  1052. cifs_dbg(FYI, "Exclusive Oplock granted on inode %p\n",
  1053. &cinode->vfs_inode);
  1054. } else if (oplock == SMB2_OPLOCK_LEVEL_II) {
  1055. cinode->oplock = CIFS_CACHE_READ_FLG;
  1056. cifs_dbg(FYI, "Level II Oplock granted on inode %p\n",
  1057. &cinode->vfs_inode);
  1058. } else
  1059. cinode->oplock = 0;
  1060. }
  1061. static void
  1062. smb21_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1063. unsigned int epoch, bool *purge_cache)
  1064. {
  1065. char message[5] = {0};
  1066. oplock &= 0xFF;
  1067. if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE)
  1068. return;
  1069. cinode->oplock = 0;
  1070. if (oplock & SMB2_LEASE_READ_CACHING_HE) {
  1071. cinode->oplock |= CIFS_CACHE_READ_FLG;
  1072. strcat(message, "R");
  1073. }
  1074. if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) {
  1075. cinode->oplock |= CIFS_CACHE_HANDLE_FLG;
  1076. strcat(message, "H");
  1077. }
  1078. if (oplock & SMB2_LEASE_WRITE_CACHING_HE) {
  1079. cinode->oplock |= CIFS_CACHE_WRITE_FLG;
  1080. strcat(message, "W");
  1081. }
  1082. if (!cinode->oplock)
  1083. strcat(message, "None");
  1084. cifs_dbg(FYI, "%s Lease granted on inode %p\n", message,
  1085. &cinode->vfs_inode);
  1086. }
  1087. static void
  1088. smb3_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock,
  1089. unsigned int epoch, bool *purge_cache)
  1090. {
  1091. unsigned int old_oplock = cinode->oplock;
  1092. smb21_set_oplock_level(cinode, oplock, epoch, purge_cache);
  1093. if (purge_cache) {
  1094. *purge_cache = false;
  1095. if (old_oplock == CIFS_CACHE_READ_FLG) {
  1096. if (cinode->oplock == CIFS_CACHE_READ_FLG &&
  1097. (epoch - cinode->epoch > 0))
  1098. *purge_cache = true;
  1099. else if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1100. (epoch - cinode->epoch > 1))
  1101. *purge_cache = true;
  1102. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1103. (epoch - cinode->epoch > 1))
  1104. *purge_cache = true;
  1105. else if (cinode->oplock == 0 &&
  1106. (epoch - cinode->epoch > 0))
  1107. *purge_cache = true;
  1108. } else if (old_oplock == CIFS_CACHE_RH_FLG) {
  1109. if (cinode->oplock == CIFS_CACHE_RH_FLG &&
  1110. (epoch - cinode->epoch > 0))
  1111. *purge_cache = true;
  1112. else if (cinode->oplock == CIFS_CACHE_RHW_FLG &&
  1113. (epoch - cinode->epoch > 1))
  1114. *purge_cache = true;
  1115. }
  1116. cinode->epoch = epoch;
  1117. }
  1118. }
  1119. static bool
  1120. smb2_is_read_op(__u32 oplock)
  1121. {
  1122. return oplock == SMB2_OPLOCK_LEVEL_II;
  1123. }
  1124. static bool
  1125. smb21_is_read_op(__u32 oplock)
  1126. {
  1127. return (oplock & SMB2_LEASE_READ_CACHING_HE) &&
  1128. !(oplock & SMB2_LEASE_WRITE_CACHING_HE);
  1129. }
  1130. static __le32
  1131. map_oplock_to_lease(u8 oplock)
  1132. {
  1133. if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE)
  1134. return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING;
  1135. else if (oplock == SMB2_OPLOCK_LEVEL_II)
  1136. return SMB2_LEASE_READ_CACHING;
  1137. else if (oplock == SMB2_OPLOCK_LEVEL_BATCH)
  1138. return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING |
  1139. SMB2_LEASE_WRITE_CACHING;
  1140. return 0;
  1141. }
  1142. static char *
  1143. smb2_create_lease_buf(u8 *lease_key, u8 oplock)
  1144. {
  1145. struct create_lease *buf;
  1146. buf = kzalloc(sizeof(struct create_lease), GFP_KERNEL);
  1147. if (!buf)
  1148. return NULL;
  1149. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1150. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1151. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1152. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1153. (struct create_lease, lcontext));
  1154. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context));
  1155. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1156. (struct create_lease, Name));
  1157. buf->ccontext.NameLength = cpu_to_le16(4);
  1158. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1159. buf->Name[0] = 'R';
  1160. buf->Name[1] = 'q';
  1161. buf->Name[2] = 'L';
  1162. buf->Name[3] = 's';
  1163. return (char *)buf;
  1164. }
  1165. static char *
  1166. smb3_create_lease_buf(u8 *lease_key, u8 oplock)
  1167. {
  1168. struct create_lease_v2 *buf;
  1169. buf = kzalloc(sizeof(struct create_lease_v2), GFP_KERNEL);
  1170. if (!buf)
  1171. return NULL;
  1172. buf->lcontext.LeaseKeyLow = cpu_to_le64(*((u64 *)lease_key));
  1173. buf->lcontext.LeaseKeyHigh = cpu_to_le64(*((u64 *)(lease_key + 8)));
  1174. buf->lcontext.LeaseState = map_oplock_to_lease(oplock);
  1175. buf->ccontext.DataOffset = cpu_to_le16(offsetof
  1176. (struct create_lease_v2, lcontext));
  1177. buf->ccontext.DataLength = cpu_to_le32(sizeof(struct lease_context_v2));
  1178. buf->ccontext.NameOffset = cpu_to_le16(offsetof
  1179. (struct create_lease_v2, Name));
  1180. buf->ccontext.NameLength = cpu_to_le16(4);
  1181. /* SMB2_CREATE_REQUEST_LEASE is "RqLs" */
  1182. buf->Name[0] = 'R';
  1183. buf->Name[1] = 'q';
  1184. buf->Name[2] = 'L';
  1185. buf->Name[3] = 's';
  1186. return (char *)buf;
  1187. }
  1188. static __u8
  1189. smb2_parse_lease_buf(void *buf, unsigned int *epoch)
  1190. {
  1191. struct create_lease *lc = (struct create_lease *)buf;
  1192. *epoch = 0; /* not used */
  1193. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1194. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1195. return le32_to_cpu(lc->lcontext.LeaseState);
  1196. }
  1197. static __u8
  1198. smb3_parse_lease_buf(void *buf, unsigned int *epoch)
  1199. {
  1200. struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
  1201. *epoch = le16_to_cpu(lc->lcontext.Epoch);
  1202. if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS)
  1203. return SMB2_OPLOCK_LEVEL_NOCHANGE;
  1204. return le32_to_cpu(lc->lcontext.LeaseState);
  1205. }
  1206. static unsigned int
  1207. smb2_wp_retry_size(struct inode *inode)
  1208. {
  1209. return min_t(unsigned int, CIFS_SB(inode->i_sb)->wsize,
  1210. SMB2_MAX_BUFFER_SIZE);
  1211. }
  1212. static bool
  1213. smb2_dir_needs_close(struct cifsFileInfo *cfile)
  1214. {
  1215. return !cfile->invalidHandle;
  1216. }
  1217. struct smb_version_operations smb20_operations = {
  1218. .compare_fids = smb2_compare_fids,
  1219. .setup_request = smb2_setup_request,
  1220. .setup_async_request = smb2_setup_async_request,
  1221. .check_receive = smb2_check_receive,
  1222. .add_credits = smb2_add_credits,
  1223. .set_credits = smb2_set_credits,
  1224. .get_credits_field = smb2_get_credits_field,
  1225. .get_credits = smb2_get_credits,
  1226. .wait_mtu_credits = cifs_wait_mtu_credits,
  1227. .get_next_mid = smb2_get_next_mid,
  1228. .read_data_offset = smb2_read_data_offset,
  1229. .read_data_length = smb2_read_data_length,
  1230. .map_error = map_smb2_to_linux_error,
  1231. .find_mid = smb2_find_mid,
  1232. .check_message = smb2_check_message,
  1233. .dump_detail = smb2_dump_detail,
  1234. .clear_stats = smb2_clear_stats,
  1235. .print_stats = smb2_print_stats,
  1236. .is_oplock_break = smb2_is_valid_oplock_break,
  1237. .downgrade_oplock = smb2_downgrade_oplock,
  1238. .need_neg = smb2_need_neg,
  1239. .negotiate = smb2_negotiate,
  1240. .negotiate_wsize = smb2_negotiate_wsize,
  1241. .negotiate_rsize = smb2_negotiate_rsize,
  1242. .sess_setup = SMB2_sess_setup,
  1243. .logoff = SMB2_logoff,
  1244. .tree_connect = SMB2_tcon,
  1245. .tree_disconnect = SMB2_tdis,
  1246. .qfs_tcon = smb2_qfs_tcon,
  1247. .is_path_accessible = smb2_is_path_accessible,
  1248. .can_echo = smb2_can_echo,
  1249. .echo = SMB2_echo,
  1250. .query_path_info = smb2_query_path_info,
  1251. .get_srv_inum = smb2_get_srv_inum,
  1252. .query_file_info = smb2_query_file_info,
  1253. .set_path_size = smb2_set_path_size,
  1254. .set_file_size = smb2_set_file_size,
  1255. .set_file_info = smb2_set_file_info,
  1256. .set_compression = smb2_set_compression,
  1257. .mkdir = smb2_mkdir,
  1258. .mkdir_setinfo = smb2_mkdir_setinfo,
  1259. .rmdir = smb2_rmdir,
  1260. .unlink = smb2_unlink,
  1261. .rename = smb2_rename_path,
  1262. .create_hardlink = smb2_create_hardlink,
  1263. .query_symlink = smb2_query_symlink,
  1264. .open = smb2_open_file,
  1265. .set_fid = smb2_set_fid,
  1266. .close = smb2_close_file,
  1267. .flush = smb2_flush_file,
  1268. .async_readv = smb2_async_readv,
  1269. .async_writev = smb2_async_writev,
  1270. .sync_read = smb2_sync_read,
  1271. .sync_write = smb2_sync_write,
  1272. .query_dir_first = smb2_query_dir_first,
  1273. .query_dir_next = smb2_query_dir_next,
  1274. .close_dir = smb2_close_dir,
  1275. .calc_smb_size = smb2_calc_size,
  1276. .is_status_pending = smb2_is_status_pending,
  1277. .oplock_response = smb2_oplock_response,
  1278. .queryfs = smb2_queryfs,
  1279. .mand_lock = smb2_mand_lock,
  1280. .mand_unlock_range = smb2_unlock_range,
  1281. .push_mand_locks = smb2_push_mandatory_locks,
  1282. .get_lease_key = smb2_get_lease_key,
  1283. .set_lease_key = smb2_set_lease_key,
  1284. .new_lease_key = smb2_new_lease_key,
  1285. .calc_signature = smb2_calc_signature,
  1286. .is_read_op = smb2_is_read_op,
  1287. .set_oplock_level = smb2_set_oplock_level,
  1288. .create_lease_buf = smb2_create_lease_buf,
  1289. .parse_lease_buf = smb2_parse_lease_buf,
  1290. .clone_range = smb2_clone_range,
  1291. .wp_retry_size = smb2_wp_retry_size,
  1292. .dir_needs_close = smb2_dir_needs_close,
  1293. };
  1294. struct smb_version_operations smb21_operations = {
  1295. .compare_fids = smb2_compare_fids,
  1296. .setup_request = smb2_setup_request,
  1297. .setup_async_request = smb2_setup_async_request,
  1298. .check_receive = smb2_check_receive,
  1299. .add_credits = smb2_add_credits,
  1300. .set_credits = smb2_set_credits,
  1301. .get_credits_field = smb2_get_credits_field,
  1302. .get_credits = smb2_get_credits,
  1303. .wait_mtu_credits = smb2_wait_mtu_credits,
  1304. .get_next_mid = smb2_get_next_mid,
  1305. .read_data_offset = smb2_read_data_offset,
  1306. .read_data_length = smb2_read_data_length,
  1307. .map_error = map_smb2_to_linux_error,
  1308. .find_mid = smb2_find_mid,
  1309. .check_message = smb2_check_message,
  1310. .dump_detail = smb2_dump_detail,
  1311. .clear_stats = smb2_clear_stats,
  1312. .print_stats = smb2_print_stats,
  1313. .is_oplock_break = smb2_is_valid_oplock_break,
  1314. .downgrade_oplock = smb2_downgrade_oplock,
  1315. .need_neg = smb2_need_neg,
  1316. .negotiate = smb2_negotiate,
  1317. .negotiate_wsize = smb2_negotiate_wsize,
  1318. .negotiate_rsize = smb2_negotiate_rsize,
  1319. .sess_setup = SMB2_sess_setup,
  1320. .logoff = SMB2_logoff,
  1321. .tree_connect = SMB2_tcon,
  1322. .tree_disconnect = SMB2_tdis,
  1323. .qfs_tcon = smb2_qfs_tcon,
  1324. .is_path_accessible = smb2_is_path_accessible,
  1325. .can_echo = smb2_can_echo,
  1326. .echo = SMB2_echo,
  1327. .query_path_info = smb2_query_path_info,
  1328. .get_srv_inum = smb2_get_srv_inum,
  1329. .query_file_info = smb2_query_file_info,
  1330. .set_path_size = smb2_set_path_size,
  1331. .set_file_size = smb2_set_file_size,
  1332. .set_file_info = smb2_set_file_info,
  1333. .set_compression = smb2_set_compression,
  1334. .mkdir = smb2_mkdir,
  1335. .mkdir_setinfo = smb2_mkdir_setinfo,
  1336. .rmdir = smb2_rmdir,
  1337. .unlink = smb2_unlink,
  1338. .rename = smb2_rename_path,
  1339. .create_hardlink = smb2_create_hardlink,
  1340. .query_symlink = smb2_query_symlink,
  1341. .query_mf_symlink = smb3_query_mf_symlink,
  1342. .create_mf_symlink = smb3_create_mf_symlink,
  1343. .open = smb2_open_file,
  1344. .set_fid = smb2_set_fid,
  1345. .close = smb2_close_file,
  1346. .flush = smb2_flush_file,
  1347. .async_readv = smb2_async_readv,
  1348. .async_writev = smb2_async_writev,
  1349. .sync_read = smb2_sync_read,
  1350. .sync_write = smb2_sync_write,
  1351. .query_dir_first = smb2_query_dir_first,
  1352. .query_dir_next = smb2_query_dir_next,
  1353. .close_dir = smb2_close_dir,
  1354. .calc_smb_size = smb2_calc_size,
  1355. .is_status_pending = smb2_is_status_pending,
  1356. .oplock_response = smb2_oplock_response,
  1357. .queryfs = smb2_queryfs,
  1358. .mand_lock = smb2_mand_lock,
  1359. .mand_unlock_range = smb2_unlock_range,
  1360. .push_mand_locks = smb2_push_mandatory_locks,
  1361. .get_lease_key = smb2_get_lease_key,
  1362. .set_lease_key = smb2_set_lease_key,
  1363. .new_lease_key = smb2_new_lease_key,
  1364. .calc_signature = smb2_calc_signature,
  1365. .is_read_op = smb21_is_read_op,
  1366. .set_oplock_level = smb21_set_oplock_level,
  1367. .create_lease_buf = smb2_create_lease_buf,
  1368. .parse_lease_buf = smb2_parse_lease_buf,
  1369. .clone_range = smb2_clone_range,
  1370. .wp_retry_size = smb2_wp_retry_size,
  1371. .dir_needs_close = smb2_dir_needs_close,
  1372. };
  1373. struct smb_version_operations smb30_operations = {
  1374. .compare_fids = smb2_compare_fids,
  1375. .setup_request = smb2_setup_request,
  1376. .setup_async_request = smb2_setup_async_request,
  1377. .check_receive = smb2_check_receive,
  1378. .add_credits = smb2_add_credits,
  1379. .set_credits = smb2_set_credits,
  1380. .get_credits_field = smb2_get_credits_field,
  1381. .get_credits = smb2_get_credits,
  1382. .wait_mtu_credits = smb2_wait_mtu_credits,
  1383. .get_next_mid = smb2_get_next_mid,
  1384. .read_data_offset = smb2_read_data_offset,
  1385. .read_data_length = smb2_read_data_length,
  1386. .map_error = map_smb2_to_linux_error,
  1387. .find_mid = smb2_find_mid,
  1388. .check_message = smb2_check_message,
  1389. .dump_detail = smb2_dump_detail,
  1390. .clear_stats = smb2_clear_stats,
  1391. .print_stats = smb2_print_stats,
  1392. .dump_share_caps = smb2_dump_share_caps,
  1393. .is_oplock_break = smb2_is_valid_oplock_break,
  1394. .downgrade_oplock = smb2_downgrade_oplock,
  1395. .need_neg = smb2_need_neg,
  1396. .negotiate = smb2_negotiate,
  1397. .negotiate_wsize = smb2_negotiate_wsize,
  1398. .negotiate_rsize = smb2_negotiate_rsize,
  1399. .sess_setup = SMB2_sess_setup,
  1400. .logoff = SMB2_logoff,
  1401. .tree_connect = SMB2_tcon,
  1402. .tree_disconnect = SMB2_tdis,
  1403. .qfs_tcon = smb3_qfs_tcon,
  1404. .is_path_accessible = smb2_is_path_accessible,
  1405. .can_echo = smb2_can_echo,
  1406. .echo = SMB2_echo,
  1407. .query_path_info = smb2_query_path_info,
  1408. .get_srv_inum = smb2_get_srv_inum,
  1409. .query_file_info = smb2_query_file_info,
  1410. .set_path_size = smb2_set_path_size,
  1411. .set_file_size = smb2_set_file_size,
  1412. .set_file_info = smb2_set_file_info,
  1413. .set_compression = smb2_set_compression,
  1414. .mkdir = smb2_mkdir,
  1415. .mkdir_setinfo = smb2_mkdir_setinfo,
  1416. .rmdir = smb2_rmdir,
  1417. .unlink = smb2_unlink,
  1418. .rename = smb2_rename_path,
  1419. .create_hardlink = smb2_create_hardlink,
  1420. .query_symlink = smb2_query_symlink,
  1421. .query_mf_symlink = smb3_query_mf_symlink,
  1422. .create_mf_symlink = smb3_create_mf_symlink,
  1423. .open = smb2_open_file,
  1424. .set_fid = smb2_set_fid,
  1425. .close = smb2_close_file,
  1426. .flush = smb2_flush_file,
  1427. .async_readv = smb2_async_readv,
  1428. .async_writev = smb2_async_writev,
  1429. .sync_read = smb2_sync_read,
  1430. .sync_write = smb2_sync_write,
  1431. .query_dir_first = smb2_query_dir_first,
  1432. .query_dir_next = smb2_query_dir_next,
  1433. .close_dir = smb2_close_dir,
  1434. .calc_smb_size = smb2_calc_size,
  1435. .is_status_pending = smb2_is_status_pending,
  1436. .oplock_response = smb2_oplock_response,
  1437. .queryfs = smb2_queryfs,
  1438. .mand_lock = smb2_mand_lock,
  1439. .mand_unlock_range = smb2_unlock_range,
  1440. .push_mand_locks = smb2_push_mandatory_locks,
  1441. .get_lease_key = smb2_get_lease_key,
  1442. .set_lease_key = smb2_set_lease_key,
  1443. .new_lease_key = smb2_new_lease_key,
  1444. .generate_signingkey = generate_smb3signingkey,
  1445. .calc_signature = smb3_calc_signature,
  1446. .is_read_op = smb21_is_read_op,
  1447. .set_oplock_level = smb3_set_oplock_level,
  1448. .create_lease_buf = smb3_create_lease_buf,
  1449. .parse_lease_buf = smb3_parse_lease_buf,
  1450. .clone_range = smb2_clone_range,
  1451. .validate_negotiate = smb3_validate_negotiate,
  1452. .wp_retry_size = smb2_wp_retry_size,
  1453. .dir_needs_close = smb2_dir_needs_close,
  1454. .fallocate = smb3_fallocate,
  1455. };
  1456. struct smb_version_values smb20_values = {
  1457. .version_string = SMB20_VERSION_STRING,
  1458. .protocol_id = SMB20_PROT_ID,
  1459. .req_capabilities = 0, /* MBZ */
  1460. .large_lock_type = 0,
  1461. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1462. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1463. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1464. .header_size = sizeof(struct smb2_hdr),
  1465. .max_header_size = MAX_SMB2_HDR_SIZE,
  1466. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1467. .lock_cmd = SMB2_LOCK,
  1468. .cap_unix = 0,
  1469. .cap_nt_find = SMB2_NT_FIND,
  1470. .cap_large_files = SMB2_LARGE_FILES,
  1471. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1472. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1473. .create_lease_size = sizeof(struct create_lease),
  1474. };
  1475. struct smb_version_values smb21_values = {
  1476. .version_string = SMB21_VERSION_STRING,
  1477. .protocol_id = SMB21_PROT_ID,
  1478. .req_capabilities = 0, /* MBZ on negotiate req until SMB3 dialect */
  1479. .large_lock_type = 0,
  1480. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1481. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1482. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1483. .header_size = sizeof(struct smb2_hdr),
  1484. .max_header_size = MAX_SMB2_HDR_SIZE,
  1485. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1486. .lock_cmd = SMB2_LOCK,
  1487. .cap_unix = 0,
  1488. .cap_nt_find = SMB2_NT_FIND,
  1489. .cap_large_files = SMB2_LARGE_FILES,
  1490. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1491. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1492. .create_lease_size = sizeof(struct create_lease),
  1493. };
  1494. struct smb_version_values smb30_values = {
  1495. .version_string = SMB30_VERSION_STRING,
  1496. .protocol_id = SMB30_PROT_ID,
  1497. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1498. .large_lock_type = 0,
  1499. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1500. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1501. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1502. .header_size = sizeof(struct smb2_hdr),
  1503. .max_header_size = MAX_SMB2_HDR_SIZE,
  1504. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1505. .lock_cmd = SMB2_LOCK,
  1506. .cap_unix = 0,
  1507. .cap_nt_find = SMB2_NT_FIND,
  1508. .cap_large_files = SMB2_LARGE_FILES,
  1509. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1510. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1511. .create_lease_size = sizeof(struct create_lease_v2),
  1512. };
  1513. struct smb_version_values smb302_values = {
  1514. .version_string = SMB302_VERSION_STRING,
  1515. .protocol_id = SMB302_PROT_ID,
  1516. .req_capabilities = SMB2_GLOBAL_CAP_DFS | SMB2_GLOBAL_CAP_LEASING | SMB2_GLOBAL_CAP_LARGE_MTU,
  1517. .large_lock_type = 0,
  1518. .exclusive_lock_type = SMB2_LOCKFLAG_EXCLUSIVE_LOCK,
  1519. .shared_lock_type = SMB2_LOCKFLAG_SHARED_LOCK,
  1520. .unlock_lock_type = SMB2_LOCKFLAG_UNLOCK,
  1521. .header_size = sizeof(struct smb2_hdr),
  1522. .max_header_size = MAX_SMB2_HDR_SIZE,
  1523. .read_rsp_size = sizeof(struct smb2_read_rsp) - 1,
  1524. .lock_cmd = SMB2_LOCK,
  1525. .cap_unix = 0,
  1526. .cap_nt_find = SMB2_NT_FIND,
  1527. .cap_large_files = SMB2_LARGE_FILES,
  1528. .signing_enabled = SMB2_NEGOTIATE_SIGNING_ENABLED | SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1529. .signing_required = SMB2_NEGOTIATE_SIGNING_REQUIRED,
  1530. .create_lease_size = sizeof(struct create_lease_v2),
  1531. };