Skip to content

Commit fe3944f

Browse files
bvanasschebrauner
authored andcommitted
fs: Move enum rw_hint into a new header file
Move enum rw_hint into a new header file to prepare for using this data type in the block layer. Add the attribute __packed to reduce the space occupied by instances of this data type from four bytes to one byte. Change the data type of i_write_hint from u8 into enum rw_hint. Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Chao Yu <chao@kernel.org> # for the F2FS part Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Jan Kara <jack@suse.cz> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20240202203926.2478590-5-bvanassche@acm.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 1505ba0 commit fe3944f

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/blkdev.h>
2525
#include <linux/quotaops.h>
2626
#include <linux/part_stat.h>
27+
#include <linux/rw_hint.h>
2728
#include <crypto/hash.h>
2829

2930
#include <linux/fscrypt.h>

fs/fcntl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/memfd.h>
2828
#include <linux/compat.h>
2929
#include <linux/mount.h>
30+
#include <linux/rw_hint.h>
3031

3132
#include <linux/poll.h>
3233
#include <asm/siginfo.h>

fs/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/ratelimit.h>
2121
#include <linux/list_lru.h>
2222
#include <linux/iversion.h>
23+
#include <linux/rw_hint.h>
2324
#include <trace/events/writeback.h>
2425
#include "internal.h"
2526

include/linux/fs.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/cred.h>
4444
#include <linux/mnt_idmapping.h>
4545
#include <linux/slab.h>
46+
#include <linux/rw_hint.h>
4647

4748
#include <asm/byteorder.h>
4849
#include <uapi/linux/fs.h>
@@ -309,19 +310,6 @@ struct address_space;
309310
struct writeback_control;
310311
struct readahead_control;
311312

312-
/*
313-
* Write life time hint values.
314-
* Stored in struct inode as u8.
315-
*/
316-
enum rw_hint {
317-
WRITE_LIFE_NOT_SET = 0,
318-
WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE,
319-
WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT,
320-
WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM,
321-
WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG,
322-
WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME,
323-
};
324-
325313
/* Match RWF_* bits to IOCB bits */
326314
#define IOCB_HIPRI (__force int) RWF_HIPRI
327315
#define IOCB_DSYNC (__force int) RWF_DSYNC
@@ -677,7 +665,7 @@ struct inode {
677665
spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
678666
unsigned short i_bytes;
679667
u8 i_blkbits;
680-
u8 i_write_hint;
668+
enum rw_hint i_write_hint;
681669
blkcnt_t i_blocks;
682670

683671
#ifdef __NEED_I_SIZE_ORDERED

include/linux/rw_hint.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_RW_HINT_H
3+
#define _LINUX_RW_HINT_H
4+
5+
#include <linux/build_bug.h>
6+
#include <linux/compiler_attributes.h>
7+
#include <uapi/linux/fcntl.h>
8+
9+
/* Block storage write lifetime hint values. */
10+
enum rw_hint {
11+
WRITE_LIFE_NOT_SET = RWH_WRITE_LIFE_NOT_SET,
12+
WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE,
13+
WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT,
14+
WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM,
15+
WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG,
16+
WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME,
17+
} __packed;
18+
19+
/* Sparse ignores __packed annotations on enums, hence the #ifndef below. */
20+
#ifndef __CHECKER__
21+
static_assert(sizeof(enum rw_hint) == 1);
22+
#endif
23+
24+
#endif /* _LINUX_RW_HINT_H */

0 commit comments

Comments
 (0)