dev-replace.c (3c09ec59cdea5b132212d97154d625fd34e436dd) | dev-replace.c (5b316468983dfa9473ff0f1c42e4e30b4c267141) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) STRATO AG 2012. All rights reserved. 4 */ 5 6#include <linux/sched.h> 7#include <linux/bio.h> 8#include <linux/slab.h> --- 7 unchanged lines hidden (view full) --- 16#include "transaction.h" 17#include "print-tree.h" 18#include "volumes.h" 19#include "async-thread.h" 20#include "check-integrity.h" 21#include "rcu-string.h" 22#include "dev-replace.h" 23#include "sysfs.h" | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) STRATO AG 2012. All rights reserved. 4 */ 5 6#include <linux/sched.h> 7#include <linux/bio.h> 8#include <linux/slab.h> --- 7 unchanged lines hidden (view full) --- 16#include "transaction.h" 17#include "print-tree.h" 18#include "volumes.h" 19#include "async-thread.h" 20#include "check-integrity.h" 21#include "rcu-string.h" 22#include "dev-replace.h" 23#include "sysfs.h" |
24#include "zoned.h" |
|
24 25/* 26 * Device replace overview 27 * 28 * [Objective] 29 * To copy all extents (both new and on-disk) from source device to target 30 * device, while still keeping the filesystem read-write. 31 * --- 54 unchanged lines hidden (view full) --- 86 } 87 88 key.objectid = 0; 89 key.type = BTRFS_DEV_REPLACE_KEY; 90 key.offset = 0; 91 ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0); 92 if (ret) { 93no_valid_dev_replace_entry_found: | 25 26/* 27 * Device replace overview 28 * 29 * [Objective] 30 * To copy all extents (both new and on-disk) from source device to target 31 * device, while still keeping the filesystem read-write. 32 * --- 54 unchanged lines hidden (view full) --- 87 } 88 89 key.objectid = 0; 90 key.type = BTRFS_DEV_REPLACE_KEY; 91 key.offset = 0; 92 ret = btrfs_search_slot(NULL, dev_root, &key, path, 0, 0); 93 if (ret) { 94no_valid_dev_replace_entry_found: |
95 /* 96 * We don't have a replace item or it's corrupted. If there is 97 * a replace target, fail the mount. 98 */ 99 if (btrfs_find_device(fs_info->fs_devices, 100 BTRFS_DEV_REPLACE_DEVID, NULL, NULL)) { 101 btrfs_err(fs_info, 102 "found replace target device without a valid replace item"); 103 ret = -EUCLEAN; 104 goto out; 105 } |
|
94 ret = 0; 95 dev_replace->replace_state = 96 BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED; 97 dev_replace->cont_reading_from_srcdev_mode = 98 BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS; 99 dev_replace->time_started = 0; 100 dev_replace->time_stopped = 0; 101 atomic64_set(&dev_replace->num_write_errors, 0); --- 36 unchanged lines hidden (view full) --- 138 dev_replace->cursor_right = btrfs_dev_replace_cursor_right(eb, ptr); 139 dev_replace->is_valid = 1; 140 141 dev_replace->item_needs_writeback = 0; 142 switch (dev_replace->replace_state) { 143 case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED: 144 case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED: 145 case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED: | 106 ret = 0; 107 dev_replace->replace_state = 108 BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED; 109 dev_replace->cont_reading_from_srcdev_mode = 110 BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS; 111 dev_replace->time_started = 0; 112 dev_replace->time_stopped = 0; 113 atomic64_set(&dev_replace->num_write_errors, 0); --- 36 unchanged lines hidden (view full) --- 150 dev_replace->cursor_right = btrfs_dev_replace_cursor_right(eb, ptr); 151 dev_replace->is_valid = 1; 152 153 dev_replace->item_needs_writeback = 0; 154 switch (dev_replace->replace_state) { 155 case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED: 156 case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED: 157 case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED: |
146 dev_replace->srcdev = NULL; 147 dev_replace->tgtdev = NULL; | 158 /* 159 * We don't have an active replace item but if there is a 160 * replace target, fail the mount. 161 */ 162 if (btrfs_find_device(fs_info->fs_devices, 163 BTRFS_DEV_REPLACE_DEVID, NULL, NULL)) { 164 btrfs_err(fs_info, 165 "replace devid present without an active replace item"); 166 ret = -EUCLEAN; 167 } else { 168 dev_replace->srcdev = NULL; 169 dev_replace->tgtdev = NULL; 170 } |
148 break; 149 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED: 150 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED: 151 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, | 171 break; 172 case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED: 173 case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED: 174 dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, |
152 src_devid, NULL, NULL, true); | 175 src_devid, NULL, NULL); |
153 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, 154 BTRFS_DEV_REPLACE_DEVID, | 176 dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, 177 BTRFS_DEV_REPLACE_DEVID, |
155 NULL, NULL, true); | 178 NULL, NULL); |
156 /* 157 * allow 'btrfs dev replace_cancel' if src/tgt device is 158 * missing 159 */ 160 if (!dev_replace->srcdev && 161 !btrfs_test_opt(fs_info, DEGRADED)) { 162 ret = -EIO; 163 btrfs_warn(fs_info, --- 122 unchanged lines hidden (view full) --- 286 device->bdev = bdev; 287 set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); 288 set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); 289 device->mode = FMODE_EXCL; 290 device->dev_stats_valid = 1; 291 set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); 292 device->fs_devices = fs_info->fs_devices; 293 | 179 /* 180 * allow 'btrfs dev replace_cancel' if src/tgt device is 181 * missing 182 */ 183 if (!dev_replace->srcdev && 184 !btrfs_test_opt(fs_info, DEGRADED)) { 185 ret = -EIO; 186 btrfs_warn(fs_info, --- 122 unchanged lines hidden (view full) --- 309 device->bdev = bdev; 310 set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); 311 set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); 312 device->mode = FMODE_EXCL; 313 device->dev_stats_valid = 1; 314 set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); 315 device->fs_devices = fs_info->fs_devices; 316 |
317 ret = btrfs_get_dev_zone_info(device); 318 if (ret) 319 goto error; 320 |
|
294 mutex_lock(&fs_info->fs_devices->device_list_mutex); 295 list_add(&device->dev_list, &fs_info->fs_devices->devices); 296 fs_info->fs_devices->num_devices++; 297 fs_info->fs_devices->open_devices++; 298 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 299 300 *device_out = device; 301 return 0; --- 818 unchanged lines hidden --- | 321 mutex_lock(&fs_info->fs_devices->device_list_mutex); 322 list_add(&device->dev_list, &fs_info->fs_devices->devices); 323 fs_info->fs_devices->num_devices++; 324 fs_info->fs_devices->open_devices++; 325 mutex_unlock(&fs_info->fs_devices->device_list_mutex); 326 327 *device_out = device; 328 return 0; --- 818 unchanged lines hidden --- |