From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gx+/Yx9U; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 085CA5A004C for ; Tue, 29 Oct 2024 11:23:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730197415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cQpqKYw/Ig3h1SIZXO829sZRviKqthUDOxiXd5coUMU=; b=Gx+/Yx9UhBQvRA5uEJCspOmk0AloKIStQ6MEhp+z9OmHhSSUjfUON1yz8G+UYdEDUWO3eJ Sk+1xnPXKQ9cQxSfJFIaDDlbWspq9YZZe9tn30GWU+Zb5M21iyOfwkUnHIdJn3mR7jj8/A saE14exn5ge/jBRDMyBQC2IwKJHI01o= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-520-PKafd5SiP16sJYqY6OVilg-1; Tue, 29 Oct 2024 06:23:34 -0400 X-MC-Unique: PKafd5SiP16sJYqY6OVilg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37d5016d21eso2573320f8f.3 for ; Tue, 29 Oct 2024 03:23:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730197412; x=1730802212; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cQpqKYw/Ig3h1SIZXO829sZRviKqthUDOxiXd5coUMU=; b=O2ifuOzIeOnD2v562lwmdzL/Da4vtCY2llDBNppjZl/B/XNjGQtWSCNKNt95XmMy/T DLDvdRAAwa9z3HWnvYKExGo+pnq2ULOF4xnO6ZbKFgT2+UFdDyBJdy5cAqLDQSBDESVg PSzDUjFfChnvvBxM036ctOcQYSYwHJKUvC8U38tDn3dyOK33GRZ2lXWgQspvPkMJsarl iRHFeruo5261jyyM1V3euUSxlDFziaG4WTsE0XWSjJJkcg1kJJOPZh0QjdIUYjN7EM35 y0dFLU+hgqlYIXw78u8oMFMx3OtyfgWXTpinzds9C0qtsWHMmoIsT/RrfbDE450X6ra0 AN6g== X-Gm-Message-State: AOJu0YxKYeQq6GpZmchdm9nzSaK0Jm6qkatbJAI+7ggCDPV7EkhajR+q 8wy0a9FyxYp5489zxrZiw36crQADWQOpwyW2tvAAjg/JjjqRtC7dB74b6TxFyaOHPlr5b6u+bY0 FdHDRgt+NqAsWT2m3F8tdAPgQMVheCl0g12sM3PYWZ7ilrmW7WJ37sXoxCA== X-Received: by 2002:adf:e84f:0:b0:37d:4956:b0c2 with SMTP id ffacd0b85a97d-3806122f97emr7903989f8f.58.1730197411709; Tue, 29 Oct 2024 03:23:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaYOtD9TqUWIV8XOBF0l4tsYpud1jhfVXlni16r4dGZ9NeoFCE95hkK26zx65seIKCCKIuig== X-Received: by 2002:adf:e84f:0:b0:37d:4956:b0c2 with SMTP id ffacd0b85a97d-3806122f97emr7903967f8f.58.1730197411135; Tue, 29 Oct 2024 03:23:31 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b3b956sm12018339f8f.36.2024.10.29.03.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 03:23:30 -0700 (PDT) Date: Tue, 29 Oct 2024 11:23:29 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v3 5/9] log: Don't use O_APPEND at all Message-ID: <20241029112329.25f2503b@elisabeth> In-Reply-To: References: <20241028100044.939714-1-sbrivio@redhat.com> <20241028100044.939714-6-sbrivio@redhat.com> <20241029094850.206c06bc@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: VHR2HBHZPWXTNA5P5WS7SLMBGIISEQZ6 X-Message-ID-Hash: VHR2HBHZPWXTNA5P5WS7SLMBGIISEQZ6 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 29 Oct 2024 20:32:40 +1100 David Gibson wrote: > On Tue, Oct 29, 2024 at 09:48:50AM +0100, Stefano Brivio wrote: > > On Tue, 29 Oct 2024 15:20:56 +1100 > > David Gibson wrote: > > > > > On Mon, Oct 28, 2024 at 11:00:40AM +0100, Stefano Brivio wrote: > > > > We open the log file with O_APPEND, but switch it off before seeking, > > > > and turn it back on afterwards. > > > > > > > > We never seek when O_APPEND is on, so we don't actually need it, as > > > > its only function is to override the offset for writes so that they > > > > are always performed at the end regardless of the current offset > > > > (which is at the end anyway, for us). > > > > > > Sorry, this sounded fishy to me on the call, but I figured I was just > > > missing something. But looking at this the reasoning doesn't make > > > sense to me. > > > > > > We don't seek with O_APPEND, but we do write(), which is exactly where > > > it matters. AIUI the point of O_APPEND is that if you have multiple > > > processes writing to the same file, they won't clobber each others > > > writes because of a stale file pointer. > > > > That's not the reason why I originally added it though: it was there > > because I thought I would lseek() to do the rotation and possibly end > > up with the cursor somewhere before the end. Then restart writing, and > > the write would happen in the middle of the file: > > I don't entirely follow. I see why you disable O_APPEND across the > rotation, but I'm not clear on why it's opened with O_APPEND in the > first place, if it's not for the typical logging reason. I initially opened it with O_APPEND because I _thought_ I would set the offset to a possibly inconsistent value around the rotation. Then I dropped O_APPEND around the rotation, forgetting about the initial reason why I added it at all. So it makes no sense to have O_APPEND at all. > > $ cat append.c > > #include > > #include > > #include > > #include > > > > int main(int argc, char **argv) > > { > > int flags = O_CREAT | O_TRUNC | O_WRONLY | ((argc == 3) ? O_APPEND : 0); > > int fd = open(argv[1], flags, S_IRUSR | S_IWUSR); > > char buf[BUFSIZ]; > > > > memset(buf, 'a', BUFSIZ); > > write(fd, buf, 10); > > lseek(fd, 1, SEEK_SET); > > memset(buf, 'b', BUFSIZ); > > write(fd, buf, 10); > > write(fd, (char *){ "\n" }, 1); > > > > return 0; > > } > > $ gcc -o append{,.c} > > $ ./append test append > > $ cat test > > aaaaaaaaaabbbbbbbbbb > > $ ./append test > > $ cat test > > abbbbbbbbbb > > > > > That's usually not > > > _necessary_ for us as such, but it's perhaps valuable since it reduces > > > the likelihood of data loss if somehow you do get two instances > > > logging to the same file. > > > > The result will be completely unreadable anyway, so I don't think it > > matters for us. > > Not necessarily. It certainly can get garbled, but individual writes > of reasonable size - such as a single log line will generally complete > atomically. With a text logging format, that's not ideal but often > pretty decipherable. Particularly if each writer includes a prefix > identifying itself. > > > > Of course the rotation process *can* clobber things (which is exactly > > > why I was always a bit sceptical of this "in place" rotation, not that > > > we really have other options). > > > > Why would it clobber things? logfile_rotate_fallocate() and > > logfile_rotate_move() take care of cutting cleanly at a line boundary, > > and tests check that. > > I mean that in the case that there are multiple writers, the rotation > breaks that "no data loss, and probably readable-ish" property of > O_APPEND. Ah, sure. But I think that supporting multiple writers would need more work anyway (at least adding a prefix as you mentioned). Well, anyway, if you think this might add a regression with multiple writers, I can add an extra flag to output_file_open() and keep O_APPEND for the log file. But I really struggle to see the actual use case. -- Stefano