Skip to contentSkip to conversation

libceph: sparse-read misc fixes

PATCH Superseded [email protected] 2 participants 13 messages Oct 24, 2023 – Nov 1, 2023 Ceph common code (libceph)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover libceph: sparse-read misc fixes

From: Xiubo Li <[email protected]>

One bug fix and one improvment for the sparse-read.

Xiubo Li (3):
libceph: do not decrease the data length more than once
libceph: save and covert sr_datalen to host-endian
libceph: check the data length when finishes

 include/linux/ceph/osd_client.h |  3 ++-
 net/ceph/messenger_v2.c         |  1 -
 net/ceph/osd_client.c           | 16 +++++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH 1/3 libceph: do not decrease the data length more than once

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/messenger_v2.c | 1 -
 1 file changed, 1 deletion(-)
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
 				bv.bv_offset = 0;
 			}
 			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
 			return 0;
 		}
 	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 16 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/messenger_v2.c | 1 -
 1 file changed, 1 deletion(-)
net/ceph/messenger_v2.c +0 -0
index d09a39ff2cf0..9e3f95d5e425 100644

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 7 lines
net/ceph/messenger_v2.c +0 -1
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
 				bv.bv_offset = 0;
 			}
 			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
 			return 0;
 		}
 	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#3 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 12 lines · Jeff Layton
Quoted 11 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/messenger_v2.c | 1 -
 1 file changed, 1 deletion(-)
Quoted 16 lines

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 12 lines
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
 				bv.bv_offset = 0;
 			}
 			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
 			return 0;
 		}
 	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

My question was a bit vague, so let me elaborate a bit:

data_len_remain should be how much unconsumed data is in the message (IIRC). As we call prepare_sparse_read_cont multiple times, we're consuming the message data and this gets decremented as we go.

In the above case, we're consuming the message data into the bvec, so why shouldn't we be decrementing the remaining data by that amount?

Signature · 1 line
Jeff Layton <[email protected]>
author
#4 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 28 lines · Jeff Layton
Quoted 12 lines · Jeff Layton
Quoted 11 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
  net/ceph/messenger_v2.c | 1 -
  1 file changed, 1 deletion(-)
Quoted 15 lines

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 12 lines
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
  				bv.bv_offset = 0;
  			}
  			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
  			return 0;
  		}
  	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

Quoted 8 lines

My question was a bit vague, so let me elaborate a bit:

data_len_remain should be how much unconsumed data is in the message (IIRC). As we call prepare_sparse_read_cont multiple times, we're consuming the message data and this gets decremented as we go.

In the above case, we're consuming the message data into the bvec, so why shouldn't we be decrementing the remaining data by that amount?

Hi Jeff,

If I didn't miss something about this. IMO we have already decreased it in the following two cases:

[1] https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2000

[2] https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2025

And here won't we decrease them twice ?

Thanks

- Xiubo

#5 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 43 lines · Xiubo Li
Quoted 28 lines · Jeff Layton
Quoted 12 lines · Jeff Layton
Quoted 11 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
  net/ceph/messenger_v2.c | 1 -
  1 file changed, 1 deletion(-)
Quoted 15 lines

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 12 lines
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
  				bv.bv_offset = 0;
  			}
  			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
  			return 0;
  		}
  	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

Quoted 8 lines

My question was a bit vague, so let me elaborate a bit:

data_len_remain should be how much unconsumed data is in the message (IIRC). As we call prepare_sparse_read_cont multiple times, we're consuming the message data and this gets decremented as we go.

In the above case, we're consuming the message data into the bvec, so why shouldn't we be decrementing the remaining data by that amount?

Hi Jeff,

If I didn't miss something about this. IMO we have already decreased it in the following two cases:

Quoted 9 lines

[1]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2000

[2]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2025

And here won't we decrease them twice ?

I don't get it. The functions returns in both of those cases just after decrementing data_len_remain, so how can it have already decremented it?

Maybe I don't understand the bug you're trying to fix. data_len_remain only comes into play when we need to revert. Does the problem involve a trip through revoke_at_prepare_sparse_data()?

Signature · 1 line
Jeff Layton <[email protected]>
author
#6 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 52 lines · Jeff Layton
Quoted 42 lines · Xiubo Li
Quoted 28 lines · Jeff Layton
Quoted 12 lines · Jeff Layton
Quoted 11 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
   net/ceph/messenger_v2.c | 1 -
   1 file changed, 1 deletion(-)
