cli/dd: Write an O_APPEND stdout in order #130

Open
koolkhel wants to merge 1 commits from koolkhel/vitastor:dd-stdout-position into master
Contributor

Description

With no of=, vitastor-cli dd has treated a regular-file stdout as seekable since 0f98db3a, and it writes such a stdout with positional writes. On a shell's >> (vitastor-cli dd iimg=X >> file) the kernel appends every positional write, so with iodepth > 1 (4 by default) the blocks landed in their completion order. The file got the right size and scrambled content, and dd exited with 0.

Treat an O_APPEND stdout like oflag=append.

Tested: a new case in tests/test_dd.sh, >> into a file with a prefix at bs=64k iodepth=16. It fails without the fix, and the whole test passes with it.

Writing a shared stdout from its current position ({ printf hdr; vitastor-cli dd iimg=X; printf trailer; } > file) was also in this PR before. It is now a separate commit, not part of this PR: 4a083ac3db

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description With no `of=`, `vitastor-cli dd` has treated a regular-file stdout as seekable since 0f98db3a, and it writes such a stdout with positional writes. On a shell's `>>` (`vitastor-cli dd iimg=X >> file`) the kernel appends every positional write, so with `iodepth` > 1 (4 by default) the blocks landed in their completion order. The file got the right size and scrambled content, and dd exited with 0. Treat an `O_APPEND` stdout like `oflag=append`. Tested: a new case in `tests/test_dd.sh`, `>>` into a file with a prefix at `bs=64k iodepth=16`. It fails without the fix, and the whole test passes with it. Writing a shared stdout from its current position (`{ printf hdr; vitastor-cli dd iimg=X; printf trailer; } > file`) was also in this PR before. It is now a separate commit, not part of this PR: https://git.yourcmc.ru/koolkhel/vitastor/commit/4a083ac3db28f2178c7c7bfcfce9d5d63e80e503 ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-18 20:40:55 +03:00
With no of=, dd treated a regular-file stdout as seekable and wrote it
with positional writes from offset 0. On a shell's >> the kernel appends
every positional write, so with iodepth > 1 the blocks landed in their
completion order. Without O_APPEND, dd overwrote what the shell had
written before it and left the position at 0 for what came after.

Treat an O_APPEND stdout like oflag=append, write a seekable stdout from
its current position, and leave the position at the end of the copy.
koolkhel force-pushed dd-stdout-position from 04bd387433 to 45dee04172 2026-11-18 22:18:52 +03:00 Compare
koolkhel force-pushed dd-stdout-position from 45dee04172 to 0a78467afc 2026-11-19 02:12:01 +03:00 Compare
koolkhel force-pushed dd-stdout-position from 0a78467afc to ee7692750b 2026-11-19 05:14:44 +03:00 Compare
Owner

Вот вангую что сами и сломали прошлыми PR )

Вот вангую что сами и сломали прошлыми PR )
Owner

1 и 2 - это два отдельных фикса. разделите их

1 и 2 - это два отдельных фикса. разделите их
koolkhel force-pushed dd-stdout-position from ee7692750b to 50a19ed99f 2026-11-19 22:32:26 +03:00 Compare
vitalif reviewed 2026-11-20 19:29:38 +03:00
tests/test_dd.sh Outdated
@@ -79,0 +86,4 @@
(cat ./testdata/over ./testdata/testfile; head -c 64M /dev/zero; cat ./testdata/over) | cmp - ./testdata/testfile1 || format_error "dd to a shared stdout overwrote the data around the copy"
rm ./testdata/testfile1
# seek= on a shared stdout counts from its current position
{ cat ./testdata/over; $VITASTOR_CLI dd iimg=testimg bs=64k iodepth=16 seek=2 count=160; cat ./testdata/over; } > ./testdata/testfile1
Owner

Ууу. То есть это ради вот такого хитрого кейса - если у нас append в stdout, но при этом stdout seekable? Это конечно извращение то ещё, да.

Тут мне нужно ещё подумать, как я к такому кейсу отношусь...

Ууу. То есть это ради вот такого хитрого кейса - если у нас append в stdout, но при этом stdout seekable? Это конечно извращение то ещё, да. Тут мне нужно ещё подумать, как я к такому кейсу отношусь...
koolkhel force-pushed dd-stdout-position from 50a19ed99f to 1768fdc5f7 2026-11-21 10:11:25 +03:00 Compare
koolkhel changed title from cli/dd: Respect O_APPEND and the current position of stdout to cli/dd: Write an O_APPEND stdout in order 2026-11-21 10:17:29 +03:00
Author
Contributor

То есть это ради вот такого хитрого кейса - если у нас append в stdout, но при этом stdout seekable?

Тут два разных кейса, я их разделил.

  1. Обычный >>: vitastor-cli dd iimg=X >> file. Такой stdout — обычный файл, открытый с O_APPEND, то есть seekable. С 0f98db3a dd пишет в него позиционной записью, а ядро на O_APPEND дописывает каждую запись в конец. При iodepth 4 (по умолчанию) блоки ложатся в порядке завершения: размер верный, содержимое перемешано, код возврата 0. Исправление — одна строка: stdout с O_APPEND обрабатывается как oflag=append. В #130 теперь только оно и тест на >>.

  2. Общий stdout — про него тест на seek=: { printf hdr; vitastor-cli dd iimg=X; printf trailer; } > file или { vitastor-cli dd iimg=a; vitastor-cli dd iimg=b; } > file. Так работает coreutils dd: пишет stdout с текущей позиции, seek= считает от неё (lseek с SEEK_CUR) и оставляет позицию после копии. vitastor-cli dd до 0f98db3a вёл себя так же, потому что писал последовательно, а сейчас второй dd пишет с нуля поверх первого. Это вынесено в отдельный коммит, PR на него я не открывал: 4a083ac3db. Если решишь, что такой кейс стоит поддерживать, открою PR; если нет — так и оставим.

> То есть это ради вот такого хитрого кейса - если у нас append в stdout, но при этом stdout seekable? Тут два разных кейса, я их разделил. 1. Обычный `>>`: `vitastor-cli dd iimg=X >> file`. Такой stdout — обычный файл, открытый с O_APPEND, то есть seekable. С 0f98db3a dd пишет в него позиционной записью, а ядро на O_APPEND дописывает каждую запись в конец. При iodepth 4 (по умолчанию) блоки ложатся в порядке завершения: размер верный, содержимое перемешано, код возврата 0. Исправление — одна строка: stdout с O_APPEND обрабатывается как oflag=append. В #130 теперь только оно и тест на `>>`. 2. Общий stdout — про него тест на seek=: `{ printf hdr; vitastor-cli dd iimg=X; printf trailer; } > file` или `{ vitastor-cli dd iimg=a; vitastor-cli dd iimg=b; } > file`. Так работает coreutils dd: пишет stdout с текущей позиции, seek= считает от неё (lseek с SEEK_CUR) и оставляет позицию после копии. vitastor-cli dd до 0f98db3a вёл себя так же, потому что писал последовательно, а сейчас второй dd пишет с нуля поверх первого. Это вынесено в отдельный коммит, PR на него я не открывал: https://git.yourcmc.ru/koolkhel/vitastor/commit/4a083ac3db28f2178c7c7bfcfce9d5d63e80e503. Если решишь, что такой кейс стоит поддерживать, открою PR; если нет — так и оставим.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u dd-stdout-position:koolkhel-dd-stdout-position
git checkout koolkhel-dd-stdout-position
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#130
No description provided.