···1475 cFYI(1, ("write_end for page %p from pos %lld with %d bytes",1476 page, pos, copied));14771478- if (!PageUptodate(page) && copied == PAGE_CACHE_SIZE)00001479 SetPageUptodate(page);14801481 if (!PageUptodate(page)) {···2066{2067 pgoff_t index = pos >> PAGE_CACHE_SHIFT;2068 loff_t offset = pos & (PAGE_CACHE_SIZE - 1);000020692070 cFYI(1, ("write_begin from %lld len %d", (long long)pos, len));20712072- *pagep = __grab_cache_page(mapping, index);2073- if (!*pagep)2074- return -ENOMEM;0020752076- if (PageUptodate(*pagep))2077- return 0;20782079- /* If we are writing a full page it will be up to date,2080- no need to read from the server */2081- if (len == PAGE_CACHE_SIZE && flags & AOP_FLAG_UNINTERRUPTIBLE)2082- return 0;00000000000000000000000000020832084 if ((file->f_flags & O_ACCMODE) != O_WRONLY) {2085- int rc;2086-2087- /* might as well read a page, it is fast enough */2088- rc = cifs_readpage_worker(file, *pagep, &offset);2089-2090- /* we do not need to pass errors back2091- e.g. if we do not have read access to the file2092- because cifs_write_end will attempt synchronous writes2093- -- shaggy */2094 } else {2095 /* we could try using another file handle if there is one -2096 but how would we lock it to prevent close of that handle2097 racing with this read? In any case2098 this will be written out by write_end so is fine */2099 }2100-2101- return 0;02102}21032104const struct address_space_operations cifs_addr_ops = {
···1475 cFYI(1, ("write_end for page %p from pos %lld with %d bytes",1476 page, pos, copied));14771478+ if (PageChecked(page)) {1479+ if (copied == len)1480+ SetPageUptodate(page);1481+ ClearPageChecked(page);1482+ } else if (!PageUptodate(page) && copied == PAGE_CACHE_SIZE)1483 SetPageUptodate(page);14841485 if (!PageUptodate(page)) {···2062{2063 pgoff_t index = pos >> PAGE_CACHE_SHIFT;2064 loff_t offset = pos & (PAGE_CACHE_SIZE - 1);2065+ loff_t page_start = pos & PAGE_MASK;2066+ loff_t i_size;2067+ struct page *page;2068+ int rc = 0;20692070 cFYI(1, ("write_begin from %lld len %d", (long long)pos, len));20712072+ page = __grab_cache_page(mapping, index);2073+ if (!page) {2074+ rc = -ENOMEM;2075+ goto out;2076+ }20772078+ if (PageUptodate(page))2079+ goto out;20802081+ /*2082+ * If we write a full page it will be up to date, no need to read from2083+ * the server. If the write is short, we'll end up doing a sync write2084+ * instead.2085+ */2086+ if (len == PAGE_CACHE_SIZE)2087+ goto out;2088+2089+ /*2090+ * optimize away the read when we have an oplock, and we're not2091+ * expecting to use any of the data we'd be reading in. That2092+ * is, when the page lies beyond the EOF, or straddles the EOF2093+ * and the write will cover all of the existing data.2094+ */2095+ if (CIFS_I(mapping->host)->clientCanCacheRead) {2096+ i_size = i_size_read(mapping->host);2097+ if (page_start >= i_size ||2098+ (offset == 0 && (pos + len) >= i_size)) {2099+ zero_user_segments(page, 0, offset,2100+ offset + len,2101+ PAGE_CACHE_SIZE);2102+ /*2103+ * PageChecked means that the parts of the page2104+ * to which we're not writing are considered up2105+ * to date. Once the data is copied to the2106+ * page, it can be set uptodate.2107+ */2108+ SetPageChecked(page);2109+ goto out;2110+ }2111+ }21122113 if ((file->f_flags & O_ACCMODE) != O_WRONLY) {2114+ /*2115+ * might as well read a page, it is fast enough. If we get2116+ * an error, we don't need to return it. cifs_write_end will2117+ * do a sync write instead since PG_uptodate isn't set.2118+ */2119+ cifs_readpage_worker(file, page, &page_start);0002120 } else {2121 /* we could try using another file handle if there is one -2122 but how would we lock it to prevent close of that handle2123 racing with this read? In any case2124 this will be written out by write_end so is fine */2125 }2126+out:2127+ *pagep = page;2128+ return rc;2129}21302131const struct address_space_operations cifs_addr_ops = {