/** * Encode the flock and fcntl locks for the given inode into the pagelist. * Format is: #fcntl locks, sequential fcntl locks, #flock locks, * sequential flock locks. * Must be called with lock_flocks() already held. * If we encounter more of a specific lock type than expected, * we return the value 1. */ int ceph_encode_locks(struct inode *inode, struct ceph_pagelist *pagelist, int num_fcntl_locks, int num_flock_locks) { struct file_lock *lock; struct ceph_filelock cephlock; int err = 0; int seen_fcntl = 0; int seen_flock = 0; dout("encoding %d flock and %d fcntl locks", num_flock_locks, num_fcntl_locks); err = ceph_pagelist_append(pagelist, &num_fcntl_locks, sizeof(u32)); if (err) goto fail; for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { if (lock->fl_flags & FL_POSIX) { ++seen_fcntl; if (seen_fcntl > num_fcntl_locks) { err = -ENOSPC; goto fail; } err = lock_to_ceph_filelock(lock, &cephlock); if (err) goto fail; err = ceph_pagelist_append(pagelist, &cephlock, sizeof(struct ceph_filelock)); } if (err) goto fail; } err = ceph_pagelist_append(pagelist, &num_flock_locks, sizeof(u32)); if (err) goto fail; for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { if (lock->fl_flags & FL_FLOCK) { ++seen_flock; if (seen_flock > num_flock_locks) { err = -ENOSPC; goto fail; } err = lock_to_ceph_filelock(lock, &cephlock); if (err) goto fail; err = ceph_pagelist_append(pagelist, &cephlock, sizeof(struct ceph_filelock)); } if (err) goto fail; } fail: return err; }
/** * Encode the flock and fcntl locks for the given inode into the ceph_filelock * array. Must be called with lock_flocks() already held. * If we encounter more of a specific lock type than expected, return -ENOSPC. */ int ceph_encode_locks_to_buffer(struct inode *inode, struct ceph_filelock *flocks, int num_fcntl_locks, int num_flock_locks) { struct file_lock *lock; int err = 0; int seen_fcntl = 0; int seen_flock = 0; int l = 0; dout("encoding %d flock and %d fcntl locks", num_flock_locks, num_fcntl_locks); for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { if (lock->fl_flags & FL_POSIX) { ++seen_fcntl; if (seen_fcntl > num_fcntl_locks) { err = -ENOSPC; goto fail; } err = lock_to_ceph_filelock(lock, &flocks[l]); if (err) goto fail; ++l; } } for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) { if (lock->fl_flags & FL_FLOCK) { ++seen_flock; if (seen_flock > num_flock_locks) { err = -ENOSPC; goto fail; } err = lock_to_ceph_filelock(lock, &flocks[l]); if (err) goto fail; ++l; } } fail: return err; }