From d4ae823e83c3ee7d09fe6415534378c222b23a56 Mon Sep 17 00:00:00 2001 From: liangzhen Date: Mon, 20 Feb 2006 09:32:44 +0000 Subject: [PATCH] 1. Fix to data copy of obdclass ioctl in Darwin. 2. smallfix to echo client. --- lustre/include/lustre_lib.h | 12 +++++++++--- lustre/llite/llite_close.c | 2 +- lustre/obdclass/class_obd.c | 8 ++++---- lustre/obdclass/darwin/darwin-module.c | 21 +++++++++++++++++++-- lustre/obdclass/linux/linux-module.c | 11 +++++++++++ lustre/obdecho/echo_client.c | 4 +++- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/lustre/include/lustre_lib.h b/lustre/include/lustre_lib.h index 58ad7b6..d2def9b 100644 --- a/lustre/include/lustre_lib.h +++ b/lustre/include/lustre_lib.h @@ -300,6 +300,7 @@ static inline int obd_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, #ifdef __KERNEL__ /* function defined in lustre/obdclass//-module.c */ int obd_ioctl_getdata(char **buf, int *len, void *arg); +int obd_ioctl_popdata(void *arg, void *data, int len); #else /* buffer MUST be at least the size of obd_ioctl_hdr */ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg) @@ -375,6 +376,14 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg) EXIT; return 0; } + +static inline int obd_ioctl_popdata(void *arg, void *data, int len) +{ + int err = copy_to_user(arg, data, len); + if (err) + err = -EFAULT; + return err; +} #endif static inline void obd_ioctl_freedata(char *buf, int len) @@ -545,7 +554,6 @@ struct l_wait_info { do { \ cfs_waitlink_t __wait; \ cfs_duration_t __timed_out = 0; \ - unsigned long irqflags; \ cfs_sigset_t blocked; \ cfs_time_t timeout_remaining; \ \ @@ -598,9 +606,7 @@ do { \ /* -EINTR when the RPC actually succeeded. */ \ /* the RECALC_SIGPENDING below will deliver the */ \ /* signal properly. */ \ - cfs_sigmask_lock(irqflags); \ cfs_clear_sigpending(); \ - cfs_sigmask_unlock(irqflags); \ } \ } \ } \ diff --git a/lustre/llite/llite_close.c b/lustre/llite/llite_close.c index 80d35e0..e033af1 100644 --- a/lustre/llite/llite_close.c +++ b/lustre/llite/llite_close.c @@ -200,7 +200,7 @@ static int ll_close_thread(void *arg) char name[sizeof(current->comm)]; unsigned long flags; snprintf(name, sizeof(name) - 1, "ll_close"); - libcfs_daemonize(name); + cfs_daemonize(name); SIGNAL_MASK_LOCK(current, flags); sigfillset(¤t->blocked); RECALC_SIGPENDING; diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 78b8181..ff6b41d 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -205,7 +205,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) memcpy(data->ioc_bulk, BUILD_VERSION, strlen(BUILD_VERSION) + 1); - err = copy_to_user((void *)arg, data, len); + err = obd_ioctl_popdata((void *)arg, data, len); if (err) err = -EFAULT; GOTO(out, err); @@ -222,7 +222,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) if (dev < 0) GOTO(out, err = -EINVAL); - err = copy_to_user((void *)arg, data, sizeof(*data)); + err = obd_ioctl_popdata((void *)arg, data, sizeof(*data)); if (err) err = -EFAULT; GOTO(out, err); @@ -256,7 +256,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1, dev); - err = copy_to_user((void *)arg, data, sizeof(*data)); + err = obd_ioctl_popdata((void *)arg, data, sizeof(*data)); if (err) err = -EFAULT; GOTO(out, err); @@ -299,7 +299,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) if (err) GOTO(out, err); - err = copy_to_user((void *)arg, data, len); + err = obd_ioctl_popdata((void *)arg, data, len); if (err) err = -EFAULT; GOTO(out, err); diff --git a/lustre/obdclass/darwin/darwin-module.c b/lustre/obdclass/darwin/darwin-module.c index 87d0554..336fe2e 100644 --- a/lustre/obdclass/darwin/darwin-module.c +++ b/lustre/obdclass/darwin/darwin-module.c @@ -55,8 +55,8 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg) *len = hdr->ioc_len; data = (struct obd_ioctl_data *)*buf; - bzero(*buf, hdr->ioc_len); - memcpy(*buf, (void *)arg, sizeof(struct obd_ioctl_data)); + bzero(data, hdr->ioc_len); + memcpy(data, (void *)arg, sizeof(struct obd_ioctl_data)); if (data->ioc_inlbuf1) err = copy_from_user(&data->ioc_bulk[0], (void *)data->ioc_inlbuf1, hdr->ioc_len - ((void *)&data->ioc_bulk[0] - (void *)data)); @@ -89,6 +89,23 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg) return 0; } +int obd_ioctl_popdata(void *arg, void *data, int len) +{ + /* + * Xnu ioctl copyout(uaddr, arg, sizeof(struct obd_ioctl_data)), + * we have to copy out data by ourself only if + * len > sizeof(struct obd_ioctl_data) + */ + if (len <= sizeof(struct obd_ioctl_data)) { + memcpy(arg, data, len); + return 0; + } else { + struct obd_ioctl_data *u = (struct obd_ioctl_data *)arg; + struct obd_ioctl_data *k = (struct obd_ioctl_data *)data; + return copy_to_user((void *)u->ioc_inlbuf1, &k->ioc_bulk[0], + len -((void *)&k->ioc_bulk[0] -(void *)k)); + } +} /* * cfs pseudo device */ diff --git a/lustre/obdclass/linux/linux-module.c b/lustre/obdclass/linux/linux-module.c index d8454d4..9b95f02 100644 --- a/lustre/obdclass/linux/linux-module.c +++ b/lustre/obdclass/linux/linux-module.c @@ -144,7 +144,18 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg) return 0; } +int obd_ioctl_popdata(void *arg, void *data, int len) +{ + int err; + + err = copy_to_user(arg, data, len); + if (err) + err = -EFAULT; + return err; +} + EXPORT_SYMBOL(obd_ioctl_getdata); +EXPORT_SYMBOL(obd_ioctl_popdata); #define OBD_MINOR 241 extern struct cfs_psdev_ops obd_psdev_ops; diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 2df0db90..0dac6d4 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -280,8 +280,10 @@ echo_get_object (struct ec_object **ecop, struct obd_device *obd, spin_lock (&ec->ec_lock); eco = echo_find_object_locked (obd, oa->o_id); if (eco != NULL) { - if (eco->eco_deleted) /* being deleted */ + if (eco->eco_deleted) { /* being deleted */ + spin_unlock (&ec->ec_lock); return (-EAGAIN); /* (see comment in cleanup) */ + } eco->eco_refcount++; spin_unlock (&ec->ec_lock); -- 1.8.3.1