Whamcloud - gitweb
EX-7601 ofd: same-ify preprw_read and preprw_write
authorPatrick Farrell <pfarrell@whamcloud.com>
Tue, 12 Dec 2023 17:07:35 +0000 (12:07 -0500)
committerAndreas Dilger <adilger@whamcloud.com>
Sat, 6 Jan 2024 08:18:41 +0000 (08:18 +0000)
preprw_read and preprw_write have some sections which are
functionally the same but which have diverged slightly.
(These can't easily be shared between the functions.)

This is a short patch to make them more similar before
adding eof checking to reads.

Test-Parameters: trivial
Signed-off-by: Patrick Farrell <pfarrell@whamcloud.com>
Change-Id: I7bce912e99e61a4eec4060d6b49d4917894b44c4
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/53426
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Artem Blagodarenko <ablagodarenko@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/ofd/ofd_io.c

index afed3b5..3dd4912 100644 (file)
@@ -589,12 +589,16 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
                           struct niobuf_local *lnb, int chunk_size)
 {
        struct ofd_object *fo;
-       int i, j, rc, tot_bytes = 0;
        enum dt_bufs_type dbt = DT_BUFS_TYPE_READ;
-       bool chunk_rounded = false;
+       bool compr_unaligned_read = false;
        int maxlnb = *nr_local;
-       __u64 begin, end;
        __u64 prev_buf_end = 0;
+       int tot_bytes = 0;
+       __u64 begin;
+       __u64 end;
+       int rc;
+       int i;
+       int j;
 
        ENTRY;
        LASSERT(env != NULL);
@@ -628,9 +632,9 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
        end = 0;
 
        for (*nr_local = 0, i = 0, j = 0; i < niocount; i++) {
-               __u64 orig_buf_start;
-               __u64 orig_buf_end;
+               __u64 orig_start;
                __u64 buf_start;
+               __u64 orig_end;
                __u64 buf_end;
                int buf_len;
 
@@ -643,8 +647,8 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
 
                buf_start = rnb[i].rnb_offset;
                buf_end = rnb[i].rnb_offset + rnb[i].rnb_len;
-               orig_buf_start = buf_start;
-               orig_buf_end = buf_end;
+               orig_start = buf_start;
+               orig_end = buf_end;
 
                CDEBUG(D_SEC, "rnb %d buf_start %llu, buf_end %llu\n",
                       i, buf_start, buf_end);
@@ -652,12 +656,6 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
                /* compressed reads must be rounded to cover whole chunks */
                if (chunk_size) {
                        chunk_round(&buf_start, &buf_end, chunk_size);
-                       /* if we rounded the chunk, then we're going to do
-                        * decompression and dt_read_prep needs to know this
-                        */
-                       if (buf_start != orig_buf_start ||
-                           buf_end != orig_buf_end)
-                               chunk_rounded = true;
 
                        /* rounded rnbs can overlap at the chunk level, but it's
                         * important we don't allocate multiple buffers for the
@@ -666,8 +664,9 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
                         */
                        if (buf_start < prev_buf_end) {
                                CDEBUG(D_SEC,
-                                      "overlaps previous rounded read, start %llu < prev end %llu\n",
-                                      buf_start, prev_buf_end);
+                                      "overlaps previous rounded IO, start %llu < prev end %llu (end %llu, orig start %llu, orig end %llu\n",
+                                      buf_start, prev_buf_end, buf_end,
+                                      orig_start, orig_end);
                                buf_start = prev_buf_end;
                                /* two rnbs may be entirely inside the same
                                 * chunk, in which case we're already doing IO
@@ -675,12 +674,19 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
                                 */
                                if (buf_start == buf_end) {
                                        CDEBUG(D_SEC,
-                                              "read inside previous rounded read, skipping\n");
+                                              "IO inside previous compression chunk, skipping\n");
                                        prev_buf_end = buf_end;
                                        continue;
                                }
                        }
                        prev_buf_end = buf_end;
+
+                       /* if we rounded the chunk, then we're going to do
+                        * decompression and dt_read_prep needs to know this
+                        */
+                       if (buf_start != orig_start ||
+                           buf_end != orig_end)
+                               compr_unaligned_read = true;
                }
 
                buf_len = buf_end - buf_start;
@@ -700,7 +706,7 @@ static int ofd_preprw_read(const struct lu_env *env, struct obd_export *exp,
 
        LASSERT(*nr_local > 0 && *nr_local <= PTLRPC_MAX_BRW_PAGES);
        rc = dt_read_prep(env, ofd_object_child(fo), lnb, *nr_local,
-                         chunk_rounded);
+                         compr_unaligned_read);
        if (unlikely(rc))
                GOTO(buf_put, rc);
        ofd_read_unlock(env, fo);
@@ -908,11 +914,16 @@ static int ofd_preprw_write(const struct lu_env *env, struct obd_export *exp,
                    && (eof_rnb == INT_MAX)) {
                        chunk_round(&buf_start, &buf_end, chunk_size);
 
+                       /* rounded rnbs can overlap at the chunk level, but it's
+                        * important we don't allocate multiple buffers for the
+                        * same page, so move the start of this buffer to the
+                        * end of the previous one
+                        */
                        if (buf_start < prev_buf_end) {
                                CDEBUG(D_SEC,
-                                      "buf_start %llu orig_start %llu buf_end %llu orig_end %llu\n",
-                                      buf_start, orig_start, buf_end,
-                                      orig_end);
+                                      "overlaps previous rounded IO, start %llu < prev end %llu (end %llu, orig start %llu, orig end %llu\n",
+                                      buf_start, prev_buf_end, buf_end,
+                                      orig_start, orig_end);
                                start_rounded_up = true;
                                buf_start = prev_buf_end;
                                /* two rnbs may be entirely inside the same
@@ -920,8 +931,11 @@ static int ofd_preprw_write(const struct lu_env *env, struct obd_export *exp,
                                 * for that chunk, so skip it
                                 */
                                prev_buf_end = buf_end;
-                               if (buf_start == buf_end)
+                               if (buf_start == buf_end) {
+                                       CDEBUG(D_SEC,
+                                              "IO inside previous compression chunk, skipping\n");
                                        continue;
+                               }
                        }
                        CDEBUG(D_SEC,
                               "buf_start %llu orig_start %llu buf_end %llu orig_end %llu\n",