Quoted 15 lines

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 12 lines
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
   				bv.bv_offset = 0;
   			}
   			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
   			return 0;
   		}
   	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

Quoted 8 lines

My question was a bit vague, so let me elaborate a bit:

data_len_remain should be how much unconsumed data is in the message (IIRC). As we call prepare_sparse_read_cont multiple times, we're consuming the message data and this gets decremented as we go.

In the above case, we're consuming the message data into the bvec, so why shouldn't we be decrementing the remaining data by that amount?

Hi Jeff,

If I didn't miss something about this. IMO we have already decreased it in the following two cases:

Quoted 9 lines

[1]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2000

[2]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2025

And here won't we decrease them twice ?

Quoted 6 lines

I don't get it. The functions returns in both of those cases just after decrementing data_len_remain, so how can it have already decremented it?

Maybe I don't understand the bug you're trying to fix. data_len_remain only comes into play when we need to revert. Does the problem involve a trip through revoke_at_prepare_sparse_data()?

Such as for the first time to read the data it will trigger:

prepare_sparse_read_cont()

  --> ret = con->ops->sparse_read()

       --> cursor->sr_resid = elen;

  --> if (buf) {con->v2.data_len_remain -= ret;}   // After calling ->sparse_read() it will decrease 'ret', which is 'elen'.

Then the msg will try to read data from the socket buffer, and if the data read is less than expected 'elen' then it will go to the code:

https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L1960-L1971

And then won't it decrease 'data_len_remain' twice ?

Did I misreading it the sparse read state machine ?

Thanks

- Xiubo

#7 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 73 lines · Xiubo Li
Quoted 52 lines · Jeff Layton
Quoted 42 lines · Xiubo Li
Quoted 28 lines · Jeff Layton
Quoted 12 lines · Jeff Layton
Quoted 11 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
   net/ceph/messenger_v2.c | 1 -
   1 file changed, 1 deletion(-)
Quoted 15 lines

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 12 lines
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
   				bv.bv_offset = 0;
   			}
   			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
   			return 0;
   		}
   	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

Quoted 8 lines

My question was a bit vague, so let me elaborate a bit:

data_len_remain should be how much unconsumed data is in the message (IIRC). As we call prepare_sparse_read_cont multiple times, we're consuming the message data and this gets decremented as we go.

In the above case, we're consuming the message data into the bvec, so why shouldn't we be decrementing the remaining data by that amount?

Hi Jeff,

If I didn't miss something about this. IMO we have already decreased it in the following two cases:

Quoted 9 lines

[1]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2000

[2]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2025

And here won't we decrease them twice ?

Quoted 6 lines

I don't get it. The functions returns in both of those cases just after decrementing data_len_remain, so how can it have already decremented it?

Maybe I don't understand the bug you're trying to fix. data_len_remain only comes into play when we need to revert. Does the problem involve a trip through revoke_at_prepare_sparse_data()?

Such as for the first time to read the data it will trigger:

prepare_sparse_read_cont()

  --> ret = con->ops->sparse_read()

       --> cursor->sr_resid = elen;

  --> if (buf) {con->v2.data_len_remain -= ret;}   // After calling
->sparse_read() it will decrease 'ret', which is 'elen'.

Quoted 9 lines

Then the msg will try to read data from the socket buffer, and if the data read is less than expected 'elen' then it will go to the code:

https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L1960-L1971

And then won't it decrease 'data_len_remain' twice ?

Did I misreading it the sparse read state machine ?

Here's the full snippet of code around that area. In this code, we've just received the data from "in" iter into the current bvec and have either copied it from the bounce buffer or done the CRC for the last bvec. Now, we're advancing the iter by the amount we've just read, and reducing the sr_resid value (which is the residual data in the current extent):

                ceph_msg_data_advance(cursor, con->v2.in_bvec.bv_len);
                cursor->sr_resid -= con->v2.in_bvec.bv_len;
                dout("%s: advance by 0x%x sr_resid 0x%x\n", __func__,
                     con->v2.in_bvec.bv_len, cursor->sr_resid);
                WARN_ON_ONCE(cursor->sr_resid > cursor->total_resid);
                if (cursor->sr_resid) {

There's still some more data in this extent? Set up the next bvec for the next receive:

                        get_bvec_at(cursor, &bv);
                        if (bv.bv_len > cursor->sr_resid)
                                bv.bv_len = cursor->sr_resid;
                        if (ceph_test_opt(from_msgr(con->msgr), RXBOUNCE)) {
                                bv.bv_page = con->bounce_page;
                                bv.bv_offset = 0;
                        }
                        set_in_bvec(con, &bv);
                        con->v2.data_len_remain -= bv.bv_len;

...and reduce the data_len_remain for the amount of that next bvec.

                        return 0;
                }

