title: How do I replace a device in a zfs pool that is simultaneously attached and detached?
body: <p>I've got a mirrored zfs pool that has a device that needs to be replaced. I've taken the old device offline:</p>
  
  <pre><code>$ sudo zpool status
    pool: tank
   state: DEGRADED
  status: One or more devices has been taken offline by the administrator.
          Sufficient replicas exist for the pool to continue functioning in a
          degraded state.
  action: Online the device using 'zpool online' or replace the device with
          'zpool replace'.
    scan: scrub repaired 0 in 7h20m with 0 errors on Mon Feb 15 23:41:23 2016
  config:
  
          NAME                                   STATE     READ WRITE CKSUM
          tank                                   DEGRADED     0     0     0
            mirror-0                             DEGRADED     0     0     0
              16381379971886761370               OFFLINE      0     0     0  was /dev/disk/by-id/scsi-35000cca250cedea5
              ST4000DM000-1F2168_Z303WH86-part1  ONLINE       0     0     0
  </code></pre>
  
  <p>I try to replace the offlined device:</p>
  
  <pre><code>$ sudo zpool replace tank 16381379971886761370 /dev/mapper/HGST_HDN724040ALE640_PK1334PEH1R1JS
  invalid vdev specification
  use '-f' to override the following errors:
  /dev/mapper/HGST_HDN724040ALE640_PK1334PEH1R1JS is part of active pool 'tank'
  </code></pre>
  
  <p>Which suggests that it's already part of a pool, but when I try to detach it from the pool:</p>
  
  <pre><code>$ sudo zpool detach tank /dev/mapper/HGST_HDN724040ALE640_PK1334PEH1R1JS
  cannot detach /dev/mapper/HGST_HDN724040ALE640_PK1334PEH1R1JS: no such device in pool
  </code></pre>
  
  <p>It looks like it's not actually part of the pool. This seems like the device is part of the pool and /not/ part of the pool at the same time. Any ideas how I might add the device to the 'tank' pool?</p>