From patchwork Mon May 11 20:56:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 23081 Received: from lists.samba.org (mail.samba.org [66.70.73.150]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4BKudhh006507 for ; Mon, 11 May 2009 20:56:39 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 56E22163BCF for ; Mon, 11 May 2009 20:56:13 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on dp.samba.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.8 tests=BAYES_00 autolearn=ham version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by lists.samba.org (Postfix) with ESMTP id 94CE7163BFA for ; Mon, 11 May 2009 20:55:55 +0000 (GMT) Received: from hch by bombadil.infradead.org with local (Exim 4.69 #1 (Red Hat Linux)) id 1M3cXt-0003wd-AU; Mon, 11 May 2009 20:56:21 +0000 Date: Mon, 11 May 2009 16:56:21 -0400 From: Christoph Hellwig To: Jeff Layton Message-ID: <20090511205620.GC5751@infradead.org> References: <1242073472-7100-1-git-send-email-jlayton@redhat.com> <1242073472-7100-4-git-send-email-jlayton@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1242073472-7100-4-git-send-email-jlayton@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Cc: linux-fsdevel@vger.kernel.org, linux-cifs-client@lists.samba.org Subject: [linux-cifs-client] Re: [PATCH 03/13] cifs: allow get_cifs_acl to be called without an inode X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Errors-To: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org On Mon, May 11, 2009 at 04:24:22PM -0400, Jeff Layton wrote: > We'll need this later when we restructure cifs_get_inode_info. > > Signed-off-by: Jeff Layton > --- > fs/cifs/cifsacl.c | 25 ++++++------------------- > 1 files changed, 6 insertions(+), 19 deletions(-) > > static struct cifs_ntsd *get_cifs_acl(u32 *pacllen, struct inode *inode, > - const char *path, const __u16 *pfid) > + const char *path, const __u16 *pfid) > { > struct cifsFileInfo *open_file = NULL; > - bool unlock_file = false; > int xid; > int rc = -EIO; > __u16 fid; > - struct super_block *sb; > - struct cifs_sb_info *cifs_sb; > struct cifs_ntsd *pntsd = NULL; > + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); This isn't going to work with a NULL inode. But this whole set_cifs_acl function is a real mess anyway and needs some splitting up. What about the untested patch below? Index: linux-2.6/fs/cifs/cifsacl.c =================================================================== --- linux-2.6.orig/fs/cifs/cifsacl.c 2009-05-11 22:35:29.841784452 +0200 +++ linux-2.6/fs/cifs/cifsacl.c 2009-05-11 22:55:19.465660251 +0200 @@ -552,67 +552,65 @@ static int build_sec_desc(struct cifs_nt return rc; } - -/* Retrieve an ACL from the server */ -static struct cifs_ntsd *get_cifs_acl(u32 *pacllen, struct inode *inode, - const char *path, const __u16 *pfid) +static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, + __u16 fid, u32 *pacllen) { - struct cifsFileInfo *open_file = NULL; - bool unlock_file = false; - int xid; - int rc = -EIO; - __u16 fid; - struct super_block *sb; - struct cifs_sb_info *cifs_sb; struct cifs_ntsd *pntsd = NULL; + int xid, rc; - cFYI(1, ("get mode from ACL for %s", path)); + xid = GetXid(); + rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen); + FreeXid(xid); - if (inode == NULL) - return NULL; - xid = GetXid(); - if (pfid == NULL) - open_file = find_readable_file(CIFS_I(inode)); - else - fid = *pfid; + cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen)); + return pntsd; +} - sb = inode->i_sb; - if (sb == NULL) { - FreeXid(xid); - return NULL; - } - cifs_sb = CIFS_SB(sb); +static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, + const char *path, u32 *pacllen) +{ + struct cifs_ntsd *pntsd = NULL; + int oplock = 0; + int xid, rc; + __u16 fid; - if (open_file) { - unlock_file = true; - fid = open_file->netfid; - } else if (pfid == NULL) { - int oplock = 0; - /* open file */ - rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN, - READ_CONTROL, 0, &fid, &oplock, NULL, - cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & - CIFS_MOUNT_MAP_SPECIAL_CHR); - if (rc != 0) { - cERROR(1, ("Unable to open file to get ACL")); - FreeXid(xid); - return NULL; - } + xid = GetXid(); + + rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN, READ_CONTROL, 0, + &fid, &oplock, NULL, cifs_sb->local_nls, + cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); + if (rc) { + cERROR(1, ("Unable to open file to get ACL")); + goto out; } rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen); cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen)); - if (unlock_file == true) /* find_readable_file increments ref count */ - atomic_dec(&open_file->wrtPending); - else if (pfid == NULL) /* if opened above we have to close the handle */ - CIFSSMBClose(xid, cifs_sb->tcon, fid); - /* else handle was passed in by caller */ + CIFSSMBClose(xid, cifs_sb->tcon, fid); + out: FreeXid(xid); return pntsd; } +/* Retrieve an ACL from the server */ +static struct cifs_ntsd *get_cifs_acl(u32 *pacllen, struct inode *inode, + const char *path) +{ + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); + struct cifs_ntsd *pntsd = NULL; + struct cifsFileInfo *open_file; + + open_file = find_readable_file(CIFS_I(inode)); + if (!open_file) + return get_cifs_acl_by_path(cifs_sb, path, pacllen); + + pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen); + atomic_dec(&open_file->wrtPending); + return pntsd; +} + /* Set an ACL on the server */ static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, struct inode *inode, const char *path) @@ -675,7 +673,13 @@ void acl_to_uid_mode(struct inode *inode int rc = 0; cFYI(DBG2, ("converting ACL to mode for %s", path)); - pntsd = get_cifs_acl(&acllen, inode, path, pfid); + + if (pfid) { + pntsd = get_cifs_acl_by_fid(CIFS_SB(inode->i_sb), *pfid, + &acllen); + } else { + pntsd = get_cifs_acl(&acllen, inode, path); + } /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ if (pntsd) @@ -698,7 +702,7 @@ int mode_to_acl(struct inode *inode, con cFYI(DBG2, ("set ACL from mode for %s", path)); /* Get the security descriptor */ - pntsd = get_cifs_acl(&secdesclen, inode, path, NULL); + pntsd = get_cifs_acl(&secdesclen, inode, path); /* Add three ACEs for owner, group, everyone getting rid of other ACEs as chmod disables ACEs and set the security descriptor */