Whamcloud - gitweb
LU-9859 libcfs: remove Lustre specific bitmap handling 22/48222/3
authorJames Simmons <jsimmons@infradead.org>
Tue, 16 Aug 2022 13:46:36 +0000 (09:46 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 1 Sep 2022 05:55:24 +0000 (05:55 +0000)
Only the NRS TBF handling uses the Lustre specific bitmap
handling. Convert to the Linux bitmap API and remove the
Lustre specific bitmap handling.

Test-Parameters: trivial testlist=sanityn env=ONLY=77
Change-Id: I58dcf869778d6cf6349c16e73d75e53735ffb97d
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/48222
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/bitmap.h [deleted file]
libcfs/include/libcfs/libcfs.h
lustre/include/lustre_nrs_tbf.h
lustre/include/obd.h
lustre/ptlrpc/nrs_tbf.c

index be29cfb..3da9711 100644 (file)
@@ -6,7 +6,6 @@ DIST_SUBDIRS += crypto
 libcfsdir = $(includedir)/libcfs
 
 EXTRA_DIST = \
-       bitmap.h \
        libcfs.h \
        libcfs_cpu.h \
        libcfs_crypto.h \
diff --git a/libcfs/include/libcfs/bitmap.h b/libcfs/include/libcfs/bitmap.h
deleted file mode 100644 (file)
index b2bd599..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, 2014, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- */
-#ifndef _LIBCFS_BITMAP_H_
-#define _LIBCFS_BITMAP_H_
-
-#include <linux/interrupt.h>
-#include <libcfs/libcfs_private.h>
-
-struct cfs_bitmap {
-       unsigned int size;
-       unsigned long data[0];
-};
-
-#define CFS_BITMAP_SIZE(nbits) \
-       (BITS_TO_LONGS(nbits) * sizeof(long) + sizeof(struct cfs_bitmap))
-
-static inline
-struct cfs_bitmap *CFS_ALLOCATE_BITMAP(int size)
-{
-       struct cfs_bitmap *ptr;
-
-       LIBCFS_ALLOC(ptr, CFS_BITMAP_SIZE(size));
-       if (ptr == NULL)
-               RETURN(ptr);
-
-       ptr->size = size;
-
-       RETURN(ptr);
-}
-
-static inline void CFS_RESET_BITMAP(struct cfs_bitmap *bitmap)
-{
-       if (bitmap->size > 0) {
-               int nbits = bitmap->size;
-
-               memset(bitmap, 0, CFS_BITMAP_SIZE(nbits));
-               bitmap->size = nbits;
-       }
-}
-
-#define CFS_FREE_BITMAP(ptr)   LIBCFS_FREE(ptr, CFS_BITMAP_SIZE(ptr->size))
-
-static inline
-void cfs_bitmap_set(struct cfs_bitmap *bitmap, int nbit)
-{
-       set_bit(nbit, bitmap->data);
-}
-
-static inline
-void cfs_bitmap_clear(struct cfs_bitmap *bitmap, int nbit)
-{
-       test_and_clear_bit(nbit, bitmap->data);
-}
-
-static inline
-int cfs_bitmap_check(struct cfs_bitmap *bitmap, int nbit)
-{
-       return test_bit(nbit, bitmap->data);
-}
-
-static inline
-int cfs_bitmap_test_and_clear(struct cfs_bitmap *bitmap, int nbit)
-{
-       return test_and_clear_bit(nbit, bitmap->data);
-}
-
-/* return 0 is bitmap has none set bits */
-static inline
-int cfs_bitmap_check_empty(struct cfs_bitmap *bitmap)
-{
-       return find_first_bit(bitmap->data, bitmap->size) == bitmap->size;
-}
-
-static inline
-void cfs_bitmap_copy(struct cfs_bitmap *new, struct cfs_bitmap *old)
-{
-       size_t newsize;
-
-       LASSERT(new->size >= old->size);
-       newsize = new->size;
-       memcpy(new, old, CFS_BITMAP_SIZE(old->size));
-       new->size = newsize;
-}
-
-#define cfs_foreach_bit(bitmap, pos)                                   \
-       for ((pos) = find_first_bit((bitmap)->data, bitmap->size);      \
-            (pos) < (bitmap)->size;                                    \
-            (pos) = find_next_bit((bitmap)->data, (bitmap)->size, (pos) + 1))
-
-#endif
index 50ad978..6cfe6a4 100644 (file)
@@ -48,7 +48,6 @@
 #include <uapi/linux/lnet/libcfs_ioctl.h>
 #include <libcfs/libcfs_debug.h>
 #include <libcfs/libcfs_private.h>
-#include <libcfs/bitmap.h>
 #include <libcfs/libcfs_cpu.h>
 #include <libcfs/libcfs_string.h>
 #include <libcfs/libcfs_workitem.h>
index feffa4e..4bc9abf 100644 (file)
@@ -161,7 +161,8 @@ struct nrs_tbf_rule {
        /** uid/gid list string of the rule. */
        char                            *tr_ids_str;
        /** Opcode bitmap of the rule. */
-       struct cfs_bitmap               *tr_opcodes;
+       unsigned long                   *tr_opcodes;
+       u32                             tr_opcodes_cnt;
        /** Opcode list string of the rule.*/
        char                            *tr_opcodes_str;
        /** Condition list of the rule.*/
@@ -332,7 +333,8 @@ enum nrs_tbf_field {
 struct nrs_tbf_expression {
        enum nrs_tbf_field       te_field;
        struct list_head         te_cond;
-       struct cfs_bitmap       *te_opcodes;
+       unsigned long           *te_opcodes;
+       u32                      te_opcodes_cnt;
        struct list_head         te_linkage;
 };
 
index 1e8df87..78ac884 100644 (file)
@@ -41,7 +41,6 @@
 
 #include <uapi/linux/lustre/lustre_idl.h>
 #include <lustre_lib.h>
-#include <libcfs/bitmap.h>
 #ifdef HAVE_SERVER_SUPPORT
 # include <lu_target.h>
 # include <obd_target.h>
index 1c8d3b0..eca5bb5 100644 (file)
@@ -1760,7 +1760,7 @@ nrs_tbf_expression_free(struct nrs_tbf_expression *expr)
                nrs_tbf_jobid_list_free(&expr->te_cond);
                break;
        case NRS_TBF_FIELD_OPCODE:
-               CFS_FREE_BITMAP(expr->te_opcodes);
+               bitmap_free(expr->te_opcodes);
                break;
        case NRS_TBF_FIELD_UID:
        case NRS_TBF_FIELD_GID:
@@ -1824,7 +1824,7 @@ nrs_tbf_check_field(struct cfs_lstr *field, char *str)
 }
 
 static int
-nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr);
+nrs_tbf_opcode_list_parse(char *str, int len, unsigned long **bitmaptr);
 static int
 nrs_tbf_id_list_parse(char *str, int len, struct list_head *id_list,
                      enum nrs_tbf_flag tif);
@@ -1978,7 +1978,7 @@ nrs_tbf_expression_match(struct nrs_tbf_expression *expr,
        case NRS_TBF_FIELD_JOBID:
                return nrs_tbf_jobid_list_match(&expr->te_cond, cli->tc_jobid);
        case NRS_TBF_FIELD_OPCODE:
-               return cfs_bitmap_check(expr->te_opcodes, cli->tc_opcode);
+               return test_bit(cli->tc_opcode, expr->te_opcodes);
        case NRS_TBF_FIELD_UID:
        case NRS_TBF_FIELD_GID:
                return nrs_tbf_id_list_match(&expr->te_cond, cli->tc_id);
@@ -2087,8 +2087,8 @@ static struct nrs_tbf_ops nrs_tbf_generic_ops = {
 
 static void nrs_tbf_opcode_rule_fini(struct nrs_tbf_rule *rule)
 {
-       if (rule->tr_opcodes != NULL)
-               CFS_FREE_BITMAP(rule->tr_opcodes);
+       if (rule->tr_opcodes)
+               bitmap_free(rule->tr_opcodes);
 
        LASSERT(rule->tr_opcodes_str != NULL);
        OBD_FREE(rule->tr_opcodes_str, strlen(rule->tr_opcodes_str) + 1);
@@ -2219,7 +2219,7 @@ nrs_tbf_opcode_cli_init(struct nrs_tbf_client *cli,
 
 #define MAX_OPCODE_LEN 32
 static int
-nrs_tbf_opcode_set_bit(const struct cfs_lstr *id, struct cfs_bitmap *opcodes)
+nrs_tbf_opcode_set_bit(const struct cfs_lstr *id, unsigned long *opcodes)
 {
        int     op = 0;
        char    opcode_str[MAX_OPCODE_LEN];
@@ -2234,21 +2234,21 @@ nrs_tbf_opcode_set_bit(const struct cfs_lstr *id, struct cfs_bitmap *opcodes)
        if (op < 0)
                return -EINVAL;
 
-       cfs_bitmap_set(opcodes, op);
+       set_bit(op, opcodes);
        return 0;
 }
 
 static int
-nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
+nrs_tbf_opcode_list_parse(char *str, int len, unsigned long **bitmaptr)
 {
-       struct cfs_bitmap *opcodes;
+       unsigned long *opcodes;
        struct cfs_lstr src;
        struct cfs_lstr res;
        int rc = 0;
-       ENTRY;
 
-       opcodes = CFS_ALLOCATE_BITMAP(LUSTRE_MAX_OPCODES);
-       if (opcodes == NULL)
+       ENTRY;
+       opcodes = bitmap_zalloc(LUSTRE_MAX_OPCODES, GFP_KERNEL);
+       if (!opcodes)
                return -ENOMEM;
 
        src.ls_str = str;
@@ -2267,7 +2267,7 @@ nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
        if (rc == 0 && bitmaptr)
                *bitmaptr = opcodes;
        else
-               CFS_FREE_BITMAP(opcodes);
+               bitmap_free(opcodes);
 
        RETURN(rc);
 }
@@ -2314,7 +2314,7 @@ nrs_tbf_opcode_rule_match(struct nrs_tbf_rule *rule,
        if (rule->tr_opcodes == NULL)
                return 0;
 
-       return cfs_bitmap_check(rule->tr_opcodes, cli->tc_opcode);
+       return test_bit(cli->tc_opcode, rule->tr_opcodes);
 }
 
 static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy,