}
_DEFINE_ABS_WRAPPER(DEVICE_ABSENT);
+/* Device is absent or "empty". We get -ENOMEDIUM from CD/DVD devices, also in VMs. */
+static inline bool ERRNO_IS_NEG_DEVICE_ABSENT_OR_EMPTY(intmax_t r) {
+ return ERRNO_IS_NEG_DEVICE_ABSENT(r) ||
+ r == -ENOMEDIUM;
+}
+_DEFINE_ABS_WRAPPER(DEVICE_ABSENT_OR_EMPTY);
+
/* Quite often we want to handle cases where the backing FS doesn't support extended attributes at all and
* where it simply doesn't have the requested xattr the same way */
static inline bool ERRNO_IS_NEG_XATTR_ABSENT(intmax_t r) {
fd = open(ASSERT_PTR(arg_device), O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
"Failed to open device node '%s'%s: %m",
arg_device, ignore ? ", ignoring" : "");
mtd_fd = open(argv[1], O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (mtd_fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
"Failed to open device node '%s'%s: %m",
argv[1], ignore ? ", ignoring" : "");
fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
log_device_debug_errno(dev, fd, "Failed to open block device %s%s: %m",
devnode, ignore ? ", ignoring" : "");
return ignore ? 0 : fd;
_cleanup_close_ int fd = open("/dev/btrfs-control", O_RDWR|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
- if (ERRNO_IS_DEVICE_ABSENT(errno)) {
+ if (ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno)) {
/* Driver not installed? Then we aren't ready. This is useful in initrds that lack
* btrfs.ko. After the host transition (where btrfs.ko will hopefully become
* available) the device can be retriggered and will then be considered ready. */
if (fd < 0) {
fd = sd_device_open(dev, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
"Failed to open device '%s'%s: %m",
node, ignore ? ", ignoring" : "");
if (fd < 0) {
fd = sd_device_open(dev, O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
"Failed to open device '%s'%s: %m",
node, ignore ? ", ignoring" : "");
_cleanup_close_ int fd = sd_device_open(dev, O_CLOEXEC|O_PATH);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
"Failed to open device node%s: %m",
ignore ? ", ignoring" : "");
return r;
r = node_get_current(slink, dirfd, ¤t_id, add ? ¤t_prio : NULL);
- if (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))
+ if (r < 0 && !ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(r))
return log_device_debug_errno(dev, r, "Failed to get the current device node priority for '%s': %m", slink);
r = stack_directory_update(dev, dirfd, add);
node_fd = sd_device_open(dev, O_PATH|O_CLOEXEC);
if (node_fd < 0) {
- if (ERRNO_IS_DEVICE_ABSENT(node_fd)) {
+ if (ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(node_fd)) {
log_device_debug_errno(dev, node_fd, "Device node %s is missing, skipping handling.", devnode);
return 0; /* This is necessarily racey, so ignore missing the device */
}
node_fd = open(devnode, O_PATH|O_CLOEXEC);
if (node_fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
"Failed to open device node '%s'%s: %m",
devnode, ignore ? ", ignoring" : "");
fd = sd_device_open(dev_whole_disk, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
log_device_debug_errno(dev, fd, "Failed to open '%s'%s: %m", whole_disk, ignore ? ", ignoring" : "");
if (!ignore)
_cleanup_close_ int fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(fd);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(fd);
log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, fd,
"Failed to open device node '%s'%s: %m",
node, ignore ? ", ignoring" : "");
fd = open(arg_device, O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0) {
- bool ignore = ERRNO_IS_DEVICE_ABSENT(errno);
+ bool ignore = ERRNO_IS_DEVICE_ABSENT_OR_EMPTY(errno);
log_full_errno(ignore ? LOG_DEBUG : LOG_WARNING, errno,
"Failed to open device node '%s'%s: %m",
arg_device, ignore ? ", ignoring" : "");