So yeah, I think this is not being decremented twice. The code is dealing with a different bvec at the point where data_len_remain is reduced above and it looks correct to me.

What problem are you trying to solve with this patch?

Signature · 1 line
Jeff Layton <[email protected]>
author
#8 lore raw

Re: [PATCH 1/3] libceph: do not decrease the data length more than once

Quoted 108 lines · Jeff Layton
Quoted 70 lines · Xiubo Li
Quoted 52 lines · Jeff Layton
Quoted 42 lines · Xiubo Li
Quoted 28 lines · Jeff Layton
Quoted 12 lines · Jeff Layton
Quoted 11 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

No need to decrease the data length again if we need to read the left data.

URL: https://tracker.ceph.com/issues/62081

---
    net/ceph/messenger_v2.c | 1 -
    1 file changed, 1 deletion(-)
Quoted 15 lines

net/ceph/messenger_v2.c static int prepare_sparse_read_cont(struct ceph_connection *con) · line 1971

Quoted 12 lines
net/ceph/messenger_v2.c +0 -1
index d09a39ff2cf0..9e3f95d5e425 100644
@@ -1966,7 +1966,6 @@ static int prepare_sparse_read_cont(struct ceph_connection *con)
    				bv.bv_offset = 0;
    			}
    			set_in_bvec(con, &bv);
