From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 6B9D2384402C for ; Wed, 1 Jul 2020 21:27:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6B9D2384402C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-7shv0y_IPMC67leoFdYtzg-1; Wed, 01 Jul 2020 17:27:23 -0400 X-MC-Unique: 7shv0y_IPMC67leoFdYtzg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 66992108BD09 for ; Wed, 1 Jul 2020 21:27:22 +0000 (UTC) Received: from greed.delorie.com (ovpn-113-9.phx2.redhat.com [10.3.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3BB1277884; Wed, 1 Jul 2020 21:27:17 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 061LRGdu007349; Wed, 1 Jul 2020 17:27:16 -0400 From: DJ Delorie To: "Carlos O'Donell" Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 2/4] : New abstraction for combining NSS modules and NSS actions In-Reply-To: <3133c91b-52bf-e45d-cd39-72e923cea450@redhat.com> (carlos@redhat.com) Date: Wed, 01 Jul 2020 17:27:16 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jul 2020 21:27:26 -0000 "Carlos O'Donell" writes: >> + /* The next element of the list.x */ > > s/.x/./g Done. > Suggest: > > /* Lock covers the nss_actions list. */ Changed. >> +/* Returns true if the actions are equal (same module, same actions >> + aray). */ > > s/aray/array/g Changed. >> + >> +/* Returns true if the COUNT actions at A and B are equal (according >> + to actions_equal above). */ > > Suggest: > > /* Returns true if COUNT actions at A and B are equal (according > to actions_equal above). Caller must ensure that A and B have > at least COUNT actions. */ Went with: /* Returns true if COUNT actions at A and B are equal (according to actions_equal above). Caller must ensure that either A or B have at least COUNT actions. */ Like strcmp, a NULL entry will end the search early but safely (as a mismatch). The only case that causes problems is if both A and B are equal, but both shorter than COUNT - then we iterate past the NULL terminator record. >> +/* Index in actions. */ > > Suggest: > > /* Value to add to first nss_status value to get zero. */ > #define NSS_STATUS_BIAS 2 > /* Number of bits per lookup action. */ > #define NSS_BPL 2 > #define NSS_BPL_MASK ((1 << NSS_BPL) - 1) > > /* Index in actions of an NSS status. > Note that in nss/nss.h the status starts at -2, and > we shift that up to zero by adding 2. Thus for example > NSS_STATUS_TRYAGAIN, which is -2, would index into the > 0th bit place as expected. */ Changed. >> +static inline int >> +nss_actions_bits_index (enum nss_status status) >> +{ >> + return 2 * (2 + status); > > Suggest: > > return NSS_BPL * (NSS_STATUS_BIAS + status); Changed. >> +nss_action_get (const struct nss_action *action, enum nss_status status) >> +{ >> + return (action->action_bits >> nss_actions_bits_index (status)) & 3; > > Suggest: > > return (action->action_bits >> nss_actions_bits_index (status)) & NSS_BPL_MASK; Changed. >> + int offset = nss_actions_bits_index (status); >> + unsigned int mask = 3 << offset; > > Use NSS_BPL_MASK and then "mask" makes sense. Changed. >> + unsigned int bits = actions; >> + /* Produces 0b00 .. 00 AA AA AA AA AA. */ >> + action->action_bits = bits * 0x155; > > This needs to be rewritten to be expressed as a function of all the > nss_status entries. That is to say you need to call nss_action_set > for all status and actions. I dislike the above magic. It should be > immediately readable and understandable that we set all the entries. I went with this: unsigned int bits = actions & NSS_BPL_MASK; action->action_bits = ( bits | (bits << (NSS_BPL * 1)) | (bits << (NSS_BPL * 2)) | (bits << (NSS_BPL * 3)) | (bits << (NSS_BPL * 4)) ); Sadly, GCC does not optimize this to a single multiplication, but at least it's only called when parsing a new /etc/nsswitch.conf so performance here isn't critical.