Skip to contentSkip to conversation

2.54.0-rc1 NO_WRITEV=Nope does not work

DISCUSSION [email protected] 4 participants 6 messages Apr 9 – Apr 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

With a completely clean build, we are getting writev() being used anyway on NonStop:

/usr/coreutils/bin/make NO_TCLTK=NoThanks NO_WRITEV=Nope V=1 prefix=/usr/local-ssl3.5 CFLAGS=-g -O2 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Winline -I/usr/local-ssl3.5/include -I/usr/coreutils/include -I/usr/tandem/xml/T0625L01_AAE/include LDFLAGS=-D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 /usr/coreutils/lib/libz.a -L/usr/local-ssl3.5/lib -L/usr/coreutils/lib -L/usr/tandem/xml/T0625L01_AAE/lib SHELL=/usr/coreutils/bin/bash GIT_VERSION=2.54.0.rc1

Down to the first instance:

Cloning into bare repository 'clone.git'...
remote: Enumerating objects: 629, done.
fatal: writev error: Invalid function argument
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
not ok 25 - clone from bitmapped repository
#
#                       rm -fr clone.git &&
#                       git clone --no-local --bare . clone.git && #                       git rev-parse HEAD >expect &&
#                       git --git-dir=clone.git rev-parse HEAD >actual && #                       test_cmp expect actual
#

Did I mess this up?

--
Brief whoami: NonStop&UNIX developer since approximately UNIX(421664400)
NonStop(211288444200000000)
-- In real life, I talk too much.

#1 lore raw
Quoted 11 lines · On Thu, Apr 09, 2026 at 03:48:16PM -0400, [email protected] wrote:

With a completely clean build, we are getting writev() being used anyway on NonStop:

/usr/coreutils/bin/make NO_TCLTK=NoThanks NO_WRITEV=Nope V=1 prefix=/usr/local-ssl3.5 CFLAGS=-g -O2 -D_LARGEFILE64_SOURCE=1

(quoted diff) +0 -2
-D_FILE_OFFSET_BITS=64 -Winline -I/usr/local-ssl3.5/include
-I/usr/coreutils/include -I/usr/tandem/xml/T0625L01_AAE/include

LDFLAGS=-D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 /usr/coreutils/lib/libz.a -L/usr/local-ssl3.5/lib -L/usr/coreutils/lib -L/usr/tandem/xml/T0625L01_AAE/lib SHELL=/usr/coreutils/bin/bash GIT_VERSION=2.54.0.rc1

Hmm, the plot thickens. I think our fallback wrapper is being overly picky. It does:

           for (int i = 0; i < iovcnt; i++) {
                  if (iov[i].iov_len > maximum_signed_value_of_type(ssize_t) ||
                      iov[i].iov_len + sum > maximum_signed_value_of_type(ssize_t)) {
                          errno = EINVAL;
                          return -1;
                  }
  
                  sum += iov[i].iov_len;
          }

so you are probably hitting that EINVAL! Which is trying to emulate how a system writev() would work, but the fundamental problem is that it _doesn't_ work on your system, because ssize_t is too small for how we're using writev(), which assumes we can pass in 64k at a time.

It is tempting to just delete the EINVAL check shown above, but then the rest of the fallback function needs to be more clever, and return a partial write before incrementing total_written over the ssize_t limit (otherwise we have no way to report to the caller how much was actually written).

Yuck. I think for 2.54 we either have to truly implement MAX_IO_SIZE support, or we have to revert the use of writev() in send_sideband() until we do.

-Peff

#2 lore raw

Re* 2.54.0-rc1 NO_WRITEV=Nope does not work

Quoted 4 lines · Jeff King

so you are probably hitting that EINVAL! Which is trying to emulate how a system writev() would work, but the fundamental problem is that it _doesn't_ work on your system, because ssize_t is too small for how we're using writev(), which assumes we can pass in 64k at a time.

Sigh.

Quoted 9 lines

It is tempting to just delete the EINVAL check shown above, but then the rest of the fallback function needs to be more clever, and return a partial write before incrementing total_written over the ssize_t limit (otherwise we have no way to report to the caller how much was actually written).

