From: Stefan Metzmacher Date: Wed, 27 Aug 2025 15:15:55 +0000 (+0200) Subject: smb: smbdirect: introduce smbdirect_connection_idle_timer_work() X-Git-Tag: v7.1-rc1~128^2~131 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1593f5d004f5f3812ba175f4253fba07853db24e;p=thirdparty%2Flinux.git smb: smbdirect: introduce smbdirect_connection_idle_timer_work() This is basically a copy of idle_connection_timer() in the client and smb_direct_idle_connection_timer() in the server. The only difference is that the server does not have logging. Currently the callers set their own timer function after smbdirect_socket_prepare_create(), but that will change in the next steps... Cc: Steve French Cc: Tom Talpey Cc: Long Li Cc: Namjae Jeon Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Signed-off-by: Stefan Metzmacher Acked-by: Namjae Jeon Signed-off-by: Steve French --- diff --git a/fs/smb/common/smbdirect/smbdirect_connection.c b/fs/smb/common/smbdirect/smbdirect_connection.c index ce10aff54349b..6e4b7aa2440dd 100644 --- a/fs/smb/common/smbdirect/smbdirect_connection.c +++ b/fs/smb/common/smbdirect/smbdirect_connection.c @@ -82,3 +82,34 @@ smbdirect_connection_reassembly_first_recv_io(struct smbdirect_socket *sc) return msg; } + +static void smbdirect_connection_idle_timer_work(struct work_struct *work) +{ + struct smbdirect_socket *sc = + container_of(work, struct smbdirect_socket, idle.timer_work.work); + const struct smbdirect_socket_parameters *sp = &sc->parameters; + + if (sc->idle.keepalive != SMBDIRECT_KEEPALIVE_NONE) { + smbdirect_log_keep_alive(sc, SMBDIRECT_LOG_ERR, + "%s => timeout sc->idle.keepalive=%s\n", + smbdirect_socket_status_string(sc->status), + sc->idle.keepalive == SMBDIRECT_KEEPALIVE_SENT ? + "SENT" : "PENDING"); + smbdirect_socket_schedule_cleanup(sc, -ETIMEDOUT); + return; + } + + if (sc->status != SMBDIRECT_SOCKET_CONNECTED) + return; + + /* + * Now use the keepalive timeout (instead of keepalive interval) + * in order to wait for a response + */ + sc->idle.keepalive = SMBDIRECT_KEEPALIVE_PENDING; + mod_delayed_work(sc->workqueue, &sc->idle.timer_work, + msecs_to_jiffies(sp->keepalive_timeout_msec)); + smbdirect_log_keep_alive(sc, SMBDIRECT_LOG_INFO, + "schedule send of empty idle message\n"); + queue_work(sc->workqueue, &sc->idle.immediate_work); +} diff --git a/fs/smb/common/smbdirect/smbdirect_internal.h b/fs/smb/common/smbdirect/smbdirect_internal.h index c946e53f94cd4..2d7c69f71ee06 100644 --- a/fs/smb/common/smbdirect/smbdirect_internal.h +++ b/fs/smb/common/smbdirect/smbdirect_internal.h @@ -32,4 +32,6 @@ static void __smbdirect_socket_schedule_cleanup(struct smbdirect_socket *sc, __func__, __LINE__, __error, &__force_status); \ } while (0) +static void smbdirect_connection_idle_timer_work(struct work_struct *work); + #endif /* __FS_SMB_COMMON_SMBDIRECT_INTERNAL_H__ */ diff --git a/fs/smb/common/smbdirect/smbdirect_socket.c b/fs/smb/common/smbdirect/smbdirect_socket.c index ba7e3ac32d920..34971c2700eec 100644 --- a/fs/smb/common/smbdirect/smbdirect_socket.c +++ b/fs/smb/common/smbdirect/smbdirect_socket.c @@ -27,6 +27,8 @@ static void smbdirect_socket_prepare_create(struct smbdirect_socket *sc, sc->workqueue = workqueue; INIT_WORK(&sc->disconnect_work, smbdirect_socket_cleanup_work); + + INIT_DELAYED_WORK(&sc->idle.timer_work, smbdirect_connection_idle_timer_work); } __maybe_unused /* this is temporary while this file is included in others */ @@ -67,7 +69,6 @@ static void smbdirect_socket_wake_up_all(struct smbdirect_socket *sc) wake_up_all(&sc->mr_io.cleanup.wait_queue); } -__maybe_unused /* this is temporary while this file is included in others */ static void __smbdirect_socket_schedule_cleanup(struct smbdirect_socket *sc, const char *macro_name, unsigned int lvl,