From patchwork Wed Jul 17 00:02:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 11046831 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 181E46C5 for ; Wed, 17 Jul 2019 00:03:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4EDB286E4 for ; Wed, 17 Jul 2019 00:03:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8C4C286F1; Wed, 17 Jul 2019 00:03:02 +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,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 59564286E4 for ; Wed, 17 Jul 2019 00:03:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728597AbfGQADB (ORCPT ); Tue, 16 Jul 2019 20:03:01 -0400 Received: from mail-pl1-f177.google.com ([209.85.214.177]:42649 "EHLO mail-pl1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728235AbfGQADB (ORCPT ); Tue, 16 Jul 2019 20:03:01 -0400 Received: by mail-pl1-f177.google.com with SMTP id ay6so10940269plb.9; Tue, 16 Jul 2019 17:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=6qtRzCGL7WK76UGXP+HRSEdebM0ElpllvtXWv0KXh+k=; b=nWjYiwIsvy2m3ZL48akqQF57rrKGmA7iHENDwP7ja3iIPEnx4yLNgcyPw45fgGN6WU hOPHtq1nrWg/CKWr4kHxDMbniajrAdM+lV3/1iP7iGwSACLOkYGUmYGKZDUVJ/a6mHng SCbDA1m9DQ8T0kx/tAVkTaOir1dVZcVYzaY/GkMorX5UYoccoh5P7Gk9iHouPR5XYG7A vdkPC7pflDxuH9jHiPhMI9bB0uSpcmpuICdTopZDtYfdDqcCbxu3D3aKvEFYeZTM8uFl 5xmsq0TJ1U3WJEbRpEo/3bmxk4wTJF/UZpuzGTXjcNQH8HkzLt4Bi0nf82fr99d4SChE tdXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=6qtRzCGL7WK76UGXP+HRSEdebM0ElpllvtXWv0KXh+k=; b=tE/BLB/GwS9C+iikyOX7fuSJxDtogzlIlooGAkImh0Y8R3VNj7cEiFRzAAq6bt6Raf hQ8OeEGFmbqMRf6rWo30vKy07uN/UNtiP4ojoG35/fZ12KWDCKlqqG4xkerlDA0FInuv dtuvyrfJWq/ZGU9FNKE51MMzW1G7a427gwhbm9qKp8XvCGpK9jec85QiRrIdr4ZtAF/n b2FKBGvu8wuv4TcuKjrcDc8sm5oC/91MZIE7MVvBVu9OyWJvXM0sau2nhXGwPsk+j3Dn Ab0cPrZFYfUDXiJyAHyFBJtJdfIWcSYj70F4ZWOXEPyAF80Sq690tAK1uXToUnTyepLR HZ5w== X-Gm-Message-State: APjAAAVu73QsnCnVYjYafzR0FZGqxPvT2vJXDk3OyXBLIXLPHL4jcz2U Go7GXt0Nzv+GexvoUneqoi42gr98qixu6m4/vw3zNyXu X-Google-Smtp-Source: APXvYqzYlcIxK8DZAZ2lJxHm/qKgtSlmbXhMo9AJTr27xxbj04/ojlCXKhVcZag7HFx5+gp4CxGkjhFZ1tyc7dmO4NY= X-Received: by 2002:a17:902:20b:: with SMTP id 11mr39595363plc.78.1563321779919; Tue, 16 Jul 2019 17:02:59 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Tue, 16 Jul 2019 19:02:48 -0500 Message-ID: Subject: [PATCH][CIFS] Add flock support To: linux-fsdevel , CIFS Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The attached patch adds support for flock support similar to AFS, NFS etc. Although the patch did seem to work in my experiments with flock, I did notice that xfstest generic/504 fails because /proc/locks is not updated by cifs.ko after a successful lock. Any idea which helper function does that? Reviewed-by: Pavel Shilovsky From 9de8e68a8ab0c7e59080874f05b1df37477cf691 Mon Sep 17 00:00:00 2001 From: Steve French Date: Tue, 16 Jul 2019 18:55:38 -0500 Subject: [PATCH] cifs: add support for flock The flock system call locks the whole file rather than a byte range and is currently emulated by various other file systems by simply sending a byte range lock for the whole file. This version of the patch needs a minor update to pass xfstest generic/504 (we need to figure out how to update /proc/locks after an flock call is granted) Signed-off-by: Steve French --- fs/cifs/cifsfs.c | 3 +++ fs/cifs/cifsfs.h | 1 + fs/cifs/file.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 320c7a6fd318..a674f52b0403 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1168,6 +1168,7 @@ const struct file_operations cifs_file_ops = { .open = cifs_open, .release = cifs_close, .lock = cifs_lock, + .flock = cifs_flock, .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, @@ -1187,6 +1188,7 @@ const struct file_operations cifs_file_strict_ops = { .open = cifs_open, .release = cifs_close, .lock = cifs_lock, + .flock = cifs_flock, .fsync = cifs_strict_fsync, .flush = cifs_flush, .mmap = cifs_file_strict_mmap, @@ -1206,6 +1208,7 @@ const struct file_operations cifs_file_direct_ops = { .open = cifs_open, .release = cifs_close, .lock = cifs_lock, + .flock = cifs_flock, .fsync = cifs_fsync, .flush = cifs_flush, .mmap = cifs_file_mmap, diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index aea005703785..262f709822ee 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h @@ -108,6 +108,7 @@ extern ssize_t cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to); extern ssize_t cifs_user_writev(struct kiocb *iocb, struct iov_iter *from); extern ssize_t cifs_direct_writev(struct kiocb *iocb, struct iov_iter *from); extern ssize_t cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from); +extern int cifs_flock(struct file *file, int cmd, struct file_lock *fl); extern int cifs_lock(struct file *, int, struct file_lock *); extern int cifs_fsync(struct file *, loff_t, loff_t, int); extern int cifs_strict_fsync(struct file *, loff_t, loff_t, int); diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 97090693d182..641927755d0b 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1685,6 +1685,60 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, return rc; } +int cifs_flock(struct file *file, int cmd, struct file_lock *fl) +{ + int rc, xid; + int lock = 0, unlock = 0; + bool wait_flag = false; + bool posix_lck = false; + struct cifs_sb_info *cifs_sb; + struct cifs_tcon *tcon; + struct cifsInodeInfo *cinode; + struct cifsFileInfo *cfile; + __u16 netfid; + __u32 type; + + rc = -EACCES; + xid = get_xid(); + + if (!(fl->fl_flags & FL_FLOCK)) { + cifs_dbg(VFS, "ret nolock\n"); + return -ENOLCK; + } + + cfile = (struct cifsFileInfo *)file->private_data; + tcon = tlink_tcon(cfile->tlink); + + cifs_read_flock(fl, &type, &lock, &unlock, &wait_flag, + tcon->ses->server); + cifs_sb = CIFS_FILE_SB(file); + netfid = cfile->fid.netfid; + cinode = CIFS_I(file_inode(file)); + + if (cap_unix(tcon->ses) && + (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) && + ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) + posix_lck = true; + + if (!lock && !unlock) { + /* + * if no lock or unlock then nothing to do since we do not + * know what it is + */ + cifs_dbg(VFS, "return FLOCK EOPNOTSUPP\n"); + free_xid(xid); + return -EOPNOTSUPP; + } + + rc = cifs_setlk(file, fl, type, wait_flag, posix_lck, lock, unlock, + xid); + free_xid(xid); + cifs_dbg(VFS, "FLOCK rc = %d\n", rc); + return rc; + + +} + int cifs_lock(struct file *file, int cmd, struct file_lock *flock) { int rc, xid; -- 2.20.1