For our plugins which are reading from one or more local files, calling .pread is likely to populate the kernel's file cache to our advantage; these plugins are complicated enough that there is nothing better like posix_fadvise() that we can try. Implementing .can_cache is sufficient to let nbdkit do the desired work on our behalf. Full list of plugins changed: ext2, floppy, iso, linuxdisk, partitioning Note that the tar plugin would likewise probably benefit from .pread treatment; but for that, we'd first have to wire up .can_cache to the perl language binding. Signed-off-by: Eric Blake <eblake@redhat.com> --- plugins/ext2/ext2.c | 10 +++++++++- plugins/floppy/floppy.c | 11 ++++++++++- plugins/iso/iso.c | 10 +++++++++- plugins/linuxdisk/linuxdisk.c | 9 +++++++++ plugins/partitioning/partitioning.c | 11 ++++++++++- 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/plugins/ext2/ext2.c b/plugins/ext2/ext2.c index 17f88fe..6698d99 100644 --- a/plugins/ext2/ext2.c +++ b/plugins/ext2/ext2.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2017-2018 Red Hat Inc. + * Copyright (C) 2017-2019 Red Hat Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -212,6 +212,13 @@ ext2_can_fua (void *handle) return NBDKIT_FUA_NATIVE; } +static int +ext2_can_cache (void *handle) +{ + /* Let nbdkit call pread to populate the file system cache. */ + return NBDKIT_CACHE_EMULATE; +} + /* It might be possible to relax this, but it's complicated. * * It's desirable for ‘nbdkit -r’ to behave the same way as @@ -345,6 +352,7 @@ static struct nbdkit_plugin plugin = { .open = ext2_open, .close = ext2_close, .can_fua = ext2_can_fua, + .can_cache = ext2_can_cache, .get_size = ext2_get_size, .pread = ext2_pread, .pwrite = ext2_pwrite, diff --git a/plugins/floppy/floppy.c b/plugins/floppy/floppy.c index ebdea5b..41a2364 100644 --- a/plugins/floppy/floppy.c +++ b/plugins/floppy/floppy.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2018 Red Hat Inc. + * Copyright (C) 2018-2019 Red Hat Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -128,6 +128,14 @@ floppy_can_multi_conn (void *handle) return 1; } +/* Cache. */ +static int +floppy_can_cache (void *handle) +{ + /* Let nbdkit call pread to populate the file system cache. */ + return NBDKIT_CACHE_EMULATE; +} + /* Read data from the file. */ static int floppy_pread (void *handle, void *buf, uint32_t count, uint64_t offset) @@ -199,6 +207,7 @@ static struct nbdkit_plugin plugin = { .open = floppy_open, .get_size = floppy_get_size, .can_multi_conn = floppy_can_multi_conn, + .can_cache = floppy_can_cache, .pread = floppy_pread, .errno_is_preserved = 1, }; diff --git a/plugins/iso/iso.c b/plugins/iso/iso.c index 586f1f9..4728ff3 100644 --- a/plugins/iso/iso.c +++ b/plugins/iso/iso.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2018 Red Hat Inc. + * Copyright (C) 2018-2019 Red Hat Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -215,6 +215,13 @@ iso_can_multi_conn (void *handle) return 1; } +static int +iso_can_cache (void *handle) +{ + /* Let nbdkit call pread to populate the file system cache. */ + return NBDKIT_CACHE_EMULATE; +} + /* Read data from the file. */ static int iso_pread (void *handle, void *buf, uint32_t count, uint64_t offset) @@ -249,6 +256,7 @@ static struct nbdkit_plugin plugin = { .open = iso_open, .get_size = iso_get_size, .can_multi_conn = iso_can_multi_conn, + .can_cache = iso_can_cache, .pread = iso_pread, .errno_is_preserved = 1, }; diff --git a/plugins/linuxdisk/linuxdisk.c b/plugins/linuxdisk/linuxdisk.c index 1ba7114..99dbc99 100644 --- a/plugins/linuxdisk/linuxdisk.c +++ b/plugins/linuxdisk/linuxdisk.c @@ -159,6 +159,14 @@ linuxdisk_can_multi_conn (void *handle) return 1; } +/* Cache. */ +static int +linuxdisk_can_cache (void *handle) +{ + /* Let nbdkit call pread to populate the file system cache. */ + return NBDKIT_CACHE_EMULATE; +} + /* Read data from the virtual disk. */ static int linuxdisk_pread (void *handle, void *buf, uint32_t count, uint64_t offset, @@ -221,6 +229,7 @@ static struct nbdkit_plugin plugin = { .open = linuxdisk_open, .get_size = linuxdisk_get_size, .can_multi_conn = linuxdisk_can_multi_conn, + .can_cache = linuxdisk_can_cache, .pread = linuxdisk_pread, .errno_is_preserved = 1, }; diff --git a/plugins/partitioning/partitioning.c b/plugins/partitioning/partitioning.c index 630c6d2..90333bf 100644 --- a/plugins/partitioning/partitioning.c +++ b/plugins/partitioning/partitioning.c @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2018 Red Hat Inc. + * Copyright (C) 2018-2019 Red Hat Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -297,6 +297,14 @@ partitioning_can_multi_conn (void *handle) return 1; } +/* Cache. */ +static int +partitioning_can_cache (void *handle) +{ + /* Let nbdkit call pread to populate the file system cache. */ + return NBDKIT_CACHE_EMULATE; +} + /* Read data. */ static int partitioning_pread (void *handle, void *buf, uint32_t count, uint64_t offset) @@ -426,6 +434,7 @@ static struct nbdkit_plugin plugin = { .open = partitioning_open, .get_size = partitioning_get_size, .can_multi_conn = partitioning_can_multi_conn, + .can_cache = partitioning_can_cache, .pread = partitioning_pread, .pwrite = partitioning_pwrite, .flush = partitioning_flush, -- 2.20.1