libmultipath: open_file: rewind after writing the header
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.
--- libmultipath/file.c | 5 +++++ 1 file changed, 5 insertions(+)
libmultipath/file.c +5 -0
@@ -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
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/bindingsfatal configuration error, abortingThis 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")Signed-off-by Alex Brett <[email protected]>Assisted-by Claude:claude-opus-5-5
Martin Wilck
AppliedQuoted 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]>