• Anand Jain's avatar
    btrfs: sysfs, add devid/dev_state kobject and device attributes · 668e48af
    Anand Jain authored
    New sysfs attributes that track the filesystem status of devices, stored
    in the per-filesystem directory in /sys/fs/btrfs/FSID/devinfo . There's
    a directory for each device, with name corresponding to the numerical
    device id.
    
      in_fs_metadata    - device is in the list of fs metadata
      missing           - device is missing (no device node or block device)
      replace_target    - device is target of replace
      writeable         - writes from fs are allowed
    
    These attributes reflect the state of the device::dev_state and created
    at mount time.
    
    Sample output:
      $ pwd
       /sys/fs/btrfs/6e1961f1-5918-4ecc-a22f-948897b409f7/devinfo/1/
      $ ls
        in_fs_metadata  missing  replace_target  writeable
      $ cat missing
        0
    
    The output from these attributes are 0 or 1. 0 indicates unset and 1
    indicates set.  These attributes are readonly.
    
    It is observed that the device delete thread and sysfs read thread will
    not race because the delete thread calls sysfs kobject_put() which in
    turn waits for existing sysfs read to complete.
    
    Note for device replace devid swap:
    
    During the replace the target device temporarily assumes devid 0 before
    assigning the devid of the soruce device.
    
    In btrfs_dev_replace_finishing() we remove source sysfs devid using the
    function btrfs_sysfs_remove_devices_attr(), so after that call
    kobject_rename() to update the devid in the sysfs.  This adds and calls
    btrfs_sysfs_update_devid() helper function to update the device id.
    Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    [ update changelog ]
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    668e48af
dev-replace.c 31.3 KB