set_lock.type = req->head.args.filelock_change.type;
bool will_wait = req->head.args.filelock_change.wait;
+ dout(0) << "handle_client_file_setlock: " << set_lock << dendl;
+
ceph_lock_state_t *lock_state = NULL;
// get the appropriate lock state
return;
}
+ dout(0) << "state prior to lock change: " << *lock_state << dendl;;
if (CEPH_LOCK_UNLOCK == set_lock.type) {
+ dout(0) << "got unlock" << dendl;
list<ceph_filelock> activated_locks;
lock_state->remove_lock(set_lock, activated_locks);
reply_request(mdr, 0);
cur->take_waiting(CInode::WAIT_FLOCK, waiters);
mds->queue_waiters(waiters);
} else {
+ dout(0) << "got lock" << dendl;
if (lock_state->add_lock(set_lock, will_wait)) {
// lock set successfully
+ dout(0) << "it succeeded" << dendl;
reply_request(mdr, 0);
} else {
+ dout(0) << "it failed on this attempt" << dendl;
// couldn't set lock right now
if (!will_wait)
reply_request(mdr, -1);
- else
+ else {
+ dout(0) << "but it's a wait" << dendl;
cur->add_waiter(CInode::WAIT_FLOCK, new C_MDS_RetryRequest(mdcache, mdr));
+ }
}
}
+ dout(0) << "state after lock change: " << *lock_state << dendl;
}
void Server::handle_client_file_readlock(MDRequest *mdr)
};
-
-
+inline ostream& operator<<(ostream& out, ceph_lock_state_t& l) {
+ out << "ceph_lock_state_t. held_locks.size()=" << l.held_locks.size()
+ << ", waiting_locks.size()=" << l.waiting_locks.size()
+ << ", client_held_lock_counts -- " << l.client_held_lock_counts
+ << "\n client_waiting_lock_counts -- " << l.client_waiting_lock_counts
+ << "\n held_locks -- ";
+ for (multimap<uint64_t, ceph_filelock>::iterator iter = l.held_locks.begin();
+ iter != l.held_locks.end();
+ ++iter)
+ out << iter->second;
+ out << "\n waiting_locks -- ";
+ for (multimap<uint64_t, ceph_filelock>::iterator iter =l.waiting_locks.begin();
+ iter != l.waiting_locks.end();
+ ++iter)
+ out << iter->second << "\n";
+ out << std::endl;
+ return out;
+}
#endif
return l.first == r.first && l.last == r.last;
}
+inline ostream& operator<<(ostream& out, ceph_filelock& l) {
+ out << "start: " << l.start << ", length: " << l.length
+ << ", client: " << l.client << ", pid: " << l.pid
+ << ", type: " << (int)l.type
+ << std::endl;
+ return out;
+}
struct ceph_lock_state_t {
multimap<__u64, ceph_filelock> held_locks; // current locks
if (old_lock_end > new_lock_end) { //add extra lock after new_lock
ceph_filelock appended_lock = *old_lock;
appended_lock.start = new_lock_end + 1;
- appended_lock.length = old_lock_end - appended_lock.start;
+ appended_lock.length = old_lock_end - appended_lock.start + 1;
held_locks.insert(pair<__u64, ceph_filelock>
(appended_lock.start, appended_lock));
++client_held_lock_counts[old_lock->client];
if ((lower_bound->first != start)
&& (start != 0)
&& (lower_bound != lock_map.begin())) --lower_bound;
+ if (lock_map.end() == lower_bound)
+ dout(0) << "get_lower_bound returning end()" << dendl;
+ else dout(0) << "get_lower_bound returning iterator pointing to "
+ << lower_bound->second << dendl;
return lower_bound;
}
multimap<__u64, ceph_filelock>::iterator last =
lock_map.upper_bound(end);
if (last != lock_map.begin()) --last;
+ if (lock_map.end() == last)
+ dout(0) << "get_last_before returning end()" << dendl;
+ else dout(0) << "get_last_before returning iterator pointing to "
+ << last->second << dendl;
return last;
}
*/
bool share_space(multimap<__u64, ceph_filelock>::iterator& iter,
__u64 start, __u64 end) {
- return ((iter->first > start && iter->first < end) ||
- ((iter->first < start) &&
- (((iter->first + iter->second.length - 1) > start) ||
- (0 == iter->second.length))));
+ bool ret = ((iter->first >= start && iter->first <= end) ||
+ ((iter->first < start) &&
+ (((iter->first + iter->second.length - 1) >= start) ||
+ (0 == iter->second.length))));
+ dout(0) << "share_space got start: " << start << ", end: " << end
+ << ", lock: " << iter->second << ", returning " << ret << dendl;
+ return ret;
}
bool share_space(multimap<__u64, ceph_filelock>::iterator& iter,
ceph_filelock& lock) {
*/
bool get_overlapping_locks(ceph_filelock& lock,
list<ceph_filelock*>& overlaps) {
+ dout(0) << "get_overlapping_locks" << dendl;
multimap<__u64, ceph_filelock>::iterator iter =
get_last_before(lock.start + lock.length - 1, held_locks);
bool cont = iter != held_locks.end();
*/
bool get_waiting_overlaps(ceph_filelock& lock,
list<ceph_filelock*>& overlaps) {
+ dout(0) << "get_waiting_overlaps" << dendl;
multimap<__u64, ceph_filelock>::iterator iter =
get_last_before(lock.start + lock.length - 1, waiting_locks);
- bool cont = iter != held_locks.end();
+ bool cont = iter != waiting_locks.end();
while(cont) {
if (share_space(iter, lock)) overlaps.push_front(&iter->second);
if (held_locks.begin() == iter) cont = false;