file.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  1. /*
  2. * fs/cifs/file.c
  3. *
  4. * vfs operations that deal with files
  5. *
  6. * Copyright (C) International Business Machines Corp., 2002,2007
  7. * Author(s): Steve French (sfrench@us.ibm.com)
  8. * Jeremy Allison (jra@samba.org)
  9. *
  10. * This library is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published
  12. * by the Free Software Foundation; either version 2.1 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  18. * the GNU Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/fs.h>
  25. #include <linux/backing-dev.h>
  26. #include <linux/stat.h>
  27. #include <linux/fcntl.h>
  28. #include <linux/pagemap.h>
  29. #include <linux/pagevec.h>
  30. #include <linux/writeback.h>
  31. #include <linux/task_io_accounting_ops.h>
  32. #include <linux/delay.h>
  33. #include <linux/mount.h>
  34. #include <linux/slab.h>
  35. #include <asm/div64.h>
  36. #include "cifsfs.h"
  37. #include "cifspdu.h"
  38. #include "cifsglob.h"
  39. #include "cifsproto.h"
  40. #include "cifs_unicode.h"
  41. #include "cifs_debug.h"
  42. #include "cifs_fs_sb.h"
  43. static inline int cifs_convert_flags(unsigned int flags)
  44. {
  45. if ((flags & O_ACCMODE) == O_RDONLY)
  46. return GENERIC_READ;
  47. else if ((flags & O_ACCMODE) == O_WRONLY)
  48. return GENERIC_WRITE;
  49. else if ((flags & O_ACCMODE) == O_RDWR) {
  50. /* GENERIC_ALL is too much permission to request
  51. can cause unnecessary access denied on create */
  52. /* return GENERIC_ALL; */
  53. return (GENERIC_READ | GENERIC_WRITE);
  54. }
  55. return (READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES |
  56. FILE_WRITE_EA | FILE_APPEND_DATA | FILE_WRITE_DATA |
  57. FILE_READ_DATA);
  58. }
  59. static inline fmode_t cifs_posix_convert_flags(unsigned int flags)
  60. {
  61. fmode_t posix_flags = 0;
  62. if ((flags & O_ACCMODE) == O_RDONLY)
  63. posix_flags = FMODE_READ;
  64. else if ((flags & O_ACCMODE) == O_WRONLY)
  65. posix_flags = FMODE_WRITE;
  66. else if ((flags & O_ACCMODE) == O_RDWR) {
  67. /* GENERIC_ALL is too much permission to request
  68. can cause unnecessary access denied on create */
  69. /* return GENERIC_ALL; */
  70. posix_flags = FMODE_READ | FMODE_WRITE;
  71. }
  72. /* can not map O_CREAT or O_EXCL or O_TRUNC flags when
  73. reopening a file. They had their effect on the original open */
  74. if (flags & O_APPEND)
  75. posix_flags |= (fmode_t)O_APPEND;
  76. if (flags & O_DSYNC)
  77. posix_flags |= (fmode_t)O_DSYNC;
  78. if (flags & __O_SYNC)
  79. posix_flags |= (fmode_t)__O_SYNC;
  80. if (flags & O_DIRECTORY)
  81. posix_flags |= (fmode_t)O_DIRECTORY;
  82. if (flags & O_NOFOLLOW)
  83. posix_flags |= (fmode_t)O_NOFOLLOW;
  84. if (flags & O_DIRECT)
  85. posix_flags |= (fmode_t)O_DIRECT;
  86. return posix_flags;
  87. }
  88. static inline int cifs_get_disposition(unsigned int flags)
  89. {
  90. if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
  91. return FILE_CREATE;
  92. else if ((flags & (O_CREAT | O_TRUNC)) == (O_CREAT | O_TRUNC))
  93. return FILE_OVERWRITE_IF;
  94. else if ((flags & O_CREAT) == O_CREAT)
  95. return FILE_OPEN_IF;
  96. else if ((flags & O_TRUNC) == O_TRUNC)
  97. return FILE_OVERWRITE;
  98. else
  99. return FILE_OPEN;
  100. }
  101. /* all arguments to this function must be checked for validity in caller */
  102. static inline int
  103. cifs_posix_open_inode_helper(struct inode *inode, struct file *file,
  104. struct cifsInodeInfo *pCifsInode,
  105. struct cifsFileInfo *pCifsFile, __u32 oplock,
  106. u16 netfid)
  107. {
  108. write_lock(&GlobalSMBSeslock);
  109. pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
  110. if (pCifsInode == NULL) {
  111. write_unlock(&GlobalSMBSeslock);
  112. return -EINVAL;
  113. }
  114. if (pCifsInode->clientCanCacheRead) {
  115. /* we have the inode open somewhere else
  116. no need to discard cache data */
  117. goto psx_client_can_cache;
  118. }
  119. /* BB FIXME need to fix this check to move it earlier into posix_open
  120. BB fIX following section BB FIXME */
  121. /* if not oplocked, invalidate inode pages if mtime or file
  122. size changed */
  123. /* temp = cifs_NTtimeToUnix(le64_to_cpu(buf->LastWriteTime));
  124. if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
  125. (file->f_path.dentry->d_inode->i_size ==
  126. (loff_t)le64_to_cpu(buf->EndOfFile))) {
  127. cFYI(1, ("inode unchanged on server"));
  128. } else {
  129. if (file->f_path.dentry->d_inode->i_mapping) {
  130. rc = filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping);
  131. if (rc != 0)
  132. CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc;
  133. }
  134. cFYI(1, ("invalidating remote inode since open detected it "
  135. "changed"));
  136. invalidate_remote_inode(file->f_path.dentry->d_inode);
  137. } */
  138. psx_client_can_cache:
  139. if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
  140. pCifsInode->clientCanCacheAll = true;
  141. pCifsInode->clientCanCacheRead = true;
  142. cFYI(1, ("Exclusive Oplock granted on inode %p",
  143. file->f_path.dentry->d_inode));
  144. } else if ((oplock & 0xF) == OPLOCK_READ)
  145. pCifsInode->clientCanCacheRead = true;
  146. /* will have to change the unlock if we reenable the
  147. filemap_fdatawrite (which does not seem necessary */
  148. write_unlock(&GlobalSMBSeslock);
  149. return 0;
  150. }
  151. static struct cifsFileInfo *
  152. cifs_fill_filedata(struct file *file)
  153. {
  154. struct list_head *tmp;
  155. struct cifsFileInfo *pCifsFile = NULL;
  156. struct cifsInodeInfo *pCifsInode = NULL;
  157. /* search inode for this file and fill in file->private_data */
  158. pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
  159. read_lock(&GlobalSMBSeslock);
  160. list_for_each(tmp, &pCifsInode->openFileList) {
  161. pCifsFile = list_entry(tmp, struct cifsFileInfo, flist);
  162. if ((pCifsFile->pfile == NULL) &&
  163. (pCifsFile->pid == current->tgid)) {
  164. /* mode set in cifs_create */
  165. /* needed for writepage */
  166. pCifsFile->pfile = file;
  167. file->private_data = pCifsFile;
  168. break;
  169. }
  170. }
  171. read_unlock(&GlobalSMBSeslock);
  172. if (file->private_data != NULL) {
  173. return pCifsFile;
  174. } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL))
  175. cERROR(1, ("could not find file instance for "
  176. "new file %p", file));
  177. return NULL;
  178. }
  179. /* all arguments to this function must be checked for validity in caller */
  180. static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
  181. struct cifsInodeInfo *pCifsInode, struct cifsFileInfo *pCifsFile,
  182. struct cifsTconInfo *pTcon, int *oplock, FILE_ALL_INFO *buf,
  183. char *full_path, int xid)
  184. {
  185. struct timespec temp;
  186. int rc;
  187. if (pCifsInode->clientCanCacheRead) {
  188. /* we have the inode open somewhere else
  189. no need to discard cache data */
  190. goto client_can_cache;
  191. }
  192. /* BB need same check in cifs_create too? */
  193. /* if not oplocked, invalidate inode pages if mtime or file
  194. size changed */
  195. temp = cifs_NTtimeToUnix(buf->LastWriteTime);
  196. if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
  197. (file->f_path.dentry->d_inode->i_size ==
  198. (loff_t)le64_to_cpu(buf->EndOfFile))) {
  199. cFYI(1, ("inode unchanged on server"));
  200. } else {
  201. if (file->f_path.dentry->d_inode->i_mapping) {
  202. /* BB no need to lock inode until after invalidate
  203. since namei code should already have it locked? */
  204. rc = filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping);
  205. if (rc != 0)
  206. CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc;
  207. }
  208. cFYI(1, ("invalidating remote inode since open detected it "
  209. "changed"));
  210. invalidate_remote_inode(file->f_path.dentry->d_inode);
  211. }
  212. client_can_cache:
  213. if (pTcon->unix_ext)
  214. rc = cifs_get_inode_info_unix(&file->f_path.dentry->d_inode,
  215. full_path, inode->i_sb, xid);
  216. else
  217. rc = cifs_get_inode_info(&file->f_path.dentry->d_inode,
  218. full_path, buf, inode->i_sb, xid, NULL);
  219. if ((*oplock & 0xF) == OPLOCK_EXCLUSIVE) {
  220. pCifsInode->clientCanCacheAll = true;
  221. pCifsInode->clientCanCacheRead = true;
  222. cFYI(1, ("Exclusive Oplock granted on inode %p",
  223. file->f_path.dentry->d_inode));
  224. } else if ((*oplock & 0xF) == OPLOCK_READ)
  225. pCifsInode->clientCanCacheRead = true;
  226. return rc;
  227. }
  228. int cifs_open(struct inode *inode, struct file *file)
  229. {
  230. int rc = -EACCES;
  231. int xid;
  232. __u32 oplock;
  233. struct cifs_sb_info *cifs_sb;
  234. struct cifsTconInfo *tcon;
  235. struct cifsFileInfo *pCifsFile;
  236. struct cifsInodeInfo *pCifsInode;
  237. char *full_path = NULL;
  238. int desiredAccess;
  239. int disposition;
  240. __u16 netfid;
  241. FILE_ALL_INFO *buf = NULL;
  242. xid = GetXid();
  243. cifs_sb = CIFS_SB(inode->i_sb);
  244. tcon = cifs_sb->tcon;
  245. pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
  246. pCifsFile = cifs_fill_filedata(file);
  247. if (pCifsFile) {
  248. rc = 0;
  249. FreeXid(xid);
  250. return rc;
  251. }
  252. full_path = build_path_from_dentry(file->f_path.dentry);
  253. if (full_path == NULL) {
  254. rc = -ENOMEM;
  255. FreeXid(xid);
  256. return rc;
  257. }
  258. cFYI(1, ("inode = 0x%p file flags are 0x%x for %s",
  259. inode, file->f_flags, full_path));
  260. if (oplockEnabled)
  261. oplock = REQ_OPLOCK;
  262. else
  263. oplock = 0;
  264. if (!tcon->broken_posix_open && tcon->unix_ext &&
  265. (tcon->ses->capabilities & CAP_UNIX) &&
  266. (CIFS_UNIX_POSIX_PATH_OPS_CAP &
  267. le64_to_cpu(tcon->fsUnixInfo.Capability))) {
  268. int oflags = (int) cifs_posix_convert_flags(file->f_flags);
  269. /* can not refresh inode info since size could be stale */
  270. rc = cifs_posix_open(full_path, &inode, file->f_path.mnt,
  271. cifs_sb->mnt_file_mode /* ignored */,
  272. oflags, &oplock, &netfid, xid);
  273. if (rc == 0) {
  274. cFYI(1, ("posix open succeeded"));
  275. /* no need for special case handling of setting mode
  276. on read only files needed here */
  277. pCifsFile = cifs_fill_filedata(file);
  278. cifs_posix_open_inode_helper(inode, file, pCifsInode,
  279. pCifsFile, oplock, netfid);
  280. goto out;
  281. } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
  282. if (tcon->ses->serverNOS)
  283. cERROR(1, ("server %s of type %s returned"
  284. " unexpected error on SMB posix open"
  285. ", disabling posix open support."
  286. " Check if server update available.",
  287. tcon->ses->serverName,
  288. tcon->ses->serverNOS));
  289. tcon->broken_posix_open = true;
  290. } else if ((rc != -EIO) && (rc != -EREMOTE) &&
  291. (rc != -EOPNOTSUPP)) /* path not found or net err */
  292. goto out;
  293. /* else fallthrough to retry open the old way on network i/o
  294. or DFS errors */
  295. }
  296. desiredAccess = cifs_convert_flags(file->f_flags);
  297. /*********************************************************************
  298. * open flag mapping table:
  299. *
  300. * POSIX Flag CIFS Disposition
  301. * ---------- ----------------
  302. * O_CREAT FILE_OPEN_IF
  303. * O_CREAT | O_EXCL FILE_CREATE
  304. * O_CREAT | O_TRUNC FILE_OVERWRITE_IF
  305. * O_TRUNC FILE_OVERWRITE
  306. * none of the above FILE_OPEN
  307. *
  308. * Note that there is not a direct match between disposition
  309. * FILE_SUPERSEDE (ie create whether or not file exists although
  310. * O_CREAT | O_TRUNC is similar but truncates the existing
  311. * file rather than creating a new file as FILE_SUPERSEDE does
  312. * (which uses the attributes / metadata passed in on open call)
  313. *?
  314. *? O_SYNC is a reasonable match to CIFS writethrough flag
  315. *? and the read write flags match reasonably. O_LARGEFILE
  316. *? is irrelevant because largefile support is always used
  317. *? by this client. Flags O_APPEND, O_DIRECT, O_DIRECTORY,
  318. * O_FASYNC, O_NOFOLLOW, O_NONBLOCK need further investigation
  319. *********************************************************************/
  320. disposition = cifs_get_disposition(file->f_flags);
  321. /* BB pass O_SYNC flag through on file attributes .. BB */
  322. /* Also refresh inode by passing in file_info buf returned by SMBOpen
  323. and calling get_inode_info with returned buf (at least helps
  324. non-Unix server case) */
  325. /* BB we can not do this if this is the second open of a file
  326. and the first handle has writebehind data, we might be
  327. able to simply do a filemap_fdatawrite/filemap_fdatawait first */
  328. buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
  329. if (!buf) {
  330. rc = -ENOMEM;
  331. goto out;
  332. }
  333. if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS)
  334. rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
  335. desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
  336. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
  337. & CIFS_MOUNT_MAP_SPECIAL_CHR);
  338. else
  339. rc = -EIO; /* no NT SMB support fall into legacy open below */
  340. if (rc == -EIO) {
  341. /* Old server, try legacy style OpenX */
  342. rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
  343. desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
  344. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
  345. & CIFS_MOUNT_MAP_SPECIAL_CHR);
  346. }
  347. if (rc) {
  348. cFYI(1, ("cifs_open returned 0x%x", rc));
  349. goto out;
  350. }
  351. pCifsFile = cifs_new_fileinfo(inode, netfid, file, file->f_path.mnt,
  352. file->f_flags);
  353. file->private_data = pCifsFile;
  354. if (file->private_data == NULL) {
  355. rc = -ENOMEM;
  356. goto out;
  357. }
  358. rc = cifs_open_inode_helper(inode, file, pCifsInode, pCifsFile, tcon,
  359. &oplock, buf, full_path, xid);
  360. if (oplock & CIFS_CREATE_ACTION) {
  361. /* time to set mode which we can not set earlier due to
  362. problems creating new read-only files */
  363. if (tcon->unix_ext) {
  364. struct cifs_unix_set_info_args args = {
  365. .mode = inode->i_mode,
  366. .uid = NO_CHANGE_64,
  367. .gid = NO_CHANGE_64,
  368. .ctime = NO_CHANGE_64,
  369. .atime = NO_CHANGE_64,
  370. .mtime = NO_CHANGE_64,
  371. .device = 0,
  372. };
  373. CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
  374. cifs_sb->local_nls,
  375. cifs_sb->mnt_cifs_flags &
  376. CIFS_MOUNT_MAP_SPECIAL_CHR);
  377. }
  378. }
  379. out:
  380. kfree(buf);
  381. kfree(full_path);
  382. FreeXid(xid);
  383. return rc;
  384. }
  385. /* Try to reacquire byte range locks that were released when session */
  386. /* to server was lost */
  387. static int cifs_relock_file(struct cifsFileInfo *cifsFile)
  388. {
  389. int rc = 0;
  390. /* BB list all locks open on this file and relock */
  391. return rc;
  392. }
  393. static int cifs_reopen_file(struct file *file, bool can_flush)
  394. {
  395. int rc = -EACCES;
  396. int xid;
  397. __u32 oplock;
  398. struct cifs_sb_info *cifs_sb;
  399. struct cifsTconInfo *tcon;
  400. struct cifsFileInfo *pCifsFile;
  401. struct cifsInodeInfo *pCifsInode;
  402. struct inode *inode;
  403. char *full_path = NULL;
  404. int desiredAccess;
  405. int disposition = FILE_OPEN;
  406. __u16 netfid;
  407. if (file->private_data)
  408. pCifsFile = (struct cifsFileInfo *)file->private_data;
  409. else
  410. return -EBADF;
  411. xid = GetXid();
  412. mutex_lock(&pCifsFile->fh_mutex);
  413. if (!pCifsFile->invalidHandle) {
  414. mutex_unlock(&pCifsFile->fh_mutex);
  415. rc = 0;
  416. FreeXid(xid);
  417. return rc;
  418. }
  419. if (file->f_path.dentry == NULL) {
  420. cERROR(1, ("no valid name if dentry freed"));
  421. dump_stack();
  422. rc = -EBADF;
  423. goto reopen_error_exit;
  424. }
  425. inode = file->f_path.dentry->d_inode;
  426. if (inode == NULL) {
  427. cERROR(1, ("inode not valid"));
  428. dump_stack();
  429. rc = -EBADF;
  430. goto reopen_error_exit;
  431. }
  432. cifs_sb = CIFS_SB(inode->i_sb);
  433. tcon = cifs_sb->tcon;
  434. /* can not grab rename sem here because various ops, including
  435. those that already have the rename sem can end up causing writepage
  436. to get called and if the server was down that means we end up here,
  437. and we can never tell if the caller already has the rename_sem */
  438. full_path = build_path_from_dentry(file->f_path.dentry);
  439. if (full_path == NULL) {
  440. rc = -ENOMEM;
  441. reopen_error_exit:
  442. mutex_unlock(&pCifsFile->fh_mutex);
  443. FreeXid(xid);
  444. return rc;
  445. }
  446. cFYI(1, ("inode = 0x%p file flags 0x%x for %s",
  447. inode, file->f_flags, full_path));
  448. if (oplockEnabled)
  449. oplock = REQ_OPLOCK;
  450. else
  451. oplock = 0;
  452. if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) &&
  453. (CIFS_UNIX_POSIX_PATH_OPS_CAP &
  454. le64_to_cpu(tcon->fsUnixInfo.Capability))) {
  455. int oflags = (int) cifs_posix_convert_flags(file->f_flags);
  456. /* can not refresh inode info since size could be stale */
  457. rc = cifs_posix_open(full_path, NULL, file->f_path.mnt,
  458. cifs_sb->mnt_file_mode /* ignored */,
  459. oflags, &oplock, &netfid, xid);
  460. if (rc == 0) {
  461. cFYI(1, ("posix reopen succeeded"));
  462. goto reopen_success;
  463. }
  464. /* fallthrough to retry open the old way on errors, especially
  465. in the reconnect path it is important to retry hard */
  466. }
  467. desiredAccess = cifs_convert_flags(file->f_flags);
  468. /* Can not refresh inode by passing in file_info buf to be returned
  469. by SMBOpen and then calling get_inode_info with returned buf
  470. since file might have write behind data that needs to be flushed
  471. and server version of file size can be stale. If we knew for sure
  472. that inode was not dirty locally we could do this */
  473. rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desiredAccess,
  474. CREATE_NOT_DIR, &netfid, &oplock, NULL,
  475. cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
  476. CIFS_MOUNT_MAP_SPECIAL_CHR);
  477. if (rc) {
  478. mutex_unlock(&pCifsFile->fh_mutex);
  479. cFYI(1, ("cifs_open returned 0x%x", rc));
  480. cFYI(1, ("oplock: %d", oplock));
  481. } else {
  482. reopen_success:
  483. pCifsFile->netfid = netfid;
  484. pCifsFile->invalidHandle = false;
  485. mutex_unlock(&pCifsFile->fh_mutex);
  486. pCifsInode = CIFS_I(inode);
  487. if (pCifsInode) {
  488. if (can_flush) {
  489. rc = filemap_write_and_wait(inode->i_mapping);
  490. if (rc != 0)
  491. CIFS_I(inode)->write_behind_rc = rc;
  492. /* temporarily disable caching while we
  493. go to server to get inode info */
  494. pCifsInode->clientCanCacheAll = false;
  495. pCifsInode->clientCanCacheRead = false;
  496. if (tcon->unix_ext)
  497. rc = cifs_get_inode_info_unix(&inode,
  498. full_path, inode->i_sb, xid);
  499. else
  500. rc = cifs_get_inode_info(&inode,
  501. full_path, NULL, inode->i_sb,
  502. xid, NULL);
  503. } /* else we are writing out data to server already
  504. and could deadlock if we tried to flush data, and
  505. since we do not know if we have data that would
  506. invalidate the current end of file on the server
  507. we can not go to the server to get the new inod
  508. info */
  509. if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
  510. pCifsInode->clientCanCacheAll = true;
  511. pCifsInode->clientCanCacheRead = true;
  512. cFYI(1, ("Exclusive Oplock granted on inode %p",
  513. file->f_path.dentry->d_inode));
  514. } else if ((oplock & 0xF) == OPLOCK_READ) {
  515. pCifsInode->clientCanCacheRead = true;
  516. pCifsInode->clientCanCacheAll = false;
  517. } else {
  518. pCifsInode->clientCanCacheRead = false;
  519. pCifsInode->clientCanCacheAll = false;
  520. }
  521. cifs_relock_file(pCifsFile);
  522. }
  523. }
  524. kfree(full_path);
  525. FreeXid(xid);
  526. return rc;
  527. }
  528. int cifs_close(struct inode *inode, struct file *file)
  529. {
  530. int rc = 0;
  531. int xid, timeout;
  532. struct cifs_sb_info *cifs_sb;
  533. struct cifsTconInfo *pTcon;
  534. struct cifsFileInfo *pSMBFile =
  535. (struct cifsFileInfo *)file->private_data;
  536. xid = GetXid();
  537. cifs_sb = CIFS_SB(inode->i_sb);
  538. pTcon = cifs_sb->tcon;
  539. if (pSMBFile) {
  540. struct cifsLockInfo *li, *tmp;
  541. write_lock(&GlobalSMBSeslock);
  542. pSMBFile->closePend = true;
  543. if (pTcon) {
  544. /* no sense reconnecting to close a file that is
  545. already closed */
  546. if (!pTcon->need_reconnect) {
  547. write_unlock(&GlobalSMBSeslock);
  548. timeout = 2;
  549. while ((atomic_read(&pSMBFile->count) != 1)
  550. && (timeout <= 2048)) {
  551. /* Give write a better chance to get to
  552. server ahead of the close. We do not
  553. want to add a wait_q here as it would
  554. increase the memory utilization as
  555. the struct would be in each open file,
  556. but this should give enough time to
  557. clear the socket */
  558. cFYI(DBG2,
  559. ("close delay, write pending"));
  560. msleep(timeout);
  561. timeout *= 4;
  562. }
  563. if (!pTcon->need_reconnect &&
  564. !pSMBFile->invalidHandle)
  565. rc = CIFSSMBClose(xid, pTcon,
  566. pSMBFile->netfid);
  567. } else
  568. write_unlock(&GlobalSMBSeslock);
  569. } else
  570. write_unlock(&GlobalSMBSeslock);
  571. /* Delete any outstanding lock records.
  572. We'll lose them when the file is closed anyway. */
  573. mutex_lock(&pSMBFile->lock_mutex);
  574. list_for_each_entry_safe(li, tmp, &pSMBFile->llist, llist) {
  575. list_del(&li->llist);
  576. kfree(li);
  577. }
  578. mutex_unlock(&pSMBFile->lock_mutex);
  579. write_lock(&GlobalSMBSeslock);
  580. list_del(&pSMBFile->flist);
  581. list_del(&pSMBFile->tlist);
  582. write_unlock(&GlobalSMBSeslock);
  583. cifsFileInfo_put(file->private_data);
  584. file->private_data = NULL;
  585. } else
  586. rc = -EBADF;
  587. read_lock(&GlobalSMBSeslock);
  588. if (list_empty(&(CIFS_I(inode)->openFileList))) {
  589. cFYI(1, ("closing last open instance for inode %p", inode));
  590. /* if the file is not open we do not know if we can cache info
  591. on this inode, much less write behind and read ahead */
  592. CIFS_I(inode)->clientCanCacheRead = false;
  593. CIFS_I(inode)->clientCanCacheAll = false;
  594. }
  595. read_unlock(&GlobalSMBSeslock);
  596. if ((rc == 0) && CIFS_I(inode)->write_behind_rc)
  597. rc = CIFS_I(inode)->write_behind_rc;
  598. FreeXid(xid);
  599. return rc;
  600. }
  601. int cifs_closedir(struct inode *inode, struct file *file)
  602. {
  603. int rc = 0;
  604. int xid;
  605. struct cifsFileInfo *pCFileStruct =
  606. (struct cifsFileInfo *)file->private_data;
  607. char *ptmp;
  608. cFYI(1, ("Closedir inode = 0x%p", inode));
  609. xid = GetXid();
  610. if (pCFileStruct) {
  611. struct cifsTconInfo *pTcon;
  612. struct cifs_sb_info *cifs_sb =
  613. CIFS_SB(file->f_path.dentry->d_sb);
  614. pTcon = cifs_sb->tcon;
  615. cFYI(1, ("Freeing private data in close dir"));
  616. write_lock(&GlobalSMBSeslock);
  617. if (!pCFileStruct->srch_inf.endOfSearch &&
  618. !pCFileStruct->invalidHandle) {
  619. pCFileStruct->invalidHandle = true;
  620. write_unlock(&GlobalSMBSeslock);
  621. rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid);
  622. cFYI(1, ("Closing uncompleted readdir with rc %d",
  623. rc));
  624. /* not much we can do if it fails anyway, ignore rc */
  625. rc = 0;
  626. } else
  627. write_unlock(&GlobalSMBSeslock);
  628. ptmp = pCFileStruct->srch_inf.ntwrk_buf_start;
  629. if (ptmp) {
  630. cFYI(1, ("closedir free smb buf in srch struct"));
  631. pCFileStruct->srch_inf.ntwrk_buf_start = NULL;
  632. if (pCFileStruct->srch_inf.smallBuf)
  633. cifs_small_buf_release(ptmp);
  634. else
  635. cifs_buf_release(ptmp);
  636. }
  637. kfree(file->private_data);
  638. file->private_data = NULL;
  639. }
  640. /* BB can we lock the filestruct while this is going on? */
  641. FreeXid(xid);
  642. return rc;
  643. }
  644. static int store_file_lock(struct cifsFileInfo *fid, __u64 len,
  645. __u64 offset, __u8 lockType)
  646. {
  647. struct cifsLockInfo *li =
  648. kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL);
  649. if (li == NULL)
  650. return -ENOMEM;
  651. li->offset = offset;
  652. li->length = len;
  653. li->type = lockType;
  654. mutex_lock(&fid->lock_mutex);
  655. list_add(&li->llist, &fid->llist);
  656. mutex_unlock(&fid->lock_mutex);
  657. return 0;
  658. }
  659. int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
  660. {
  661. int rc, xid;
  662. __u32 numLock = 0;
  663. __u32 numUnlock = 0;
  664. __u64 length;
  665. bool wait_flag = false;
  666. struct cifs_sb_info *cifs_sb;
  667. struct cifsTconInfo *tcon;
  668. __u16 netfid;
  669. __u8 lockType = LOCKING_ANDX_LARGE_FILES;
  670. bool posix_locking = 0;
  671. length = 1 + pfLock->fl_end - pfLock->fl_start;
  672. rc = -EACCES;
  673. xid = GetXid();
  674. cFYI(1, ("Lock parm: 0x%x flockflags: "
  675. "0x%x flocktype: 0x%x start: %lld end: %lld",
  676. cmd, pfLock->fl_flags, pfLock->fl_type, pfLock->fl_start,
  677. pfLock->fl_end));
  678. if (pfLock->fl_flags & FL_POSIX)
  679. cFYI(1, ("Posix"));
  680. if (pfLock->fl_flags & FL_FLOCK)
  681. cFYI(1, ("Flock"));
  682. if (pfLock->fl_flags & FL_SLEEP) {
  683. cFYI(1, ("Blocking lock"));
  684. wait_flag = true;
  685. }
  686. if (pfLock->fl_flags & FL_ACCESS)
  687. cFYI(1, ("Process suspended by mandatory locking - "
  688. "not implemented yet"));
  689. if (pfLock->fl_flags & FL_LEASE)
  690. cFYI(1, ("Lease on file - not implemented yet"));
  691. if (pfLock->fl_flags &
  692. (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE)))
  693. cFYI(1, ("Unknown lock flags 0x%x", pfLock->fl_flags));
  694. if (pfLock->fl_type == F_WRLCK) {
  695. cFYI(1, ("F_WRLCK "));
  696. numLock = 1;
  697. } else if (pfLock->fl_type == F_UNLCK) {
  698. cFYI(1, ("F_UNLCK"));
  699. numUnlock = 1;
  700. /* Check if unlock includes more than
  701. one lock range */
  702. } else if (pfLock->fl_type == F_RDLCK) {
  703. cFYI(1, ("F_RDLCK"));
  704. lockType |= LOCKING_ANDX_SHARED_LOCK;
  705. numLock = 1;
  706. } else if (pfLock->fl_type == F_EXLCK) {
  707. cFYI(1, ("F_EXLCK"));
  708. numLock = 1;
  709. } else if (pfLock->fl_type == F_SHLCK) {
  710. cFYI(1, ("F_SHLCK"));
  711. lockType |= LOCKING_ANDX_SHARED_LOCK;
  712. numLock = 1;
  713. } else
  714. cFYI(1, ("Unknown type of lock"));
  715. cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
  716. tcon = cifs_sb->tcon;
  717. if (file->private_data == NULL) {
  718. rc = -EBADF;
  719. FreeXid(xid);
  720. return rc;
  721. }
  722. netfid = ((struct cifsFileInfo *)file->private_data)->netfid;
  723. if ((tcon->ses->capabilities & CAP_UNIX) &&
  724. (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
  725. ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
  726. posix_locking = 1;
  727. /* BB add code here to normalize offset and length to
  728. account for negative length which we can not accept over the
  729. wire */
  730. if (IS_GETLK(cmd)) {
  731. if (posix_locking) {
  732. int posix_lock_type;
  733. if (lockType & LOCKING_ANDX_SHARED_LOCK)
  734. posix_lock_type = CIFS_RDLCK;
  735. else
  736. posix_lock_type = CIFS_WRLCK;
  737. rc = CIFSSMBPosixLock(xid, tcon, netfid, 1 /* get */,
  738. length, pfLock,
  739. posix_lock_type, wait_flag);
  740. FreeXid(xid);
  741. return rc;
  742. }
  743. /* BB we could chain these into one lock request BB */
  744. rc = CIFSSMBLock(xid, tcon, netfid, length, pfLock->fl_start,
  745. 0, 1, lockType, 0 /* wait flag */ );
  746. if (rc == 0) {
  747. rc = CIFSSMBLock(xid, tcon, netfid, length,
  748. pfLock->fl_start, 1 /* numUnlock */ ,
  749. 0 /* numLock */ , lockType,
  750. 0 /* wait flag */ );
  751. pfLock->fl_type = F_UNLCK;
  752. if (rc != 0)
  753. cERROR(1, ("Error unlocking previously locked "
  754. "range %d during test of lock", rc));
  755. rc = 0;
  756. } else {
  757. /* if rc == ERR_SHARING_VIOLATION ? */
  758. rc = 0;
  759. if (lockType & LOCKING_ANDX_SHARED_LOCK) {
  760. pfLock->fl_type = F_WRLCK;
  761. } else {
  762. rc = CIFSSMBLock(xid, tcon, netfid, length,
  763. pfLock->fl_start, 0, 1,
  764. lockType | LOCKING_ANDX_SHARED_LOCK,
  765. 0 /* wait flag */);
  766. if (rc == 0) {
  767. rc = CIFSSMBLock(xid, tcon, netfid,
  768. length, pfLock->fl_start, 1, 0,
  769. lockType |
  770. LOCKING_ANDX_SHARED_LOCK,
  771. 0 /* wait flag */);
  772. pfLock->fl_type = F_RDLCK;
  773. if (rc != 0)
  774. cERROR(1, ("Error unlocking "
  775. "previously locked range %d "
  776. "during test of lock", rc));
  777. rc = 0;
  778. } else {
  779. pfLock->fl_type = F_WRLCK;
  780. rc = 0;
  781. }
  782. }
  783. }
  784. FreeXid(xid);
  785. return rc;
  786. }
  787. if (!numLock && !numUnlock) {
  788. /* if no lock or unlock then nothing
  789. to do since we do not know what it is */
  790. FreeXid(xid);
  791. return -EOPNOTSUPP;
  792. }
  793. if (posix_locking) {
  794. int posix_lock_type;
  795. if (lockType & LOCKING_ANDX_SHARED_LOCK)
  796. posix_lock_type = CIFS_RDLCK;
  797. else
  798. posix_lock_type = CIFS_WRLCK;
  799. if (numUnlock == 1)
  800. posix_lock_type = CIFS_UNLCK;
  801. rc = CIFSSMBPosixLock(xid, tcon, netfid, 0 /* set */,
  802. length, pfLock,
  803. posix_lock_type, wait_flag);
  804. } else {
  805. struct cifsFileInfo *fid =
  806. (struct cifsFileInfo *)file->private_data;
  807. if (numLock) {
  808. rc = CIFSSMBLock(xid, tcon, netfid, length,
  809. pfLock->fl_start,
  810. 0, numLock, lockType, wait_flag);
  811. if (rc == 0) {
  812. /* For Windows locks we must store them. */
  813. rc = store_file_lock(fid, length,
  814. pfLock->fl_start, lockType);
  815. }
  816. } else if (numUnlock) {
  817. /* For each stored lock that this unlock overlaps
  818. completely, unlock it. */
  819. int stored_rc = 0;
  820. struct cifsLockInfo *li, *tmp;
  821. rc = 0;
  822. mutex_lock(&fid->lock_mutex);
  823. list_for_each_entry_safe(li, tmp, &fid->llist, llist) {
  824. if (pfLock->fl_start <= li->offset &&
  825. (pfLock->fl_start + length) >=
  826. (li->offset + li->length)) {
  827. stored_rc = CIFSSMBLock(xid, tcon,
  828. netfid,
  829. li->length, li->offset,
  830. 1, 0, li->type, false);
  831. if (stored_rc)
  832. rc = stored_rc;
  833. list_del(&li->llist);
  834. kfree(li);
  835. }
  836. }
  837. mutex_unlock(&fid->lock_mutex);
  838. }
  839. }
  840. if (pfLock->fl_flags & FL_POSIX)
  841. posix_lock_file_wait(file, pfLock);
  842. FreeXid(xid);
  843. return rc;
  844. }
  845. /*
  846. * Set the timeout on write requests past EOF. For some servers (Windows)
  847. * these calls can be very long.
  848. *
  849. * If we're writing >10M past the EOF we give a 180s timeout. Anything less
  850. * than that gets a 45s timeout. Writes not past EOF get 15s timeouts.
  851. * The 10M cutoff is totally arbitrary. A better scheme for this would be
  852. * welcome if someone wants to suggest one.
  853. *
  854. * We may be able to do a better job with this if there were some way to
  855. * declare that a file should be sparse.
  856. */
  857. static int
  858. cifs_write_timeout(struct cifsInodeInfo *cifsi, loff_t offset)
  859. {
  860. if (offset <= cifsi->server_eof)
  861. return CIFS_STD_OP;
  862. else if (offset > (cifsi->server_eof + (10 * 1024 * 1024)))
  863. return CIFS_VLONG_OP;
  864. else
  865. return CIFS_LONG_OP;
  866. }
  867. /* update the file size (if needed) after a write */
  868. static void
  869. cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
  870. unsigned int bytes_written)
  871. {
  872. loff_t end_of_write = offset + bytes_written;
  873. if (end_of_write > cifsi->server_eof)
  874. cifsi->server_eof = end_of_write;
  875. }
  876. ssize_t cifs_user_write(struct file *file, const char __user *write_data,
  877. size_t write_size, loff_t *poffset)
  878. {
  879. int rc = 0;
  880. unsigned int bytes_written = 0;
  881. unsigned int total_written;
  882. struct cifs_sb_info *cifs_sb;
  883. struct cifsTconInfo *pTcon;
  884. int xid, long_op;
  885. struct cifsFileInfo *open_file;
  886. struct cifsInodeInfo *cifsi = CIFS_I(file->f_path.dentry->d_inode);
  887. cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
  888. pTcon = cifs_sb->tcon;
  889. /* cFYI(1,
  890. (" write %d bytes to offset %lld of %s", write_size,
  891. *poffset, file->f_path.dentry->d_name.name)); */
  892. if (file->private_data == NULL)
  893. return -EBADF;
  894. open_file = (struct cifsFileInfo *) file->private_data;
  895. rc = generic_write_checks(file, poffset, &write_size, 0);
  896. if (rc)
  897. return rc;
  898. xid = GetXid();
  899. long_op = cifs_write_timeout(cifsi, *poffset);
  900. for (total_written = 0; write_size > total_written;
  901. total_written += bytes_written) {
  902. rc = -EAGAIN;
  903. while (rc == -EAGAIN) {
  904. if (file->private_data == NULL) {
  905. /* file has been closed on us */
  906. FreeXid(xid);
  907. /* if we have gotten here we have written some data
  908. and blocked, and the file has been freed on us while
  909. we blocked so return what we managed to write */
  910. return total_written;
  911. }
  912. if (open_file->closePend) {
  913. FreeXid(xid);
  914. if (total_written)
  915. return total_written;
  916. else
  917. return -EBADF;
  918. }
  919. if (open_file->invalidHandle) {
  920. /* we could deadlock if we called
  921. filemap_fdatawait from here so tell
  922. reopen_file not to flush data to server
  923. now */
  924. rc = cifs_reopen_file(file, false);
  925. if (rc != 0)
  926. break;
  927. }
  928. rc = CIFSSMBWrite(xid, pTcon,
  929. open_file->netfid,
  930. min_t(const int, cifs_sb->wsize,
  931. write_size - total_written),
  932. *poffset, &bytes_written,
  933. NULL, write_data + total_written, long_op);
  934. }
  935. if (rc || (bytes_written == 0)) {
  936. if (total_written)
  937. break;
  938. else {
  939. FreeXid(xid);
  940. return rc;
  941. }
  942. } else {
  943. cifs_update_eof(cifsi, *poffset, bytes_written);
  944. *poffset += bytes_written;
  945. }
  946. long_op = CIFS_STD_OP; /* subsequent writes fast -
  947. 15 seconds is plenty */
  948. }
  949. cifs_stats_bytes_written(pTcon, total_written);
  950. /* since the write may have blocked check these pointers again */
  951. if ((file->f_path.dentry) && (file->f_path.dentry->d_inode)) {
  952. struct inode *inode = file->f_path.dentry->d_inode;
  953. /* Do not update local mtime - server will set its actual value on write
  954. * inode->i_ctime = inode->i_mtime =
  955. * current_fs_time(inode->i_sb);*/
  956. if (total_written > 0) {
  957. spin_lock(&inode->i_lock);
  958. if (*poffset > file->f_path.dentry->d_inode->i_size)
  959. i_size_write(file->f_path.dentry->d_inode,
  960. *poffset);
  961. spin_unlock(&inode->i_lock);
  962. }
  963. mark_inode_dirty_sync(file->f_path.dentry->d_inode);
  964. }
  965. FreeXid(xid);
  966. return total_written;
  967. }
  968. static ssize_t cifs_write(struct file *file, const char *write_data,
  969. size_t write_size, loff_t *poffset)
  970. {
  971. int rc = 0;
  972. unsigned int bytes_written = 0;
  973. unsigned int total_written;
  974. struct cifs_sb_info *cifs_sb;
  975. struct cifsTconInfo *pTcon;
  976. int xid, long_op;
  977. struct cifsFileInfo *open_file;
  978. struct cifsInodeInfo *cifsi = CIFS_I(file->f_path.dentry->d_inode);
  979. cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
  980. pTcon = cifs_sb->tcon;
  981. cFYI(1, ("write %zd bytes to offset %lld of %s", write_size,
  982. *poffset, file->f_path.dentry->d_name.name));
  983. if (file->private_data == NULL)
  984. return -EBADF;
  985. open_file = (struct cifsFileInfo *)file->private_data;
  986. xid = GetXid();
  987. long_op = cifs_write_timeout(cifsi, *poffset);
  988. for (total_written = 0; write_size > total_written;
  989. total_written += bytes_written) {
  990. rc = -EAGAIN;
  991. while (rc == -EAGAIN) {
  992. if (file->private_data == NULL) {
  993. /* file has been closed on us */
  994. FreeXid(xid);
  995. /* if we have gotten here we have written some data
  996. and blocked, and the file has been freed on us
  997. while we blocked so return what we managed to
  998. write */
  999. return total_written;
  1000. }
  1001. if (open_file->closePend) {
  1002. FreeXid(xid);
  1003. if (total_written)
  1004. return total_written;
  1005. else
  1006. return -EBADF;
  1007. }
  1008. if (open_file->invalidHandle) {
  1009. /* we could deadlock if we called
  1010. filemap_fdatawait from here so tell
  1011. reopen_file not to flush data to
  1012. server now */
  1013. rc = cifs_reopen_file(file, false);
  1014. if (rc != 0)
  1015. break;
  1016. }
  1017. if (experimEnabled || (pTcon->ses->server &&
  1018. ((pTcon->ses->server->secMode &
  1019. (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  1020. == 0))) {
  1021. struct kvec iov[2];
  1022. unsigned int len;
  1023. len = min((size_t)cifs_sb->wsize,
  1024. write_size - total_written);
  1025. /* iov[0] is reserved for smb header */
  1026. iov[1].iov_base = (char *)write_data +
  1027. total_written;
  1028. iov[1].iov_len = len;
  1029. rc = CIFSSMBWrite2(xid, pTcon,
  1030. open_file->netfid, len,
  1031. *poffset, &bytes_written,
  1032. iov, 1, long_op);
  1033. } else
  1034. rc = CIFSSMBWrite(xid, pTcon,
  1035. open_file->netfid,
  1036. min_t(const int, cifs_sb->wsize,
  1037. write_size - total_written),
  1038. *poffset, &bytes_written,
  1039. write_data + total_written,
  1040. NULL, long_op);
  1041. }
  1042. if (rc || (bytes_written == 0)) {
  1043. if (total_written)
  1044. break;
  1045. else {
  1046. FreeXid(xid);
  1047. return rc;
  1048. }
  1049. } else {
  1050. cifs_update_eof(cifsi, *poffset, bytes_written);
  1051. *poffset += bytes_written;
  1052. }
  1053. long_op = CIFS_STD_OP; /* subsequent writes fast -
  1054. 15 seconds is plenty */
  1055. }
  1056. cifs_stats_bytes_written(pTcon, total_written);
  1057. /* since the write may have blocked check these pointers again */
  1058. if ((file->f_path.dentry) && (file->f_path.dentry->d_inode)) {
  1059. /*BB We could make this contingent on superblock ATIME flag too */
  1060. /* file->f_path.dentry->d_inode->i_ctime =
  1061. file->f_path.dentry->d_inode->i_mtime = CURRENT_TIME;*/
  1062. if (total_written > 0) {
  1063. spin_lock(&file->f_path.dentry->d_inode->i_lock);
  1064. if (*poffset > file->f_path.dentry->d_inode->i_size)
  1065. i_size_write(file->f_path.dentry->d_inode,
  1066. *poffset);
  1067. spin_unlock(&file->f_path.dentry->d_inode->i_lock);
  1068. }
  1069. mark_inode_dirty_sync(file->f_path.dentry->d_inode);
  1070. }
  1071. FreeXid(xid);
  1072. return total_written;
  1073. }
  1074. #ifdef CONFIG_CIFS_EXPERIMENTAL
  1075. struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *cifs_inode)
  1076. {
  1077. struct cifsFileInfo *open_file = NULL;
  1078. read_lock(&GlobalSMBSeslock);
  1079. /* we could simply get the first_list_entry since write-only entries
  1080. are always at the end of the list but since the first entry might
  1081. have a close pending, we go through the whole list */
  1082. list_for_each_entry(open_file, &cifs_inode->openFileList, flist) {
  1083. if (open_file->closePend)
  1084. continue;
  1085. if (open_file->pfile && ((open_file->pfile->f_flags & O_RDWR) ||
  1086. (open_file->pfile->f_flags & O_RDONLY))) {
  1087. if (!open_file->invalidHandle) {
  1088. /* found a good file */
  1089. /* lock it so it will not be closed on us */
  1090. cifsFileInfo_get(open_file);
  1091. read_unlock(&GlobalSMBSeslock);
  1092. return open_file;
  1093. } /* else might as well continue, and look for
  1094. another, or simply have the caller reopen it
  1095. again rather than trying to fix this handle */
  1096. } else /* write only file */
  1097. break; /* write only files are last so must be done */
  1098. }
  1099. read_unlock(&GlobalSMBSeslock);
  1100. return NULL;
  1101. }
  1102. #endif
  1103. struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode)
  1104. {
  1105. struct cifsFileInfo *open_file;
  1106. bool any_available = false;
  1107. int rc;
  1108. /* Having a null inode here (because mapping->host was set to zero by
  1109. the VFS or MM) should not happen but we had reports of on oops (due to
  1110. it being zero) during stress testcases so we need to check for it */
  1111. if (cifs_inode == NULL) {
  1112. cERROR(1, ("Null inode passed to cifs_writeable_file"));
  1113. dump_stack();
  1114. return NULL;
  1115. }
  1116. read_lock(&GlobalSMBSeslock);
  1117. refind_writable:
  1118. list_for_each_entry(open_file, &cifs_inode->openFileList, flist) {
  1119. if (open_file->closePend ||
  1120. (!any_available && open_file->pid != current->tgid))
  1121. continue;
  1122. if (open_file->pfile &&
  1123. ((open_file->pfile->f_flags & O_RDWR) ||
  1124. (open_file->pfile->f_flags & O_WRONLY))) {
  1125. cifsFileInfo_get(open_file);
  1126. if (!open_file->invalidHandle) {
  1127. /* found a good writable file */
  1128. read_unlock(&GlobalSMBSeslock);
  1129. return open_file;
  1130. }
  1131. read_unlock(&GlobalSMBSeslock);
  1132. /* Had to unlock since following call can block */
  1133. rc = cifs_reopen_file(open_file->pfile, false);
  1134. if (!rc) {
  1135. if (!open_file->closePend)
  1136. return open_file;
  1137. else { /* start over in case this was deleted */
  1138. /* since the list could be modified */
  1139. read_lock(&GlobalSMBSeslock);
  1140. cifsFileInfo_put(open_file);
  1141. goto refind_writable;
  1142. }
  1143. }
  1144. /* if it fails, try another handle if possible -
  1145. (we can not do this if closePending since
  1146. loop could be modified - in which case we
  1147. have to start at the beginning of the list
  1148. again. Note that it would be bad
  1149. to hold up writepages here (rather than
  1150. in caller) with continuous retries */
  1151. cFYI(1, ("wp failed on reopen file"));
  1152. read_lock(&GlobalSMBSeslock);
  1153. /* can not use this handle, no write
  1154. pending on this one after all */
  1155. cifsFileInfo_put(open_file);
  1156. if (open_file->closePend) /* list could have changed */
  1157. goto refind_writable;
  1158. /* else we simply continue to the next entry. Thus
  1159. we do not loop on reopen errors. If we
  1160. can not reopen the file, for example if we
  1161. reconnected to a server with another client
  1162. racing to delete or lock the file we would not
  1163. make progress if we restarted before the beginning
  1164. of the loop here. */
  1165. }
  1166. }
  1167. /* couldn't find useable FH with same pid, try any available */
  1168. if (!any_available) {
  1169. any_available = true;
  1170. goto refind_writable;
  1171. }
  1172. read_unlock(&GlobalSMBSeslock);
  1173. return NULL;
  1174. }
  1175. static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
  1176. {
  1177. struct address_space *mapping = page->mapping;
  1178. loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
  1179. char *write_data;
  1180. int rc = -EFAULT;
  1181. int bytes_written = 0;
  1182. struct cifs_sb_info *cifs_sb;
  1183. struct cifsTconInfo *pTcon;
  1184. struct inode *inode;
  1185. struct cifsFileInfo *open_file;
  1186. if (!mapping || !mapping->host)
  1187. return -EFAULT;
  1188. inode = page->mapping->host;
  1189. cifs_sb = CIFS_SB(inode->i_sb);
  1190. pTcon = cifs_sb->tcon;
  1191. offset += (loff_t)from;
  1192. write_data = kmap(page);
  1193. write_data += from;
  1194. if ((to > PAGE_CACHE_SIZE) || (from > to)) {
  1195. kunmap(page);
  1196. return -EIO;
  1197. }
  1198. /* racing with truncate? */
  1199. if (offset > mapping->host->i_size) {
  1200. kunmap(page);
  1201. return 0; /* don't care */
  1202. }
  1203. /* check to make sure that we are not extending the file */
  1204. if (mapping->host->i_size - offset < (loff_t)to)
  1205. to = (unsigned)(mapping->host->i_size - offset);
  1206. open_file = find_writable_file(CIFS_I(mapping->host));
  1207. if (open_file) {
  1208. bytes_written = cifs_write(open_file->pfile, write_data,
  1209. to-from, &offset);
  1210. cifsFileInfo_put(open_file);
  1211. /* Does mm or vfs already set times? */
  1212. inode->i_atime = inode->i_mtime = current_fs_time(inode->i_sb);
  1213. if ((bytes_written > 0) && (offset))
  1214. rc = 0;
  1215. else if (bytes_written < 0)
  1216. rc = bytes_written;
  1217. } else {
  1218. cFYI(1, ("No writeable filehandles for inode"));
  1219. rc = -EIO;
  1220. }
  1221. kunmap(page);
  1222. return rc;
  1223. }
  1224. static int cifs_writepages(struct address_space *mapping,
  1225. struct writeback_control *wbc)
  1226. {
  1227. struct backing_dev_info *bdi = mapping->backing_dev_info;
  1228. unsigned int bytes_to_write;
  1229. unsigned int bytes_written;
  1230. struct cifs_sb_info *cifs_sb;
  1231. int done = 0;
  1232. pgoff_t end;
  1233. pgoff_t index;
  1234. int range_whole = 0;
  1235. struct kvec *iov;
  1236. int len;
  1237. int n_iov = 0;
  1238. pgoff_t next;
  1239. int nr_pages;
  1240. __u64 offset = 0;
  1241. struct cifsFileInfo *open_file;
  1242. struct cifsInodeInfo *cifsi = CIFS_I(mapping->host);
  1243. struct page *page;
  1244. struct pagevec pvec;
  1245. int rc = 0;
  1246. int scanned = 0;
  1247. int xid, long_op;
  1248. cifs_sb = CIFS_SB(mapping->host->i_sb);
  1249. /*
  1250. * If wsize is smaller that the page cache size, default to writing
  1251. * one page at a time via cifs_writepage
  1252. */
  1253. if (cifs_sb->wsize < PAGE_CACHE_SIZE)
  1254. return generic_writepages(mapping, wbc);
  1255. if ((cifs_sb->tcon->ses) && (cifs_sb->tcon->ses->server))
  1256. if (cifs_sb->tcon->ses->server->secMode &
  1257. (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
  1258. if (!experimEnabled)
  1259. return generic_writepages(mapping, wbc);
  1260. iov = kmalloc(32 * sizeof(struct kvec), GFP_KERNEL);
  1261. if (iov == NULL)
  1262. return generic_writepages(mapping, wbc);
  1263. /*
  1264. * BB: Is this meaningful for a non-block-device file system?
  1265. * If it is, we should test it again after we do I/O
  1266. */
  1267. if (wbc->nonblocking && bdi_write_congested(bdi)) {
  1268. wbc->encountered_congestion = 1;
  1269. kfree(iov);
  1270. return 0;
  1271. }
  1272. xid = GetXid();
  1273. pagevec_init(&pvec, 0);
  1274. if (wbc->range_cyclic) {
  1275. index = mapping->writeback_index; /* Start from prev offset */
  1276. end = -1;
  1277. } else {
  1278. index = wbc->range_start >> PAGE_CACHE_SHIFT;
  1279. end = wbc->range_end >> PAGE_CACHE_SHIFT;
  1280. if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
  1281. range_whole = 1;
  1282. scanned = 1;
  1283. }
  1284. retry:
  1285. while (!done && (index <= end) &&
  1286. (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
  1287. PAGECACHE_TAG_DIRTY,
  1288. min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1))) {
  1289. int first;
  1290. unsigned int i;
  1291. first = -1;
  1292. next = 0;
  1293. n_iov = 0;
  1294. bytes_to_write = 0;
  1295. for (i = 0; i < nr_pages; i++) {
  1296. page = pvec.pages[i];
  1297. /*
  1298. * At this point we hold neither mapping->tree_lock nor
  1299. * lock on the page itself: the page may be truncated or
  1300. * invalidated (changing page->mapping to NULL), or even
  1301. * swizzled back from swapper_space to tmpfs file
  1302. * mapping
  1303. */
  1304. if (first < 0)
  1305. lock_page(page);
  1306. else if (!trylock_page(page))
  1307. break;
  1308. if (unlikely(page->mapping != mapping)) {
  1309. unlock_page(page);
  1310. break;
  1311. }
  1312. if (!wbc->range_cyclic && page->index > end) {
  1313. done = 1;
  1314. unlock_page(page);
  1315. break;
  1316. }
  1317. if (next && (page->index != next)) {
  1318. /* Not next consecutive page */
  1319. unlock_page(page);
  1320. break;
  1321. }
  1322. if (wbc->sync_mode != WB_SYNC_NONE)
  1323. wait_on_page_writeback(page);
  1324. if (PageWriteback(page) ||
  1325. !clear_page_dirty_for_io(page)) {
  1326. unlock_page(page);
  1327. break;
  1328. }
  1329. /*
  1330. * This actually clears the dirty bit in the radix tree.
  1331. * See cifs_writepage() for more commentary.
  1332. */
  1333. set_page_writeback(page);
  1334. if (page_offset(page) >= mapping->host->i_size) {
  1335. done = 1;
  1336. unlock_page(page);
  1337. end_page_writeback(page);
  1338. break;
  1339. }
  1340. /*
  1341. * BB can we get rid of this? pages are held by pvec
  1342. */
  1343. page_cache_get(page);
  1344. len = min(mapping->host->i_size - page_offset(page),
  1345. (loff_t)PAGE_CACHE_SIZE);
  1346. /* reserve iov[0] for the smb header */
  1347. n_iov++;
  1348. iov[n_iov].iov_base = kmap(page);
  1349. iov[n_iov].iov_len = len;
  1350. bytes_to_write += len;
  1351. if (first < 0) {
  1352. first = i;
  1353. offset = page_offset(page);
  1354. }
  1355. next = page->index + 1;
  1356. if (bytes_to_write + PAGE_CACHE_SIZE > cifs_sb->wsize)
  1357. break;
  1358. }
  1359. if (n_iov) {
  1360. /* Search for a writable handle every time we call
  1361. * CIFSSMBWrite2. We can't rely on the last handle
  1362. * we used to still be valid
  1363. */
  1364. open_file = find_writable_file(CIFS_I(mapping->host));
  1365. if (!open_file) {
  1366. cERROR(1, ("No writable handles for inode"));
  1367. rc = -EBADF;
  1368. } else {
  1369. long_op = cifs_write_timeout(cifsi, offset);
  1370. rc = CIFSSMBWrite2(xid, cifs_sb->tcon,
  1371. open_file->netfid,
  1372. bytes_to_write, offset,
  1373. &bytes_written, iov, n_iov,
  1374. long_op);
  1375. cifsFileInfo_put(open_file);
  1376. cifs_update_eof(cifsi, offset, bytes_written);
  1377. if (rc || bytes_written < bytes_to_write) {
  1378. cERROR(1, ("Write2 ret %d, wrote %d",
  1379. rc, bytes_written));
  1380. /* BB what if continued retry is
  1381. requested via mount flags? */
  1382. if (rc == -ENOSPC)
  1383. set_bit(AS_ENOSPC, &mapping->flags);
  1384. else
  1385. set_bit(AS_EIO, &mapping->flags);
  1386. } else {
  1387. cifs_stats_bytes_written(cifs_sb->tcon,
  1388. bytes_written);
  1389. }
  1390. }
  1391. for (i = 0; i < n_iov; i++) {
  1392. page = pvec.pages[first + i];
  1393. /* Should we also set page error on
  1394. success rc but too little data written? */
  1395. /* BB investigate retry logic on temporary
  1396. server crash cases and how recovery works
  1397. when page marked as error */
  1398. if (rc)
  1399. SetPageError(page);
  1400. kunmap(page);
  1401. unlock_page(page);
  1402. end_page_writeback(page);
  1403. page_cache_release(page);
  1404. }
  1405. if ((wbc->nr_to_write -= n_iov) <= 0)
  1406. done = 1;
  1407. index = next;
  1408. } else
  1409. /* Need to re-find the pages we skipped */
  1410. index = pvec.pages[0]->index + 1;
  1411. pagevec_release(&pvec);
  1412. }
  1413. if (!scanned && !done) {
  1414. /*
  1415. * We hit the last page and there is more work to be done: wrap
  1416. * back to the start of the file
  1417. */
  1418. scanned = 1;
  1419. index = 0;
  1420. goto retry;
  1421. }
  1422. if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
  1423. mapping->writeback_index = index;
  1424. FreeXid(xid);
  1425. kfree(iov);
  1426. return rc;
  1427. }
  1428. static int cifs_writepage(struct page *page, struct writeback_control *wbc)
  1429. {
  1430. int rc = -EFAULT;
  1431. int xid;
  1432. xid = GetXid();
  1433. /* BB add check for wbc flags */
  1434. page_cache_get(page);
  1435. if (!PageUptodate(page))
  1436. cFYI(1, ("ppw - page not up to date"));
  1437. /*
  1438. * Set the "writeback" flag, and clear "dirty" in the radix tree.
  1439. *
  1440. * A writepage() implementation always needs to do either this,
  1441. * or re-dirty the page with "redirty_page_for_writepage()" in
  1442. * the case of a failure.
  1443. *
  1444. * Just unlocking the page will cause the radix tree tag-bits
  1445. * to fail to update with the state of the page correctly.
  1446. */
  1447. set_page_writeback(page);
  1448. rc = cifs_partialpagewrite(page, 0, PAGE_CACHE_SIZE);
  1449. SetPageUptodate(page); /* BB add check for error and Clearuptodate? */
  1450. unlock_page(page);
  1451. end_page_writeback(page);
  1452. page_cache_release(page);
  1453. FreeXid(xid);
  1454. return rc;
  1455. }
  1456. static int cifs_write_end(struct file *file, struct address_space *mapping,
  1457. loff_t pos, unsigned len, unsigned copied,
  1458. struct page *page, void *fsdata)
  1459. {
  1460. int rc;
  1461. struct inode *inode = mapping->host;
  1462. cFYI(1, ("write_end for page %p from pos %lld with %d bytes",
  1463. page, pos, copied));
  1464. if (PageChecked(page)) {
  1465. if (copied == len)
  1466. SetPageUptodate(page);
  1467. ClearPageChecked(page);
  1468. } else if (!PageUptodate(page) && copied == PAGE_CACHE_SIZE)
  1469. SetPageUptodate(page);
  1470. if (!PageUptodate(page)) {
  1471. char *page_data;
  1472. unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
  1473. int xid;
  1474. xid = GetXid();
  1475. /* this is probably better than directly calling
  1476. partialpage_write since in this function the file handle is
  1477. known which we might as well leverage */
  1478. /* BB check if anything else missing out of ppw
  1479. such as updating last write time */
  1480. page_data = kmap(page);
  1481. rc = cifs_write(file, page_data + offset, copied, &pos);
  1482. /* if (rc < 0) should we set writebehind rc? */
  1483. kunmap(page);
  1484. FreeXid(xid);
  1485. } else {
  1486. rc = copied;
  1487. pos += copied;
  1488. set_page_dirty(page);
  1489. }
  1490. if (rc > 0) {
  1491. spin_lock(&inode->i_lock);
  1492. if (pos > inode->i_size)
  1493. i_size_write(inode, pos);
  1494. spin_unlock(&inode->i_lock);
  1495. }
  1496. unlock_page(page);
  1497. page_cache_release(page);
  1498. return rc;
  1499. }
  1500. int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
  1501. {
  1502. int xid;
  1503. int rc = 0;
  1504. struct cifsTconInfo *tcon;
  1505. struct cifsFileInfo *smbfile =
  1506. (struct cifsFileInfo *)file->private_data;
  1507. struct inode *inode = file->f_path.dentry->d_inode;
  1508. xid = GetXid();
  1509. cFYI(1, ("Sync file - name: %s datasync: 0x%x",
  1510. dentry->d_name.name, datasync));
  1511. rc = filemap_write_and_wait(inode->i_mapping);
  1512. if (rc == 0) {
  1513. rc = CIFS_I(inode)->write_behind_rc;
  1514. CIFS_I(inode)->write_behind_rc = 0;
  1515. tcon = CIFS_SB(inode->i_sb)->tcon;
  1516. if (!rc && tcon && smbfile &&
  1517. !(CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
  1518. rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
  1519. }
  1520. FreeXid(xid);
  1521. return rc;
  1522. }
  1523. /* static void cifs_sync_page(struct page *page)
  1524. {
  1525. struct address_space *mapping;
  1526. struct inode *inode;
  1527. unsigned long index = page->index;
  1528. unsigned int rpages = 0;
  1529. int rc = 0;
  1530. cFYI(1, ("sync page %p",page));
  1531. mapping = page->mapping;
  1532. if (!mapping)
  1533. return 0;
  1534. inode = mapping->host;
  1535. if (!inode)
  1536. return; */
  1537. /* fill in rpages then
  1538. result = cifs_pagein_inode(inode, index, rpages); */ /* BB finish */
  1539. /* cFYI(1, ("rpages is %d for sync page of Index %ld", rpages, index));
  1540. #if 0
  1541. if (rc < 0)
  1542. return rc;
  1543. return 0;
  1544. #endif
  1545. } */
  1546. /*
  1547. * As file closes, flush all cached write data for this inode checking
  1548. * for write behind errors.
  1549. */
  1550. int cifs_flush(struct file *file, fl_owner_t id)
  1551. {
  1552. struct inode *inode = file->f_path.dentry->d_inode;
  1553. int rc = 0;
  1554. /* Rather than do the steps manually:
  1555. lock the inode for writing
  1556. loop through pages looking for write behind data (dirty pages)
  1557. coalesce into contiguous 16K (or smaller) chunks to write to server
  1558. send to server (prefer in parallel)
  1559. deal with writebehind errors
  1560. unlock inode for writing
  1561. filemapfdatawrite appears easier for the time being */
  1562. rc = filemap_fdatawrite(inode->i_mapping);
  1563. /* reset wb rc if we were able to write out dirty pages */
  1564. if (!rc) {
  1565. rc = CIFS_I(inode)->write_behind_rc;
  1566. CIFS_I(inode)->write_behind_rc = 0;
  1567. }
  1568. cFYI(1, ("Flush inode %p file %p rc %d", inode, file, rc));
  1569. return rc;
  1570. }
  1571. ssize_t cifs_user_read(struct file *file, char __user *read_data,
  1572. size_t read_size, loff_t *poffset)
  1573. {
  1574. int rc = -EACCES;
  1575. unsigned int bytes_read = 0;
  1576. unsigned int total_read = 0;
  1577. unsigned int current_read_size;
  1578. struct cifs_sb_info *cifs_sb;
  1579. struct cifsTconInfo *pTcon;
  1580. int xid;
  1581. struct cifsFileInfo *open_file;
  1582. char *smb_read_data;
  1583. char __user *current_offset;
  1584. struct smb_com_read_rsp *pSMBr;
  1585. xid = GetXid();
  1586. cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
  1587. pTcon = cifs_sb->tcon;
  1588. if (file->private_data == NULL) {
  1589. rc = -EBADF;
  1590. FreeXid(xid);
  1591. return rc;
  1592. }
  1593. open_file = (struct cifsFileInfo *)file->private_data;
  1594. if ((file->f_flags & O_ACCMODE) == O_WRONLY)
  1595. cFYI(1, ("attempting read on write only file instance"));
  1596. for (total_read = 0, current_offset = read_data;
  1597. read_size > total_read;
  1598. total_read += bytes_read, current_offset += bytes_read) {
  1599. current_read_size = min_t(const int, read_size - total_read,
  1600. cifs_sb->rsize);
  1601. rc = -EAGAIN;
  1602. smb_read_data = NULL;
  1603. while (rc == -EAGAIN) {
  1604. int buf_type = CIFS_NO_BUFFER;
  1605. if ((open_file->invalidHandle) &&
  1606. (!open_file->closePend)) {
  1607. rc = cifs_reopen_file(file, true);
  1608. if (rc != 0)
  1609. break;
  1610. }
  1611. rc = CIFSSMBRead(xid, pTcon,
  1612. open_file->netfid,
  1613. current_read_size, *poffset,
  1614. &bytes_read, &smb_read_data,
  1615. &buf_type);
  1616. pSMBr = (struct smb_com_read_rsp *)smb_read_data;
  1617. if (smb_read_data) {
  1618. if (copy_to_user(current_offset,
  1619. smb_read_data +
  1620. 4 /* RFC1001 length field */ +
  1621. le16_to_cpu(pSMBr->DataOffset),
  1622. bytes_read))
  1623. rc = -EFAULT;
  1624. if (buf_type == CIFS_SMALL_BUFFER)
  1625. cifs_small_buf_release(smb_read_data);
  1626. else if (buf_type == CIFS_LARGE_BUFFER)
  1627. cifs_buf_release(smb_read_data);
  1628. smb_read_data = NULL;
  1629. }
  1630. }
  1631. if (rc || (bytes_read == 0)) {
  1632. if (total_read) {
  1633. break;
  1634. } else {
  1635. FreeXid(xid);
  1636. return rc;
  1637. }
  1638. } else {
  1639. cifs_stats_bytes_read(pTcon, bytes_read);
  1640. *poffset += bytes_read;
  1641. }
  1642. }
  1643. FreeXid(xid);
  1644. return total_read;
  1645. }
  1646. static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
  1647. loff_t *poffset)
  1648. {
  1649. int rc = -EACCES;
  1650. unsigned int bytes_read = 0;
  1651. unsigned int total_read;
  1652. unsigned int current_read_size;
  1653. struct cifs_sb_info *cifs_sb;
  1654. struct cifsTconInfo *pTcon;
  1655. int xid;
  1656. char *current_offset;
  1657. struct cifsFileInfo *open_file;
  1658. int buf_type = CIFS_NO_BUFFER;
  1659. xid = GetXid();
  1660. cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
  1661. pTcon = cifs_sb->tcon;
  1662. if (file->private_data == NULL) {
  1663. rc = -EBADF;
  1664. FreeXid(xid);
  1665. return rc;
  1666. }
  1667. open_file = (struct cifsFileInfo *)file->private_data;
  1668. if ((file->f_flags & O_ACCMODE) == O_WRONLY)
  1669. cFYI(1, ("attempting read on write only file instance"));
  1670. for (total_read = 0, current_offset = read_data;
  1671. read_size > total_read;
  1672. total_read += bytes_read, current_offset += bytes_read) {
  1673. current_read_size = min_t(const int, read_size - total_read,
  1674. cifs_sb->rsize);
  1675. /* For windows me and 9x we do not want to request more
  1676. than it negotiated since it will refuse the read then */
  1677. if ((pTcon->ses) &&
  1678. !(pTcon->ses->capabilities & CAP_LARGE_FILES)) {
  1679. current_read_size = min_t(const int, current_read_size,
  1680. pTcon->ses->server->maxBuf - 128);
  1681. }
  1682. rc = -EAGAIN;
  1683. while (rc == -EAGAIN) {
  1684. if ((open_file->invalidHandle) &&
  1685. (!open_file->closePend)) {
  1686. rc = cifs_reopen_file(file, true);
  1687. if (rc != 0)
  1688. break;
  1689. }
  1690. rc = CIFSSMBRead(xid, pTcon,
  1691. open_file->netfid,
  1692. current_read_size, *poffset,
  1693. &bytes_read, &current_offset,
  1694. &buf_type);
  1695. }
  1696. if (rc || (bytes_read == 0)) {
  1697. if (total_read) {
  1698. break;
  1699. } else {
  1700. FreeXid(xid);
  1701. return rc;
  1702. }
  1703. } else {
  1704. cifs_stats_bytes_read(pTcon, total_read);
  1705. *poffset += bytes_read;
  1706. }
  1707. }
  1708. FreeXid(xid);
  1709. return total_read;
  1710. }
  1711. int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
  1712. {
  1713. int rc, xid;
  1714. xid = GetXid();
  1715. rc = cifs_revalidate_file(file);
  1716. if (rc) {
  1717. cFYI(1, ("Validation prior to mmap failed, error=%d", rc));
  1718. FreeXid(xid);
  1719. return rc;
  1720. }
  1721. rc = generic_file_mmap(file, vma);
  1722. FreeXid(xid);
  1723. return rc;
  1724. }
  1725. static void cifs_copy_cache_pages(struct address_space *mapping,
  1726. struct list_head *pages, int bytes_read, char *data,
  1727. struct pagevec *plru_pvec)
  1728. {
  1729. struct page *page;
  1730. char *target;
  1731. while (bytes_read > 0) {
  1732. if (list_empty(pages))
  1733. break;
  1734. page = list_entry(pages->prev, struct page, lru);
  1735. list_del(&page->lru);
  1736. if (add_to_page_cache(page, mapping, page->index,
  1737. GFP_KERNEL)) {
  1738. page_cache_release(page);
  1739. cFYI(1, ("Add page cache failed"));
  1740. data += PAGE_CACHE_SIZE;
  1741. bytes_read -= PAGE_CACHE_SIZE;
  1742. continue;
  1743. }
  1744. target = kmap_atomic(page, KM_USER0);
  1745. if (PAGE_CACHE_SIZE > bytes_read) {
  1746. memcpy(target, data, bytes_read);
  1747. /* zero the tail end of this partial page */
  1748. memset(target + bytes_read, 0,
  1749. PAGE_CACHE_SIZE - bytes_read);
  1750. bytes_read = 0;
  1751. } else {
  1752. memcpy(target, data, PAGE_CACHE_SIZE);
  1753. bytes_read -= PAGE_CACHE_SIZE;
  1754. }
  1755. kunmap_atomic(target, KM_USER0);
  1756. flush_dcache_page(page);
  1757. SetPageUptodate(page);
  1758. unlock_page(page);
  1759. if (!pagevec_add(plru_pvec, page))
  1760. __pagevec_lru_add_file(plru_pvec);
  1761. data += PAGE_CACHE_SIZE;
  1762. }
  1763. return;
  1764. }
  1765. static int cifs_readpages(struct file *file, struct address_space *mapping,
  1766. struct list_head *page_list, unsigned num_pages)
  1767. {
  1768. int rc = -EACCES;
  1769. int xid;
  1770. loff_t offset;
  1771. struct page *page;
  1772. struct cifs_sb_info *cifs_sb;
  1773. struct cifsTconInfo *pTcon;
  1774. unsigned int bytes_read = 0;
  1775. unsigned int read_size, i;
  1776. char *smb_read_data = NULL;
  1777. struct smb_com_read_rsp *pSMBr;
  1778. struct pagevec lru_pvec;
  1779. struct cifsFileInfo *open_file;
  1780. int buf_type = CIFS_NO_BUFFER;
  1781. xid = GetXid();
  1782. if (file->private_data == NULL) {
  1783. rc = -EBADF;
  1784. FreeXid(xid);
  1785. return rc;
  1786. }
  1787. open_file = (struct cifsFileInfo *)file->private_data;
  1788. cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
  1789. pTcon = cifs_sb->tcon;
  1790. pagevec_init(&lru_pvec, 0);
  1791. cFYI(DBG2, ("rpages: num pages %d", num_pages));
  1792. for (i = 0; i < num_pages; ) {
  1793. unsigned contig_pages;
  1794. struct page *tmp_page;
  1795. unsigned long expected_index;
  1796. if (list_empty(page_list))
  1797. break;
  1798. page = list_entry(page_list->prev, struct page, lru);
  1799. offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
  1800. /* count adjacent pages that we will read into */
  1801. contig_pages = 0;
  1802. expected_index =
  1803. list_entry(page_list->prev, struct page, lru)->index;
  1804. list_for_each_entry_reverse(tmp_page, page_list, lru) {
  1805. if (tmp_page->index == expected_index) {
  1806. contig_pages++;
  1807. expected_index++;
  1808. } else
  1809. break;
  1810. }
  1811. if (contig_pages + i > num_pages)
  1812. contig_pages = num_pages - i;
  1813. /* for reads over a certain size could initiate async
  1814. read ahead */
  1815. read_size = contig_pages * PAGE_CACHE_SIZE;
  1816. /* Read size needs to be in multiples of one page */
  1817. read_size = min_t(const unsigned int, read_size,
  1818. cifs_sb->rsize & PAGE_CACHE_MASK);
  1819. cFYI(DBG2, ("rpages: read size 0x%x contiguous pages %d",
  1820. read_size, contig_pages));
  1821. rc = -EAGAIN;
  1822. while (rc == -EAGAIN) {
  1823. if ((open_file->invalidHandle) &&
  1824. (!open_file->closePend)) {
  1825. rc = cifs_reopen_file(file, true);
  1826. if (rc != 0)
  1827. break;
  1828. }
  1829. rc = CIFSSMBRead(xid, pTcon,
  1830. open_file->netfid,
  1831. read_size, offset,
  1832. &bytes_read, &smb_read_data,
  1833. &buf_type);
  1834. /* BB more RC checks ? */
  1835. if (rc == -EAGAIN) {
  1836. if (smb_read_data) {
  1837. if (buf_type == CIFS_SMALL_BUFFER)
  1838. cifs_small_buf_release(smb_read_data);
  1839. else if (buf_type == CIFS_LARGE_BUFFER)
  1840. cifs_buf_release(smb_read_data);
  1841. smb_read_data = NULL;
  1842. }
  1843. }
  1844. }
  1845. if ((rc < 0) || (smb_read_data == NULL)) {
  1846. cFYI(1, ("Read error in readpages: %d", rc));
  1847. break;
  1848. } else if (bytes_read > 0) {
  1849. task_io_account_read(bytes_read);
  1850. pSMBr = (struct smb_com_read_rsp *)smb_read_data;
  1851. cifs_copy_cache_pages(mapping, page_list, bytes_read,
  1852. smb_read_data + 4 /* RFC1001 hdr */ +
  1853. le16_to_cpu(pSMBr->DataOffset), &lru_pvec);
  1854. i += bytes_read >> PAGE_CACHE_SHIFT;
  1855. cifs_stats_bytes_read(pTcon, bytes_read);
  1856. if ((bytes_read & PAGE_CACHE_MASK) != bytes_read) {
  1857. i++; /* account for partial page */
  1858. /* server copy of file can have smaller size
  1859. than client */
  1860. /* BB do we need to verify this common case ?
  1861. this case is ok - if we are at server EOF
  1862. we will hit it on next read */
  1863. /* break; */
  1864. }
  1865. } else {
  1866. cFYI(1, ("No bytes read (%d) at offset %lld . "
  1867. "Cleaning remaining pages from readahead list",
  1868. bytes_read, offset));
  1869. /* BB turn off caching and do new lookup on
  1870. file size at server? */
  1871. break;
  1872. }
  1873. if (smb_read_data) {
  1874. if (buf_type == CIFS_SMALL_BUFFER)
  1875. cifs_small_buf_release(smb_read_data);
  1876. else if (buf_type == CIFS_LARGE_BUFFER)
  1877. cifs_buf_release(smb_read_data);
  1878. smb_read_data = NULL;
  1879. }
  1880. bytes_read = 0;
  1881. }
  1882. pagevec_lru_add_file(&lru_pvec);
  1883. /* need to free smb_read_data buf before exit */
  1884. if (smb_read_data) {
  1885. if (buf_type == CIFS_SMALL_BUFFER)
  1886. cifs_small_buf_release(smb_read_data);
  1887. else if (buf_type == CIFS_LARGE_BUFFER)
  1888. cifs_buf_release(smb_read_data);
  1889. smb_read_data = NULL;
  1890. }
  1891. FreeXid(xid);
  1892. return rc;
  1893. }
  1894. static int cifs_readpage_worker(struct file *file, struct page *page,
  1895. loff_t *poffset)
  1896. {
  1897. char *read_data;
  1898. int rc;
  1899. page_cache_get(page);
  1900. read_data = kmap(page);
  1901. /* for reads over a certain size could initiate async read ahead */
  1902. rc = cifs_read(file, read_data, PAGE_CACHE_SIZE, poffset);
  1903. if (rc < 0)
  1904. goto io_error;
  1905. else
  1906. cFYI(1, ("Bytes read %d", rc));
  1907. file->f_path.dentry->d_inode->i_atime =
  1908. current_fs_time(file->f_path.dentry->d_inode->i_sb);
  1909. if (PAGE_CACHE_SIZE > rc)
  1910. memset(read_data + rc, 0, PAGE_CACHE_SIZE - rc);
  1911. flush_dcache_page(page);
  1912. SetPageUptodate(page);
  1913. rc = 0;
  1914. io_error:
  1915. kunmap(page);
  1916. page_cache_release(page);
  1917. return rc;
  1918. }
  1919. static int cifs_readpage(struct file *file, struct page *page)
  1920. {
  1921. loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
  1922. int rc = -EACCES;
  1923. int xid;
  1924. xid = GetXid();
  1925. if (file->private_data == NULL) {
  1926. rc = -EBADF;
  1927. FreeXid(xid);
  1928. return rc;
  1929. }
  1930. cFYI(1, ("readpage %p at offset %d 0x%x\n",
  1931. page, (int)offset, (int)offset));
  1932. rc = cifs_readpage_worker(file, page, &offset);
  1933. unlock_page(page);
  1934. FreeXid(xid);
  1935. return rc;
  1936. }
  1937. static int is_inode_writable(struct cifsInodeInfo *cifs_inode)
  1938. {
  1939. struct cifsFileInfo *open_file;
  1940. read_lock(&GlobalSMBSeslock);
  1941. list_for_each_entry(open_file, &cifs_inode->openFileList, flist) {
  1942. if (open_file->closePend)
  1943. continue;
  1944. if (open_file->pfile &&
  1945. ((open_file->pfile->f_flags & O_RDWR) ||
  1946. (open_file->pfile->f_flags & O_WRONLY))) {
  1947. read_unlock(&GlobalSMBSeslock);
  1948. return 1;
  1949. }
  1950. }
  1951. read_unlock(&GlobalSMBSeslock);
  1952. return 0;
  1953. }
  1954. /* We do not want to update the file size from server for inodes
  1955. open for write - to avoid races with writepage extending
  1956. the file - in the future we could consider allowing
  1957. refreshing the inode only on increases in the file size
  1958. but this is tricky to do without racing with writebehind
  1959. page caching in the current Linux kernel design */
  1960. bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 end_of_file)
  1961. {
  1962. if (!cifsInode)
  1963. return true;
  1964. if (is_inode_writable(cifsInode)) {
  1965. /* This inode is open for write at least once */
  1966. struct cifs_sb_info *cifs_sb;
  1967. cifs_sb = CIFS_SB(cifsInode->vfs_inode.i_sb);
  1968. if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
  1969. /* since no page cache to corrupt on directio
  1970. we can change size safely */
  1971. return true;
  1972. }
  1973. if (i_size_read(&cifsInode->vfs_inode) < end_of_file)
  1974. return true;
  1975. return false;
  1976. } else
  1977. return true;
  1978. }
  1979. static int cifs_write_begin(struct file *file, struct address_space *mapping,
  1980. loff_t pos, unsigned len, unsigned flags,
  1981. struct page **pagep, void **fsdata)
  1982. {
  1983. pgoff_t index = pos >> PAGE_CACHE_SHIFT;
  1984. loff_t offset = pos & (PAGE_CACHE_SIZE - 1);
  1985. loff_t page_start = pos & PAGE_MASK;
  1986. loff_t i_size;
  1987. struct page *page;
  1988. int rc = 0;
  1989. cFYI(1, ("write_begin from %lld len %d", (long long)pos, len));
  1990. page = grab_cache_page_write_begin(mapping, index, flags);
  1991. if (!page) {
  1992. rc = -ENOMEM;
  1993. goto out;
  1994. }
  1995. if (PageUptodate(page))
  1996. goto out;
  1997. /*
  1998. * If we write a full page it will be up to date, no need to read from
  1999. * the server. If the write is short, we'll end up doing a sync write
  2000. * instead.
  2001. */
  2002. if (len == PAGE_CACHE_SIZE)
  2003. goto out;
  2004. /*
  2005. * optimize away the read when we have an oplock, and we're not
  2006. * expecting to use any of the data we'd be reading in. That
  2007. * is, when the page lies beyond the EOF, or straddles the EOF
  2008. * and the write will cover all of the existing data.
  2009. */
  2010. if (CIFS_I(mapping->host)->clientCanCacheRead) {
  2011. i_size = i_size_read(mapping->host);
  2012. if (page_start >= i_size ||
  2013. (offset == 0 && (pos + len) >= i_size)) {
  2014. zero_user_segments(page, 0, offset,
  2015. offset + len,
  2016. PAGE_CACHE_SIZE);
  2017. /*
  2018. * PageChecked means that the parts of the page
  2019. * to which we're not writing are considered up
  2020. * to date. Once the data is copied to the
  2021. * page, it can be set uptodate.
  2022. */
  2023. SetPageChecked(page);
  2024. goto out;
  2025. }
  2026. }
  2027. if ((file->f_flags & O_ACCMODE) != O_WRONLY) {
  2028. /*
  2029. * might as well read a page, it is fast enough. If we get
  2030. * an error, we don't need to return it. cifs_write_end will
  2031. * do a sync write instead since PG_uptodate isn't set.
  2032. */
  2033. cifs_readpage_worker(file, page, &page_start);
  2034. } else {
  2035. /* we could try using another file handle if there is one -
  2036. but how would we lock it to prevent close of that handle
  2037. racing with this read? In any case
  2038. this will be written out by write_end so is fine */
  2039. }
  2040. out:
  2041. *pagep = page;
  2042. return rc;
  2043. }
  2044. static void
  2045. cifs_oplock_break(struct slow_work *work)
  2046. {
  2047. struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
  2048. oplock_break);
  2049. struct inode *inode = cfile->pInode;
  2050. struct cifsInodeInfo *cinode = CIFS_I(inode);
  2051. struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->mnt->mnt_sb);
  2052. int rc, waitrc = 0;
  2053. if (inode && S_ISREG(inode->i_mode)) {
  2054. #ifdef CONFIG_CIFS_EXPERIMENTAL
  2055. if (cinode->clientCanCacheAll == 0)
  2056. break_lease(inode, O_RDONLY);
  2057. else if (cinode->clientCanCacheRead == 0)
  2058. break_lease(inode, O_WRONLY);
  2059. #endif
  2060. rc = filemap_fdatawrite(inode->i_mapping);
  2061. if (cinode->clientCanCacheRead == 0) {
  2062. waitrc = filemap_fdatawait(inode->i_mapping);
  2063. invalidate_remote_inode(inode);
  2064. }
  2065. if (!rc)
  2066. rc = waitrc;
  2067. if (rc)
  2068. cinode->write_behind_rc = rc;
  2069. cFYI(1, ("Oplock flush inode %p rc %d", inode, rc));
  2070. }
  2071. /*
  2072. * releasing stale oplock after recent reconnect of smb session using
  2073. * a now incorrect file handle is not a data integrity issue but do
  2074. * not bother sending an oplock release if session to server still is
  2075. * disconnected since oplock already released by the server
  2076. */
  2077. if (!cfile->closePend && !cfile->oplock_break_cancelled) {
  2078. rc = CIFSSMBLock(0, cifs_sb->tcon, cfile->netfid, 0, 0, 0, 0,
  2079. LOCKING_ANDX_OPLOCK_RELEASE, false);
  2080. cFYI(1, ("Oplock release rc = %d", rc));
  2081. }
  2082. }
  2083. static int
  2084. cifs_oplock_break_get(struct slow_work *work)
  2085. {
  2086. struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
  2087. oplock_break);
  2088. mntget(cfile->mnt);
  2089. cifsFileInfo_get(cfile);
  2090. return 0;
  2091. }
  2092. static void
  2093. cifs_oplock_break_put(struct slow_work *work)
  2094. {
  2095. struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
  2096. oplock_break);
  2097. mntput(cfile->mnt);
  2098. cifsFileInfo_put(cfile);
  2099. }
  2100. const struct slow_work_ops cifs_oplock_break_ops = {
  2101. .get_ref = cifs_oplock_break_get,
  2102. .put_ref = cifs_oplock_break_put,
  2103. .execute = cifs_oplock_break,
  2104. };
  2105. const struct address_space_operations cifs_addr_ops = {
  2106. .readpage = cifs_readpage,
  2107. .readpages = cifs_readpages,
  2108. .writepage = cifs_writepage,
  2109. .writepages = cifs_writepages,
  2110. .write_begin = cifs_write_begin,
  2111. .write_end = cifs_write_end,
  2112. .set_page_dirty = __set_page_dirty_nobuffers,
  2113. /* .sync_page = cifs_sync_page, */
  2114. /* .direct_IO = */
  2115. };
  2116. /*
  2117. * cifs_readpages requires the server to support a buffer large enough to
  2118. * contain the header plus one complete page of data. Otherwise, we need
  2119. * to leave cifs_readpages out of the address space operations.
  2120. */
  2121. const struct address_space_operations cifs_addr_ops_smallbuf = {
  2122. .readpage = cifs_readpage,
  2123. .writepage = cifs_writepage,
  2124. .writepages = cifs_writepages,
  2125. .write_begin = cifs_write_begin,
  2126. .write_end = cifs_write_end,
  2127. .set_page_dirty = __set_page_dirty_nobuffers,
  2128. /* .sync_page = cifs_sync_page, */
  2129. /* .direct_IO = */
  2130. };