From owner-freebsd-fs@freebsd.org Sun Apr 1 10:09:49 2018 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9DF83F7DECD for ; Sun, 1 Apr 2018 10:09:49 +0000 (UTC) (envelope-from aijazbaig1@gmail.com) Received: from mail-io0-x234.google.com (mail-io0-x234.google.com [IPv6:2607:f8b0:4001:c06::234]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5687C819C6 for ; Sun, 1 Apr 2018 10:09:49 +0000 (UTC) (envelope-from aijazbaig1@gmail.com) Received: by mail-io0-x234.google.com with SMTP id m83so15172324ioi.8 for ; Sun, 01 Apr 2018 03:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/mYCr28wYmIUFvpE93phq1gwpcGPmBLmX9JhubGScoA=; b=OOd33JsIYQEGi4u4NpXWP0RlGa9LN+NxIUiT1SMAUzxWPDqlq5v7SGa/B7tdJLRySO ptO/j77HN9nUTKo612K3LdyRi9ffmB3RpQ7JL60Kz30596cYAnhblTSOruP1+SlkVghc qH4fnLmTcOFCCyOn4wnGaYs0ZTbFtnTfmz/H7AXBSDLqzLsT368xHiv5DQtavnyPkyyR NYc+tswqBKf3UiSzKkmSN7W5/za2W4pZ+AsqsvWBICIBvbIKd67UntQ2j+e4v8Q9qz8a 1sLkOHnnoRNigiVt3vxu9LOsH69du3Za5WbVH/2mMJgq4d1xvarxf3pkQft9Ro3cMMYf BITQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=/mYCr28wYmIUFvpE93phq1gwpcGPmBLmX9JhubGScoA=; b=qds38qnyiLi37cy93U/KqHNsmDHZzF1hgMgLgx0E9quMwEeVkEL7sBRZyAr7ws/wyX YEbBAHSjxSy31PHZlFV9ppaAI2/NaoLLhXO1ls/JeTzGxs1h808xs3Wpk+cVcyZpBc15 PMuE1RTRh3e1HTnM9T9z2O5mdRgNF7RipmG8iixH21N1M6gGPLk03mvGr2XfCMYdRxnR fWMbxueT1g1Rk7cRwcHIAWB88DpkZN6lEfZyUwkw1S0MfNNCCnbUPiKu/FLrgRtSDfAi VfivROlBPS5U0gZYMkvPnZs4jjcJYoGugOQ+QqmGPygEScgjhokyyotlV+UzsflNd4gq +9Dg== X-Gm-Message-State: ALQs6tAr8d+92OwAwuJ8ubKbkC9Q8ob3gec2y9ciz1ruGxMOuLumgX8R zKQQm2MVJ35HNr0HZU1zSRi1lG4DPIx1+wWbUPM= X-Google-Smtp-Source: AIpwx4/+beP+BENmYY/OGz1jJKfBHInzXaOftwgx85UDyAUYmpnBqD/dQ+V5awPpFnjJ/pW9Vpj6k+agJ0wGfrhN/tw= X-Received: by 10.107.12.202 with SMTP id 71mr4760543iom.63.1522577388553; Sun, 01 Apr 2018 03:09:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.141.22 with HTTP; Sun, 1 Apr 2018 03:09:47 -0700 (PDT) In-Reply-To: <201802250642.w1P6g8Wm064509@chez.mckusick.com> References: <201802250642.w1P6g8Wm064509@chez.mckusick.com> From: Aijaz Baig Date: Sun, 1 Apr 2018 15:39:47 +0530 Message-ID: Subject: Re: Regarding vop_vector To: Kirk McKusick Cc: freebsd-fs@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.25 X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Apr 2018 10:09:49 -0000 Thank you for the detailed summary! Will go through On Sun, Feb 25, 2018 at 12:12 PM, Kirk McKusick wrote: > > From: Aijaz Baig > > Date: Sun, 25 Feb 2018 07:24:12 +0530 > > Subject: Regarding vop_vector > > To: freebsd-fs@freebsd.org > > > > Hello > > > > I am trying to understand how the VFS layer within FreeBSD and I was > rather > > stumped while trying to find where vop_vector was declared. Upon > searching > > the internet, realized that an awk script is used to "generate" this > like so: > > > > /sys/tools/vnode_if.awk /sys/kern/vnode_if.src -q > > > > So I was wondering if anyone could provide me a (brief would be fine as > > well) walk through the memory lane as to why such an 'odd looking' way > was > > adopted (perhaps it is brilliant but my thick skull is unable to fathom > > it's brilliance). > > > > Keen to hear from you experts out there please! > > -- > > Best Regards, > > Aijaz Baig > > As the person that came up with this idea (in the 1980's) let me try to > explain my thinking. Suppose you want to add a new VFS operation. Before > I created the script, you had to create macros for it in at least four > different files. Now you just need to add a concise and readable > description > of it in /sys/kern/vnode_if.src then run the script and all the boilerplate > gets generated for you. > > Let me give you a short example. Consider the VFS operator to check to > see if a vnode is locked, typically used as > > if (VOP_ISLOCKED(vp)) { > do something with locked vp; > } > > The description of it in /sys/kern/vnode_if.src is three lines: > > vop_islocked { > IN struct vnode *vp; > }; > > Here is what is generated for it in the compile directory by the awk > script. > In /sys/amd64/compile/GENERIC/vnode_if.c: > > static int vop_islocked_vp_offsets[] = { > VOPARG_OFFSETOF(struct vop_islocked_args,a_vp), > VDESC_NO_OFFSET > }; > > > SDT_PROBE_DEFINE2(vfs, vop, vop_islocked, entry, "struct vnode *", "struct > vop_islocked_args *"); > > SDT_PROBE_DEFINE3(vfs, vop, vop_islocked, return, "struct vnode *", > "struct vop_islocked_args *", "int"); > > > int > VOP_ISLOCKED_AP(struct vop_islocked_args *a) > { > > return(VOP_ISLOCKED_APV(a->a_vp->v_op, a)); > } > > int > VOP_ISLOCKED_APV(struct vop_vector *vop, struct vop_islocked_args *a) > { > int rc; > > VNASSERT(a->a_gen.a_desc == &vop_islocked_desc, a->a_vp, > ("Wrong a_desc in vop_islocked(%p, %p)", a->a_vp, a)); > while(vop != NULL && \ > vop->vop_islocked == NULL && vop->vop_bypass == NULL) > vop = vop->vop_default; > VNASSERT(vop != NULL, a->a_vp, ("No vop_islocked(%p, %p)", > a->a_vp, a)); > SDT_PROBE2(vfs, vop, vop_islocked, entry, a->a_vp, a); > > KTR_START1(KTR_VOP, "VOP", "VOP_ISLOCKED", (uintptr_t)a, > "vp:0x%jX", (uintptr_t)a->a_vp); > VFS_PROLOGUE(a->a_vp->v_mount); > if (vop->vop_islocked != NULL) > rc = vop->vop_islocked(a); > else > rc = vop->vop_bypass(&a->a_gen); > VFS_EPILOGUE(a->a_vp->v_mount); > SDT_PROBE3(vfs, vop, vop_islocked, return, a->a_vp, a, rc); > > if (rc == 0) { > } else { > } > KTR_STOP1(KTR_VOP, "VOP", "VOP_ISLOCKED", (uintptr_t)a, > "vp:0x%jX", (uintptr_t)a->a_vp); > return (rc); > } > > struct vnodeop_desc vop_islocked_desc = { > "vop_islocked", > 0, > (vop_bypass_t *)VOP_ISLOCKED_AP, > vop_islocked_vp_offsets, > VDESC_NO_OFFSET, > VDESC_NO_OFFSET, > VDESC_NO_OFFSET, > VDESC_NO_OFFSET, > }; > > In /sys/amd64/compile/GENERIC/vnode_if.h: > > struct vop_islocked_args { > struct vop_generic_args a_gen; > struct vnode *a_vp; > }; > > extern struct vnodeop_desc vop_islocked_desc; > > int VOP_ISLOCKED_AP(struct vop_islocked_args *); > int VOP_ISLOCKED_APV(struct vop_vector *vop, struct vop_islocked_args *); > > static __inline int VOP_ISLOCKED( > struct vnode *vp) > { > struct vop_islocked_args a; > > a.a_gen.a_desc = &vop_islocked_desc; > a.a_vp = vp; > return (VOP_ISLOCKED_APV(vp->v_op, &a)); > } > > In /sys/amd64/compile/GENERIC/vnode_if_newproto.h, > an entry in the vop_vector array: > > struct vop_vector { > struct vop_vector *vop_default; > vop_bypass_t *vop_bypass; > vop_islocked_t *vop_islocked; > ... > }; > > And finally in /sys/amd64/compile/GENERIC/vnode_if_typedef.h: > > struct vop_islocked_args; > typedef int vop_islocked_t(struct vop_islocked_args *); > > And absent this script, every time you wanted to make a change in the > boilerplate, you would have to go through and fix it for every existing > VFS operator (and trust me the boilerplate has changed a *lot* since I > first did it in the 1980's :-) > > Kirk McKusick > -- Best Regards, Aijaz Baig