From patchwork Mon Sep 16 03:41:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 1162597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fu7GVOWP"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46Wt3l5bNWz9sP7 for ; Mon, 16 Sep 2019 14:06:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728808AbfIPDmB (ORCPT ); Sun, 15 Sep 2019 23:42:01 -0400 Received: from mail-io1-f54.google.com ([209.85.166.54]:38015 "EHLO mail-io1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728295AbfIPDmB (ORCPT ); Sun, 15 Sep 2019 23:42:01 -0400 Received: by mail-io1-f54.google.com with SMTP id k5so50176644iol.5 for ; Sun, 15 Sep 2019 20:41:59 -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=uhrclg99FtPrREsCN0Bh1kEhIWWOCZyDK+/CFOr8kkA=; b=fu7GVOWPjKjJS3qCfCUMqFhxMrMEw52pm2Qnf9OVsOYZh7mxpeVkUiJxkP0EpGQMw6 tonPYgzxixY6iQRV+8uBwQnlntfhizuLIrmbbnaRem6dgDCwwt//vBYGukQemHDm5418 Ghn4u0ftoazil3qma55I8GQq/VtAOaAe+XNujYn69XaABZWtX1GGogAxTWGqeYMWpE0n JdY6Ov8vir4fCdQ3wzbEo1pv80l8wIYlZmTNqDo+/hsrjorAwrM2c1Wdu6wA4+I4hXCM PlQOO4E7QW8AgDXMEnY9SIu5HWlXstvdXZg3YBezdev58ai6na+G4Q43dNMPZrvQHGtt DKrQ== 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=uhrclg99FtPrREsCN0Bh1kEhIWWOCZyDK+/CFOr8kkA=; b=K/WZrj84q5NUsGNVV/b1ybGMofuImmSlVZsgvj2pnl6kqjc8SVoe1A6e8QGPIvUxRK 4GTH9HQI8Y05meyPgAqTdEGtRfvXnup+uXqUlUi5f/ZrpQmm6QDuTAv0ZeAOb7PbrlIp L5V/VS8GhiGn6R+hKWJhNbN2pUjHAgDSdYG7Xv2ELqXbTNexgFNpUgo/SspMgAQ6eus6 Pu9TocR5eOB7t3eyJT0lUoIoAuLwhWEtK36h9fpPPCHStQ0g29rls5EJx1pI7IlLDcQS QedAwPGPuBJTOmmcMl0dlcKx8PFrfX9tvoWgS5tsx20Jt7s8EbXSUxnxLR8nRZ/ThpfI 2FPA== X-Gm-Message-State: APjAAAU8w0xzIqau3Wffmud1RDqUFRrs8it7IYfIZP2FwBm5/cH5PxVa oHVSP9mfMJEG9Ame4sxv+es7ufkB+vz7xpBt9m1i0Wpv X-Google-Smtp-Source: APXvYqxfPI2aOUmjiknkpWVbntJNoNhDjHYpczQqnRIuDtAJMcYAh98McomIpf2IsjOywd69hxicmXyHQnBfoZbEgPw= X-Received: by 2002:a6b:c38f:: with SMTP id t137mr14717725iof.137.1568605318935; Sun, 15 Sep 2019 20:41:58 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Sun, 15 Sep 2019 22:41:47 -0500 Message-ID: Subject: [PATCH][SMB3] Add worker function for smb3 change notify To: CIFS Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Fairly trivial From 727ac06cc7007afea729bff04ce44f54995a8743 Mon Sep 17 00:00:00 2001 From: Steve French Date: Sun, 15 Sep 2019 22:38:52 -0500 Subject: [PATCH] smb3: add missing worker function for SMB3 change notify SMB3 change notify is important to allow applications to wait on directory change events of different types (e.g. adding and deleting files from others systems). Add worker functions for this. Acked-by: Aurelien Aptel Signed-off-by: Steve French --- fs/cifs/smb2pdu.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ fs/cifs/trace.h | 3 ++ 2 files changed, 88 insertions(+) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index ce647cfdc04f..87066f1af12c 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -3175,6 +3175,91 @@ SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon, (void **)&uniqueid, NULL); } +/* + * CHANGE_NOTIFY Request is sent to get notifications on changes to a directory + * See MS-SMB2 2.2.35 and 2.2.36 + */ + +int +SMB2_notify_init(const unsigned int xid, struct smb_rqst *rqst, + struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, + u32 completion_filter, bool watch_tree) +{ + struct smb2_change_notify_req *req; + struct kvec *iov = rqst->rq_iov; + unsigned int total_len; + int rc; + + rc = smb2_plain_req_init(SMB2_CHANGE_NOTIFY, tcon, (void **) &req, &total_len); + if (rc) + return rc; + + req->PersistentFileId = persistent_fid; + req->VolatileFileId = volatile_fid; + req->OutputBufferLength = SMB2_MAX_BUFFER_SIZE - MAX_SMB2_HDR_SIZE; + req->CompletionFilter = cpu_to_le32(completion_filter); + if (watch_tree) + req->Flags = cpu_to_le16(SMB2_WATCH_TREE); + else + req->Flags = 0; + + iov[0].iov_base = (char *)req; + iov[0].iov_len = total_len; + + return 0; +} + +int +SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon, + u64 persistent_fid, u64 volatile_fid, bool watch_tree, + u32 completion_filter) +{ + struct cifs_ses *ses = tcon->ses; + struct smb_rqst rqst; + struct kvec iov[1]; + struct kvec rsp_iov = {NULL, 0}; + int resp_buftype = CIFS_NO_BUFFER; + int flags = 0; + int rc = 0; + + cifs_dbg(FYI, "change notify\n"); + if (!ses || !(ses->server)) + return -EIO; + + if (smb3_encryption_required(tcon)) + flags |= CIFS_TRANSFORM_REQ; + + memset(&rqst, 0, sizeof(struct smb_rqst)); + memset(&iov, 0, sizeof(iov)); + rqst.rq_iov = iov; + rqst.rq_nvec = 1; + + rc = SMB2_notify_init(xid, &rqst, tcon, persistent_fid, volatile_fid, + completion_filter, watch_tree); + if (rc) + goto cnotify_exit; + + trace_smb3_notify_enter(xid, persistent_fid, tcon->tid, ses->Suid, + (u8)watch_tree, completion_filter); + rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov); + + if (rc != 0) { + cifs_stats_fail_inc(tcon, SMB2_CHANGE_NOTIFY_HE); + trace_smb3_notify_err(xid, persistent_fid, tcon->tid, ses->Suid, + (u8)watch_tree, completion_filter, rc); + } else + trace_smb3_notify_done(xid, persistent_fid, tcon->tid, + ses->Suid, (u8)watch_tree, completion_filter); + + cnotify_exit: + if (rqst.rq_iov) + cifs_small_buf_release(rqst.rq_iov[0].iov_base); /* request */ + free_rsp_buf(resp_buftype, rsp_iov.iov_base); + return rc; +} + + + /* * This is a no-op for now. We're not really interested in the reply, but * rather in the fact that the server sent one and that server->lstrp diff --git a/fs/cifs/trace.h b/fs/cifs/trace.h index f1339f4a2d07..e7e350b13d6a 100644 --- a/fs/cifs/trace.h +++ b/fs/cifs/trace.h @@ -235,6 +235,8 @@ DEFINE_EVENT(smb3_inf_enter_class, smb3_##name, \ DEFINE_SMB3_INF_ENTER_EVENT(query_info_enter); DEFINE_SMB3_INF_ENTER_EVENT(query_info_done); +DEFINE_SMB3_INF_ENTER_EVENT(notify_enter); +DEFINE_SMB3_INF_ENTER_EVENT(notify_done); DECLARE_EVENT_CLASS(smb3_inf_err_class, TP_PROTO(unsigned int xid, @@ -281,6 +283,7 @@ DEFINE_EVENT(smb3_inf_err_class, smb3_##name, \ DEFINE_SMB3_INF_ERR_EVENT(query_info_err); DEFINE_SMB3_INF_ERR_EVENT(set_info_err); +DEFINE_SMB3_INF_ERR_EVENT(notify_err); DEFINE_SMB3_INF_ERR_EVENT(fsctl_err); DECLARE_EVENT_CLASS(smb3_inf_compound_enter_class, -- 2.20.1