+static void ll_update_atime(struct inode *inode)
+{
+ struct iattr attr;
+
+ attr.ia_atime = CURRENT_TIME;
+ attr.ia_valid = ATTR_ATIME;
+
+ if (inode->i_atime == attr.ia_atime) return;
+ if (IS_RDONLY(inode)) return;
+ if (IS_NOATIME(inode)) return;
+
+ /* ll_inode_setattr() sets inode->i_atime from attr.ia_atime */
+ ll_inode_setattr(inode, &attr, 0);
+}
+
+static int ll_lock_callback(struct lustre_handle *lockh,
+ struct ldlm_lock_desc *new,
+ void *data, __u32 data_len,
+ struct ptlrpc_request **reqp)
+{
+ struct inode *inode = data;
+ ENTRY;
+
+ if (new == NULL) {
+ /* Completion AST. Do nothing. */
+ RETURN(0);
+ }
+
+ if (data_len != sizeof(struct inode))
+ LBUG();
+
+ /* FIXME: do something better than throwing away everything */
+ if (inode == NULL)
+ LBUG();
+ down(&inode->i_sem);
+ CDEBUG(D_INODE, "invalidating obdo/inode %ld\n", inode->i_ino);
+ invalidate_inode_pages(inode);
+ up(&inode->i_sem);
+
+ if (ldlm_cli_cancel(lockh) < 0)
+ LBUG();
+ RETURN(0);
+}
+
+static ssize_t ll_file_read(struct file *filp, char *buf, size_t count,
+ loff_t *ppos)
+{
+ struct ll_file_data *fd = (struct ll_file_data *)filp->private_data;
+ struct inode *inode = filp->f_dentry->d_inode;
+ struct ll_sb_info *sbi = ll_i2sbi(inode);
+ struct ldlm_extent extent;
+ struct lustre_handle lockh;
+ __u64 res_id[RES_NAME_SIZE] = {inode->i_ino};
+ int flags = 0;
+ ldlm_error_t err;
+ ssize_t retval;
+ ENTRY;
+
+ if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK)) {
+ extent.start = *ppos;
+ extent.end = *ppos + count;
+ CDEBUG(D_INFO, "Locking inode %ld, start %Lu end %Lu\n",
+ inode->i_ino, extent.start, extent.end);
+
+ err = obd_enqueue(&sbi->ll_osc_conn, NULL, res_id, LDLM_EXTENT,
+ &extent, sizeof(extent), LCK_PR, &flags,
+ ll_lock_callback, inode, sizeof(*inode),
+ &lockh);
+ if (err != ELDLM_OK) {
+ CERROR("lock enqueue: err: %d\n", err);
+ RETURN(err);
+ }
+ ldlm_lock_dump((void *)(unsigned long)lockh.addr);
+ }
+
+ CDEBUG(D_INFO, "Reading inode %ld, %d bytes, offset %Ld\n",
+ inode->i_ino, count, *ppos);
+ retval = generic_file_read(filp, buf, count, ppos);
+
+ if (retval > 0)
+ ll_update_atime(inode);
+
+ if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK)) {
+ err = obd_cancel(&sbi->ll_osc_conn, LCK_PR, &lockh);
+ if (err != ELDLM_OK) {
+ CERROR("lock cancel: err: %d\n", err);
+ RETURN(err);
+ }
+ }
+
+ RETURN(retval);
+}