Yuck. I think for 2.54 we either have to truly implement MAX_IO_SIZE support, or we have to revert the use of writev() in send_sideband() until we do.

Sigh again.

$ git log -Swritev --oneline 8023abc632^..
89152af176 cmake: use writev(3p) wrapper as needed
26986f4cba sideband: use writev(3p) to send pktlines
1970fcef93 wrapper: introduce writev(3p) wrappers
3b9b2c2a29 compat/posix: introduce writev(3p) wrapper

Reverting them gave us the following patch relative to the tip of 'master'.

----- >8 -----
Subject: writev: retract the topic until we have a better emulation

The emulation layer we added for writev(3p) tries to be too faithful to the spec that on systems with SSIZE_MAX set to lower than 64kB to fit a single sideband packet would fail just like the real system writev(), which makes our use of writev() for sideband messages unworkable.

Let's revert them and reboot the effort after the release.

---
 Makefile                            |  4 ----
 compat/posix.h                      | 14 ------------
 compat/writev.c                     | 44 -------------------------------------
 config.mak.uname                    |  2 --
 contrib/buildsystems/CMakeLists.txt |  6 +----
 meson.build                         |  1 -
 sideband.c                          | 14 +++---------
 wrapper.c                           | 41 ----------------------------------
 wrapper.h                           |  9 --------
 write-or-die.c                      |  8 -------
 write-or-die.h                      |  1 -
 11 files changed, 4 insertions(+), 140 deletions(-)
Makefile +0 -4
index 5d22394c2e..cedc234173 100644
@@ -2029,10 +2029,6 @@ ifdef NO_PREAD
 	COMPAT_CFLAGS += -DNO_PREAD
 	COMPAT_OBJS += compat/pread.o
 endif
-ifdef NO_WRITEV
-	COMPAT_CFLAGS += -DNO_WRITEV
-	COMPAT_OBJS += compat/writev.o
-endif
 ifdef NO_FAST_WORKING_DIRECTORY
 	BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
 endif
compat/posix.h +0 -14
index 94699a03fa..faaae1b655 100644
@@ -137,9 +137,6 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/statvfs.h>
-#ifndef NO_WRITEV
-#include <sys/uio.h>
-#endif
 #include <termios.h>
 #ifndef NO_SYS_SELECT_H
 #include <sys/select.h>
@@ -326,17 +323,6 @@ int git_lstat(const char *, struct stat *);
 ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);
 #endif
 
-#ifdef NO_WRITEV
-#define writev git_writev
-#define iovec git_iovec
-struct git_iovec {
-	void *iov_base;
-	size_t iov_len;
-};
-
-ssize_t git_writev(int fd, const struct iovec *iov, int iovcnt);
-#endif
-
 #ifdef NO_SETENV
 #define setenv gitsetenv
 int gitsetenv(const char *, const char *, int);
compat/writev.c deleted +0 -44

44 lines not on this page · raw message

config.mak.uname +0 -2
index ccb3f71881..5feb582558 100644
@@ -459,7 +459,6 @@ ifeq ($(uname_S),Windows)
 	SANE_TOOL_PATH ?= $(msvc_bin_dir_msys)
 	HAVE_ALLOCA_H = YesPlease
 	NO_PREAD = YesPlease
-	NO_WRITEV = YesPlease
 	NEEDS_CRYPTO_WITH_SSL = YesPlease
 	NO_LIBGEN_H = YesPlease
 	NO_POLL = YesPlease
@@ -675,7 +674,6 @@ ifeq ($(uname_S),MINGW)
 	pathsep = ;
 	HAVE_ALLOCA_H = YesPlease
 	NO_PREAD = YesPlease
-	NO_WRITEV = YesPlease
 	NEEDS_CRYPTO_WITH_SSL = YesPlease
 	NO_LIBGEN_H = YesPlease
 	NO_POLL = YesPlease
contrib/buildsystems/CMakeLists.txt +1 -5
index d7a087e584..81b4306e72 100644
@@ -376,7 +376,7 @@ endif()
 #function checks
 set(function_checks
 	strcasestr memmem strlcpy strtoimax strtoumax strtoull
-	setenv mkdtemp poll pread memmem writev)
+	setenv mkdtemp poll pread memmem)
 
 #unsetenv,hstrerror are incompatible with windows build
 if(NOT WIN32)
