Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp687884lqh; Thu, 28 Mar 2024 13:10:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXobYx7ggBkfGk5dqCXDTCIg9TRBSQSk7EIf/BVw4dmpa4tCqBEe2njTjvxl4L87IphF1r5Vo69MslRcJyx9FW9fRz6ZPMoBHDMKWmEig== X-Google-Smtp-Source: AGHT+IGAooX1ZtplEa1f1aC/jA1SOw+79QTfUNBR4AbkIBRyxQwSyPsqoKRe+8VduDlT+rwEpPSa X-Received: by 2002:a17:906:69b:b0:a4e:21e0:2e60 with SMTP id u27-20020a170906069b00b00a4e21e02e60mr164887ejb.57.1711656638645; Thu, 28 Mar 2024 13:10:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711656638; cv=pass; d=google.com; s=arc-20160816; b=qNhzQBtzevbhZjQZjHTkWTUEuRGGgAw3aBj+/5ke0VFzJMuxxvilb4wCXGvHVUQJx9 AHLHVsfD56JDMfBAYtWz1C15ZCZwpnySDn/fmTrO4ZYjokCLvfy3M3TVY5x4qi8Gdkc3 HBmyKdRA7P4P0yLCRBjJJGoLlJoOAothMPl2lvFU+YoiSAc4etnav380RXmTC9fsWwEJ RipOjI+wqQ5z5PurasI2bZgUW/XlrGb/bYmH7rCr4fb/3dOpnzQduy1zLT7EJjxeREZB saHwhGiNgV3lAfERwFBINm5e3RGN33+1qGsRIEDfU9xnRf0ClI+6gOKoWoX+leDCnN88 oB5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=GNg3TCDxUYWvdrmVC0UYgD/Q/dbAYox1jgT+XpQu6rw=; fh=5JJKlCrebTH8WA7Jh/lHbU+oaEdhlPiuf2epOKhCYhA=; b=G89T/aUlVBKvICg51y3ehmZDxcuzSdv47TX/HhnJhu1SXTtTRLNje51uxjvBzOgSqN tlRRgk2P/9rrqUrgMpjU53jRKctx8tFp/rAvXB+6lLuLd9bIG6jI6XzV1WL2MXwg647A +CZ2mr2oMNc20mqqYR6BaKdCxfUugtYPjUH5y0I/KIYpEk8CtUybTLgpaU7uVLO/RKqT aumsxm6d5eObQX5n5hwxI+F58rM8v1utcN+ZCOfeIJU9YzD+sm5Bv0IdIPmoznVSKr7C Mvr+dffVkB4AIqsgrYNbu+mX0m/q0vwEyQzWfK+8akOuAeL6B0UBB4wMD6iYeQRSZpPN 4yBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kr4kmRks; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-123548-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123548-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dk4-20020a170906f0c400b00a47413903b2si974243ejb.800.2024.03.28.13.10.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 13:10:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123548-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kr4kmRks; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-123548-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123548-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 35CC81F284D9 for ; Thu, 28 Mar 2024 20:10:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53A73139CFA; Thu, 28 Mar 2024 20:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kr4kmRks" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 5B99B135A4D; Thu, 28 Mar 2024 20:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711656603; cv=none; b=aPZZPD0ZxZu8esOU7PLuOb5z3/vVDCh9c+kPhvyPl8WX26PgLu4Mv07a5VXT6pAguORkSztIGbmp1oP5O7W//s79D0ZHdTslwOEVDgx8bIgvuyLF55WxDUELaKKrzhspvN/ROzvSBiEbENz3YfeAt20WqAHAfOkHqy7ZUHJsYU8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711656603; c=relaxed/simple; bh=B0boc5nHCqXEMmaaCwtZm9t/Mtn0OCgA0SpVDAjwwB0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bAdMZiNkxJVn4amjD+akpbwZjOMwnZsEW7JKyAzEDAjp7p/pOsEBtmJybB4AxIwmBbamXPs3DVirBFqbrC04tRDB0CqbDiFyKM1vQFDaO7p6laqHTmZwzXaHWcgtO6UFGWL5uk3D+BqhU+diCrX3ZZriXIQgweLrR8/YJm7KBuU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=kr4kmRks; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711656601; x=1743192601; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=B0boc5nHCqXEMmaaCwtZm9t/Mtn0OCgA0SpVDAjwwB0=; b=kr4kmRkscLEaxzJht2ojccT2z6JlyIgh5EqOzIsrSUc9XTJ4J6G31EAh 8DvO/EjWlbhaRjq+xbwjPq1rXaVVCkiZZcb1V7ZU4V6Lq/ZzlpW5/u9Ef FhXE+v7YrG1Do+iLy3vOLkzfIdALmO6+QlUFLU9ISWXGpUNmf3PH0+Aol RZsHjrB82QO0f/gG6Wft6Mjih1f8jMXtJH0O54N4EZwU2GvvcgZdrzx3S z6fGdQHn1nreudEbJDOmUCdJEF/8lQljk01pOkin2XgYUHDGollWA/p4/ VSSfJMeWNHH3aa0loKf1c1cr6P5aUf6LWd0gjpbm4mFPal6v1n+kQju9t g==; X-CSE-ConnectionGUID: snKe/knISP6l9VsurJsrEg== X-CSE-MsgGUID: a+oiXOLGQeGMvwDoL7FsHg== X-IronPort-AV: E=McAfee;i="6600,9927,11027"; a="24326334" X-IronPort-AV: E=Sophos;i="6.07,162,1708416000"; d="scan'208";a="24326334" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 13:10:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,162,1708416000"; d="scan'208";a="16633871" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [10.212.81.17]) ([10.212.81.17]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 13:09:59 -0700 Message-ID: <3cfc1dd4-e1a1-4d87-86f6-0f1833185172@intel.com> Date: Thu, 28 Mar 2024 13:09:59 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 15/26] range: Add range_overlaps() Content-Language: en-US To: Ira Weiny , Fan Ni , Jonathan Cameron , Navneet Singh Cc: Dan Williams , Davidlohr Bueso , Alison Schofield , Vishal Verma , linux-btrfs@vger.kernel.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Mason , Josef Bacik , David Sterba References: <20240324-dcd-type2-upstream-v1-0-b7b00d623625@intel.com> <20240324-dcd-type2-upstream-v1-15-b7b00d623625@intel.com> From: Dave Jiang In-Reply-To: <20240324-dcd-type2-upstream-v1-15-b7b00d623625@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/24/24 4:18 PM, Ira Weiny wrote: > Code to support CXL Dynamic Capacity devices will have extent ranges > which need to be compared for intersection not a subset as is being > checked in range_contains(). > > range_overlaps() is defined in btrfs with a different meaning from what > is required in the standard range code. Dan Williams pointed this out > in [1]. Adjust the btrfs call according to his suggestion there. > > Then add a generic range_overlaps(). > > Cc: Dan Williams > Cc: Chris Mason > Cc: Josef Bacik > Cc: David Sterba > Cc: linux-btrfs@vger.kernel.org > Signed-off-by: Ira Weiny Reviewed-by: Dave Jiang > > [1] https://lore.kernel.org/all/65949f79ef908_8dc68294f2@dwillia2-xfh.jf.intel.com.notmuch/ > --- > fs/btrfs/ordered-data.c | 10 +++++----- > include/linux/range.h | 7 +++++++ > 2 files changed, 12 insertions(+), 5 deletions(-) > > diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c > index 59850dc17b22..032d30a49edc 100644 > --- a/fs/btrfs/ordered-data.c > +++ b/fs/btrfs/ordered-data.c > @@ -111,8 +111,8 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 file_offset, > return NULL; > } > > -static int range_overlaps(struct btrfs_ordered_extent *entry, u64 file_offset, > - u64 len) > +static int btrfs_range_overlaps(struct btrfs_ordered_extent *entry, u64 file_offset, > + u64 len) > { > if (file_offset + len <= entry->file_offset || > entry->file_offset + entry->num_bytes <= file_offset) > @@ -914,7 +914,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_range( > > while (1) { > entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); > - if (range_overlaps(entry, file_offset, len)) > + if (btrfs_range_overlaps(entry, file_offset, len)) > break; > > if (entry->file_offset >= file_offset + len) { > @@ -1043,12 +1043,12 @@ struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range( > } > if (prev) { > entry = rb_entry(prev, struct btrfs_ordered_extent, rb_node); > - if (range_overlaps(entry, file_offset, len)) > + if (btrfs_range_overlaps(entry, file_offset, len)) > goto out; > } > if (next) { > entry = rb_entry(next, struct btrfs_ordered_extent, rb_node); > - if (range_overlaps(entry, file_offset, len)) > + if (btrfs_range_overlaps(entry, file_offset, len)) > goto out; > } > /* No ordered extent in the range */ > diff --git a/include/linux/range.h b/include/linux/range.h > index 6ad0b73cb7ad..9a46f3212965 100644 > --- a/include/linux/range.h > +++ b/include/linux/range.h > @@ -13,11 +13,18 @@ static inline u64 range_len(const struct range *range) > return range->end - range->start + 1; > } > > +/* True if r1 completely contains r2 */ > static inline bool range_contains(struct range *r1, struct range *r2) > { > return r1->start <= r2->start && r1->end >= r2->end; > } > > +/* True if any part of r1 overlaps r2 */ > +static inline bool range_overlaps(struct range *r1, struct range *r2) > +{ > + return r1->start <= r2->end && r1->end >= r2->start; > +} > + > int add_range(struct range *range, int az, int nr_range, > u64 start, u64 end); > >