-			con->v2.data_len_remain -= bv.bv_len;
    			return 0;
    		}
    	} else if (iov_iter_is_kvec(&con->v2.in_iter)) {

It's been a while since I was in this code, but where does this get decremented if you're removing it here?

Quoted 8 lines

My question was a bit vague, so let me elaborate a bit:

data_len_remain should be how much unconsumed data is in the message (IIRC). As we call prepare_sparse_read_cont multiple times, we're consuming the message data and this gets decremented as we go.

In the above case, we're consuming the message data into the bvec, so why shouldn't we be decrementing the remaining data by that amount?

Hi Jeff,

If I didn't miss something about this. IMO we have already decreased it in the following two cases:

Quoted 9 lines

[1]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2000

[2]
https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L2025

And here won't we decrease them twice ?

Quoted 6 lines

I don't get it. The functions returns in both of those cases just after decrementing data_len_remain, so how can it have already decremented it?

Maybe I don't understand the bug you're trying to fix. data_len_remain only comes into play when we need to revert. Does the problem involve a trip through revoke_at_prepare_sparse_data()?

Such as for the first time to read the data it will trigger:

prepare_sparse_read_cont()

    --> ret = con->ops->sparse_read()
         --> cursor->sr_resid = elen;

  --> if (buf) {con->v2.data_len_remain -= ret;}   // After calling
->sparse_read() it will decrease 'ret', which is 'elen'.

Quoted 9 lines

Then the msg will try to read data from the socket buffer, and if the data read is less than expected 'elen' then it will go to the code:

https://github.com/ceph/ceph-client/blob/for-linus/net/ceph/messenger_v2.c#L1960-L1971

And then won't it decrease 'data_len_remain' twice ?

Did I misreading it the sparse read state machine ?

Here's the full snippet of code around that area. In this code, we've just received the data from "in" iter into the current bvec and have either copied it from the bounce buffer or done the CRC for the last bvec. Now, we're advancing the iter by the amount we've just read, and reducing the sr_resid value (which is the residual data in the current extent):

                 ceph_msg_data_advance(cursor, con->v2.in_bvec.bv_len);
                 cursor->sr_resid -= con->v2.in_bvec.bv_len;
                 dout("%s: advance by 0x%x sr_resid 0x%x\n", __func__,
                      con->v2.in_bvec.bv_len, cursor->sr_resid);
                 WARN_ON_ONCE(cursor->sr_resid > cursor->total_resid);
                 if (cursor->sr_resid) {

There's still some more data in this extent? Set up the next bvec for the next receive:

                         get_bvec_at(cursor, &bv);
                         if (bv.bv_len > cursor->sr_resid)
                                 bv.bv_len = cursor->sr_resid;
                         if (ceph_test_opt(from_msgr(con->msgr), RXBOUNCE)) {
                                 bv.bv_page = con->bounce_page;
                                 bv.bv_offset = 0;
                         }
                         set_in_bvec(con, &bv);
                         con->v2.data_len_remain -= bv.bv_len;
Quoted 8 lines

...and reduce the data_len_remain for the amount of that next bvec.

                         return 0;
                 }

So yeah, I think this is not being decremented twice. The code is dealing with a different bvec at the point where data_len_remain is reduced above and it looks correct to me.

Okay, I think I misreading the sparse-read state machine.

Quoted 1 line

What problem are you trying to solve with this patch?

Currently no any issue from this. I just added many debug logs to reproduce and debug the issue https://tracker.ceph.com/issues/62081, and found odd logs. Such as the improvment for the other two patches:

 90279 <6>[ 5483.137183] libceph: osd_sparse_read:5923 ---> sr->sr_datalen: 251723776, sr->sr_index: 0, count: 0

The sr_datalen is not zero when the extents array is empty.

The following is a normal log, and the extent array size is 1.

 90275 <6>[ 5477.553113] libceph: osd_sparse_read:5919 ---> sr->sr_datalen: 16384, sr->sr_index: 0, count: 1

For this patch I just found it when going through the code. I will remove it for next version.

Thanks Jeff for your reviewing.

- Xiubo

#9 lore raw

PATCH 2/3 libceph: save and covert sr_datalen to host-endian

In reply to [email protected]

From: Xiubo Li <[email protected]>

We need to save the real data length to determine exactly how many data we can parse later.

URL: https://tracker.ceph.com/issues/62081

---
 include/linux/ceph/osd_client.h | 3 ++-
 net/ceph/osd_client.c           | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/ceph/osd_client.h +2 -1
index bf9823956758..f703fb8030de 100644
@@ -45,6 +45,7 @@ enum ceph_sparse_read_state {
 	CEPH_SPARSE_READ_HDR	= 0,
 	CEPH_SPARSE_READ_EXTENTS,
 	CEPH_SPARSE_READ_DATA_LEN,
+	CEPH_SPARSE_READ_DATA_PRE,
 	CEPH_SPARSE_READ_DATA,
 };
 
@@ -64,7 +65,7 @@ struct ceph_sparse_read {
 	u64				sr_req_len;  /* orig request length */
 	u64				sr_pos;      /* current pos in buffer */
 	int				sr_index;    /* current extent index */
-	__le32				sr_datalen;  /* length of actual data */
+	u32				sr_datalen;  /* length of actual data */
 	u32				sr_count;    /* extent count in reply */
 	int				sr_ext_len;  /* length of extent array */
 	struct ceph_sparse_extent	*sr_extent;  /* extent array */
net/ceph/osd_client.c +6 -1
index d3a759e052c8..800a2acec069 100644
@@ -5912,8 +5912,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		convert_extent_map(sr);
 		ret = sizeof(sr->sr_datalen);
 		*pbuf = (char *)&sr->sr_datalen;
-		sr->sr_state = CEPH_SPARSE_READ_DATA;
+		sr->sr_state = CEPH_SPARSE_READ_DATA_PRE;
 		break;
+	case CEPH_SPARSE_READ_DATA_PRE:
+		/* Convert sr_datalen to host-endian */
+		sr->sr_datalen = le32_to_cpu((__force __le32)sr->sr_datalen);
+		sr->sr_state = CEPH_SPARSE_READ_DATA;
+		fallthrough;
 	case CEPH_SPARSE_READ_DATA:
 		if (sr->sr_index >= count) {
 			sr->sr_state = CEPH_SPARSE_READ_HDR;
Signature · 1 line
2.39.1
Reviewed-by on v1 2/3
#10 lore raw

Re: [PATCH 2/3] libceph: save and covert sr_datalen to host-endian

Quoted 42 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

We need to save the real data length to determine exactly how many data we can parse later.

URL: https://tracker.ceph.com/issues/62081

---
 include/linux/ceph/osd_client.h | 3 ++-
 net/ceph/osd_client.c           | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
include/linux/ceph/osd_client.h +2 -1
index bf9823956758..f703fb8030de 100644
@@ -45,6 +45,7 @@ enum ceph_sparse_read_state {
 	CEPH_SPARSE_READ_HDR	= 0,
 	CEPH_SPARSE_READ_EXTENTS,
 	CEPH_SPARSE_READ_DATA_LEN,
+	CEPH_SPARSE_READ_DATA_PRE,
 	CEPH_SPARSE_READ_DATA,
 };
 
@@ -64,7 +65,7 @@ struct ceph_sparse_read {
 	u64				sr_req_len;  /* orig request length */
 	u64				sr_pos;      /* current pos in buffer */
 	int				sr_index;    /* current extent index */
-	__le32				sr_datalen;  /* length of actual data */
+	u32				sr_datalen;  /* length of actual data */
 	u32				sr_count;    /* extent count in reply */
 	int				sr_ext_len;  /* length of extent array */
 	struct ceph_sparse_extent	*sr_extent;  /* extent array */
net/ceph/osd_client.c +0 -1
index d3a759e052c8..800a2acec069 100644
@@ -5912,8 +5912,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		convert_extent_map(sr);
 		ret = sizeof(sr->sr_datalen);
 		*pbuf = (char *)&sr->sr_datalen;
-		sr->sr_state = CEPH_SPARSE_READ_DATA;

net/ceph/osd_client.c static int osd_sparse_read(struct ceph_connection *con, · line 5924

Quoted 10 lines
net/ceph/osd_client.c +6 -0
+		sr->sr_state = CEPH_SPARSE_READ_DATA_PRE;
 		break;
+	case CEPH_SPARSE_READ_DATA_PRE:
+		/* Convert sr_datalen to host-endian */
+		sr->sr_datalen = le32_to_cpu((__force __le32)sr->sr_datalen);
+		sr->sr_state = CEPH_SPARSE_READ_DATA;
+		fallthrough;
 	case CEPH_SPARSE_READ_DATA:
 		if (sr->sr_index >= count) {
 			sr->sr_state = CEPH_SPARSE_READ_HDR;
#11 lore raw

PATCH 3/3 libceph: check the data length when finishes

In reply to [email protected]

From: Xiubo Li <[email protected]>

For sparse reading the real length of the data should equal to the total length from the extent array.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/osd_client.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/ceph/osd_client.c +9 -0
index 800a2acec069..7af35106acaf 100644
@@ -5921,6 +5921,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		fallthrough;
 	case CEPH_SPARSE_READ_DATA:
 		if (sr->sr_index >= count) {
+			if (sr->sr_datalen && count) {
+				pr_warn_ratelimited("sr_datalen %d sr_index %d count %d\n",
+						    sr->sr_datalen, sr->sr_index,
+						    count);
+				WARN_ON_ONCE(sr->sr_datalen);
+			}
+
 			sr->sr_state = CEPH_SPARSE_READ_HDR;
 			goto next_op;
 		}
@@ -5928,6 +5935,8 @@ static int osd_sparse_read(struct ceph_connection *con,
 		eoff = sr->sr_extent[sr->sr_index].off;
 		elen = sr->sr_extent[sr->sr_index].len;
 
+		sr->sr_datalen -= elen;
+
 		dout("[%d] ext %d off 0x%llx len 0x%llx\n",
 		     o->o_osd, sr->sr_index, eoff, elen);
 
Signature · 1 line
2.39.1
Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] libceph: check the data length when finishes

Quoted 30 lines · On Tue, 2023-10-24 at 13:00 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

For sparse reading the real length of the data should equal to the total length from the extent array.

URL: https://tracker.ceph.com/issues/62081

---
 net/ceph/osd_client.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/ceph/osd_client.c +7 -0
index 800a2acec069..7af35106acaf 100644
@@ -5921,6 +5921,13 @@ static int osd_sparse_read(struct ceph_connection *con,
 		fallthrough;
 	case CEPH_SPARSE_READ_DATA:
 		if (sr->sr_index >= count) {
+			if (sr->sr_datalen && count) {
+				pr_warn_ratelimited("sr_datalen %d sr_index %d count %d\n",
+						    sr->sr_datalen, sr->sr_index,
+						    count);
+				WARN_ON_ONCE(sr->sr_datalen);
+			}
+
 			sr->sr_state = CEPH_SPARSE_READ_HDR;
 			goto next_op;
 		}

net/ceph/osd_client.c static int osd_sparse_read(struct ceph_connection *con, · line 5942

Quoted 8 lines
net/ceph/osd_client.c +2 -0
@@ -5928,6 +5935,8 @@ static int osd_sparse_read(struct ceph_connection *con,
 		eoff = sr->sr_extent[sr->sr_index].off;
 		elen = sr->sr_extent[sr->sr_index].len;
 
+		sr->sr_datalen -= elen;
+
 		dout("[%d] ext %d off 0x%llx len 0x%llx\n",
 		     o->o_osd, sr->sr_index, eoff, elen);
 

Seems like a reasonable sanity check.