Patchwork [07/20] udev-cache: Update cache tarball atomically

login
register
mail settings
Submitter Ben Shelton
Date Aug. 4, 2014, 6:40 p.m.
Message ID <02ffdae63da4c286825773a18ab377d8027ae6c0.1407177403.git.ben.shelton@ni.com>
Download mbox | patch
Permalink /patch/77223/
State Accepted
Commit bd7fb7c3ca50b3eea2d173487f24b3006470f6df
Headers show

Comments

Ben Shelton - Aug. 4, 2014, 6:40 p.m.
From: Richard Tollerton <rich.tollerton@ni.com>

Overwriting the tarball in-place could cause a partial write, if the
system stops at an inopportune time. This is mitigated by first writing to a
temporary file, then moving that file on top of the final location.

Natinst-Rally-ID: TA44427
Acked-by: Gratian Crisan <gratian.crisan@ni.com>
Natinst-ReviewBoard-ID: 58620
Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
---
 meta/recipes-core/udev/udev/udev-cache | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Otavio Salvador - Aug. 4, 2014, 7:35 p.m.
On Mon, Aug 4, 2014 at 3:40 PM, Ben Shelton <ben.shelton@ni.com> wrote:
> From: Richard Tollerton <rich.tollerton@ni.com>
>
> Overwriting the tarball in-place could cause a partial write, if the
> system stops at an inopportune time. This is mitigated by first writing to a
> temporary file, then moving that file on top of the final location.
>
> Natinst-Rally-ID: TA44427
> Acked-by: Gratian Crisan <gratian.crisan@ni.com>
> Natinst-ReviewBoard-ID: 58620
> Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>


Acked-by: Otavio Salvador <otavio@ossystems.com.br>

As an improvement, this could be written in tmpfs so it avoid
duplicated writting. For NAND devices without much free space this
might matter.

Patch

diff --git a/meta/recipes-core/udev/udev/udev-cache b/meta/recipes-core/udev/udev/udev-cache
index 11c5f0e..679adb4 100644
--- a/meta/recipes-core/udev/udev/udev-cache
+++ b/meta/recipes-core/udev/udev/udev-cache
@@ -25,7 +25,8 @@  fi
 
 if [ "$DEVCACHE" != "" -a -e /dev/shm/udev.cache ]; then
 	[ "${VERBOSE}" != "no" ] && echo "Populating dev cache"
-	tar czf "$DEVCACHE" dev -C / --exclude=log
+	tar czf "${DEVCACHE}.tmp" dev -C / --exclude=log
+	mv -f "${DEVCACHE}.tmp" "$DEVCACHE"
 	mv /dev/shm/udev.cache /etc/udev/cache.data
 fi