]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: support list direct io
authorMing Lei <tom.leiming@gmail.com>
Tue, 17 Nov 2015 14:32:48 +0000 (22:32 +0800)
committerKarel Zak <kzak@redhat.com>
Thu, 19 Nov 2015 10:27:36 +0000 (11:27 +0100)
So that user can see if DIO is set for current loop device.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
include/loopdev.h
lib/loopdev.c
sys-utils/losetup.c

index 9a7f6ba69db45ca67d1a631c00328683899f3d96..18ca41fe836f0a89cd0df8010b7966825670fe4c 100644 (file)
@@ -40,6 +40,7 @@ enum {
        LO_FLAGS_USE_AOPS   = 2,
        LO_FLAGS_AUTOCLEAR  = 4,        /* kernel >= 2.6.25 */
        LO_FLAGS_PARTSCAN   = 8,        /* kernel >= 3.2 */
+       LO_FLAGS_DIRECT_IO  = 16,       /* kernel >= 4.2 */
 };
 
 #define LO_NAME_SIZE   64
@@ -181,6 +182,7 @@ extern int loopcxt_get_encrypt_type(struct loopdev_cxt *lc, uint32_t *type);
 extern const char *loopcxt_get_crypt_name(struct loopdev_cxt *lc);
 extern int loopcxt_is_autoclear(struct loopdev_cxt *lc);
 extern int loopcxt_is_readonly(struct loopdev_cxt *lc);
+extern int loopcxt_is_dio(struct loopdev_cxt *lc);
 extern int loopcxt_is_partscan(struct loopdev_cxt *lc);
 extern int loopcxt_find_by_backing_file(struct loopdev_cxt *lc,
                                const char *filename,
index ff99dd444e4a068eeae2afd362821a9a22fea46d..54c62004877a91367b92a95c7e33371952dd65e9 100644 (file)
@@ -953,6 +953,28 @@ int loopcxt_is_readonly(struct loopdev_cxt *lc)
        return 0;
 }
 
+/*
+ * @lc: context
+ *
+ * Returns: 1 if the dio flags is set.
+ */
+int loopcxt_is_dio(struct loopdev_cxt *lc)
+{
+       struct sysfs_cxt *sysfs = loopcxt_get_sysfs(lc);
+
+       if (sysfs) {
+               int fl;
+               if (sysfs_read_int(sysfs, "loop/dio", &fl) == 0)
+                       return fl;
+       }
+       if (loopcxt_ioctl_enabled(lc)) {
+               struct loop_info64 *lo = loopcxt_get_info(lc);
+               if (lo)
+                       return lo->lo_flags & LO_FLAGS_DIRECT_IO;
+       }
+       return 0;
+}
+
 /*
  * @lc: context
  * @st: backing file stat or NULL
index 68f77779802f24480af2c124264844e07e853b6c..918c34da6cb70b4e4a07b60fe99c5f76ec8f3f6c 100644 (file)
@@ -49,6 +49,7 @@ enum {
        COL_PARTSCAN,
        COL_RO,
        COL_SIZELIMIT,
+       COL_DIO,
 };
 
 /* basic output flags */
@@ -74,6 +75,7 @@ static struct colinfo infos[] = {
        [COL_RO]          = { "RO",           1, SCOLS_FL_RIGHT, N_("read-only device")},
        [COL_SIZELIMIT]   = { "SIZELIMIT",    5, SCOLS_FL_RIGHT, N_("size limit of the file in bytes")},
        [COL_MAJMIN]      = { "MAJ:MIN",      3, 0, N_("loop device major:minor number")},
+       [COL_DIO]         = { "DIO",          1, SCOLS_FL_RIGHT, N_("access backing file with direct-io")},
 };
 
 static int columns[ARRAY_SIZE(infos) * 2] = {-1};
@@ -271,6 +273,9 @@ static int set_scols_data(struct loopdev_cxt *lc, struct libscols_line *ln)
                case COL_RO:
                        p = loopcxt_is_readonly(lc) ? "1" : "0";
                        break;
+               case COL_DIO:
+                       p = loopcxt_is_dio(lc) ? "1" : "0";
+                       break;
                case COL_PARTSCAN:
                        p = loopcxt_is_partscan(lc) ? "1" : "0";
                        break;
@@ -599,6 +604,7 @@ int main(int argc, char **argv)
                columns[ncolumns++] = COL_AUTOCLR;
                columns[ncolumns++] = COL_RO;
                columns[ncolumns++] = COL_BACK_FILE;
+               columns[ncolumns++] = COL_DIO;
        }
 
        if (act == A_FIND_FREE && optind < argc) {