Skip to contentSkip to conversation

libmultipath: open_file: rewind after writing the header

PATCH Applied Alex Brett 3 participants 3 messages Nov 6 Device mapper

lore
Share & tools
lore

Alex Brett

author
#0 lore raw

PATCH 1/1 libmultipath: open_file: rewind after writing the header

When creating a new file, open_file() returns it with the offset after the header it has just written, but on opening an existing file it will return it with the offset at 0.

_read_bindings_file() reads sequentially from the returned fd, so on a newly created bindings file the header check in _check_bindings_file() hits EOF and declares the file bad. Without -B this is masked by rewriting the file, but "multipath -B" may not write it and aborts:

ERROR: bad settings in read-only bindings file /etc/multipath/bindings fatal configuration error, aborting

This affects the first "multipath -B" on any system without a bindings file, such as an installer environment.

The wwids and prkeys code paths seek before every access and are unaffected.

Fixes 7eaeb33ae9f7 ("multipathd: watch bindings file with inotify + timestamp")
Assisted-by Claude:claude-opus-5-5
---
 libmultipath/file.c | 5 +++++
 1 file changed, 5 insertions(+)
libmultipath/file.c +5 -0
index ce9ff610..215a48cd 100644
@@ -159,6 +159,11 @@ open_file(const char *file, int *can_write, const char *header)
 			goto fail;
 		}
 		fsync(fd);
+		if (lseek(fd, 0, SEEK_SET) < 0) {
+			condlog(0, "Cannot rewind file %s : %s", file,
+				strerror(errno));
+			goto fail;
+		}
 		condlog(3, "Initialized new file [%s]", file);
 	}
 
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Alex Brett

When creating a new file, open_file() returns it with the offset after the header it has just written, but on opening an existing file it will return it with the offset at 0.

_read_bindings_file() reads sequentially from the returned fd, so on a newly created bindings file the header check in _check_bindings_file() hits EOF and declares the file bad. Without -B this is masked by rewriting the file, but "multipath -B" may not write it and aborts:

ERROR: bad settings in read-only bindings file /etc/multipath/bindings fatal configuration error, aborting

This affects the first "multipath -B" on any system without a bindings file, such as an installer environment.

Quoted 6 lines

The wwids and prkeys code paths seek before every access and are unaffected.

Fixes 7eaeb33ae9f7 ("multipathd: watch bindings file with inotify + timestamp")
Assisted-by Claude:claude-opus-5-5
Applied
#2 lore raw
In reply to Alex Brett
Quoted 1 line · Alex Brett

libmultipath: open_file: rewind after writing the header

Applied, thanks!

[1/1] libmultipath: open_file: rewind after writing the header

      commit: 29c489fe288f461789970ff7f607a7ded16d1c59

Best regards,

Signature · 1 line
Martin Wilck <[email protected]>