Skip to contentSkip to conversation

ksmbd: remove unnecessary generic_fillattr in smb2_open

PATCH Superseded Hyunchul Lee 2 participants 7 messages Aug 10, 2022 – Aug 11, 2022

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ksmbd: remove unnecessary generic_fillattr in smb2_open

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation. But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +6 -9
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
 	list_add(&fp->node, &fp->f_ci->m_fp_list);
 	write_unlock(&fp->f_ci->m_lock);
 
-	rc = ksmbd_vfs_getattr(&path, &stat);
-	if (rc) {
-		generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-		rc = 0;
-	}
-
 	/* Check delete pending among previous fp before oplock break */
 	if (ksmbd_inode_pending_delete(fp)) {
 		rc = -EBUSY;
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
 		}
 	}
 
+	rc = ksmbd_vfs_getattr(&path, &stat);
+	if (rc) {
+		generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+		rc = 0;
+	}
+
 	if (stat.result_mask & STATX_BTIME)
 		fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
 	else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
 	memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
 
-	generic_fillattr(user_ns, file_inode(fp->filp),
-			 &stat);
-
 	rsp->StructureSize = cpu_to_le16(89);
 	rcu_read_lock();
 	opinfo = rcu_dereference(fp->f_opinfo);
Signature · 1 line
2.17.1
maintainer
#1 lore raw

2022-08-10 10:04 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 8 lines

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation.

So what causes delay allocation between the lines you moved this code?

Quoted 55 lines

But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +6 -10
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
 	list_add(&fp->node, &fp->f_ci->m_fp_list);
 	write_unlock(&fp->f_ci->m_lock);
 
-	rc = ksmbd_vfs_getattr(&path, &stat);
-	if (rc) {
-		generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-		rc = 0;
-	}
-
 	/* Check delete pending among previous fp before oplock break */
 	if (ksmbd_inode_pending_delete(fp)) {
 		rc = -EBUSY;
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
 		}
 	}
 
+	rc = ksmbd_vfs_getattr(&path, &stat);
+	if (rc) {
+		generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+		rc = 0;
+	}
+
 	if (stat.result_mask & STATX_BTIME)
 		fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
 	else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
 	memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
 
-	generic_fillattr(user_ns, file_inode(fp->filp),
-			 &stat);
-
 	rsp->StructureSize = cpu_to_le16(89);
 	rcu_read_lock();
 	opinfo = rcu_dereference(fp->f_opinfo);
--

2.17.1

maintainer
#2 lore raw

2022-08-10 16:58 GMT+09:00, Namjae Jeon <[email protected]>:

Quoted 10 lines

2022-08-10 10:04 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 8 lines

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation.

So what causes delay allocation between the lines you moved this code?

And how can I reproduce problem and make sure that it is improved?

Quoted 57 lines
Quoted 56 lines

But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +6 -10
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
 	list_add(&fp->node, &fp->f_ci->m_fp_list);
 	write_unlock(&fp->f_ci->m_lock);
 
-	rc = ksmbd_vfs_getattr(&path, &stat);
-	if (rc) {
-		generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-		rc = 0;
-	}
-
 	/* Check delete pending among previous fp before oplock break */
 	if (ksmbd_inode_pending_delete(fp)) {
 		rc = -EBUSY;
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
 		}
 	}
 
+	rc = ksmbd_vfs_getattr(&path, &stat);
+	if (rc) {
+		generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+		rc = 0;
+	}
+
 	if (stat.result_mask & STATX_BTIME)
 		fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
 	else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
 	memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
 
-	generic_fillattr(user_ns, file_inode(fp->filp),
-			 &stat);
-
 	rsp->StructureSize = cpu_to_le16(89);
 	rcu_read_lock();
 	opinfo = rcu_dereference(fp->f_opinfo);
--

2.17.1

#3 lore raw

2022년 8월 10일 (수) 오후 5:00, Namjae Jeon <[email protected]>님이 작성:

Quoted 7 lines

