Skip to contentSkip to conversation

erofs: support STATX_DIOALIGN

PATCH New Hongbo Li via Linux-erofs 3 participants 5 messages Jul 18, 2024 – Jul 26, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 erofs: support STATX_DIOALIGN

Add support for STATX_DIOALIGN to erofs, so that direct I/O alignment restrictions are exposed to userspace in a generic way.

[Before]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:0
dio offset align:0
```

[After]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:512
dio offset align:512
```

---
v2:
- Removing the non-bdev case for obtaining the bsize.

v1: https://lore.kernel.org/all/[email protected]/T/

---
 fs/erofs/inode.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
fs/erofs/inode.c +17 -0
index 5f6439a63af7..7c1163e47cb7 100644
@@ -342,6 +342,23 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
 	stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
 				  STATX_ATTR_IMMUTABLE);
 
+	/*
+	 * Return the DIO alignment restrictions if requested.
+	 *
+	 * In erofs, STATX_DIOALIGN is not supported in ondemand mode and
+	 * the compressed file, so in these cases we report no DIO support.
+	 */
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
+		stat->result_mask |= STATX_DIOALIGN;
+		if (!erofs_is_fscache_mode(inode->i_sb) &&
+			!erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) {
+			struct block_device *bdev = inode->i_sb->s_bdev;
+
+			stat->dio_mem_align = bdev_logical_block_size(bdev);
+			stat->dio_offset_align = stat->dio_mem_align;
+		}
+	}
+
 	generic_fillattr(idmap, request_mask, inode, stat);
 	return 0;
 }
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/1 erofs: support STATX_DIOALIGN

From: Hongbo Li via Linux-erofs <[email protected]>

Add support for STATX_DIOALIGN to erofs, so that direct I/O alignment restrictions are exposed to userspace in a generic way.

[Before]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:0
dio offset align:0
```

[After]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:512
dio offset align:512
```

---
Hi Hongbo,

I tidy up the patch a bit according to the current codebase, I will apply this later for this cycle.

Also r-v-bs are always welcome...

Thanks,
Gao Xiang

 fs/erofs/inode.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
fs/erofs/inode.c +17 -2
index 5f6439a63af7..43c09aae2afc 100644
@@ -334,14 +334,29 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
 		  unsigned int query_flags)
 {
 	struct inode *const inode = d_inode(path->dentry);
+	bool compressed =
+		erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout);
 
-	if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
+	if (compressed)
 		stat->attributes |= STATX_ATTR_COMPRESSED;
-
 	stat->attributes |= STATX_ATTR_IMMUTABLE;
 	stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
 				  STATX_ATTR_IMMUTABLE);
 
+	/*
+	 * Return the DIO alignment restrictions if requested.
+	 *
+	 * In EROFS, STATX_DIOALIGN is not supported in ondemand mode and
+	 * compressed files, so in these cases we report no DIO support.
+	 */
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
+		stat->result_mask |= STATX_DIOALIGN;
+		if (!erofs_is_fscache_mode(inode->i_sb) && !compressed) {
+			stat->dio_mem_align =
+				bdev_logical_block_size(inode->i_sb->s_bdev);
+			stat->dio_offset_align = stat->dio_mem_align;
+		}
+	}
 	generic_fillattr(idmap, request_mask, inode, stat);
 	return 0;
 }
Signature · 1 line
2.43.5
#2 lore raw
Quoted 1 line · Gao Xiang

From: Hongbo Li via Linux-erofs <[email protected]>

Also I will fix the email address issue (Hongbo Li <[email protected]>) when applying too.

Quoted 73 lines

Add support for STATX_DIOALIGN to erofs, so that direct I/O alignment restrictions are exposed to userspace in a generic way.

[Before]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:0
dio offset align:0
```

[After]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:512
dio offset align:512
```

---
Hi Hongbo,

I tidy up the patch a bit according to the current codebase, I will apply this later for this cycle.

Also r-v-bs are always welcome...

Thanks,
Gao Xiang

  fs/erofs/inode.c | 19 +++++++++++++++++--
  1 file changed, 17 insertions(+), 2 deletions(-)
