smb2ops.c 57 KB

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