2022-08-10 16:58 GMT+09:00, Namjae Jeon <[email protected]>:

Quoted 5 lines

2022-08-10 10:04 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 4 lines

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation.

And how can I reproduce problem and make sure that it is improved?

This issue can be reproduce with commands below:

touch ${FILENAME}
xfs_io -c "pwrite -S 0xAB 0 40k" ${FILENAME}
xfs_io -c "stat" ${FILENAME}

40KB are written, but the number of blocks are 8
stat.size = 40960
stat.blocks = 8

Quoted 1 line
Quoted 1 line

So what causes delay allocation between the lines you moved this code?

For the example above, the second command writes 40KB but inode->i_blocks is not updated because of delayed allocation. And when the third command is executed, in smb2_open ksmbd_vfs_getattr returns stat.blocks which is 80, but the following generic_fillattr returns stat.blocks which 8.

With this patch applied, the third command returns stat.blocks which is 88, not 80.
I will look into this.

Quoted 46 lines
Quoted 46 lines
Quoted 46 lines

But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +6 -6
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
     list_add(&fp->node, &fp->f_ci->m_fp_list);
     write_unlock(&fp->f_ci->m_lock);
 
-    rc = ksmbd_vfs_getattr(&path, &stat);
-    if (rc) {
-            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-            rc = 0;
-    }
-
     /* Check delete pending among previous fp before oplock break */
     if (ksmbd_inode_pending_delete(fp)) {
             rc = -EBUSY;
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
             }
     }
 
+    rc = ksmbd_vfs_getattr(&path, &stat);
+    if (rc) {
+            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+            rc = 0;
+    }
+
     if (stat.result_mask & STATX_BTIME)
             fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
     else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
     memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
 
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
fs/ksmbd/smb2pdu.c +0 -4
-    generic_fillattr(user_ns, file_inode(fp->filp),
-                     &stat);
-
     rsp->StructureSize = cpu_to_le16(89);
     rcu_read_lock();
     opinfo = rcu_dereference(fp->f_opinfo);
--

2.17.1

--
Thanks,
Hyunchul

#4 lore raw

2022년 8월 11일 (목) 오전 8:18, Hyunchul Lee <[email protected]>님이 작성:

Quoted 34 lines

2022년 8월 10일 (수) 오후 5:00, Namjae Jeon <[email protected]>님이 작성:

Quoted 7 lines

2022-08-10 16:58 GMT+09:00, Namjae Jeon <[email protected]>:

Quoted 5 lines

2022-08-10 10:04 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 4 lines

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation.

And how can I reproduce problem and make sure that it is improved?

This issue can be reproduce with commands below:

touch ${FILENAME}
xfs_io -c "pwrite -S 0xAB 0 40k" ${FILENAME}
xfs_io -c "stat" ${FILENAME}

40KB are written, but the number of blocks are 8
stat.size = 40960
stat.blocks = 8

Quoted 1 line
Quoted 1 line

So what causes delay allocation between the lines you moved this code?

For the example above, the second command writes 40KB but inode->i_blocks is not updated because of delayed allocation. And when the third command is executed, in smb2_open ksmbd_vfs_getattr returns stat.blocks which is 80, but the following generic_fillattr returns stat.blocks which 8.

Quoted 4 lines

With this patch applied, the third command returns stat.blocks which is 88, not 80.
I will look into this.

This is not a problem and happens only when acl_xattr config is enabled. If the config is enabled. The security descriptor is written to xattr as not inline,
and the blocks for xattr are counted.

Quoted 65 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines

But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +6 -6
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
     list_add(&fp->node, &fp->f_ci->m_fp_list);
     write_unlock(&fp->f_ci->m_lock);
 
-    rc = ksmbd_vfs_getattr(&path, &stat);
-    if (rc) {
-            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-            rc = 0;
-    }
-
     /* Check delete pending among previous fp before oplock break */
     if (ksmbd_inode_pending_delete(fp)) {
             rc = -EBUSY;
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
             }
     }
 
+    rc = ksmbd_vfs_getattr(&path, &stat);
+    if (rc) {
+            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+            rc = 0;
+    }
+
     if (stat.result_mask & STATX_BTIME)
             fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
     else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
     memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
 
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
fs/ksmbd/smb2pdu.c +0 -4
-    generic_fillattr(user_ns, file_inode(fp->filp),
-                     &stat);
-
     rsp->StructureSize = cpu_to_le16(89);
     rcu_read_lock();
     opinfo = rcu_dereference(fp->f_opinfo);
--

2.17.1

--
Thanks,
Hyunchul

Signature · 2 lines
Thanks,
Hyunchul
maintainer
#5 lore raw

2022-08-11 14:32 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 41 lines

2022년 8월 11일 (목) 오전 8:18, Hyunchul Lee <[email protected]>님이 작성:

Quoted 35 lines

2022년 8월 10일 (수) 오후 5:00, Namjae Jeon <[email protected]>님이 작성:

Quoted 7 lines

2022-08-10 16:58 GMT+09:00, Namjae Jeon <[email protected]>:

Quoted 5 lines

2022-08-10 10:04 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 4 lines

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation.

And how can I reproduce problem and make sure that it is improved?

This issue can be reproduce with commands below:

touch ${FILENAME}
xfs_io -c "pwrite -S 0xAB 0 40k" ${FILENAME}
xfs_io -c "stat" ${FILENAME}

40KB are written, but the number of blocks are 8
stat.size = 40960
stat.blocks = 8

Quoted 2 lines
Quoted 2 lines

So what causes delay allocation between the lines you moved this code?

For the example above, the second command writes 40KB but inode->i_blocks is not updated because of delayed allocation. And when the third command is executed, in smb2_open ksmbd_vfs_getattr returns stat.blocks which is 80, but the following generic_fillattr returns stat.blocks which 8.

Quoted 4 lines

With this patch applied, the third command returns stat.blocks which is 88, not 80.
I will look into this.

Quoted 4 lines

This is not a problem and happens only when acl_xattr config is enabled. If the config is enabled. The security descriptor is written to xattr as not inline,
and the blocks for xattr are counted.

Okay, The The patch description seems to be wrong.
You describe that unneeded generic_fillattr call cause this problem, not moving the call of ksmbd_vfs_getattr() in patch description. Right ?

Quoted 75 lines
Quoted 65 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +0 -6
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
     list_add(&fp->node, &fp->f_ci->m_fp_list);
     write_unlock(&fp->f_ci->m_lock);
 
-    rc = ksmbd_vfs_getattr(&path, &stat);
-    if (rc) {
-            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-            rc = 0;
-    }
-
     /* Check delete pending among previous fp before oplock break
 */
     if (ksmbd_inode_pending_delete(fp)) {
             rc = -EBUSY;
fs/ksmbd/smb2pdu.c +6 -0
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
             }
     }
 
+    rc = ksmbd_vfs_getattr(&path, &stat);
+    if (rc) {
+            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+            rc = 0;
+    }
+
     if (stat.result_mask & STATX_BTIME)
             fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
     else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
     memcpy(fp->client_guid, conn->ClientGUID,
 SMB2_CLIENT_GUID_SIZE);
 
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
fs/ksmbd/smb2pdu.c +0 -3
-    generic_fillattr(user_ns, file_inode(fp->filp),
-                     &stat);
-
     rsp->StructureSize = cpu_to_le16(89);
     rcu_read_lock();
     opinfo = rcu_dereference(fp->f_opinfo);

--
2.17.1

Quoted 3 lines

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

#6 lore raw

2022년 8월 11일 (목) 오후 2:46, Namjae Jeon <[email protected]>님이 작성:

Quoted 43 lines

2022-08-11 14:32 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 41 lines

2022년 8월 11일 (목) 오전 8:18, Hyunchul Lee <[email protected]>님이 작성:

Quoted 39 lines

2022년 8월 10일 (수) 오후 5:00, Namjae Jeon <[email protected]>님이 작성:

