Skip to content

Commit

Permalink
kobj_read_file: Return -1 on vn_rdwr() error
Browse files Browse the repository at this point in the history
I noticed that the SPL implementation of kobj_read_file is not correct
after comparing it with the userland implementation of kobj_read_file()
in openzfs/zfs#4104.

The function is tiny enough that my patch could qualify to be called a
"rewrite", so I am just copying the function on the basis that a rewrite
allows me to license the code under both the CDDL and GPL.

Signed-off-by: Richard Yao <[email protected]>
  • Loading branch information
ryao committed Dec 15, 2015
1 parent e0ed96f commit ab142af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/sys/kobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct _buf buf_t;
extern struct _buf *kobj_open_file(const char *name);
extern void kobj_close_file(struct _buf *file);
extern int kobj_read_file(struct _buf *file, char *buf,
ssize_t size, offset_t off);
unsigned size, unsigned off);
extern int kobj_get_filesize(struct _buf *file, uint64_t *size);

#endif /* SPL_KOBJ_H */
11 changes: 8 additions & 3 deletions module/spl/spl-kobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,15 @@ kobj_close_file(struct _buf *file)
EXPORT_SYMBOL(kobj_close_file);

int
kobj_read_file(struct _buf *file, char *buf, ssize_t size, offset_t off)
kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off)
{
return (vn_rdwr(UIO_READ, file->vp, buf, size, off,
UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL));
ssize_t resid;

if (vn_rdwr(UIO_READ, (vnode_t *)file->_fd, buf, size, (offset_t)off,
UIO_SYSSPACE, 0, 0, 0, &resid) != 0)
return (-1);

return (size - resid);
} /* kobj_read_file() */
EXPORT_SYMBOL(kobj_read_file);

Expand Down

0 comments on commit ab142af

Please sign in to comment.