@@ -421,10 +421,6 @@ if(NOT HAVE_MEMMEM)
 	list(APPEND compat_SOURCES compat/memmem.c)
 endif()
 
-if(NOT HAVE_WRITEV)
-	list(APPEND compat_SOURCES compat/writev.c)
-endif()
-
 if(NOT WIN32)
 	if(NOT HAVE_UNSETENV)
 		list(APPEND compat_SOURCES compat/unsetenv.c)
meson.build +0 -1
index 8309942d18..11488623bf 100644
@@ -1429,7 +1429,6 @@ checkfuncs = {
   'initgroups' : [],
   'strtoumax' : ['strtoumax.c', 'strtoimax.c'],
   'pread' : ['pread.c'],
-  'writev' : ['writev.c'],
 }
 
 if host_machine.system() == 'windows'
sideband.c +3 -11
index 1ed6614eaf..ea7c25211e 100644
@@ -264,7 +264,6 @@ void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_ma
 	const char *p = data;
 
 	while (sz) {
-		struct iovec iov[2];
 		unsigned n;
 		char hdr[5];
 
@@ -274,19 +273,12 @@ void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_ma
 		if (0 <= band) {
 			xsnprintf(hdr, sizeof(hdr), "%04x", n + 5);
 			hdr[4] = band;
-			iov[0].iov_base = hdr;
-			iov[0].iov_len = 5;
+			write_or_die(fd, hdr, 5);
 		} else {
 			xsnprintf(hdr, sizeof(hdr), "%04x", n + 4);
-			iov[0].iov_base = hdr;
-			iov[0].iov_len = 4;
+			write_or_die(fd, hdr, 4);
 		}
-
-		iov[1].iov_base = (void *) p;
-		iov[1].iov_len = n;
-
-		writev_or_die(fd, iov, ARRAY_SIZE(iov));
-
+		write_or_die(fd, p, n);
 		p += n;
 		sz -= n;
 	}
wrapper.c +0 -41

47 lines not on this page · raw message

wrapper.h +0 -9
index 27519b32d1..15ac3bab6e 100644
@@ -47,15 +47,6 @@ ssize_t read_in_full(int fd, void *buf, size_t count);
 ssize_t write_in_full(int fd, const void *buf, size_t count);
 ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
 
-/*
- * Try to write all iovecs. Returns -1 in case an error occurred with a proper
- * errno set, the number of bytes written otherwise.
- *
- * Note that the iovec will be modified as a result of this call to adjust for
- * partial writes!
- */
-ssize_t writev_in_full(int fd, struct iovec *iov, int iovcnt);
-
 static inline ssize_t write_str_in_full(int fd, const char *str)
 {
 	return write_in_full(fd, str, strlen(str));
write-or-die.c +0 -8
index 5f522fb728..01a9a51fa2 100644
@@ -96,14 +96,6 @@ void write_or_die(int fd, const void *buf, size_t count)
 	}
 }
 
