* [PATCH -next 0/3] cifs: Use some helper function for preamble size
@ 2022-08-23 12:51 Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 1/3] cifs: Use help macro to get the header " Zhang Xiaoxu
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 12:51 UTC (permalink / raw)
To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad, rohiths,
smfrench
*** BLURB HERE ***
The unfolded expression of header_preamble_size is too long, in addition,
some expressions have specific semantics, e.g.:
calculate the position of the mid,
confirm it's smb2+ server or not.
Zhang Xiaoxu (3):
cifs: Use help macro to get the header preamble size
cifs: Use help macro to get the mid header size
cifs: Add helper function to check smb2+ server
fs/cifs/cifsencrypt.c | 3 +--
fs/cifs/cifsglob.h | 7 +++++++
fs/cifs/connect.c | 28 +++++++++++-----------------
fs/cifs/transport.c | 21 ++++++++++-----------
4 files changed, 29 insertions(+), 30 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH -next 1/3] cifs: Use help macro to get the header preamble size
2022-08-23 12:51 [PATCH -next 0/3] cifs: Use some helper function for preamble size Zhang Xiaoxu
@ 2022-08-23 12:52 ` Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 2/3] cifs: Use help macro to get the mid header size Zhang Xiaoxu
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 12:52 UTC (permalink / raw)
To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad, rohiths,
smfrench
It's better to use HEADER_PREAMBLE_SIZE because the unfolded expression
too long. No actual functional changes, minor readability improvement.
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
fs/cifs/cifsencrypt.c | 2 +-
fs/cifs/cifsglob.h | 1 +
fs/cifs/connect.c | 20 ++++++++++----------
fs/cifs/transport.c | 21 ++++++++++-----------
4 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 8f7835ccbca1..61a9fed56548 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -32,7 +32,7 @@ int __cifs_calc_signature(struct smb_rqst *rqst,
int rc;
struct kvec *iov = rqst->rq_iov;
int n_vec = rqst->rq_nvec;
- int is_smb2 = server->vals->header_preamble_size == 0;
+ bool is_smb2 = HEADER_PREAMBLE_SIZE(server) == 0;
/* iov[0] is actual data and not the rfc1002 length for SMB2+ */
if (is_smb2) {
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 187b32158da8..0057228b47cc 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -556,6 +556,7 @@ struct smb_version_values {
#define HEADER_SIZE(server) (server->vals->header_size)
#define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
+#define HEADER_PREAMBLE_SIZE(server) (server->vals->header_preamble_size)
/**
* CIFS superblock mount flags (mnt_cifs_flags) to consider when
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 9111c025bcb8..8a4ba1e93269 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -871,7 +871,7 @@ smb2_get_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
/*
* SMB1 does not use credits.
*/
- if (server->vals->header_preamble_size)
+ if (HEADER_PREAMBLE_SIZE(server))
return 0;
return le16_to_cpu(shdr->CreditRequest);
@@ -1050,7 +1050,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
/* make sure this will fit in a large buffer */
if (pdu_length > CIFSMaxBufSize + MAX_HEADER_SIZE(server) -
- server->vals->header_preamble_size) {
+ HEADER_PREAMBLE_SIZE(server)) {
cifs_server_dbg(VFS, "SMB response too long (%u bytes)\n", pdu_length);
cifs_reconnect(server, true);
return -ECONNABORTED;
@@ -1065,8 +1065,8 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
/* now read the rest */
length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
- pdu_length - HEADER_SIZE(server) + 1
- + server->vals->header_preamble_size);
+ pdu_length - HEADER_SIZE(server) + 1 +
+ HEADER_PREAMBLE_SIZE(server));
if (length < 0)
return length;
@@ -1122,7 +1122,7 @@ smb2_add_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
/*
* SMB1 does not use credits.
*/
- if (server->vals->header_preamble_size)
+ if (HEADER_PREAMBLE_SIZE(server))
return;
if (shdr->CreditRequest) {
@@ -1180,7 +1180,7 @@ cifs_demultiplex_thread(void *p)
if (length < 0)
continue;
- if (server->vals->header_preamble_size == 0)
+ if (HEADER_PREAMBLE_SIZE(server) == 0)
server->total_read = 0;
else
server->total_read = length;
@@ -1199,7 +1199,7 @@ cifs_demultiplex_thread(void *p)
/* make sure we have enough to get to the MID */
if (server->pdu_size < HEADER_SIZE(server) - 1 -
- server->vals->header_preamble_size) {
+ HEADER_PREAMBLE_SIZE(server)) {
cifs_server_dbg(VFS, "SMB response too short (%u bytes)\n",
server->pdu_size);
cifs_reconnect(server, true);
@@ -1208,9 +1208,9 @@ cifs_demultiplex_thread(void *p)
/* read down to the MID */
length = cifs_read_from_socket(server,
- buf + server->vals->header_preamble_size,
- HEADER_SIZE(server) - 1
- - server->vals->header_preamble_size);
+ buf + HEADER_PREAMBLE_SIZE(server),
+ HEADER_SIZE(server) - 1 -
+ HEADER_PREAMBLE_SIZE(server));
if (length < 0)
continue;
server->total_read += length;
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index de7aeced7e16..bb1052dbac5b 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -261,8 +261,8 @@ smb_rqst_len(struct TCP_Server_Info *server, struct smb_rqst *rqst)
int nvec;
unsigned long buflen = 0;
- if (server->vals->header_preamble_size == 0 &&
- rqst->rq_nvec >= 2 && rqst->rq_iov[0].iov_len == 4) {
+ if (HEADER_PREAMBLE_SIZE(server) == 0 && rqst->rq_nvec >= 2 &&
+ rqst->rq_iov[0].iov_len == 4) {
iov = &rqst->rq_iov[1];
nvec = rqst->rq_nvec - 1;
} else {
@@ -346,7 +346,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
sigprocmask(SIG_BLOCK, &mask, &oldmask);
/* Generate a rfc1002 marker for SMB2+ */
- if (server->vals->header_preamble_size == 0) {
+ if (HEADER_PREAMBLE_SIZE(server) == 0) {
struct kvec hiov = {
.iov_base = &rfc1002_marker,
.iov_len = 4
@@ -1238,7 +1238,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
buf = (char *)midQ[i]->resp_buf;
resp_iov[i].iov_base = buf;
resp_iov[i].iov_len = midQ[i]->resp_buf_size +
- server->vals->header_preamble_size;
+ HEADER_PREAMBLE_SIZE(server);
if (midQ[i]->large_buf)
resp_buf_type[i] = CIFS_LARGE_BUFFER;
@@ -1643,7 +1643,7 @@ int
cifs_discard_remaining_data(struct TCP_Server_Info *server)
{
unsigned int rfclen = server->pdu_size;
- int remaining = rfclen + server->vals->header_preamble_size -
+ int remaining = rfclen + HEADER_PREAMBLE_SIZE(server) -
server->total_read;
while (remaining > 0) {
@@ -1689,8 +1689,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
unsigned int data_offset, data_len;
struct cifs_readdata *rdata = mid->callback_data;
char *buf = server->smallbuf;
- unsigned int buflen = server->pdu_size +
- server->vals->header_preamble_size;
+ unsigned int buflen = server->pdu_size + HEADER_PREAMBLE_SIZE(server);
bool use_rdma_mr = false;
cifs_dbg(FYI, "%s: mid=%llu offset=%llu bytes=%u\n",
@@ -1724,10 +1723,10 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
/* set up first two iov for signature check and to get credits */
rdata->iov[0].iov_base = buf;
- rdata->iov[0].iov_len = server->vals->header_preamble_size;
- rdata->iov[1].iov_base = buf + server->vals->header_preamble_size;
+ rdata->iov[0].iov_len = HEADER_PREAMBLE_SIZE(server);
+ rdata->iov[1].iov_base = buf + HEADER_PREAMBLE_SIZE(server);
rdata->iov[1].iov_len =
- server->total_read - server->vals->header_preamble_size;
+ server->total_read - HEADER_PREAMBLE_SIZE(server);
cifs_dbg(FYI, "0: iov_base=%p iov_len=%zu\n",
rdata->iov[0].iov_base, rdata->iov[0].iov_len);
cifs_dbg(FYI, "1: iov_base=%p iov_len=%zu\n",
@@ -1752,7 +1751,7 @@ cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid)
}
data_offset = server->ops->read_data_offset(buf) +
- server->vals->header_preamble_size;
+ HEADER_PREAMBLE_SIZE(server);
if (data_offset < server->total_read) {
/*
* win2k8 sometimes sends an offset of 0 when the read
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 2/3] cifs: Use help macro to get the mid header size
2022-08-23 12:51 [PATCH -next 0/3] cifs: Use some helper function for preamble size Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 1/3] cifs: Use help macro to get the header " Zhang Xiaoxu
@ 2022-08-23 12:52 ` Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 3/3] cifs: Add helper function to check smb1+ server Zhang Xiaoxu
2022-08-23 17:23 ` [PATCH -next 0/3] cifs: Use some helper function for preamble size Paulo Alcantara
3 siblings, 0 replies; 6+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 12:52 UTC (permalink / raw)
To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad, rohiths,
smfrench
It's better to use MID_HEADER_SIZE because the unfolded expression
too long. No actual functional changes, minor readability improvement.
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
fs/cifs/cifsglob.h | 1 +
fs/cifs/connect.c | 9 +++------
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 0057228b47cc..544f69634063 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -557,6 +557,7 @@ struct smb_version_values {
#define HEADER_SIZE(server) (server->vals->header_size)
#define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
#define HEADER_PREAMBLE_SIZE(server) (server->vals->header_preamble_size)
+#define MID_HEADER_SIZE(server) (HEADER_SIZE(server) - 1 - HEADER_PREAMBLE_SIZE(server))
/**
* CIFS superblock mount flags (mnt_cifs_flags) to consider when
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 8a4ba1e93269..24df04d9b0f3 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1065,8 +1065,7 @@ standard_receive3(struct TCP_Server_Info *server, struct mid_q_entry *mid)
/* now read the rest */
length = cifs_read_from_socket(server, buf + HEADER_SIZE(server) - 1,
- pdu_length - HEADER_SIZE(server) + 1 +
- HEADER_PREAMBLE_SIZE(server));
+ pdu_length - MID_HEADER_SIZE(server));
if (length < 0)
return length;
@@ -1198,8 +1197,7 @@ cifs_demultiplex_thread(void *p)
server->pdu_size = pdu_length;
/* make sure we have enough to get to the MID */
- if (server->pdu_size < HEADER_SIZE(server) - 1 -
- HEADER_PREAMBLE_SIZE(server)) {
+ if (server->pdu_size < MID_HEADER_SIZE(server)) {
cifs_server_dbg(VFS, "SMB response too short (%u bytes)\n",
server->pdu_size);
cifs_reconnect(server, true);
@@ -1209,8 +1207,7 @@ cifs_demultiplex_thread(void *p)
/* read down to the MID */
length = cifs_read_from_socket(server,
buf + HEADER_PREAMBLE_SIZE(server),
- HEADER_SIZE(server) - 1 -
- HEADER_PREAMBLE_SIZE(server));
+ MID_HEADER_SIZE(server));
if (length < 0)
continue;
server->total_read += length;
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 3/3] cifs: Add helper function to check smb1+ server
2022-08-23 12:51 [PATCH -next 0/3] cifs: Use some helper function for preamble size Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 1/3] cifs: Use help macro to get the header " Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 2/3] cifs: Use help macro to get the mid header size Zhang Xiaoxu
@ 2022-08-23 12:52 ` Zhang Xiaoxu
2022-08-23 17:23 ` [PATCH -next 0/3] cifs: Use some helper function for preamble size Paulo Alcantara
3 siblings, 0 replies; 6+ messages in thread
From: Zhang Xiaoxu @ 2022-08-23 12:52 UTC (permalink / raw)
To: linux-cifs, zhangxiaoxu5, sfrench, pc, lsahlber, sprasad, rohiths,
smfrench
SMB1 server's header_preamble_size is not 0, add use is_smb1 function
to simplify the code, no actual functional changes.
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
fs/cifs/cifsencrypt.c | 3 +--
fs/cifs/cifsglob.h | 5 +++++
fs/cifs/connect.c | 10 +++++-----
fs/cifs/transport.c | 4 ++--
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 61a9fed56548..46f5718754f9 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -32,10 +32,9 @@ int __cifs_calc_signature(struct smb_rqst *rqst,
int rc;
struct kvec *iov = rqst->rq_iov;
int n_vec = rqst->rq_nvec;
- bool is_smb2 = HEADER_PREAMBLE_SIZE(server) == 0;
/* iov[0] is actual data and not the rfc1002 length for SMB2+ */
- if (is_smb2) {
+ if (!is_smb1(server)) {
if (iov[0].iov_len <= 4)
return -EIO;
i = 0;
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 544f69634063..45d21ebaff9f 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -751,6 +751,11 @@ struct TCP_Server_Info {
#endif
};
+static inline bool is_smb1(struct TCP_Server_Info *server)
+{
+ return HEADER_PREAMBLE_SIZE(server) != 0;
+}
+
static inline void cifs_server_lock(struct TCP_Server_Info *server)
{
unsigned int nofs_flag = memalloc_nofs_save();
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 24df04d9b0f3..7d4f8119006d 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -871,7 +871,7 @@ smb2_get_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
/*
* SMB1 does not use credits.
*/
- if (HEADER_PREAMBLE_SIZE(server))
+ if (is_smb1(server))
return 0;
return le16_to_cpu(shdr->CreditRequest);
@@ -1121,7 +1121,7 @@ smb2_add_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
/*
* SMB1 does not use credits.
*/
- if (HEADER_PREAMBLE_SIZE(server))
+ if (is_smb1(server))
return;
if (shdr->CreditRequest) {
@@ -1179,10 +1179,10 @@ cifs_demultiplex_thread(void *p)
if (length < 0)
continue;
- if (HEADER_PREAMBLE_SIZE(server) == 0)
- server->total_read = 0;
- else
+ if (is_smb1(server))
server->total_read = length;
+ else
+ server->total_read = 0;
/*
* The right amount was read from socket - 4 bytes,
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index bb1052dbac5b..c2fe035e573b 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -261,7 +261,7 @@ smb_rqst_len(struct TCP_Server_Info *server, struct smb_rqst *rqst)
int nvec;
unsigned long buflen = 0;
- if (HEADER_PREAMBLE_SIZE(server) == 0 && rqst->rq_nvec >= 2 &&
+ if (!is_smb1(server) && rqst->rq_nvec >= 2 &&
rqst->rq_iov[0].iov_len == 4) {
iov = &rqst->rq_iov[1];
nvec = rqst->rq_nvec - 1;
@@ -346,7 +346,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
sigprocmask(SIG_BLOCK, &mask, &oldmask);
/* Generate a rfc1002 marker for SMB2+ */
- if (HEADER_PREAMBLE_SIZE(server) == 0) {
+ if (!is_smb1(server)) {
struct kvec hiov = {
.iov_base = &rfc1002_marker,
.iov_len = 4
--
2.31.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH -next 0/3] cifs: Use some helper function for preamble size
2022-08-23 12:51 [PATCH -next 0/3] cifs: Use some helper function for preamble size Zhang Xiaoxu
` (2 preceding siblings ...)
2022-08-23 12:52 ` [PATCH -next 3/3] cifs: Add helper function to check smb1+ server Zhang Xiaoxu
@ 2022-08-23 17:23 ` Paulo Alcantara
2022-08-24 5:57 ` Steve French
3 siblings, 1 reply; 6+ messages in thread
From: Paulo Alcantara @ 2022-08-23 17:23 UTC (permalink / raw)
To: Zhang Xiaoxu, linux-cifs, zhangxiaoxu5, sfrench, lsahlber,
sprasad, rohiths, smfrench
Zhang Xiaoxu <zhangxiaoxu5@huawei.com> writes:
>
> *** BLURB HERE ***
> The unfolded expression of header_preamble_size is too long, in addition,
> some expressions have specific semantics, e.g.:
> calculate the position of the mid,
> confirm it's smb2+ server or not.
>
> Zhang Xiaoxu (3):
> cifs: Use help macro to get the header preamble size
> cifs: Use help macro to get the mid header size
> cifs: Add helper function to check smb2+ server
>
> fs/cifs/cifsencrypt.c | 3 +--
> fs/cifs/cifsglob.h | 7 +++++++
> fs/cifs/connect.c | 28 +++++++++++-----------------
> fs/cifs/transport.c | 21 ++++++++++-----------
> 4 files changed, 29 insertions(+), 30 deletions(-)
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH -next 0/3] cifs: Use some helper function for preamble size
2022-08-23 17:23 ` [PATCH -next 0/3] cifs: Use some helper function for preamble size Paulo Alcantara
@ 2022-08-24 5:57 ` Steve French
0 siblings, 0 replies; 6+ messages in thread
From: Steve French @ 2022-08-24 5:57 UTC (permalink / raw)
To: Paulo Alcantara
Cc: Zhang Xiaoxu, CIFS, Steve French, Ronnie Sahlberg, Shyam Prasad N,
rohiths
tentatively merged into cifs-2.6.git for-next pending testing
On Tue, Aug 23, 2022 at 12:23 PM Paulo Alcantara <pc@cjr.nz> wrote:
>
> Zhang Xiaoxu <zhangxiaoxu5@huawei.com> writes:
>
> >
> > *** BLURB HERE ***
> > The unfolded expression of header_preamble_size is too long, in addition,
> > some expressions have specific semantics, e.g.:
> > calculate the position of the mid,
> > confirm it's smb2+ server or not.
> >
> > Zhang Xiaoxu (3):
> > cifs: Use help macro to get the header preamble size
> > cifs: Use help macro to get the mid header size
> > cifs: Add helper function to check smb2+ server
> >
> > fs/cifs/cifsencrypt.c | 3 +--
> > fs/cifs/cifsglob.h | 7 +++++++
> > fs/cifs/connect.c | 28 +++++++++++-----------------
> > fs/cifs/transport.c | 21 ++++++++++-----------
> > 4 files changed, 29 insertions(+), 30 deletions(-)
>
> Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-08-24 5:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23 12:51 [PATCH -next 0/3] cifs: Use some helper function for preamble size Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 1/3] cifs: Use help macro to get the header " Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 2/3] cifs: Use help macro to get the mid header size Zhang Xiaoxu
2022-08-23 12:52 ` [PATCH -next 3/3] cifs: Add helper function to check smb1+ server Zhang Xiaoxu
2022-08-23 17:23 ` [PATCH -next 0/3] cifs: Use some helper function for preamble size Paulo Alcantara
2022-08-24 5:57 ` Steve French
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox