+
+/**
+ * Attempt to open a file with Lustre file identifier \a fid
+ * and return an open file descriptor.
+ *
+ * \param[in] lustre_dir path within Lustre filesystem containing \a fid
+ * \param[in] fid Lustre file identifier of file to open
+ * \param[in] flags open() flags
+ *
+ * \retval non-negative file descriptor on successful open
+ * \retval -1 if an error occurred
+ */
+int llapi_open_by_fid(const char *lustre_dir, const lustre_fid *fid, int flags)
+{
+ char mntdir[PATH_MAX];
+ char path[PATH_MAX];
+ int rc;
+
+ rc = llapi_search_mounts(lustre_dir, 0, mntdir, NULL);
+ if (rc != 0)
+ return -1;
+
+ snprintf(path, sizeof(path), "%s/.lustre/fid/"DFID, mntdir, PFID(fid));
+ return open(path, flags);
+}
+
+/**
+ * Take group lock.
+ *
+ * \param fd File to lock.
+ * \param gid Group Identifier.
+ *
+ * \retval 0 on success.
+ * \retval -errno on failure.
+ */
+int llapi_group_lock(int fd, int gid)
+{
+ int rc;
+
+ rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid);
+ if (rc < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot get group lock");
+ }
+ return rc;
+}
+
+/**
+ * Put group lock.
+ *
+ * \param fd File to unlock.
+ * \param gid Group Identifier.
+ *
+ * \retval 0 on success.
+ * \retval -errno on failure.
+ */
+int llapi_group_unlock(int fd, int gid)
+{
+ int rc;
+
+ rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid);
+ if (rc < 0) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot put group lock");
+ }
+ return rc;
+}