Fix rbd trash mv: image belongs to a group (Ceph Squid, Tentacle)
Since Squid 19.2.3 and Tentacle 20.2.0, RBD images in a group cannot be moved to trash. Run rbd group image remove, then rbd trash mv again.
rbd: error: image belongs to a groupRemove the image from the group and try again.When rbd trash mv stops with these two lines, the image is a member of an RBD group. Since Squid 19.2.3 and Tentacle 20.2.0, images in a group cannot be moved to the trash, and rbd trash mv refuses for the same reason rbd rm does. Take the image out of the group with rbd group image remove, then move it again. The block above is not captured output; it is the text in the rbd tool source ([Trash.cc L100-L104, v20.2.4](https://github.com/ceph/ceph/blob/v20.2.4/src/tools/rbd/action/Trash.cc#L100-L104); the same lines exist in v19.2.3).
[1] Check when it changed. It is not Tentacle-only.
| Version | Source |
|---|---|
| Squid 19.2.3 | Squid release notes, 19.2.3 RBD entry; changelog "squid: librbd: disallow “rbd trash mv” if image is in a group (pr#62968)" |
| Tentacle 20.2.0 | Tentacle release notes, 20.2.0 RBD entry: "The rbd trash mv command now behaves the same way as rbd rm in this scenario." |
In the source, librbd's move-to-trash code has a group check in v19.2.3 and v20.2.4 that v19.2.0 did not have. For an image in a group it logs image is in a group - not moving to trash and returns -EMLINK ([librbd/api/Trash.cc L220-L226, v20.2.4](https://github.com/ceph/ceph/blob/v20.2.4/src/librbd/api/Trash.cc#L220-L226)). The only exception is when live migration uses the trash.
[2] If you searched for Too many links, it is the same cause. The standard description of EMLINK, which the library returns, is "Too many links" (errno(3)). The rbd tool in v19.2.3 and v20.2.4 turns EMLINK into the group message above, so output of the form rbd: deferred delete error: … with that description could not be confirmed. Programs that call librbd directly get EMLINK, and the Python binding raises rbd.ImageMemberOfGroup ("RBD image is member of group …") ([rbd.pyx L275-L278 · L330](https://github.com/ceph/ceph/blob/v20.2.4/src/pybind/rbd/rbd.pyx#L275-L278)).
[3] Find which group holds the image. Use the group commands from the rbd man page.
$ rbd group ls mypool$ rbd group image list mypool/mygroupWith several groups, run the second command per group until the image shows up. Also check for group snapshots.
$ rbd group snap list mypool/mygroupWhat happens to existing group snapshots when an image leaves the group could not be confirmed. If you plan to roll back to a group snapshot, stop before removing the image.
[4] Remove the image from the group.
$ rbd group image remove mypool/mygroup mypool/myimageTo undo it, run rbd group image add mypool/mygroup mypool/myimage. Groups exist so several images can be snapshotted together; check first that whatever created the group (a backup or replication tool, for example) no longer needs this image.
[5] Before moving it to the trash, check whether the pool has a trash purge schedule. As the rbd man page example shows, the expiration time of rbd trash mv (--expires-at) defaults to now. rbd trash purge removes all expired images, so on a pool with a trash purge schedule the image can be permanently deleted at the next scheduled run.
$ rbd trash purge schedule list -p mypool$ rbd trash purge schedule status -p mypoolIf there is a schedule, or you need the image kept until you have checked, push the expiration out when you move it.
$ rbd trash mv mypool/myimage --expires-at "tomorrow"$ rbd trash ls mypoolUntil it is purged, get the image ID from rbd trash ls and bring it back with rbd trash restore mypool/<image-id>. Once a purge has removed it, this command cannot undo it.
[6] Group images that were trashed before the upgrade fail when you delete them. The source comment calls this path "this is to handle any image that was trashed earlier", and rbd trash rm prints the same two lines ([Trash.cc L171-L177](https://github.com/ceph/ceph/blob/v20.2.4/src/tools/rbd/action/Trash.cc#L171-L177)). rbd trash purge reports it in one combined message (L463-L470).
rbd: some expired images could not be removedEnsure that they are closed/unmapped, do not have snapshots (including trashed snapshots with linked clones), are not in a group and were moved to the trash successfully.In that case restore the image, remove it from the group, and trash it again.
$ rbd trash ls mypool$ rbd trash restore mypool/<image-id>$ rbd group image remove mypool/mygroup mypool/myimage$ rbd trash mv mypool/myimagerbd rm also refuses a group image and even names the group ([Remove.cc L118-L145](https://github.com/ceph/ceph/blob/v20.2.4/src/tools/rbd/action/Remove.cc#L118-L145)). But it deletes any image that is not in a group right away, so do not run rbd rm just to learn the group name.
For another RBD change after the upgrade, see rbd map possible ms_mode mismatch.