Skip to main content

Importing a raw disk image into an atlas-native volume

POST /api/atlas/v1/volumes/{id}/import queues a job that streams a disk image from an HTTP(S) server into an existing block volume, then proves the volume holds it. Raw bytes are written as they arrive. A qcow2 image is converted with qemu-img convert -O raw first; sha256 is the hash of the file at url (the qcow2, or the raw image). It is the Atlas end of a VMware exit: Scout scores the estate, h2kvm repairs and converts the guest, and this job lands the disk.

Ceph RBD volumes are written with librbd (rbd:pool/image). NFS, ZFS and other backends are not. VMDK is not read. See Limits.

Turn it on​

The gateway fetches whatever host the request names, so the feature is off until you list the hosts it may fetch from:

ATLAS_IMPORT_ALLOWED_HOSTS=images.internal,10.0.0.5 # comma-separated names or IP literals

A request for any other host is refused with 403. URLs with embedded credentials are refused, because the job record stores the URL; serve the image from a host that does not need them, and pin it by checksum. Redirects are never followed, so an allowed host cannot send the gateway somewhere else.

Request​

curl -X POST "$ATLAS/api/atlas/v1/volumes/$VOLUME/import" \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{
"url": "http://10.0.0.5:8099/web-prod-01.raw",
"sha256": "<64 hex characters, the SHA-256 of the whole image>",
"size_bytes": 42949672960
}'
FieldMeaning
urlhttp or https URL of the image.
sha256SHA-256 of the file at url. Required. For qcow2 this is the qcow2 file, not the raw disk.
formatraw (default) or qcow2.
size_bytesOptional image length, checked against what the server sends and against the volume size.
resume_from_jobOptional id of an earlier, finished import job for the same volume whose progress this one continues.

The volume must already exist, be a block volume on a backend the gateway has a driver for (atlas-native or Ceph RBD), and be large enough. A Ceph volume's id must be rbd:pool/image. The caller needs the operator role and access to the volume's tenant. The response is 202 with a job id; progress, the result and cancel are the ordinary job API (GET /jobs/{id}, POST /jobs/{id}/cancel).

How it works​

  1. The image is read in 4 MiB blocks. Each block is hashed and, unless it is all zeros, written to the volume. A volume reads never-written bytes as zeros, so a sparse image stays sparse and a mostly empty 40 GiB disk transfers quickly. The count of skipped bytes is in the result.
  2. Every 64 MiB the job records bytes_done and the percentage on its row.
  3. When the stream ends, its SHA-256 is compared with the one you gave. A mismatch fails the job.
  4. The volume is then read back and hashed, and that hash must match too. This is the check that the bytes on the volume, not only the bytes that crossed the wire, are the image.

The result of a successful job:

{ "volume_id": "vol_native_...", "bytes": 42949672960, "sha256": "...", "verified": true,
"zero_bytes_skipped": 31457280000, "resumed_from": 0 }

Resuming​

A job that fails part-way is retried (five times by default, ATLAS_IMPORT_MAX_RETRIES), and each retry continues from the recorded bytes_done instead of starting over. To start a new job after the retries run out, or after a gateway restart interrupted one, pass the old job as resume_from_job.

On resume the bytes already on the volume are read back and hashed again before new data is written, so a volume that was damaged in the meantime, or a source that changed, fails the final checksum instead of producing a silently wrong disk. If the server does not support Range requests, it is streamed from the start and the part already written is skipped.

A checksum mismatch throws the recorded progress away, because some of what was written may be wrong; the next attempt starts from zero.

Limits​

  • Raw and qcow2. qcow2 needs qemu-img on the gateway (QEMU_IMG overrides the binary). The job checks the qcow2 checksum, converts to raw, then checks the volume against the raw bytes. VMDK and other formats are refused.
  • atlas-native and Ceph RBD. RBD reads and writes go through the python rbd module (ATLAS_RBD_PYTHON, CEPH_CONF). The volume id must be rbd:pool/image. NFS and ZFS are not supported.
  • Imports run beside the job worker, two at a time. An import never holds up other jobs, and a third waits as queued until a slot is free (ATLAS_IMPORT_CONCURRENCY, default 2). An import can be cancelled while it runs or waits. Its timeout is a day (ATLAS_IMPORT_TIMEOUT_SECS) instead of two hours. The slots are per gateway process, not shared between replicas.
  • A failed import leaves the volume as it is. That is what makes resuming possible. Delete the volume to discard the partial data. Nothing stops two imports into the same volume at once.
  • Single stream. One HTTP connection, in order. There is no parallel or ranged transfer.
  • The host check is by name. It does not defend against a name that is later pointed at another address. Use IP literals or hosts you control.

Testing​

cargo test -p atlas-jobs image_import covers the streaming algorithm (sparse blocks, resume, damaged resume, both checksum failures, a short or oversized image, progress marks) and the HTTP source (range and non-range servers, refused redirects). cargo test -p atlas-gateway --test image_import runs the route and the job end to end against the fixture native driver and a local HTTP server. It has not been run against a real atlas-native cluster or a multi-gigabyte image.