This is an additon to commit 1fea38856a ("Remove v1.10 migrator")
aka PR #38265. Since that one, CreateRWLayerByGraphID() is not
used anywhere, so let's drop it.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit b4e9b507655e7dbdfb44d4ee284dcd658b859b3f)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -3,7 +3,6 @@ package layer // import "github.com/docker/docker/layer" |
| 3 | 3 |
import ( |
| 4 | 4 |
"compress/gzip" |
| 5 | 5 |
"errors" |
| 6 |
- "fmt" |
|
| 7 | 6 |
"io" |
| 8 | 7 |
"os" |
| 9 | 8 |
|
| ... | ... |
@@ -13,64 +12,6 @@ import ( |
| 13 | 13 |
"github.com/vbatts/tar-split/tar/storage" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
-// CreateRWLayerByGraphID creates a RWLayer in the layer store using |
|
| 17 |
-// the provided name with the given graphID. To get the RWLayer |
|
| 18 |
-// after migration the layer may be retrieved by the given name. |
|
| 19 |
-func (ls *layerStore) CreateRWLayerByGraphID(name, graphID string, parent ChainID) (err error) {
|
|
| 20 |
- ls.mountL.Lock() |
|
| 21 |
- m := ls.mounts[name] |
|
| 22 |
- ls.mountL.Unlock() |
|
| 23 |
- if m != nil {
|
|
| 24 |
- if m.parent.chainID != parent {
|
|
| 25 |
- return errors.New("name conflict, mismatched parent")
|
|
| 26 |
- } |
|
| 27 |
- if m.mountID != graphID {
|
|
| 28 |
- return errors.New("mount already exists")
|
|
| 29 |
- } |
|
| 30 |
- |
|
| 31 |
- return nil |
|
| 32 |
- } |
|
| 33 |
- |
|
| 34 |
- if !ls.driver.Exists(graphID) {
|
|
| 35 |
- return fmt.Errorf("graph ID does not exist: %q", graphID)
|
|
| 36 |
- } |
|
| 37 |
- |
|
| 38 |
- var p *roLayer |
|
| 39 |
- if string(parent) != "" {
|
|
| 40 |
- p = ls.get(parent) |
|
| 41 |
- if p == nil {
|
|
| 42 |
- return ErrLayerDoesNotExist |
|
| 43 |
- } |
|
| 44 |
- |
|
| 45 |
- // Release parent chain if error |
|
| 46 |
- defer func() {
|
|
| 47 |
- if err != nil {
|
|
| 48 |
- ls.layerL.Lock() |
|
| 49 |
- ls.releaseLayer(p) |
|
| 50 |
- ls.layerL.Unlock() |
|
| 51 |
- } |
|
| 52 |
- }() |
|
| 53 |
- } |
|
| 54 |
- |
|
| 55 |
- // TODO: Ensure graphID has correct parent |
|
| 56 |
- |
|
| 57 |
- m = &mountedLayer{
|
|
| 58 |
- name: name, |
|
| 59 |
- parent: p, |
|
| 60 |
- mountID: graphID, |
|
| 61 |
- layerStore: ls, |
|
| 62 |
- references: map[RWLayer]*referencedRWLayer{},
|
|
| 63 |
- } |
|
| 64 |
- |
|
| 65 |
- // Check for existing init layer |
|
| 66 |
- initID := fmt.Sprintf("%s-init", graphID)
|
|
| 67 |
- if ls.driver.Exists(initID) {
|
|
| 68 |
- m.initID = initID |
|
| 69 |
- } |
|
| 70 |
- |
|
| 71 |
- return ls.saveMount(m) |
|
| 72 |
-} |
|
| 73 |
- |
|
| 74 | 16 |
func (ls *layerStore) ChecksumForGraphID(id, parent, oldTarDataPath, newTarDataPath string) (diffID DiffID, size int64, err error) {
|
| 75 | 17 |
defer func() {
|
| 76 | 18 |
if err != nil {
|
| ... | ... |
@@ -3,7 +3,6 @@ package layer // import "github.com/docker/docker/layer" |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"compress/gzip" |
| 6 |
- "fmt" |
|
| 7 | 6 |
"io" |
| 8 | 7 |
"io/ioutil" |
| 9 | 8 |
"os" |
| ... | ... |
@@ -12,7 +11,6 @@ import ( |
| 12 | 12 |
"testing" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/docker/docker/daemon/graphdriver" |
| 15 |
- "github.com/docker/docker/pkg/archive" |
|
| 16 | 15 |
"github.com/docker/docker/pkg/stringid" |
| 17 | 16 |
"github.com/vbatts/tar-split/tar/asm" |
| 18 | 17 |
"github.com/vbatts/tar-split/tar/storage" |
| ... | ... |
@@ -269,161 +267,3 @@ func TestLayerMigrationNoTarsplit(t *testing.T) {
|
| 269 | 269 |
|
| 270 | 270 |
assertMetadata(t, metadata, createMetadata(layer2a)) |
| 271 | 271 |
} |
| 272 |
- |
|
| 273 |
-func TestMountMigration(t *testing.T) {
|
|
| 274 |
- // TODO Windows: Figure out why this is failing (obvious - paths... needs porting) |
|
| 275 |
- if runtime.GOOS == "windows" {
|
|
| 276 |
- t.Skip("Failing on Windows")
|
|
| 277 |
- } |
|
| 278 |
- ls, _, cleanup := newTestStore(t) |
|
| 279 |
- defer cleanup() |
|
| 280 |
- |
|
| 281 |
- baseFiles := []FileApplier{
|
|
| 282 |
- newTestFile("/root/.bashrc", []byte("# Boring configuration"), 0644),
|
|
| 283 |
- newTestFile("/etc/profile", []byte("# Base configuration"), 0644),
|
|
| 284 |
- } |
|
| 285 |
- initFiles := []FileApplier{
|
|
| 286 |
- newTestFile("/etc/hosts", []byte{}, 0644),
|
|
| 287 |
- newTestFile("/etc/resolv.conf", []byte{}, 0644),
|
|
| 288 |
- } |
|
| 289 |
- mountFiles := []FileApplier{
|
|
| 290 |
- newTestFile("/etc/hosts", []byte("localhost 127.0.0.1"), 0644),
|
|
| 291 |
- newTestFile("/root/.bashrc", []byte("# Updated configuration"), 0644),
|
|
| 292 |
- newTestFile("/root/testfile1.txt", []byte("nothing valuable"), 0644),
|
|
| 293 |
- } |
|
| 294 |
- |
|
| 295 |
- initTar, err := tarFromFiles(initFiles...) |
|
| 296 |
- if err != nil {
|
|
| 297 |
- t.Fatal(err) |
|
| 298 |
- } |
|
| 299 |
- |
|
| 300 |
- mountTar, err := tarFromFiles(mountFiles...) |
|
| 301 |
- if err != nil {
|
|
| 302 |
- t.Fatal(err) |
|
| 303 |
- } |
|
| 304 |
- |
|
| 305 |
- graph := ls.(*layerStore).driver |
|
| 306 |
- |
|
| 307 |
- layer1, err := createLayer(ls, "", initWithFiles(baseFiles...)) |
|
| 308 |
- if err != nil {
|
|
| 309 |
- t.Fatal(err) |
|
| 310 |
- } |
|
| 311 |
- |
|
| 312 |
- graphID1 := layer1.(*referencedCacheLayer).cacheID |
|
| 313 |
- |
|
| 314 |
- containerID := stringid.GenerateRandomID() |
|
| 315 |
- containerInit := fmt.Sprintf("%s-init", containerID)
|
|
| 316 |
- |
|
| 317 |
- if err := graph.Create(containerInit, graphID1, nil); err != nil {
|
|
| 318 |
- t.Fatal(err) |
|
| 319 |
- } |
|
| 320 |
- if _, err := graph.ApplyDiff(containerInit, graphID1, bytes.NewReader(initTar)); err != nil {
|
|
| 321 |
- t.Fatal(err) |
|
| 322 |
- } |
|
| 323 |
- |
|
| 324 |
- if err := graph.Create(containerID, containerInit, nil); err != nil {
|
|
| 325 |
- t.Fatal(err) |
|
| 326 |
- } |
|
| 327 |
- if _, err := graph.ApplyDiff(containerID, containerInit, bytes.NewReader(mountTar)); err != nil {
|
|
| 328 |
- t.Fatal(err) |
|
| 329 |
- } |
|
| 330 |
- |
|
| 331 |
- if err := ls.(*layerStore).CreateRWLayerByGraphID("migration-mount", containerID, layer1.ChainID()); err != nil {
|
|
| 332 |
- t.Fatal(err) |
|
| 333 |
- } |
|
| 334 |
- |
|
| 335 |
- rwLayer1, err := ls.GetRWLayer("migration-mount")
|
|
| 336 |
- if err != nil {
|
|
| 337 |
- t.Fatal(err) |
|
| 338 |
- } |
|
| 339 |
- |
|
| 340 |
- if _, err := rwLayer1.Mount(""); err != nil {
|
|
| 341 |
- t.Fatal(err) |
|
| 342 |
- } |
|
| 343 |
- |
|
| 344 |
- changes, err := rwLayer1.Changes() |
|
| 345 |
- if err != nil {
|
|
| 346 |
- t.Fatal(err) |
|
| 347 |
- } |
|
| 348 |
- |
|
| 349 |
- if expected := 5; len(changes) != expected {
|
|
| 350 |
- t.Logf("Changes %#v", changes)
|
|
| 351 |
- t.Fatalf("Wrong number of changes %d, expected %d", len(changes), expected)
|
|
| 352 |
- } |
|
| 353 |
- |
|
| 354 |
- sortChanges(changes) |
|
| 355 |
- |
|
| 356 |
- assertChange(t, changes[0], archive.Change{
|
|
| 357 |
- Path: "/etc", |
|
| 358 |
- Kind: archive.ChangeModify, |
|
| 359 |
- }) |
|
| 360 |
- assertChange(t, changes[1], archive.Change{
|
|
| 361 |
- Path: "/etc/hosts", |
|
| 362 |
- Kind: archive.ChangeModify, |
|
| 363 |
- }) |
|
| 364 |
- assertChange(t, changes[2], archive.Change{
|
|
| 365 |
- Path: "/root", |
|
| 366 |
- Kind: archive.ChangeModify, |
|
| 367 |
- }) |
|
| 368 |
- assertChange(t, changes[3], archive.Change{
|
|
| 369 |
- Path: "/root/.bashrc", |
|
| 370 |
- Kind: archive.ChangeModify, |
|
| 371 |
- }) |
|
| 372 |
- assertChange(t, changes[4], archive.Change{
|
|
| 373 |
- Path: "/root/testfile1.txt", |
|
| 374 |
- Kind: archive.ChangeAdd, |
|
| 375 |
- }) |
|
| 376 |
- |
|
| 377 |
- if _, err := ls.CreateRWLayer("migration-mount", layer1.ChainID(), nil); err == nil {
|
|
| 378 |
- t.Fatal("Expected error creating mount with same name")
|
|
| 379 |
- } else if err != ErrMountNameConflict {
|
|
| 380 |
- t.Fatal(err) |
|
| 381 |
- } |
|
| 382 |
- |
|
| 383 |
- rwLayer2, err := ls.GetRWLayer("migration-mount")
|
|
| 384 |
- if err != nil {
|
|
| 385 |
- t.Fatal(err) |
|
| 386 |
- } |
|
| 387 |
- |
|
| 388 |
- if getMountLayer(rwLayer1) != getMountLayer(rwLayer2) {
|
|
| 389 |
- t.Fatal("Expected same layer from get with same name as from migrate")
|
|
| 390 |
- } |
|
| 391 |
- |
|
| 392 |
- if _, err := rwLayer2.Mount(""); err != nil {
|
|
| 393 |
- t.Fatal(err) |
|
| 394 |
- } |
|
| 395 |
- |
|
| 396 |
- if _, err := rwLayer2.Mount(""); err != nil {
|
|
| 397 |
- t.Fatal(err) |
|
| 398 |
- } |
|
| 399 |
- |
|
| 400 |
- if metadata, err := ls.Release(layer1); err != nil {
|
|
| 401 |
- t.Fatal(err) |
|
| 402 |
- } else if len(metadata) > 0 {
|
|
| 403 |
- t.Fatalf("Expected no layers to be deleted, deleted %#v", metadata)
|
|
| 404 |
- } |
|
| 405 |
- |
|
| 406 |
- if err := rwLayer1.Unmount(); err != nil {
|
|
| 407 |
- t.Fatal(err) |
|
| 408 |
- } |
|
| 409 |
- |
|
| 410 |
- if _, err := ls.ReleaseRWLayer(rwLayer1); err != nil {
|
|
| 411 |
- t.Fatal(err) |
|
| 412 |
- } |
|
| 413 |
- |
|
| 414 |
- if err := rwLayer2.Unmount(); err != nil {
|
|
| 415 |
- t.Fatal(err) |
|
| 416 |
- } |
|
| 417 |
- if err := rwLayer2.Unmount(); err != nil {
|
|
| 418 |
- t.Fatal(err) |
|
| 419 |
- } |
|
| 420 |
- metadata, err := ls.ReleaseRWLayer(rwLayer2) |
|
| 421 |
- if err != nil {
|
|
| 422 |
- t.Fatal(err) |
|
| 423 |
- } |
|
| 424 |
- if len(metadata) == 0 {
|
|
| 425 |
- t.Fatal("Expected base layer to be deleted when deleting mount")
|
|
| 426 |
- } |
|
| 427 |
- |
|
| 428 |
- assertMetadata(t, metadata, createMetadata(layer1)) |
|
| 429 |
-} |