#include <linux/semaphore.h>
 #include <linux/uuid.h>
 #include <linux/list_sort.h>
+#include <linux/namei.h>
 #include "misc.h"
 #include "ctree.h"
 #include "extent_map.h"
 /*
  * Function to update ctime/mtime for a given device path.
  * Mainly used for ctime/mtime based probe like libblkid.
+ *
+ * We don't care about errors here, this is just to be kind to userspace.
  */
-static void update_dev_time(struct block_device *bdev)
+static void update_dev_time(const char *device_path)
 {
-       struct inode *inode = bdev->bd_inode;
+       struct path path;
        struct timespec64 now;
+       int ret;
 
-       /* Shouldn't happen but just in case. */
-       if (!inode)
+       ret = kern_path(device_path, LOOKUP_FOLLOW, &path);
+       if (ret)
                return;
 
-       now = current_time(inode);
-       generic_update_time(inode, &now, S_MTIME | S_CTIME);
+       now = current_time(d_inode(path.dentry));
+       inode_update_time(d_inode(path.dentry), &now, S_MTIME | S_CTIME);
+       path_put(&path);
 }
 
 static int btrfs_rm_dev_item(struct btrfs_device *device)
        btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
 
        /* Update ctime/mtime for device path for libblkid */
-       update_dev_time(bdev);
+       update_dev_time(device_path);
 }
 
 int btrfs_rm_device(struct btrfs_fs_info *fs_info,
        btrfs_forget_devices(device_path);
 
        /* Update ctime/mtime for blkid or udev */
-       update_dev_time(bdev);
+       update_dev_time(device_path);
 
        return ret;