diff mbox

[07/16] fix mutipath -W on empty wwids file

Message ID 1386744190-1295-8-git-send-email-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show

Commit Message

Benjamin Marzinski Dec. 11, 2013, 6:43 a.m. UTC
When multipath tries to open the wwids file and finds it empty or
missing, it writes the header to the file.  When it tried to wipe
the wwids from an empty or missing file, it didn't seek back to the
start of the file after truncating it.  This caused the the wwids
file to have a patch of zeroed bytes at the start. This patch fixes
this by always seeking back to the start of the file before rewriting
the header.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/wwids.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox

Patch

diff --git a/libmultipath/wwids.c b/libmultipath/wwids.c
index 91b07a7..eca1799 100644
--- a/libmultipath/wwids.c
+++ b/libmultipath/wwids.c
@@ -4,6 +4,7 @@ 
 #include <string.h>
 #include <limits.h>
 #include <stdio.h>
+#include <sys/types.h>
 
 #include "checkers.h"
 #include "vector.h"
@@ -100,6 +101,11 @@  replace_wwids(vector mp)
 		condlog(0, "cannot truncate wwids file : %s", strerror(errno));
 		goto out_file;
 	}
+	if (lseek(fd, 0, SEEK_SET) < 0) {
+		condlog(0, "cannot seek to the start of the file : %s",
+			strerror(errno));
+		goto out_file;
+	}
 	len = strlen(WWIDS_FILE_HEADER);
 	if (write_all(fd, WWIDS_FILE_HEADER, len) != len) {
 		condlog(0, "Can't write wwid file header : %s",