| 403 | } |
| 404 | |
| 405 | inline bool block_socket_check_timeout(struct block_socket* socket, u64 now, u64 timeout_jiffies) { |
| 406 | ternfs_debug("socket(%p) %pI4:%d refcount %d check timeout triggered", socket, &socket->addr.sin_addr, ntohs(socket->addr.sin_port), atomic_read(&socket->refcount)); |
| 407 | // if something is locked activity in progress, nothing to do |
| 408 | if (!spin_trylock_bh(&socket->list_lock)) { |
| 409 | return false; |
| 410 | } |
| 411 | u64 last_activity = max(socket->last_read_activity, socket->last_write_activity); |
| 412 | bool timed_out = now - min(now, last_activity) > timeout_jiffies; |
| 413 | if (timed_out) { |
| 414 | atomic_cmpxchg(&socket->err, 0, -ETIMEDOUT); |
| 415 | } |
| 416 | spin_unlock_bh(&socket->list_lock); |
| 417 | return timed_out; |
| 418 | } |
| 419 | |
| 420 | // Call periodically to check for inactive ones and schedules work on them to potentially time them out |
| 421 | static void timeout_sockets(struct block_ops* ops) { |