Skip to contentSkip to conversation

sstate: Reduce race windows

PATCH In review Richard Purdie 2 participants 2 messages Aug 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sstate: Reduce race windows

When we write to the sstate directory we try to do so atomically so consumers either see one version or another but never an imcomplete file. Unfortunately this is reliant on filesystem support and with some NFS configurations a replaced file would be lost from memory even if users held open descriptors.

It makes sense to try and avoid replacing existing files where we can.

---
 meta/classes/sstate.bbclass | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
meta/classes/sstate.bbclass +11 -1
index aa5841446c9..11222223a9b 100644
@@ -755,6 +755,11 @@ sstate_task_postfunc[dirs] = "${WORKDIR}"
 sstate_create_package () {
 	TFILE=`mktemp ${SSTATE_PKG}.XXXXXXXX`
 
+	# Exit earlu if it already exists
+	if [ -e ${SSTATE_PKG} ]; then
+		return
+	fi
+
         # Use pigz if available
         OPT="-czS"
         if [ -x "$(command -v pigz)" ]; then
@@ -774,7 +779,12 @@ sstate_create_package () {
 		tar $OPT --file=$TFILE --files-from=/dev/null
 	fi
 	chmod 0664 $TFILE
-	mv -f $TFILE ${SSTATE_PKG}
+	# Skip if it was already created by some other process
+	if [ ! -e ${SSTATE_PKG} ]; then
+		mv -f $TFILE ${SSTATE_PKG}
+	else
+		rm $TFILE
+	fi
 }
 
 python sstate_sign_package () {
Signature · 1 line
2.20.1
#1 lore raw
Quoted 3 lines · Richard Purdie

When we write to the sstate directory we try to do so atomically so consumers either see one version or another but never an imcomplete file.

                                 ^^^^

typo .

Quoted 6 lines

Unfortunately this is reliant on filesystem support and with some NFS configurations a replaced file would be lost from memory even if users held open descriptors.

It makes sense to try and avoid replacing existing files where we can.

yes this is helpful. Change looks good.

Quoted 10 lines
---
 meta/classes/sstate.bbclass | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
meta/classes/sstate.bbclass +0 -0
index aa5841446c9..11222223a9b 100644

meta/classes/sstate.bbclass sstate_task_postfunc[dirs] = "${WORKDIR}" · line 758

Quoted 4 lines
meta/classes/sstate.bbclass +1 -0
@@ -755,6 +755,11 @@ sstate_task_postfunc[dirs] = "${WORKDIR}"
 sstate_create_package () {
        TFILE=`mktemp ${SSTATE_PKG}.XXXXXXXX`
 
+       # Exit earlu if it already exists
                       ^^^

typo

Quoted 29 lines
meta/classes/sstate.bbclass +10 -2
+       if [ -e ${SSTATE_PKG} ]; then
+               return
+       fi
+
         # Use pigz if available
         OPT="-czS"
         if [ -x "$(command -v pigz)" ]; then
@@ -774,7 +779,12 @@ sstate_create_package () {
                tar $OPT --file=$TFILE --files-from=/dev/null
        fi
        chmod 0664 $TFILE
-       mv -f $TFILE ${SSTATE_PKG}
+       # Skip if it was already created by some other process
+       if [ ! -e ${SSTATE_PKG} ]; then
+               mv -f $TFILE ${SSTATE_PKG}
+       else
+               rm $TFILE
+       fi
 }
 
 python sstate_sign_package () {
--

2.20.1

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