Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1672165pxv; Fri, 23 Jul 2021 14:26:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMiMLa/28HpHov/dgL9DCtnRwdGvLxnEA9vLFljIEVI61j2pS/9xu1HcTiZwqmDQ/YEhfJ X-Received: by 2002:a17:906:7d2:: with SMTP id m18mr6451031ejc.229.1627075568226; Fri, 23 Jul 2021 14:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627075568; cv=none; d=google.com; s=arc-20160816; b=J1iC+wuT/waTqKmJ8YB3HpQJVlS74eqrYZj+LDEO18jLClnNQlG1IE0uH9wNEPzDSS gPrweWcr2/Xu/h9eUPRWTO60hDREz/Oz9mtkcLNGnsxJ6P8gCZAJXlTQ5zNt17tgITMc 4BG2r3AwsZ3NxgNaEJMDQL7oOEjHWUPzKIgppu7xjccjoAA2ZrzYNEmUit039fuHku+V l3f+DbDTackmabEIJX7wE+WDKWcq2mPPlKkyzO/GZ1B0qPhu9MGQ7Ude4PupBgLKqK2Q MCdX/yLK81QMAGT9fASNXH12Q87PLus1lGS8aNMznG47GkhOhxqtUONCo9UEtj0f4eK8 wVsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wQEW1Zu14b+R7FeuiGiNcVClEU9cUjB1xm2SO1PApJ0=; b=ySnWIK8BWyzUs45qI36ElxSEmwnmkOye49LeIOqMtempgIEBQgpLD2rkYmBPPRsXJY YC9uPveZjEJ+IhO0DjENt51MUWTBT8xEEVSLsIGzG6iq5RyFpNtQbV+sZQwlC7qBOCPa 9DGwZOPWPjOYIwjFvBfXUOTxX7teD5YYwrbch7T7HMUSmZguOiNBYsPRphNaLXoYNtCF yThjIrDUASdHx+PO40bEjcKUiExWvX40JZNyjXYL3mfanfX3qHtxCxontK3A7KzXxEjw 4m1gX92x8g09R0qH9w0WoQWjiIoMsbJN6Kd3/rGbpn7PrTqURcG+jniEAFPo8rpNFsyt x5yg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si29064913edx.585.2021.07.23.14.25.45; Fri, 23 Jul 2021 14:26:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232156AbhGWUne (ORCPT + 99 others); Fri, 23 Jul 2021 16:43:34 -0400 Received: from mail-pl1-f176.google.com ([209.85.214.176]:45586 "EHLO mail-pl1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231951AbhGWUnd (ORCPT ); Fri, 23 Jul 2021 16:43:33 -0400 Received: by mail-pl1-f176.google.com with SMTP id k1so4460334plt.12 for ; Fri, 23 Jul 2021 14:24:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wQEW1Zu14b+R7FeuiGiNcVClEU9cUjB1xm2SO1PApJ0=; b=bE5kHy6pCpkbEMCDun6XIJFWVJXw1g3eRI7yWw9DDNpEjGMaFPHsk+xOwNQEeCHEL+ 6B+5u4eUo+THOc+nJ68Bs0MPV6K5/R6T/v60t5BgC9ALZiveIdBO4aodn1A1KIgEBAjM l77lCH/BBimBLRHYreSmH+4uJ86k4QPZ866NAbVQJ3buqaXxF1D3ARrqbyyF1NnA7VDR MDe5XrgCO1Om9f+ztTnYVGUHEzD2NQF4jeyKbRDZdtkeuB4NKhivUdb6WhDjZOQ0vOr7 A8EZLO22+uLV2QZTckJNoo9oxj+P6U0yKdrZkzCr2Bj8ujFCnX+pUsU1aRrZP11G7ktM sqIQ== X-Gm-Message-State: AOAM5327EH3LfpmZm4T3YkFLCrGd05TMtJGEdZmQSQMl7OK6CfPuv6BU mBFF498r8+4KzbFz4js5a8k= X-Received: by 2002:a62:e90f:0:b029:307:8154:9ff7 with SMTP id j15-20020a62e90f0000b029030781549ff7mr6170833pfh.79.1627075445743; Fri, 23 Jul 2021 14:24:05 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:1:db72:85bb:463f:5c41]) by smtp.gmail.com with ESMTPSA id w16sm39854011pgi.41.2021.07.23.14.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 14:24:05 -0700 (PDT) From: Bart Van Assche To: Christoph Hellwig Cc: Joel Becker , linux-kernel@vger.kernel.org, Bodo Stroesser , "Martin K . Petersen" , Yanko Kaneti , Brendan Higgins , Bart Van Assche Subject: [PATCH 2/4] configfs: Fix writing at a non-zero offset Date: Fri, 23 Jul 2021 14:23:51 -0700 Message-Id: <20210723212353.896343-3-bvanassche@acm.org> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog In-Reply-To: <20210723212353.896343-1-bvanassche@acm.org> References: <20210723212353.896343-1-bvanassche@acm.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Store data at the right offset when writing with a non-zero offset. I think this patch fixes behavior introduced in the initial configfs commit. From a source code comment in the initial configfs commit: "There is no easy way for us to know if userspace is only doing a partial write, so we don't support them." Cc: Bodo Stroesser Cc: Martin K. Petersen Cc: Yanko Kaneti Cc: Brendan Higgins Signed-off-by: Bart Van Assche --- fs/configfs/file.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 8121bb1b2121..3b2ddc2e5d42 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c @@ -226,14 +226,16 @@ static ssize_t configfs_write_iter(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct configfs_buffer *buffer = file->private_data; - ssize_t len; + int len, written = 0; mutex_lock(&buffer->mutex); len = fill_write_buffer(buffer, iocb->ki_pos, from); if (len > 0) - len = flush_write_buffer(file, buffer, len); - if (len > 0) - iocb->ki_pos += len; + written = flush_write_buffer(file, buffer, iocb->ki_pos + len); + if (written > 0) { + len = max_t(int, 0, written - iocb->ki_pos); + iocb->ki_pos = written; + } mutex_unlock(&buffer->mutex); return len; }