^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (C) 2001 Clemson University and The University of Chicago
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (C) 2011 Omnibond Systems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Changes by Acxiom Corporation to implement generic service_operation()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * function, Copyright Acxiom Corporation, 2005.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * See COPYING in top-level directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * In-kernel waitqueue operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "orangefs-kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "orangefs-bufmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static int wait_for_matching_downcall(struct orangefs_kernel_op_s *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) long timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) __acquires(op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static void orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) __releases(op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * What we do in this function is to walk the list of operations that are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * present in the request queue and mark them as purged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * NOTE: This is called from the device close after client-core has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * guaranteed that no new operations could appear on the list since the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * client-core is anyway going to exit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void purge_waiting_ops(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct orangefs_kernel_op_s *op, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) spin_lock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) list_for_each_entry_safe(op, tmp, &orangefs_request_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) "pvfs2-client-core: purging op tag %llu %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) llu(op->tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) get_opname_string(op));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) set_op_state_purged(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) gossip_debug(GOSSIP_DEV_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) "%s: op:%s: op_state:%d: process:%s:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) get_opname_string(op),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) op->op_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) spin_unlock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * submits a ORANGEFS operation and waits for it to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Note op->downcall.status will contain the status of the operation (in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * errno format), whether provided by pvfs2-client or a result of failure to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * service the operation. If the caller wishes to distinguish, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * op->state can be checked to see if it was serviced or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Returns contents of op->downcall.status for convenience
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int service_operation(struct orangefs_kernel_op_s *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) const char *op_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) long timeout = MAX_SCHEDULE_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) DEFINE_WAIT(wait_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) op->upcall.tgid = current->tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) op->upcall.pid = current->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) retry_servicing:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) op->downcall.status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) "%s: %s op:%p: process:%s: pid:%d:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) op_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) current->comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) current->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * If ORANGEFS_OP_NO_MUTEX was set in flags, we need to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * acquiring the request_mutex because we're servicing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * high priority remount operation and the request_mutex is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * already taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!(flags & ORANGEFS_OP_NO_MUTEX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (flags & ORANGEFS_OP_INTERRUPTIBLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = mutex_lock_interruptible(&orangefs_request_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ret = mutex_lock_killable(&orangefs_request_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * check to see if we were interrupted while waiting for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * mutex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) op->downcall.status = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) "%s: service_operation interrupted.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* queue up the operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) spin_lock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) spin_lock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) set_op_state_waiting(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) gossip_debug(GOSSIP_DEV_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) "%s: op:%s: op_state:%d: process:%s:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) get_opname_string(op),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) op->op_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* add high priority remount op to the front of the line. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (flags & ORANGEFS_OP_PRIORITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) list_add(&op->list, &orangefs_request_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) list_add_tail(&op->list, &orangefs_request_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) wake_up_interruptible(&orangefs_request_list_waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!__is_daemon_in_service()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) "%s:client core is NOT in service.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Don't wait for the userspace component to return if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * the filesystem is being umounted anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (op->upcall.type == ORANGEFS_VFS_OP_FS_UMOUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) timeout = op_timeout_secs * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) spin_unlock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!(flags & ORANGEFS_OP_NO_MUTEX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) mutex_unlock(&orangefs_request_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ret = wait_for_matching_downcall(op, timeout, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) "%s: wait_for_matching_downcall returned %d for %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* got matching downcall; make sure status is in errno format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) op->downcall.status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) orangefs_normalize_to_errno(op->downcall.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ret = op->downcall.status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* failed to get matching downcall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ret == -ETIMEDOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) gossip_err("%s: %s -- wait timed out; aborting attempt.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) op_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * remove a waiting op from the request list or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * remove an in-progress op from the in-progress list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) orangefs_clean_up_interrupted_operation(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) op->downcall.status = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* retry if operation has not been serviced and if requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) op->attempts++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) timeout = op_timeout_secs * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) "orangefs: tag %llu (%s)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) " -- operation to be retried (%d attempt)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) llu(op->tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) op_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) op->attempts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * io ops (ops that use the shared memory buffer) have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * to be returned to their caller for a retry. Other ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * can just be recycled here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (!op->uses_shared_memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) goto retry_servicing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) "%s: %s returning: %d for %p.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) op_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* This can get called on an I/O op if it had a bad service_operation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) bool orangefs_cancel_op_in_progress(struct orangefs_kernel_op_s *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u64 tag = op->tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (!op_state_in_progress(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) op->slot_to_free = op->upcall.req.io.buf_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) memset(&op->upcall, 0, sizeof(op->upcall));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) memset(&op->downcall, 0, sizeof(op->downcall));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) op->upcall.type = ORANGEFS_VFS_OP_CANCEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) op->upcall.req.cancel.op_tag = tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) op->downcall.type = ORANGEFS_VFS_OP_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) op->downcall.status = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) orangefs_new_tag(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) spin_lock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* orangefs_request_list_lock is enough of a barrier here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (!__is_daemon_in_service()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) spin_unlock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) spin_lock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) set_op_state_waiting(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) gossip_debug(GOSSIP_DEV_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) "%s: op:%s: op_state:%d: process:%s:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) get_opname_string(op),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) op->op_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) list_add(&op->list, &orangefs_request_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) spin_unlock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) "Attempting ORANGEFS operation cancellation of tag %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) llu(tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * Change an op to the "given up" state and remove it from its list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) orangefs_clean_up_interrupted_operation(struct orangefs_kernel_op_s *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) __releases(op->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * handle interrupted cases depending on what state we were in when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * the interruption is detected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Called with op->lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * List manipulation code elsewhere will ignore ops that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * have been given up upon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) op->op_state |= OP_VFS_STATE_GIVEN_UP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (list_empty(&op->list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* caught copying to/from daemon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) BUG_ON(op_state_serviced(op));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) wait_for_completion(&op->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) } else if (op_state_waiting(op)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * upcall hasn't been read; remove op from upcall request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) spin_lock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) list_del_init(&op->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) spin_unlock(&orangefs_request_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) "Interrupted: Removed op %p from request_list\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) } else if (op_state_in_progress(op)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* op must be removed from the in progress htable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) spin_lock(&orangefs_htable_ops_in_progress_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) list_del_init(&op->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) spin_unlock(&orangefs_htable_ops_in_progress_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) "Interrupted: Removed op %p"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) " from htable_ops_in_progress\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) spin_unlock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) gossip_err("interrupted operation is in a weird state 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) op->op_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) reinit_completion(&op->waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Sleeps on waitqueue waiting for matching downcall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * If client-core finishes servicing, then we are good to go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * else if client-core exits, we get woken up here, and retry with a timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * When this call returns to the caller, the specified op will no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * longer be in either the in_progress hash table or on the request list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * Returns 0 on success and -errno on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * Errors are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * EAGAIN in case we want the caller to requeue and try again..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * EINTR/EIO/ETIMEDOUT indicating we are done trying to service this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * operation since client-core seems to be exiting too often
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * or if we were interrupted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * Returns with op->lock taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static int wait_for_matching_downcall(struct orangefs_kernel_op_s *op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) long timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) __acquires(op->lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) long n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int writeback = flags & ORANGEFS_OP_WRITEBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) interruptible = flags & ORANGEFS_OP_INTERRUPTIBLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * There's a "schedule_timeout" inside of these wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * primitives, during which the op is out of the hands of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * user process that needs something done and is being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * manipulated by the client-core process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (writeback)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) n = wait_for_completion_io_timeout(&op->waitq, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) else if (!writeback && interruptible)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) n = wait_for_completion_interruptible_timeout(&op->waitq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) else /* !writeback && !interruptible but compiler complains */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) n = wait_for_completion_killable_timeout(&op->waitq, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) spin_lock(&op->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (op_state_serviced(op))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (unlikely(n < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) "%s: operation interrupted, tag %llu, %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) llu(op->tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (op_state_purged(op)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) "%s: operation purged, tag %llu, %p, %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) llu(op->tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) op->attempts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return (op->attempts < ORANGEFS_PURGE_RETRY_COUNT) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) -EAGAIN :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /* must have timed out, then... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) gossip_debug(GOSSIP_WAIT_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) "%s: operation timed out, tag %llu, %p, %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) llu(op->tag),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) op->attempts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }