diff --git a/proto/depot/cloud/v3/machine.proto b/proto/depot/cloud/v3/machine.proto index 52c407b..2b25d74 100644 --- a/proto/depot/cloud/v3/machine.proto +++ b/proto/depot/cloud/v3/machine.proto @@ -58,6 +58,8 @@ message RegisterMachineResponse { string key = 3; // Store at /etc/ceph/ceph.conf string ceph_conf = 4; + // If the image_spec is set use instead of constructing with the volume_name. + string image_spec = 5; } } diff --git a/src/gen/ts/depot/cloud/v3/machine_pb.ts b/src/gen/ts/depot/cloud/v3/machine_pb.ts index bb562ea..1cf4181 100644 --- a/src/gen/ts/depot/cloud/v3/machine_pb.ts +++ b/src/gen/ts/depot/cloud/v3/machine_pb.ts @@ -377,6 +377,13 @@ export class RegisterMachineResponse_Mount_CephVolume extends Message) { super() proto3.util.initPartial(data, this) @@ -389,6 +396,7 @@ export class RegisterMachineResponse_Mount_CephVolume extends Message): RegisterMachineResponse_Mount_CephVolume { diff --git a/src/tasks/buildkit.ts b/src/tasks/buildkit.ts index 43b038e..5b0334c 100644 --- a/src/tasks/buildkit.ts +++ b/src/tasks/buildkit.ts @@ -220,7 +220,7 @@ keepBytes = ${cacheSizeBytes} await fstrim(mount.path) } await unmountDevice(mount.path) - await unmapBlockDevice(mount.cephVolume.volumeName) + await unmapBlockDevice(mount.cephVolume.volumeName, mount.cephVolume.imageSpec) } else { await unmountDevice(mount.path) } diff --git a/src/tasks/engine.ts b/src/tasks/engine.ts index c72502a..9628a34 100644 --- a/src/tasks/engine.ts +++ b/src/tasks/engine.ts @@ -100,7 +100,7 @@ export async function startEngine(message: RegisterMachineResponse, task: Regist for (const mount of task.mounts) { if (mount.cephVolume) { await unmountDevice(mount.path) - await unmapBlockDevice(mount.cephVolume.volumeName) + await unmapBlockDevice(mount.cephVolume.volumeName, mount.cephVolume.imageSpec) } else { await unmountDevice(mount.path) } diff --git a/src/utils/mounts.ts b/src/utils/mounts.ts index f1448f8..38735da 100644 --- a/src/utils/mounts.ts +++ b/src/utils/mounts.ts @@ -64,13 +64,13 @@ async function attachCeph(cephVolume: RegisterMachineResponse_Mount_CephVolume): } } catch {} - console.log(`Attaching ceph ${volumeName} for ${clientName}`) + // Temporarily continue to use the volumeName until we switch entirely to imageSpec. + const imageSpec = cephVolume.imageSpec ? cephVolume.imageSpec : `rbd/${volumeName}/${volumeName}` + console.log(`Attaching ceph ${imageSpec} for ${clientName}`) + const keyringPath = `/etc/ceph/ceph.${clientName}.keyring` // NOTE: The API sends the device name as `/dev/rbd/rbd/${volumeName}/${volumeName}` // This means we ignore the device name returned from mapping. - - const imageSpec = `rbd/${volumeName}/${volumeName}` - const keyringPath = `/etc/ceph/ceph.${clientName}.keyring` await execa('rbd', ['map', imageSpec, '--name', clientName, '--keyring', keyringPath], {stdio: 'inherit'}) console.log(`Mapped ${imageSpec}`) const device = await getCephDeviceName(cephVolume) @@ -202,8 +202,11 @@ async function writeCephConf(clientName: string, cephConf: string, key: string) await fsp.chmod(keyringPath, 0o600) } -export async function unmapBlockDevice(volumeName: string) { - const imageSpec = `rbd/${volumeName}/${volumeName}` +export async function unmapBlockDevice(volumeName: string, imageSpec?: string) { + // Temporarily continue to use the volumeName until we switch entirely to imageSpec. + if (!imageSpec) { + imageSpec = `rbd/${volumeName}/${volumeName}` + } const {exitCode, stderr} = await execa('rbd', ['unmap', imageSpec], {reject: false, stdio: 'inherit'}) console.log(`Unmapped ${imageSpec} with exit code ${exitCode}`) // 22 means that the device is not mapped a.k.a EINVAL.