From patchwork Tue Jan 1 02:11:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10745617 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0876817E8 for ; Tue, 1 Jan 2019 02:11:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF46528B4B for ; Tue, 1 Jan 2019 02:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3CCE28B4F; Tue, 1 Jan 2019 02:11:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C8CD28B4B for ; Tue, 1 Jan 2019 02:11:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728074AbfAACLF (ORCPT ); Mon, 31 Dec 2018 21:11:05 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:32784 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728004AbfAACLF (ORCPT ); Mon, 31 Dec 2018 21:11:05 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0128ubv170750 for ; Tue, 1 Jan 2019 02:11:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=0N0dHmWxlvksMF1gpMwRKmVvhbgw0G62f/CO8trtFoI=; b=RevDtlP5/rtbcUJf9KTwaglqG+/VfH9og5cKyt9jPSCXI9aGBXaTb241kyAXU0olZRox ++Eyj0em36B54zseEZSX2TXUQjr0gCifDpfHfAmH4apg+gknCZFkhOhaapoIbwjub8+J 0x8Gabe65xvYpzorlr2v/yzgcu/lrTL51folpC2iwrM1cVAkxNd16VFL4xgvG4bRiLqF twzW5drFJQ1oPGPTgRl4FzviLGLRuHTGdYGR37DDFAcsi6YmFJoQG9+EfuMwhbJTJ/aL YW3ZD7OOLvjcwEg4yU881oNoJerlQ3hsFaoNhvHO6C7KIIn+MaI00NE3q4WnEVVxzvkg ng== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2pp1jqx3uv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 01 Jan 2019 02:11:03 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x012B3LA007389 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 1 Jan 2019 02:11:03 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x012B3gN003768 for ; Tue, 1 Jan 2019 02:11:03 GMT Received: from localhost (/10.159.150.85) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 31 Dec 2018 18:11:03 -0800 Subject: [PATCH 10/17] xfs: create a blob array data structure From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Mon, 31 Dec 2018 18:11:02 -0800 Message-ID: <154630866210.15625.7909115493059029108.stgit@magnolia> In-Reply-To: <154630859850.15625.17640302184521917854.stgit@magnolia> References: <154630859850.15625.17640302184521917854.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9123 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=715 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901010018 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Create a simple 'blob array' data structure for storage of arbitrarily sized metadata objects that will be used to reconstruct metadata. For the intended usage (temporarily storing extended attribute names and values) we only have to support storing objects and retrieving them. This initial implementation uses linked lists to store the blobs, but a subsequent patch will restructure the backend to avoid using high order pinned kernel memory. Signed-off-by: Darrick J. Wong --- fs/xfs/Makefile | 1 fs/xfs/scrub/blob.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/blob.h | 23 ++++++++++ 3 files changed, 145 insertions(+) create mode 100644 fs/xfs/scrub/blob.c create mode 100644 fs/xfs/scrub/blob.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index 5691f73711b5..ed719baac5af 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -168,6 +168,7 @@ xfs-y += $(addprefix scrub/, \ alloc_repair.o \ array.o \ bitmap.o \ + blob.o \ bmap_repair.o \ ialloc_repair.o \ inode_repair.o \ diff --git a/fs/xfs/scrub/blob.c b/fs/xfs/scrub/blob.c new file mode 100644 index 000000000000..9bcac9cd3486 --- /dev/null +++ b/fs/xfs/scrub/blob.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "scrub/array.h" +#include "scrub/blob.h" + +/* + * XFS Blob Storage + * ================ + * Stores and retrieves blobs using a list. Objects are appended to + * the list and the pointer is returned as a magic cookie for retrieval. + */ + +#define XB_KEY_MAGIC 0xABAADDAD +struct xb_key { + struct list_head list; + uint32_t magic; + uint32_t size; + /* blob comes after here */ +} __attribute__((packed)); + +#define XB_KEY_SIZE(sz) (sizeof(struct xb_key) + (sz)) + +/* Initialize a blob storage object. */ +struct xblob * +xblob_init(void) +{ + struct xblob *blob; + int error; + + error = -ENOMEM; + blob = kmem_alloc(sizeof(struct xblob), KM_NOFS | KM_MAYFAIL); + if (!blob) + return ERR_PTR(error); + + INIT_LIST_HEAD(&blob->list); + return blob; +} + +/* Destroy a blob storage object. */ +void +xblob_destroy( + struct xblob *blob) +{ + struct xb_key *key, *n; + + list_for_each_entry_safe(key, n, &blob->list, list) { + list_del(&key->list); + kmem_free(key); + } + kmem_free(blob); +} + +/* Retrieve a blob. */ +int +xblob_get( + struct xblob *blob, + xblob_cookie cookie, + void *ptr, + uint32_t size) +{ + struct xb_key *key = (struct xb_key *)cookie; + + if (key->magic != XB_KEY_MAGIC) { + ASSERT(0); + return -ENODATA; + } + if (size < key->size) { + ASSERT(0); + return -EFBIG; + } + + memcpy(ptr, key + 1, key->size); + return 0; +} + +/* Store a blob. */ +int +xblob_put( + struct xblob *blob, + xblob_cookie *cookie, + void *ptr, + uint32_t size) +{ + struct xb_key *key; + + key = kmem_alloc(XB_KEY_SIZE(size), KM_NOFS | KM_MAYFAIL); + if (!key) + return -ENOMEM; + + INIT_LIST_HEAD(&key->list); + list_add_tail(&key->list, &blob->list); + key->magic = XB_KEY_MAGIC; + key->size = size; + memcpy(key + 1, ptr, size); + *cookie = (xblob_cookie)key; + return 0; +} + +/* Free a blob. */ +int +xblob_free( + struct xblob *blob, + xblob_cookie cookie) +{ + struct xb_key *key = (struct xb_key *)cookie; + + if (key->magic != XB_KEY_MAGIC) { + ASSERT(0); + return -ENODATA; + } + key->magic = 0; + list_del(&key->list); + kmem_free(key); + return 0; +} diff --git a/fs/xfs/scrub/blob.h b/fs/xfs/scrub/blob.h new file mode 100644 index 000000000000..f10584dd5657 --- /dev/null +++ b/fs/xfs/scrub/blob.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __XFS_SCRUB_BLOB_H__ +#define __XFS_SCRUB_BLOB_H__ + +struct xblob { + struct list_head list; +}; + +typedef void *xblob_cookie; + +struct xblob *xblob_init(void); +void xblob_destroy(struct xblob *blob); +int xblob_get(struct xblob *blob, xblob_cookie cookie, void *ptr, + uint32_t size); +int xblob_put(struct xblob *blob, xblob_cookie *cookie, void *ptr, + uint32_t size); +int xblob_free(struct xblob *blob, xblob_cookie cookie); + +#endif /* __XFS_SCRUB_BLOB_H__ */