]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: During fscrypt write skip unneeded reads
authorChristopher Hoffman <choffman@redhat.com>
Tue, 12 Aug 2025 13:14:57 +0000 (13:14 +0000)
committerChristopher Hoffman <choffman@redhat.com>
Wed, 5 Nov 2025 13:59:36 +0000 (13:59 +0000)
During an fscrypt write a read may be needed to ensure changed
portion of file is merged with an existing data block. No need
to read unnecessarily when writes line up to fscrypt block and
span a whole block or more.

Signed-off-by: Christopher Hoffman <choffman@redhat.com>
src/client/Client.cc

index b7f68033e9c725fbb37b3a88f25674e561ee711e..c75e097cd7e95b7b6cd9b9f05d0de15b34b3cf52 100644 (file)
@@ -12296,14 +12296,14 @@ int Client::WriteEncMgr::read_modify_write(Context *_iofinish)
   end_block_ofs = fscrypt_block_start(endoff - 1);
   ofs_in_end_block = fscrypt_ofs_in_block(endoff - 1);
 
-  need_read_start = ofs_in_start_block >= 0;
+  need_read_start = ofs_in_start_block > 0 || (ofs_in_start_block == 0 && ((endoff - offset) < FSCRYPT_BLOCK_SIZE));
   need_read_end = (endoff <= in->effective_size() && ofs_in_end_block < FSCRYPT_BLOCK_SIZE && start_block != end_block);
   read_start_size = FSCRYPT_BLOCK_SIZE;
 
   bool need_read = need_read_start | need_read_end;
 
 
-  if (read_start_size > 0) {
+  if (need_read_start) {
     finish_read_start_ctx.reset(new iofinish_method_ctx<WriteEncMgr>(*this, &WriteEncMgr::finish_read_start_cb, &aioc));
 
     r = read(start_block_ofs, read_start_size, &startbl, finish_read_start_ctx.get());