-void writev_or_die(int fd, struct iovec *iov, int iovlen)
-{
-	if (writev_in_full(fd, iov, iovlen) < 0) {
-		check_pipe(errno);
-		die_errno("writev error");
-	}
-}
-
 void fwrite_or_die(FILE *f, const void *buf, size_t count)
 {
 	if (fwrite(buf, 1, count, f) != count)
write-or-die.h +0 -1
index a045bdfaef..ff0408bd84 100644
@@ -7,7 +7,6 @@ void fprintf_or_die(FILE *, const char *fmt, ...);
 void fwrite_or_die(FILE *f, const void *buf, size_t count);
 void fflush_or_die(FILE *f);
 void write_or_die(int fd, const void *buf, size_t count);
-void writev_or_die(int fd, struct iovec *iov, int iovlen);
 
 /*
  * These values are used to help identify parts of a repository to fsync.
#3 lore raw

Re: Re* 2.54.0-rc1 NO_WRITEV=Nope does not work

Quoted 5 lines · Junio C Hamano
Quoted 3 lines

Yuck. I think for 2.54 we either have to truly implement MAX_IO_SIZE support, or we have to revert the use of writev() in send_sideband() until we do.

Sigh again.

Yeah, I feel the same way. :(

I would be happy if somebody could prove me wrong, though.

Quoted 8 lines
$ git log -Swritev --oneline 8023abc632^..
89152af176 cmake: use writev(3p) wrapper as needed
26986f4cba sideband: use writev(3p) to send pktlines
1970fcef93 wrapper: introduce writev(3p) wrappers
3b9b2c2a29 compat/posix: introduce writev(3p) wrapper

Reverting them gave us the following patch relative to the tip of 'master'.

If we are planning to improve the topic post-release (and I think that is a good idea), then we can do a much smaller revert. If we just revert 26986f4cba (sideband: use writev(3p) to send pktlines, 2026-03-13), then nobody calls writev (neither the real one nor our fallback). The wrappers are dead code until we bring it back, but it may make things easier for fixing post-2.54.

-Peff

#4 lore raw

Re: Re* 2.54.0-rc1 NO_WRITEV=Nope does not work

Quoted 21 lines · Jeff King
Quoted 5 lines · Junio C Hamano
Quoted 3 lines

Yuck. I think for 2.54 we either have to truly implement MAX_IO_SIZE support, or we have to revert the use of writev() in send_sideband() until we do.

Sigh again.

Yeah, I feel the same way. :(

I would be happy if somebody could prove me wrong, though.

Quoted 8 lines
$ git log -Swritev --oneline 8023abc632^..
89152af176 cmake: use writev(3p) wrapper as needed
26986f4cba sideband: use writev(3p) to send pktlines
1970fcef93 wrapper: introduce writev(3p) wrappers
3b9b2c2a29 compat/posix: introduce writev(3p) wrapper

Reverting them gave us the following patch relative to the tip of 'master'.

Quoted 8 lines

If we are planning to improve the topic post-release (and I think that is a good idea), then we can do a much smaller revert. If we just revert 26986f4cba (sideband: use writev(3p) to send pktlines, 2026-03-13), then nobody calls writev (neither the real one nor our fallback). The wrappers are dead code until we bring it back, but it may make things easier for fixing post-2.54.

-Peff

Yes and no. While excising know callers is certainly safer in the code space, I do not want to hear about some compilers complaining about dead code, etc.

I am preparing another set of integration to be pushed out, queueing the reverts in 'seen'.

#5 lore raw

Re: Re* 2.54.0-rc1 NO_WRITEV=Nope does not work

Quoted 30 lines · Junio C Hamano
Quoted 28 lines · Jeff King
Quoted 5 lines · Junio C Hamano
Quoted 3 lines

Yuck. I think for 2.54 we either have to truly implement MAX_IO_SIZE support, or we have to revert the use of writev() in send_sideband() until we do.

Sigh again.

Yeah, I feel the same way. :(

I would be happy if somebody could prove me wrong, though.

Quoted 8 lines
$ git log -Swritev --oneline 8023abc632^..
89152af176 cmake: use writev(3p) wrapper as needed
26986f4cba sideband: use writev(3p) to send pktlines
1970fcef93 wrapper: introduce writev(3p) wrappers
3b9b2c2a29 compat/posix: introduce writev(3p) wrapper

Reverting them gave us the following patch relative to the tip of 'master'.

If we are planning to improve the topic post-release (and I think that is a good idea), then we can do a much smaller revert. If we just revert 26986f4cba (sideband: use writev(3p) to send pktlines, 2026-03-13), then nobody calls writev (neither the real one nor our fallback). The wrappers are dead code until we bring it back, but it may make things easier for fixing post-2.54.

Quoted 5 lines
Quoted 1 line

-Peff

Yes and no. While excising know callers is certainly safer in the code space, I do not want to hear about some compilers complaining about dead code, etc.

I guess they wouldn't as the function signature is part of a header.

Quoted 2 lines

I am preparing another set of integration to be pushed out, queueing the reverts in 'seen'.

But anyway, I'm okay with this as the safest way forward. I'll then reintroduce early in the next release cycle and hopefully weed out the existing issues.

Thanks, all!

Patrick