···14751475 cFYI(1, ("write_end for page %p from pos %lld with %d bytes",14761476 page, pos, copied));1477147714781478- if (!PageUptodate(page) && copied == PAGE_CACHE_SIZE)14781478+ if (PageChecked(page)) {14791479+ if (copied == len)14801480+ SetPageUptodate(page);14811481+ ClearPageChecked(page);14821482+ } else if (!PageUptodate(page) && copied == PAGE_CACHE_SIZE)14791483 SetPageUptodate(page);1480148414811485 if (!PageUptodate(page)) {···20662062{20672063 pgoff_t index = pos >> PAGE_CACHE_SHIFT;20682064 loff_t offset = pos & (PAGE_CACHE_SIZE - 1);20652065+ loff_t page_start = pos & PAGE_MASK;20662066+ loff_t i_size;20672067+ struct page *page;20682068+ int rc = 0;2069206920702070 cFYI(1, ("write_begin from %lld len %d", (long long)pos, len));2071207120722072- *pagep = __grab_cache_page(mapping, index);20732073- if (!*pagep)20742074- return -ENOMEM;20722072+ page = __grab_cache_page(mapping, index);20732073+ if (!page) {20742074+ rc = -ENOMEM;20752075+ goto out;20762076+ }2075207720762076- if (PageUptodate(*pagep))20772077- return 0;20782078+ if (PageUptodate(page))20792079+ goto out;2078208020792079- /* If we are writing a full page it will be up to date,20802080- no need to read from the server */20812081- if (len == PAGE_CACHE_SIZE && flags & AOP_FLAG_UNINTERRUPTIBLE)20822082- return 0;20812081+ /*20822082+ * If we write a full page it will be up to date, no need to read from20832083+ * the server. If the write is short, we'll end up doing a sync write20842084+ * instead.20852085+ */20862086+ if (len == PAGE_CACHE_SIZE)20872087+ goto out;20882088+20892089+ /*20902090+ * optimize away the read when we have an oplock, and we're not20912091+ * expecting to use any of the data we'd be reading in. That20922092+ * is, when the page lies beyond the EOF, or straddles the EOF20932093+ * and the write will cover all of the existing data.20942094+ */20952095+ if (CIFS_I(mapping->host)->clientCanCacheRead) {20962096+ i_size = i_size_read(mapping->host);20972097+ if (page_start >= i_size ||20982098+ (offset == 0 && (pos + len) >= i_size)) {20992099+ zero_user_segments(page, 0, offset,21002100+ offset + len,21012101+ PAGE_CACHE_SIZE);21022102+ /*21032103+ * PageChecked means that the parts of the page21042104+ * to which we're not writing are considered up21052105+ * to date. Once the data is copied to the21062106+ * page, it can be set uptodate.21072107+ */21082108+ SetPageChecked(page);21092109+ goto out;21102110+ }21112111+ }2083211220842113 if ((file->f_flags & O_ACCMODE) != O_WRONLY) {20852085- int rc;20862086-20872087- /* might as well read a page, it is fast enough */20882088- rc = cifs_readpage_worker(file, *pagep, &offset);20892089-20902090- /* we do not need to pass errors back20912091- e.g. if we do not have read access to the file20922092- because cifs_write_end will attempt synchronous writes20932093- -- shaggy */21142114+ /*21152115+ * might as well read a page, it is fast enough. If we get21162116+ * an error, we don't need to return it. cifs_write_end will21172117+ * do a sync write instead since PG_uptodate isn't set.21182118+ */21192119+ cifs_readpage_worker(file, page, &page_start);20942120 } else {20952121 /* we could try using another file handle if there is one -20962122 but how would we lock it to prevent close of that handle20972123 racing with this read? In any case20982124 this will be written out by write_end so is fine */20992125 }21002100-21012101- return 0;21262126+out:21272127+ *pagep = page;21282128+ return rc;21022129}2103213021042131const struct address_space_operations cifs_addr_ops = {