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=OiSnF1KE; 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 C89C05A004E for ; Wed, 30 Oct 2024 13:27:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730291253; 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=EgVgP9McgfC38GgYQYO4QFK/lpHTiFz0x4T2QBhOYp8=; b=OiSnF1KEjRQ5MQ4T65n76+YYAb1ySneBH+YCMhV+V5jP0ScIdrvjP3iQ5p97srs18UjjSj UD82ssY4S+FaesitAS6UlAfomALkiL8q5XO2zbV9HpZiJplibGvmnu/6X6kNMYSK7KBfJ9 CCaG1dOJZLU/JznjFB8R8Sfo3NS/mHg= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-aCj1CrACMb-lSDsFrfzVqQ-1; Wed, 30 Oct 2024 08:27:32 -0400 X-MC-Unique: aCj1CrACMb-lSDsFrfzVqQ-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37d52ca258eso3516395f8f.3 for ; Wed, 30 Oct 2024 05:27:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730291250; x=1730896050; 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=EgVgP9McgfC38GgYQYO4QFK/lpHTiFz0x4T2QBhOYp8=; b=Z0C+sW2OFXhFXE2gBEFDL3yehZx+BU78hA9bAj/fYfmBfSg3TJ1N0/S/HucqY0kURS YCLwn21meJp0yPO/xJvQGjxAxJErp/KKF0KWO196mCrER5BM7K1F8L/XCt0WqgT7Nlgd pDvtcgFX0wtH87bCQYy7LN8Lm5dpqPyd2CQ6lRDS6PLXmcnw4qSOaqp0P1ODeQdog08l NgoDRB27bWKplDSR2njhWKh6yX+XJX0x/9X7u9MYVg1vkcSRV00Hh0uyfMzUFWa6JuMh jKQKErufGODvYLzaOEUP50/y+h71D31sd5HuqwVPZYX71zsNcBbcOGk8m5k7SdM/u7xG 83xg== X-Gm-Message-State: AOJu0YzI14Wv28Aogw1J0f3IhzPdAira6HaqxUI+xhM1sJsYI/osaH+N Ptv9R0tNkjRP3M+0uPcdDHhDNnVEN9GlkHDtf90kMP0mY5Oyeei1RvY/1nl7BvgowEuFAPEy+dF RTYihWbOrQ7ZhfqbgE4DhWsWnpHvyL/CMP0GssvE5nq8aTtyhpePjch31+A== X-Received: by 2002:adf:e2cf:0:b0:37c:cc4b:d1ea with SMTP id ffacd0b85a97d-381b710fbe8mr2623394f8f.53.1730291249642; Wed, 30 Oct 2024 05:27:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3W1I/kN8fIq3x5lLkdGp5X2MGd7d+nAvzjh1jJYaoow9KXl4arVl1ZmdZjHkWC7KmkyL6sQ== X-Received: by 2002:adf:e2cf:0:b0:37c:cc4b:d1ea with SMTP id ffacd0b85a97d-381b710fbe8mr2623371f8f.53.1730291249125; Wed, 30 Oct 2024 05:27:29 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38058b713fbsm15290815f8f.88.2024.10.30.05.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 05:27:27 -0700 (PDT) Date: Wed, 30 Oct 2024 13:27:26 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v3 5/9] log: Don't use O_APPEND at all Message-ID: <20241030132726.5d07c8ef@elisabeth> In-Reply-To: References: <20241028100044.939714-1-sbrivio@redhat.com> <20241028100044.939714-6-sbrivio@redhat.com> <20241029094850.206c06bc@elisabeth> <20241029112329.25f2503b@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: D3XXYG35MXYGJXQKK56A3WPUZBLSZETI X-Message-ID-Hash: D3XXYG35MXYGJXQKK56A3WPUZBLSZETI 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 Wed, 30 Oct 2024 13:33:43 +1100 David Gibson wrote: > On Tue, Oct 29, 2024 at 11:23:29AM +0100, Stefano Brivio wrote: > > 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. > > Ok, that makes sense. > > Except that maybe there is a reason to use O_APPEND (the multiple > writer thing), even if it's not the one you thought of initially. > > [snip] > > > > > 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). > > That's fair. I wonder if it might make sense to flock() the logfile, > to (somewhat) enforce that only one process uses it at a time. ...but if it kind of works for multiple writers, we shouldn't prevent that usage, right? On the other hand, I don't think we should try to make that usage all nice and supported because we would need a prefix, which, in case of a single writer, just adds noise and size. And I don't think we want to detect if there are multiple writers... So, all in all, I would choose to spend no effort and leave like it is, until somebody comes up with a use case in one direction or the other. -- Stefano