From b5314c2a6ae5fe4f802e82a4f31cf2fad398ded9 Mon Sep 17 00:00:00 2001 From: Alasdair G Kergon Date: Thu, 12 May 2016 01:05:52 +0100 Subject: [PATCH] device: Retry open without O_NOATIME if it fails. --- WHATS_NEW | 1 + lib/device/dev-io.c | 13 ++++++++++++- lib/device/device.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/WHATS_NEW b/WHATS_NEW index 89fa681e7..e11a40abc 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.154 - =============================== + Retry open without O_NOATIME if it fails (not file owner/CAP_FOWNER). Version 2.02.153 - 7th May 2016 =============================== diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index 9bf6d2e14..a9a237417 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -494,11 +494,22 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet) #ifdef O_NOATIME /* Don't update atime on device inodes */ - if (!(dev->flags & DEV_REGULAR)) + if (!(dev->flags & DEV_REGULAR) && !(dev->flags & DEV_NOT_O_NOATIME)) flags |= O_NOATIME; #endif if ((dev->fd = open(name, flags, 0777)) < 0) { +#ifdef O_NOATIME + if ((errno == EPERM) && (flags & O_NOATIME)) { + flags &= ~O_NOATIME; + dev->flags |= DEV_NOT_O_NOATIME; + if ((dev->fd = open(name, flags, 0777)) >= 0) { + log_debug_devs("%s: Not using O_NOATIME", name); + goto opened; + } + } +#endif + #ifdef O_DIRECT_SUPPORT if (direct && !(dev->flags & DEV_O_DIRECT_TESTED)) { flags &= ~O_DIRECT; diff --git a/lib/device/device.h b/lib/device/device.h index aaa009fc8..fa03f1061 100644 --- a/lib/device/device.h +++ b/lib/device/device.h @@ -30,6 +30,7 @@ #define DEV_OPEN_FAILURE 0x00000080 /* Has last open failed? */ #define DEV_USED_FOR_LV 0x00000100 /* Is device used for an LV */ #define DEV_ASSUMED_FOR_LV 0x00000200 /* Is device assumed for an LV */ +#define DEV_NOT_O_NOATIME 0x00000400 /* Don't use O_NOATIME */ /* * Support for external device info. -- 2.43.5