smb2ops.c 56 KB

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