fs/erofs/inode.c +17 -2
index 5f6439a63af7..43c09aae2afc 100644
@@ -334,14 +334,29 @@ int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
  		  unsigned int query_flags)
  {
  	struct inode *const inode = d_inode(path->dentry);
+	bool compressed =
+		erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout);
 
-	if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
+	if (compressed)
  		stat->attributes |= STATX_ATTR_COMPRESSED;
-
  	stat->attributes |= STATX_ATTR_IMMUTABLE;
  	stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
  				  STATX_ATTR_IMMUTABLE);
 
+	/*
+	 * Return the DIO alignment restrictions if requested.
+	 *
+	 * In EROFS, STATX_DIOALIGN is not supported in ondemand mode and
+	 * compressed files, so in these cases we report no DIO support.
+	 */
+	if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) {
+		stat->result_mask |= STATX_DIOALIGN;
+		if (!erofs_is_fscache_mode(inode->i_sb) && !compressed) {
+			stat->dio_mem_align =
+				bdev_logical_block_size(inode->i_sb->s_bdev);
+			stat->dio_offset_align = stat->dio_mem_align;
+		}
+	}
  	generic_fillattr(idmap, request_mask, inode, stat);
  	return 0;
  }
#3 lore raw
Quoted 36 lines · Gao Xiang
Quoted 1 line · Gao Xiang

From: Hongbo Li via Linux-erofs <[email protected]>

Also I will fix the email address issue (Hongbo Li <[email protected]>) when applying too.

Quoted 28 lines

Add support for STATX_DIOALIGN to erofs, so that direct I/O alignment restrictions are exposed to userspace in a generic way.

[Before]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:0
dio offset align:0
```

[After]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:512
dio offset align:512
```

---
Hi Hongbo,

I tidy up the patch a bit according to the current codebase, I will apply this later for this cycle.

it's ok, and thank you!

Thanks,
Hongbo

Quoted 44 lines
Quoted 44 lines

Also r-v-bs are always welcome...

Thanks,
Gao Xiang

  fs/erofs/inode.c | 19 +++++++++++++++++--

  1 file changed, 17 insertions(+), 2 deletions(-)
fs/erofs/inode.c +3 -2
index 5f6439a63af7..43c09aae2afc 100644
@@ -334,14 +334,29 @@ int erofs_getattr(struct mnt_idmap *idmap, const 
 struct path *path,
             unsigned int query_flags)
   {
       struct inode *const inode = d_inode(path->dentry);
+    bool compressed =
+        erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout);
-    if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
+    if (compressed)
           stat->attributes |= STATX_ATTR_COMPRESSED;
-
       stat->attributes |= STATX_ATTR_IMMUTABLE;

      stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_IMMUTABLE);
+    /*
+     * Return the DIO alignment restrictions if requested. +     *
+     * In EROFS, STATX_DIOALIGN is not supported in ondemand mode and +     * compressed files, so in these cases we report no DIO support. +     */
+    if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) { +        stat->result_mask |= STATX_DIOALIGN;
+        if (!erofs_is_fscache_mode(inode->i_sb) && !compressed) { +            stat->dio_mem_align =
+                bdev_logical_block_size(inode->i_sb->s_bdev); +            stat->dio_offset_align = stat->dio_mem_align; +        }
+    }
      generic_fillattr(idmap, request_mask, inode, stat); return 0;
  }

maintainer Reviewed-by
#4 lore raw
In reply to Gao Xiang
Quoted 31 lines · Gao Xiang
Quoted 1 line · Gao Xiang

From: Hongbo Li via Linux-erofs <[email protected]>

Also I will fix the email address issue (Hongbo Li <[email protected]>) when applying too.

Quoted 23 lines

Add support for STATX_DIOALIGN to erofs, so that direct I/O alignment restrictions are exposed to userspace in a generic way.

[Before]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:0
dio offset align:0
```

[After]

```
./statx_test /mnt/erofs/testfile
statx(/mnt/erofs/testfile) = 0
dio mem align:512
dio offset align:512
```

Thanks,