smb2ops.c 57 KB

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