Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp781670lqh; Thu, 28 Mar 2024 17:00:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUj+qLgvC5vyXgZUD6/+d1IslkPFydNQQbRsleIfOskxSxl/CtES1DJ6jhs+lk1mu7H75HB1hd+oM/SdntHErINwkJVtBb8yE/9HOZs0Q== X-Google-Smtp-Source: AGHT+IEVT39vgBa8QIgVHG2mqT/m+A9qnlzUtjI1zwIYdQd2Kux8TNwFE2QOPywoIVqGsXsVecIP X-Received: by 2002:a17:906:e291:b0:a47:5190:1c09 with SMTP id gg17-20020a170906e29100b00a4751901c09mr418396ejb.31.1711670451219; Thu, 28 Mar 2024 17:00:51 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m11-20020a1709066d0b00b00a46a1fbc0f8si1128422ejr.401.2024.03.28.17.00.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 17:00:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123848-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@redhat.com header.s=mimecast20190719 header.b=Uf0eyr3J; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-123848-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123848-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E9A2F1F23604 for ; Fri, 29 Mar 2024 00:00:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C9588479; Fri, 29 Mar 2024 00:00:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Uf0eyr3J" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BD71A946 for ; Fri, 29 Mar 2024 00:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711670445; cv=none; b=nn1AbwAyr4P99gru5uTRgdjmQG9RGjx2tS9GFIB8LO9wYacvfoA/dOpIakMaFnBcOFmJWpEu0fa4doF4umxC3FJvhUrfx2J2RPMwvY8CaDdKagiKNAu+o5yB4th0rxm5ujmcbgGTi1eFeZaCyJMHHlCx7O6Bq4prXJ1sqt09ppE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711670445; c=relaxed/simple; bh=ENZlmKNxpzlLiGBo6kS0UnjmR03CylTphFoCV+u4xmk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FK8Sws5BUaX+hEYUCh6MGndff9pGiaf8yWCjZ19/lwLJF1C1Ywt997u7eYorKUstfgkzaYBCmtgPLQjtqfgHsftegWsMOD0S6vbEe+gEtcoUK2QggXCO6LYZzkhUewMOMbxh1ybaG5tNimAX3Y+la8HNL2kWDXRmbjRAa3EO8VE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Uf0eyr3J; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711670441; 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: in-reply-to:in-reply-to:references:references; bh=KOh0bGzRFscdK7n0pRRU7ddpBbKZJGLB2WZV3d0SUpI=; b=Uf0eyr3J3huzYiqVX/oxfL4X1MV1mZfP8jIhEn/3xKJqGE5i67dJq4Lvwaey3qu+iu8M7d CLfLVKRgv/kEYofoCdG0o/kqI0jjsx+p/B22Pji4k8NgasSWjnC7TPAN+XlpX9QlAIqL9B UIBpAkD32EqJnLKG/EBbBLBgCpImtGk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-OPZRQc8PPO2s2otDIOSCEQ-1; Thu, 28 Mar 2024 20:00:35 -0400 X-MC-Unique: OPZRQc8PPO2s2otDIOSCEQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 086C43801F53; Fri, 29 Mar 2024 00:00:35 +0000 (UTC) Received: from redhat.com (unknown [10.2.16.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 599E12166B36; Fri, 29 Mar 2024 00:00:32 +0000 (UTC) Date: Thu, 28 Mar 2024 19:00:26 -0500 From: Eric Blake To: Stefan Hajnoczi Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Alasdair Kergon , Mikulas Patocka , dm-devel@lists.linux.dev, David Teigland , Mike Snitzer , Jens Axboe , Christoph Hellwig , Joe Thornber Subject: Re: [RFC 2/9] loop: add llseek(SEEK_HOLE/SEEK_DATA) support Message-ID: References: <20240328203910.2370087-1-stefanha@redhat.com> <20240328203910.2370087-3-stefanha@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240328203910.2370087-3-stefanha@redhat.com> User-Agent: NeoMutt/20240201 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 On Thu, Mar 28, 2024 at 04:39:03PM -0400, Stefan Hajnoczi wrote: > Signed-off-by: Stefan Hajnoczi > --- > Open issues: > - The file offset is updated on both the blkdev file and the backing > file. Is there a way to avoid updating the backing file offset so the > file opened by userspace is not affected? > - Should this run in the worker or use the cgroups? > --- > drivers/block/loop.c | 36 ++++++++++++++++++++++++++++++------ > 1 file changed, 30 insertions(+), 6 deletions(-) > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > index 28a95fd366fea..6a89375de82e8 100644 > --- a/drivers/block/loop.c > +++ b/drivers/block/loop.c > @@ -750,6 +750,29 @@ static void loop_sysfs_exit(struct loop_device *lo) > &loop_attribute_group); > } > > +static loff_t lo_seek_hole_data(struct block_device *bdev, loff_t offset, > + int whence) > +{ > + /* TODO need to activate cgroups or use worker? */ > + /* TODO locking? */ > + struct loop_device *lo = bdev->bd_disk->private_data; > + struct file *file = lo->lo_backing_file; > + > + if (lo->lo_offset > 0) > + offset += lo->lo_offset; /* TODO underflow/overflow? */ > + > + /* TODO backing file offset is modified! */ > + offset = vfs_llseek(file, offset, whence); Not only did you modify the underlying offset... > + if (offset < 0) > + return offset; > + > + if (lo->lo_offset > 0) > + offset -= lo->lo_offset; /* TODO underflow/overflow? */ > + if (lo->lo_sizelimit > 0 && offset > lo->lo_sizelimit) > + offset = lo->lo_sizelimit; ..but if this code kicks in, you have clamped the return result to EOF of the loop device while leaving the underlying offset beyond the limit, which may mess up assumptions of other code expecting the loop to always have an in-bounds offset for the underlying file (offhand, I don't know if there is any such code; but since loop_ctl_fops.llseek = noop_lseek, there may be code relying on an even-tighter restriction that the offset of the underlying file never changes, not even within bounds). Furthermore, this is inconsistent with all other seek-beyond-end code that fails with -ENXIO instead of returning size. But for an RFC, the idea of being able to seek to HOLEs in a loop device is awesome! > @@ -2140,7 +2164,7 @@ static int loop_control_remove(int idx) > pr_warn_once("deleting an unspecified loop device is not supported.\n"); > return -EINVAL; > } > - > + > /* Hide this loop device for serialization. */ > ret = mutex_lock_killable(&loop_ctl_mutex); > if (ret) Unrelated whitespace change? -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org