fs: Convert kiocb rw_hint from enum to u16
authorAdam Manzanares <adam.manzanares@wdc.com>
Tue, 22 May 2018 17:52:18 +0000 (10:52 -0700)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 31 May 2018 14:50:54 +0000 (10:50 -0400)
In order to avoid kiocb bloat for per command iopriority support, rw_hint
is converted from enum to a u16. Added a guard around ki_hint assignment.

Signed-off-by: Adam Manzanares <adam.manzanares@wdc.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/aio.c
include/linux/fs.h

index b850e92..33299ec 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1434,7 +1434,7 @@ static int aio_prep_rw(struct kiocb *req, struct iocb *iocb)
        req->ki_flags = iocb_flags(req->ki_filp);
        if (iocb->aio_flags & IOCB_FLAG_RESFD)
                req->ki_flags |= IOCB_EVENTFD;
-       req->ki_hint = file_write_hint(req->ki_filp);
+       req->ki_hint = ki_hint_validate(file_write_hint(req->ki_filp));
        ret = kiocb_set_rw_flags(req, iocb->aio_rw_flags);
        if (unlikely(ret))
                fput(req->ki_filp);
index 4b6045e..b432fc3 100644 (file)
@@ -299,7 +299,7 @@ struct kiocb {
        void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
        void                    *private;
        int                     ki_flags;
-       enum rw_hint            ki_hint;
+       u16                     ki_hint;
 } __randomize_layout;
 
 static inline bool is_sync_kiocb(struct kiocb *kiocb)
@@ -1929,12 +1929,21 @@ static inline enum rw_hint file_write_hint(struct file *file)
 
 static inline int iocb_flags(struct file *file);
 
+static inline u16 ki_hint_validate(enum rw_hint hint)
+{
+       typeof(((struct kiocb *)0)->ki_hint) max_hint = -1;
+
+       if (hint <= max_hint)
+               return hint;
+       return 0;
+}
+
 static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
 {
        *kiocb = (struct kiocb) {
                .ki_filp = filp,
                .ki_flags = iocb_flags(filp),
-               .ki_hint = file_write_hint(filp),
+               .ki_hint = ki_hint_validate(file_write_hint(filp)),
        };
 }