Skip to contentSkip to conversation

wic: fallback to dd, if sparse_copy does not work

PATCH In review Dogukan Ergun 4 participants 4 messages Nov 16, 2017 – Nov 22, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wic: fallback to dd, if sparse_copy does not work

Docker's aufs filesystem doesn't support file ioctl operations like FIGETBSZ or FIEMAP.
Sparse_copy operation will fail if those ioctls are not supported. If sparse_copy fails while generating wic images, fallback to dd for copying filesystems on final image.

---
 scripts/lib/wic/plugins/imager/direct.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +8 -2
index da1c061..70f93ee 100644
@@ -577,8 +577,14 @@ class PartitionedImage():
         for part in self.partitions:
             source = part.source_file
             if source:
-                # install source_file contents into a partition
-                sparse_copy(source, self.path, seek=part.start * self.sector_size)
+                try:
+                    # install source_file contents into a partition
+                    sparse_copy(source, self.path, seek=part.start * self.sector_size)
+                except:
+                    # Sparse_copy failed, fallback to dd method
+                    dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \
+                        (source, self.path, self.sector_size, part.start, part.size_sec)
+                    exec_cmd(dd_cmd)
 
                 logger.debug("Installed %s in partition %d, sectors %d-%d, "
                              "size %d sectors", source, part.num, part.start,
Signature · 1 line
2.7.4
#1 lore raw

Would it be neater to change sparse_copy itself so that it does the fallback, not every caller?

Ross

Quoted 50 lines · Dogukan Ergun

Docker's aufs filesystem doesn't support file ioctl operations like FIGETBSZ
or FIEMAP.
Sparse_copy operation will fail if those ioctls are not supported. If sparse_copy fails while generating wic images, fallback to dd for copying
filesystems on final image.

---
 scripts/lib/wic/plugins/imager/direct.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +7 -2
index da1c061..70f93ee 100644
@@ -577,8 +577,14 @@ class PartitionedImage():
         for part in self.partitions:
             source = part.source_file
             if source:
-                # install source_file contents into a partition
-                sparse_copy(source, self.path, seek=part.start *
 self.sector_size)
+                try:
+                    # install source_file contents into a partition
+                    sparse_copy(source, self.path, seek=part.start *
 self.sector_size)
+                except:
+                    # Sparse_copy failed, fallback to dd method
+                    dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d
 conv=notrunc" % \
+                        (source, self.path, self.sector_size, part.start,

part.size_sec)
+ exec_cmd(dd_cmd)

logger.debug("Installed %s in partition %d, sectors
%d-%d, "
"size %d sectors", source, part.num,
part.start,
--
2.7.4

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

#2 lore raw
In reply to Dogukan Ergun
Quoted 16 lines · Dogukan Ergun

Docker's aufs filesystem doesn't support file ioctl operations like FIGETBSZ or FIEMAP.
Sparse_copy operation will fail if those ioctls are not supported. If sparse_copy fails while generating wic images, fallback to dd for copying filesystems on final image.

---
  scripts/lib/wic/plugins/imager/direct.py | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +0 -0
index da1c061..70f93ee 100644

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 583

Quoted 9 lines
scripts/lib/wic/plugins/imager/direct.py +4 -2
@@ -577,8 +577,14 @@ class PartitionedImage():
          for part in self.partitions:
              source = part.source_file
              if source:
-                # install source_file contents into a partition
-                sparse_copy(source, self.path, seek=part.start * self.sector_size)
+                try:
+                    # install source_file contents into a partition
+                    sparse_copy(source, self.path, seek=part.start * self.sector_size)
+                except:

I guess a failing sparse_copy() would raise an IOError. Shouldn't you limit the except to catching only those?

// Martin

Quoted 8 lines
scripts/lib/wic/plugins/imager/direct.py +4 -0
+                    # Sparse_copy failed, fallback to dd method
+                    dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \
+                        (source, self.path, self.sector_size, part.start, part.size_sec)
+                    exec_cmd(dd_cmd)
 
                  logger.debug("Installed %s in partition %d, sectors %d-%d, "
                               "size %d sectors", source, part.num, part.start,
#3 lore raw
In reply to Dogukan Ergun
Quoted 6 lines · Dogukan Ergun

Docker's aufs filesystem doesn't support file ioctl operations like FIGETBSZ or FIEMAP.
Sparse_copy operation will fail if those ioctls are not supported. If sparse_copy fails while generating wic images, fallback to dd for copying filesystems on final image.

You can make sparse_copy to use SEEK_HOLE / SEEK_DATA instead of FIEMAP. This can be done by using 'api' parameter. If AUFS supports it this there is no need to fall back to using dd.

Quoted 10 lines
---
 scripts/lib/wic/plugins/imager/direct.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
scripts/lib/wic/plugins/imager/direct.py +0 -0
index da1c061..70f93ee 100644

scripts/lib/wic/plugins/imager/direct.py class PartitionedImage(): · line 583

Quoted 9 lines
scripts/lib/wic/plugins/imager/direct.py +4 -2
@@ -577,8 +577,14 @@ class PartitionedImage():
         for part in self.partitions:
             source = part.source_file
             if source:
-                # install source_file contents into a partition
-                sparse_copy(source, self.path, seek=part.start * self.sector_size)
+                try:
+                    # install source_file contents into a partition
+                    sparse_copy(source, self.path, seek=part.start * self.sector_size)
+                except:

sparse_copy raises ErrorNotSupp if some ioctl is not supported. Please, catch this particular exception instead of any exception.

Quoted 15 lines
scripts/lib/wic/plugins/imager/direct.py +4 -0
+                    # Sparse_copy failed, fallback to dd method
+                    dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \
+                        (source, self.path, self.sector_size, part.start, part.size_sec)
+                    exec_cmd(dd_cmd)
 
                 logger.debug("Installed %s in partition %d, sectors %d-%d, "
                              "size %d sectors", source, part.num, part.start,
Signature · 7 lines
2.7.4

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Signature · 3 lines
--
Regards,
Ed