Quoted 7 lines

2022-08-10 16:58 GMT+09:00, Namjae Jeon <[email protected]>:

Quoted 5 lines

2022-08-10 10:04 GMT+09:00, Hyunchul Lee <[email protected]>:

Quoted 4 lines

Move the call of ksmbd_vfs_getattr above the place where stat is needed, and remove unnecessary the call of generic_fillattr.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

This patch fixes wrong AllocationSize of SMB2_CREATE response. Because ext4 updates inode->i_blocks only when disk space is allocated, generic_fillattr does not set stat.blocks properly for delayed allocation.

And how can I reproduce problem and make sure that it is improved?

This issue can be reproduce with commands below:

touch ${FILENAME}
xfs_io -c "pwrite -S 0xAB 0 40k" ${FILENAME}
xfs_io -c "stat" ${FILENAME}

40KB are written, but the number of blocks are 8
stat.size = 40960
stat.blocks = 8

Quoted 2 lines
Quoted 2 lines

So what causes delay allocation between the lines you moved this code?

For the example above, the second command writes 40KB but inode->i_blocks is not updated because of delayed allocation. And when the third command is executed, in smb2_open ksmbd_vfs_getattr returns stat.blocks which is 80, but the following generic_fillattr returns stat.blocks which 8.

With this patch applied, the third command returns stat.blocks which is 88, not 80.
I will look into this.

Quoted 8 lines
Quoted 4 lines

This is not a problem and happens only when acl_xattr config is enabled. If the config is enabled. The security descriptor is written to xattr as not inline,
and the blocks for xattr are counted.

Okay, The The patch description seems to be wrong.
You describe that unneeded generic_fillattr call cause this problem, not moving the call of ksmbd_vfs_getattr() in patch description. Right ?

Right, I will update the description.

Quoted 75 lines
Quoted 75 lines
Quoted 65 lines
Quoted 51 lines
Quoted 51 lines
Quoted 51 lines

But ext4 returns the blocks that include the delayed allocation blocks when getattr is called.

---
Changes from v1:
- Update the commit description.

 fs/ksmbd/smb2pdu.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/ksmbd/smb2pdu.c +0 -6
index e6f4ccc12f49..7b4bd0d81133 100644
@@ -3022,12 +3022,6 @@ int smb2_open(struct ksmbd_work *work)
     list_add(&fp->node, &fp->f_ci->m_fp_list);
     write_unlock(&fp->f_ci->m_lock);
 
-    rc = ksmbd_vfs_getattr(&path, &stat);
-    if (rc) {
-            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
-            rc = 0;
-    }
-
     /* Check delete pending among previous fp before oplock break
 */
     if (ksmbd_inode_pending_delete(fp)) {
             rc = -EBUSY;
fs/ksmbd/smb2pdu.c +6 -0
@@ -3114,6 +3108,12 @@ int smb2_open(struct ksmbd_work *work)
             }
     }
 
+    rc = ksmbd_vfs_getattr(&path, &stat);
+    if (rc) {
+            generic_fillattr(user_ns, d_inode(path.dentry), &stat);
+            rc = 0;
+    }
+
     if (stat.result_mask & STATX_BTIME)
             fp->create_time = ksmbd_UnixTimeToNT(stat.btime);
     else
@@ -3129,9 +3129,6 @@ int smb2_open(struct ksmbd_work *work)
 
     memcpy(fp->client_guid, conn->ClientGUID,
 SMB2_CLIENT_GUID_SIZE);
 
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
fs/ksmbd/smb2pdu.c +0 -3
-    generic_fillattr(user_ns, file_inode(fp->filp),
-                     &stat);
-
     rsp->StructureSize = cpu_to_le16(89);
     rcu_read_lock();
     opinfo = rcu_dereference(fp->f_opinfo);

--
2.17.1

Quoted 3 lines

--
Thanks,
Hyunchul

--
Thanks,
Hyunchul

Signature · 2 lines
Thanks,
Hyunchul