Skip to contentSkip to conversation

ide: remove ->bus_state field from ide_hwif_t

PATCH New Bartlomiej Zolnierkiewicz 1 participant 4 messages Aug 5, 2008 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 ide: remove ->bus_state field from ide_hwif_t

It is always set to BUSSTATE_ON.

---
 drivers/ide/ide.c   |    4 +---
 include/linux/ide.h |    1 -
 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/ide/ide.c +1 -3
Index: b/drivers/ide/ide.c
===================================================================
@@ -96,8 +96,6 @@ void ide_init_port_data(ide_hwif_t *hwif
 	hwif->name[2]	= 'e';
 	hwif->name[3]	= '0' + index;
 
-	hwif->bus_state	= BUSSTATE_ON;
-
 	init_completion(&hwif->gendev_rel_comp);
 
 	hwif->tp_ops = &default_tp_ops;
@@ -620,7 +618,7 @@ int generic_ide_ioctl(ide_drive_t *drive
 		case HDIO_GET_BUSSTATE:
 			if (!capable(CAP_SYS_ADMIN))
 				return -EACCES;
-			if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
+			if (put_user(BUSSTATE_ON, (long __user *)arg))
 				return -EFAULT;
 			return 0;
 
include/linux/ide.h +0 -1
Index: b/include/linux/ide.h
===================================================================
@@ -560,7 +560,6 @@ typedef struct hwif_s {
 	u8 major;	/* our major number */
 	u8 index;	/* 0 for ide0; 1 for ide1; ... */
 	u8 channel;	/* for dual-port chips: 0=primary, 1=secondary */
-	u8 bus_state;	/* power state of the IDE bus */
 
 	u32 host_flags;
 
#1 lore raw

PATCH 2/4 ide: add ide_setting_ioctl() helper

* Add struct ide_ioctl_devset representing ioctl device setting.

* Add ide_setting_ioctl() helper for matching given ioctl and its parameters against table of ioctl device settings.

* Convert ide_setting_ioctl() and idedisk_ioctl() to use ide_setting_ioctl().

* Un-export ide_setting_mtx.

While at it:

* {get,set}_lba_addressing() -> {get,set}_addressing()

There should be no functional changes caused by this patch.

---
 drivers/ide/ide-disk.c |   57 ++++++++++++++-----------------------------------
 drivers/ide/ide.c      |   53 +++++++++++++++++++++++++++++----------------
 include/linux/ide.h    |   14 +++++++++++-
 3 files changed, 64 insertions(+), 60 deletions(-)
drivers/ide/ide-disk.c +17 -40
Index: b/drivers/ide/ide-disk.c
===================================================================
@@ -682,7 +682,7 @@ static int set_acoustic(ide_drive_t *dri
 	return 0;
 }
 
-ide_devset_get(lba_addressing, addressing);
+ide_devset_get(addressing, addressing);
 
 /*
  * drive->addressing:
@@ -690,7 +690,7 @@ ide_devset_get(lba_addressing, addressin
  *	1: 48-bit
  *	2: 48-bit capable doing 28-bit
  */
-static int set_lba_addressing(ide_drive_t *drive, int arg)
+static int set_addressing(ide_drive_t *drive, int arg)
 {
 	if (arg < 0 || arg > 2)
 		return -EINVAL;
@@ -710,7 +710,7 @@ static int set_lba_addressing(ide_drive_
 
 #ifdef CONFIG_IDE_PROC_FS
 ide_devset_rw_nolock(acoustic,	0, 254, acoustic);
-ide_devset_rw_nolock(address,	0,   2, lba_addressing);
+ide_devset_rw_nolock(address,	0,   2, addressing);
 ide_devset_rw_nolock(multcount,	0,  16, multcount);
 ide_devset_rw_nolock(nowerr,	0,   1, nowerr);
 ide_devset_rw_nolock(wcache,	0,   1, wcache);
@@ -759,7 +759,7 @@ static void idedisk_setup(ide_drive_t *d
 			drive->doorlocking = 1;
 	}
 
-	(void)set_lba_addressing(drive, 1);
+	(void)set_addressing(drive, 1);
 
 	if (drive->addressing == 1) {
 		int max_s = 2048;
@@ -1006,51 +1006,28 @@ static int idedisk_getgeo(struct block_d
 	return 0;
 }
 
+static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
+{ HDIO_GET_ADDRESS,	HDIO_SET_ADDRESS,   get_addressing, set_addressing },
+{ HDIO_GET_MULTCOUNT,	HDIO_SET_MULTCOUNT, get_multcount,  set_multcount  },
+{ HDIO_GET_NOWERR,	HDIO_SET_NOWERR,    get_nowerr,	    set_nowerr	   },
+{ HDIO_GET_WCACHE,	HDIO_SET_WCACHE,    get_wcache,	    set_wcache	   },
+{ HDIO_GET_ACOUSTIC,	HDIO_SET_ACOUSTIC,  get_acoustic,   set_acoustic   },
+{ 0 }
+};
+
 static int idedisk_ioctl(struct inode *inode, struct file *file,
 			unsigned int cmd, unsigned long arg)
 {
-	unsigned long flags;
 	struct block_device *bdev = inode->i_bdev;
 	struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
 	ide_drive_t *drive = idkp->drive;
-	int err, (*getfunc)(ide_drive_t *), (*setfunc)(ide_drive_t *, int);
+	int err;
 
-	switch (cmd) {
-	case HDIO_GET_ADDRESS:	 getfunc = get_lba_addressing;	goto read_val;
-	case HDIO_GET_MULTCOUNT: getfunc = get_multcount;	goto read_val;
-	case HDIO_GET_NOWERR:	 getfunc = get_nowerr;		goto read_val;
-	case HDIO_GET_WCACHE:	 getfunc = get_wcache;		goto read_val;
-	case HDIO_GET_ACOUSTIC:	 getfunc = get_acoustic;	goto read_val;
-	case HDIO_SET_ADDRESS:	 setfunc = set_lba_addressing;	goto set_val;
-	case HDIO_SET_MULTCOUNT: setfunc = set_multcount;	goto set_val;
-	case HDIO_SET_NOWERR:	 setfunc = set_nowerr;		goto set_val;
-	case HDIO_SET_WCACHE:	 setfunc = set_wcache;		goto set_val;
-	case HDIO_SET_ACOUSTIC:	 setfunc = set_acoustic;	goto set_val;
-	}
+	err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
+	if (err != -EOPNOTSUPP)
+		return err;
 
 	return generic_ide_ioctl(drive, file, bdev, cmd, arg);
-
-read_val:
-	mutex_lock(&ide_setting_mtx);
-	spin_lock_irqsave(&ide_lock, flags);
-	err = getfunc(drive);
-	spin_unlock_irqrestore(&ide_lock, flags);
-	mutex_unlock(&ide_setting_mtx);
-	return err >= 0 ? put_user(err, (long __user *)arg) : err;
-
-set_val:
-	if (bdev != bdev->bd_contains)
-		err = -EINVAL;
-	else {
-		if (!capable(CAP_SYS_ADMIN))
-			err = -EACCES;
-		else {
-			mutex_lock(&ide_setting_mtx);
-			err = setfunc(drive, arg);
-			mutex_unlock(&ide_setting_mtx);
-		}
-	}
-	return err;
 }
 
 static int idedisk_media_changed(struct gendisk *disk)
drivers/ide/ide.c +34 -19

90 lines not on this page · raw message

include/linux/ide.h +13 -1
Index: b/include/linux/ide.h
===================================================================
@@ -930,7 +930,19 @@ struct ide_driver_s {
 int ide_device_get(ide_drive_t *);
 void ide_device_put(ide_drive_t *);
 
-int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, unsigned, unsigned long);
+struct ide_ioctl_devset {
+	unsigned int	get_ioctl;
+	unsigned int	set_ioctl;
+
+	int		(*get)(ide_drive_t *);
+	int		(*set)(ide_drive_t *, int);
+};
+
+int ide_setting_ioctl(ide_drive_t *, struct block_device *, unsigned int,
+		      unsigned long, const struct ide_ioctl_devset *);
+
+int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *,
+		      unsigned, unsigned long);
 
 extern int ide_vlb_clk;
 extern int ide_pci_clk;
#2 lore raw

PATCH 3/4 ide: cleanup generic_ide_ioctl()

In reply to Bartlomiej Zolnierkiewicz

* Fix intendation for the main 'switch ()'.

* 'switch ()' -> 'if ()' for HDIO_DRIVE_TASKFILE case.

* Move HDIO_SET_NICE case under HDIO_GET_NICE one.

---
 drivers/ide/ide.c |   97 +++++++++++++++++++++++++-----------------------------
 1 file changed, 45 insertions(+), 52 deletions(-)
drivers/ide/ide.c +45 -52
Index: b/drivers/ide/ide.c
===================================================================
@@ -565,8 +565,9 @@ static const struct ide_ioctl_devset ide
 { 0 }
 };
 
-int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
-			unsigned int cmd, unsigned long arg)
+int generic_ide_ioctl(ide_drive_t *drive, struct file *file,
+		      struct block_device *bdev,
+		      unsigned int cmd, unsigned long arg)
 {
 	int err;
 
@@ -575,57 +576,49 @@ int generic_ide_ioctl(ide_drive_t *drive
 		return err;
 
 	switch (cmd) {
-		case HDIO_OBSOLETE_IDENTITY:
-		case HDIO_GET_IDENTITY:
-			if (bdev != bdev->bd_contains)
-				return -EINVAL;
-			return ide_get_identity_ioctl(drive, cmd, arg);
-		case HDIO_GET_NICE:
-			return ide_get_nice_ioctl(drive, arg);
-#ifdef CONFIG_IDE_TASK_IOCTL
-		case HDIO_DRIVE_TASKFILE:
-		        if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
-				return -EACCES;
-			switch(drive->media) {
-				case ide_disk:
-					return ide_taskfile_ioctl(drive, cmd, arg);
-				default:
-					return -ENOMSG;
-			}
-#endif /* CONFIG_IDE_TASK_IOCTL */
-
-		case HDIO_DRIVE_CMD:
-			if (!capable(CAP_SYS_RAWIO))
-				return -EACCES;
-			return ide_cmd_ioctl(drive, cmd, arg);
-
-		case HDIO_DRIVE_TASK:
-			if (!capable(CAP_SYS_RAWIO))
-				return -EACCES;
-			return ide_task_ioctl(drive, cmd, arg);
-		case HDIO_SET_NICE:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EACCES;
-			return ide_set_nice_ioctl(drive, arg);
-		case HDIO_DRIVE_RESET:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EACCES;
-
-			return generic_drive_reset(drive);
-
-		case HDIO_GET_BUSSTATE:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EACCES;
-			if (put_user(BUSSTATE_ON, (long __user *)arg))
-				return -EFAULT;
-			return 0;
-
-		case HDIO_SET_BUSSTATE:
-			if (!capable(CAP_SYS_ADMIN))
-				return -EACCES;
-			return -EOPNOTSUPP;
-		default:
+	case HDIO_OBSOLETE_IDENTITY:
+	case HDIO_GET_IDENTITY:
+		if (bdev != bdev->bd_contains)
 			return -EINVAL;
+		return ide_get_identity_ioctl(drive, cmd, arg);
+	case HDIO_GET_NICE:
+		return ide_get_nice_ioctl(drive, arg);
+	case HDIO_SET_NICE:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
+		return ide_set_nice_ioctl(drive, arg);
+#ifdef CONFIG_IDE_TASK_IOCTL
+	case HDIO_DRIVE_TASKFILE:
+		if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
+			return -EACCES;
+		if (drive->media == ide_disk)
+			return ide_taskfile_ioctl(drive, cmd, arg);
+		return -ENOMSG;
+#endif
+	case HDIO_DRIVE_CMD:
+		if (!capable(CAP_SYS_RAWIO))
+			return -EACCES;
+		return ide_cmd_ioctl(drive, cmd, arg);
+	case HDIO_DRIVE_TASK:
+		if (!capable(CAP_SYS_RAWIO))
+			return -EACCES;
+		return ide_task_ioctl(drive, cmd, arg);
+	case HDIO_DRIVE_RESET:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
+		return generic_drive_reset(drive);
+	case HDIO_GET_BUSSTATE:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
+		if (put_user(BUSSTATE_ON, (long __user *)arg))
+			return -EFAULT;
+		return 0;
+	case HDIO_SET_BUSSTATE:
+		if (!capable(CAP_SYS_ADMIN))
+			return -EACCES;
+		return -EOPNOTSUPP;
+	default:
+		return -EINVAL;
 	}
 }
 EXPORT_SYMBOL(generic_ide_ioctl);
#3 lore raw

PATCH 4/4 ide: move ioctls handling to ide-ioctls.c

In reply to Bartlomiej Zolnierkiewicz

* Move ioctls handling to ide-ioctls.c
(except HDIO_DRIVE_TASKFILE for now).

* Make ide_{cmd,task}() static.

---
 drivers/ide/Makefile       |    4 
 drivers/ide/ide-ioctls.c   |  289 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/ide/ide-taskfile.c |  109 ----------------
 drivers/ide/ide.c          |  174 ---------------------------
 include/linux/ide.h        |    2 
 5 files changed, 291 insertions(+), 287 deletions(-)
drivers/ide/Makefile +2 -2
Index: b/drivers/ide/Makefile
===================================================================
@@ -4,8 +4,8 @@
 
 EXTRA_CFLAGS				+= -Idrivers/ide
 
-ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o \
-	      ide-pio-blacklist.o
+ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
+	      ide-taskfile.o ide-pio-blacklist.o
 
 # core IDE code
 ide-core-$(CONFIG_IDE_TIMINGS)		+= ide-timings.o
drivers/ide/ide-ioctls.c new file +289 -0

289 lines not on this page · raw message

drivers/ide/ide-taskfile.c +0 -109

112 lines not on this page · raw message

drivers/ide/ide.c +0 -174

180 lines not on this page · raw message

include/linux/ide.h +0 -2
Index: b/include/linux/ide.h
===================================================================
@@ -1126,8 +1126,6 @@ int ide_raw_taskfile(ide_drive_t *, ide_
 int ide_no_data_taskfile(ide_drive_t *, ide_task_t *);
 
 int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long);
-int ide_cmd_ioctl(ide_drive_t *, unsigned int, unsigned long);
-int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long);
 
 extern int ide_driveid_update(ide_drive_t *);
 extern int ide_config_drive_speed(ide_drive_t *, u8);