Re: [PATCH] sg_io: allow UNMAP and WRITE SAME without CAP_SYS_RAWIO

2012-09-12 Thread James Bottomley
On Tue, 2012-09-11 at 19:56 +0200, Paolo Bonzini wrote:
> The set of use cases is so variable that no single filter can accomodate
> all of them: high availability people want persistent reservations, NAS
> people want trim/discard, but these are just two groups.  Someone is
> using a Windows VM to run vendor tools and wants to have access to
> vendor-specific commands.
> 
> You can tell this last group to use root, but not everyone else who is
> already relying on Unix permissions, SELinux and/or device cgroups to
> confine their virtual machines.

This is why the whole filter thing was mutable via sysfs.  That way the
admin could set this up per device.  It sounds like this is what you
want to fix, rather than opening up more holes in an already leaky
security apparatus.  The ideal is that we would be much more restrictive
by default and give root the ability to override this both globally and
per-device to conform to whatever policy it has for the virtual
environments.

The patch which removed all of the sysfs pieces was:

commit 018e0446890661504783f92388ecce7138c1566d
Author: Jens Axboe 
Date:   Fri Jun 26 16:27:10 2009 +0200

block: get rid of queue-private command filter

So that's probably the place to start for putting it back properly.

James


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] sg_io: allow UNMAP and WRITE SAME without CAP_SYS_RAWIO

2012-09-12 Thread Paolo Bonzini
Il 12/09/2012 10:05, James Bottomley ha scritto:
> This is why the whole filter thing was mutable via sysfs.  That way the
> admin could set this up per device.  It sounds like this is what you
> want to fix, rather than opening up more holes in an already leaky
> security apparatus.

It is, thanks for the useful history lesson!

Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 0/6] ZPODD patches

2012-09-12 Thread Aaron Lu
v7:
Re work of runtime pm of sr driver, based on ideas of Alan Stern and
Oliver Neukum.

Jeff, due to the ready_to_power_off flag added, there is a small
change in [PATCH v7 6/6] libata: acpi: respect may_power_off flag,
please check if I can still get your ack, thanks.

v6:
When user changes may_power_off flag through sysfs entry and if device
is already runtime suspended, resume resume it so that it can respect
this flag next time it is runtime suspended as suggested by Alan Stern.
Call scsi_autopm_get/put_device once in sr_check_events as suggested by
Alan Stern.

v5:
Add may_power_off flag to scsi device.
Alan Stern suggested that I should not mess runtime suspend with
runtime power off, but the current zpodd implementation made it not
easy to seperate. So I re-wrote the zpodd implementation, the end
result is, normal ODD can also enter runtime suspended state, but
their power won't be removed.

v4:
Rebase on top of Linus' tree, due to this, the problem of a missing
flag in v3 is gone;
Add a new function scsi_autopm_put_device_autosuspend to first mark
last busy for the device and then put autosuspend it as suggested by
Oliver Neukum.
Typo fix as pointed by Sergei Shtylyov.
Check can_power_off flag before any runtime pm operations in sr.

v3:
Rebase on top of scsi-misc tree;
Add the sr related patches previously in Jeff's libata tree;
Re-organize the sr patches.
A problem for now: for patch
scsi: sr: support zero power ODD(ZPODD)
I can't set a flag in libata-acpi.c since a related function is
missing in scsi-misc tree. Will fix this when 3.6-rc1 released.

v2:
Bug fix for v1;
Use scsi_autopm_* in sr driver instead of pm_runtime_*;

v1:
Here are some patches to make ZPODD easier to use for end users and
a fix for using ZPODD with system suspend.

Aaron Lu (6):
  block: genhd: add an interface to set disk poll interval
  scsi: sr: support runtime pm
  scsi: sr: support zero power ODD(ZPODD)
  scsi: pm: add may_power_off flag
  scsi: sr: use may_power_off
  libata: acpi: respect may_power_off flag

 block/genhd.c  | 23 +
 drivers/ata/libata-acpi.c  | 30 +++-
 drivers/scsi/scsi_sysfs.c  | 37 +++-
 drivers/scsi/sr.c  | 86 +++---
 drivers/scsi/sr.h  |  1 +
 drivers/scsi/sr_ioctl.c|  7 +++-
 include/linux/genhd.h  |  1 +
 include/scsi/scsi_device.h |  4 +++
 8 files changed, 168 insertions(+), 21 deletions(-)

-- 
1.7.12.21.g871e293

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 1/6] block: genhd: add an interface to set disk poll interval

2012-09-12 Thread Aaron Lu
Signed-off-by: Aaron Lu 
---
 block/genhd.c | 23 +--
 include/linux/genhd.h |  1 +
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index cac7366..4244256 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1627,6 +1627,19 @@ static void disk_events_workfn(struct work_struct *work)
kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp);
 }
 
+int disk_events_set_poll_msecs(struct gendisk *disk, long intv)
+{
+   if (intv < 0 && intv != -1)
+   return -EINVAL;
+
+   disk_block_events(disk);
+   disk->ev->poll_msecs = intv;
+   __disk_unblock_events(disk, true);
+
+   return 0;
+}
+EXPORT_SYMBOL(disk_events_set_poll_msecs);
+
 /*
  * A disk events enabled device has the following sysfs nodes under
  * its /sys/block/X/ directory.
@@ -1683,16 +1696,14 @@ static ssize_t disk_events_poll_msecs_store(struct 
device *dev,
 {
struct gendisk *disk = dev_to_disk(dev);
long intv;
+   int ret;
 
if (!count || !sscanf(buf, "%ld", &intv))
return -EINVAL;
 
-   if (intv < 0 && intv != -1)
-   return -EINVAL;
-
-   disk_block_events(disk);
-   disk->ev->poll_msecs = intv;
-   __disk_unblock_events(disk, true);
+   ret = disk_events_set_poll_msecs(disk, intv);
+   if (ret)
+   return ret;
 
return count;
 }
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 4f440b3..63409e5 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -423,6 +423,7 @@ extern void disk_block_events(struct gendisk *disk);
 extern void disk_unblock_events(struct gendisk *disk);
 extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
+extern int disk_events_set_poll_msecs(struct gendisk *disk, long intv);
 
 /* drivers/char/random.c */
 extern void add_disk_randomness(struct gendisk *disk);
-- 
1.7.12.21.g871e293

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 3/6] scsi: sr: support zero power ODD(ZPODD)

2012-09-12 Thread Aaron Lu
When ODD is runtime suspended, we will check if it is OK to remove
its power:
1 For tray type, no medium inside and tray closed;
2 For slot type, no medium inside.
And if yes, we will set the ready_to_power_off flag as an indication to
ATA layer that it is safe to place this device into ACPI D3 cold power
state.

And when it is powered off, we will set the powered_off flag so that the
periodically running check_events will not bother this device by simply
return.

Signed-off-by: Aaron Lu 
---
 drivers/ata/libata-acpi.c  | 27 +++
 drivers/scsi/sr.c  | 53 ++
 drivers/scsi/sr.h  |  1 +
 drivers/scsi/sr_ioctl.c|  7 +-
 include/scsi/scsi_device.h |  3 +++
 5 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 902b5a4..9aca057 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -854,7 +854,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t 
state)
 {
struct ata_device *dev;
acpi_handle handle;
-   int acpi_state;
+   int acpi_state, ret;
 
/* channel first and then drives for power on and vica versa
   for power off */
@@ -869,17 +869,24 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t 
state)
 
if (state.event != PM_EVENT_ON) {
acpi_state = acpi_pm_device_sleep_state(
-   &dev->sdev->sdev_gendev, NULL, ACPI_STATE_D3);
-   if (acpi_state > 0)
-   acpi_bus_set_power(handle, acpi_state);
-   /* TBD: need to check if it's runtime pm request */
-   acpi_pm_device_run_wake(
-   &dev->sdev->sdev_gendev, true);
+   &dev->sdev->sdev_gendev, NULL,
+   dev->sdev->ready_to_power_off ?
+   ACPI_STATE_D3 : ACPI_STATE_D3_HOT);
+   if (acpi_state > 0) {
+   ret = acpi_bus_set_power(handle, acpi_state);
+   if (!ret && acpi_state == ACPI_STATE_D3)
+   dev->sdev->powered_off = 1;
+
+   /* TODO: check if it's runtime pm request */
+   acpi_pm_device_run_wake(
+   &dev->sdev->sdev_gendev, true);
+   }
} else {
/* Ditto */
acpi_pm_device_run_wake(
&dev->sdev->sdev_gendev, false);
acpi_bus_set_power(handle, ACPI_STATE_D0);
+   dev->sdev->powered_off = 0;
}
}
 
@@ -985,8 +992,10 @@ static void ata_acpi_wake_dev(acpi_handle handle, u32 
event, void *context)
struct ata_device *ata_dev = context;
 
if (event == ACPI_NOTIFY_DEVICE_WAKE && ata_dev &&
-   pm_runtime_suspended(&ata_dev->sdev->sdev_gendev))
-   scsi_autopm_get_device(ata_dev->sdev);
+   ata_dev->sdev->powered_off) {
+   ata_dev->sdev->need_eject = 1;
+   pm_runtime_resume(&ata_dev->sdev->sdev_gendev);
+   }
 }
 
 static void ata_acpi_add_pm_notifier(struct ata_device *dev)
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 7a8222f..ef72682 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -80,6 +80,8 @@ static DEFINE_MUTEX(sr_mutex);
 static int sr_probe(struct device *);
 static int sr_remove(struct device *);
 static int sr_done(struct scsi_cmnd *);
+static int sr_suspend(struct device *, pm_message_t msg);
+static int sr_resume(struct device *);
 
 static struct scsi_driver sr_template = {
.owner  = THIS_MODULE,
@@ -87,6 +89,8 @@ static struct scsi_driver sr_template = {
.name   = "sr",
.probe  = sr_probe,
.remove = sr_remove,
+   .suspend= sr_suspend,
+   .resume = sr_resume,
},
.done   = sr_done,
 };
@@ -172,6 +176,52 @@ static void scsi_cd_put(struct scsi_cd *cd)
mutex_unlock(&sr_ref_mutex);
 }
 
+static int sr_suspend(struct device *dev, pm_message_t msg)
+{
+   struct scsi_sense_hdr sshdr;
+   struct scsi_cd *cd = dev_get_drvdata(dev);
+
+   if (!cd->device->can_power_off)
+   return 0;
+
+   /* See if we can power off this ZPODD device */
+   scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
+   if (cd->cdi.mask & CDC_CLOSE_TRAY)
+   /* no media for caddy/slot type ODD */
+   cd->device->ready_to_power_off = scsi_sense_valid(&sshdr) &&
+   ssh

[PATCH v7 2/6] scsi: sr: support runtime pm

2012-09-12 Thread Aaron Lu
Place the ODD into runtime suspend state as soon as there is nobody
using it. The only exception is, if we just find that a new medium is
inserted, we wait for the next events checking to idle it.

Based on ideas of Alan Stern and Oliver Neukum.

Signed-off-by: Aaron Lu 
---
 drivers/scsi/sr.c | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 5fc97d2..7a8222f 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -146,8 +147,12 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk 
*disk)
kref_get(&cd->kref);
if (scsi_device_get(cd->device))
goto out_put;
+   if (scsi_autopm_get_device(cd->device))
+   goto out_pm;
goto out;
 
+ out_pm:
+   scsi_device_put(cd->device);
  out_put:
kref_put(&cd->kref, sr_kref_release);
cd = NULL;
@@ -163,6 +168,7 @@ static void scsi_cd_put(struct scsi_cd *cd)
mutex_lock(&sr_ref_mutex);
kref_put(&cd->kref, sr_kref_release);
scsi_device_put(sdev);
+   scsi_autopm_put_device(sdev);
mutex_unlock(&sr_ref_mutex);
 }
 
@@ -211,7 +217,7 @@ static unsigned int sr_check_events(struct 
cdrom_device_info *cdi,
unsigned int clearing, int slot)
 {
struct scsi_cd *cd = cdi->handle;
-   bool last_present;
+   bool last_present = cd->media_present;
struct scsi_sense_hdr sshdr;
unsigned int events;
int ret;
@@ -220,6 +226,8 @@ static unsigned int sr_check_events(struct 
cdrom_device_info *cdi,
if (CDSL_CURRENT != slot)
return 0;
 
+   scsi_autopm_get_device(cd->device);
+
events = sr_get_events(cd->device);
cd->get_event_changed |= events & DISK_EVENT_MEDIA_CHANGE;
 
@@ -246,10 +254,9 @@ static unsigned int sr_check_events(struct 
cdrom_device_info *cdi,
}
 
if (!(clearing & DISK_EVENT_MEDIA_CHANGE))
-   return events;
+   goto out;
 do_tur:
/* let's see whether the media is there with TUR */
-   last_present = cd->media_present;
ret = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES, &sshdr);
 
/*
@@ -270,7 +277,7 @@ do_tur:
}
 
if (cd->ignore_get_event)
-   return events;
+   goto out;
 
/* check whether GET_EVENT is reporting spurious MEDIA_CHANGE */
if (!cd->tur_changed) {
@@ -287,6 +294,12 @@ do_tur:
cd->tur_changed = false;
cd->get_event_changed = false;
 
+out:
+   if (cd->media_present && !last_present)
+   pm_runtime_put_noidle(&cd->device->sdev_gendev);
+   else
+   scsi_autopm_put_device(cd->device);
+
return events;
 }
 
@@ -715,9 +728,14 @@ static int sr_probe(struct device *dev)
dev_set_drvdata(dev, cd);
disk->flags |= GENHD_FL_REMOVABLE;
add_disk(disk);
+   disk_events_set_poll_msecs(disk, 5000);
 
sdev_printk(KERN_DEBUG, sdev,
"Attached scsi CD-ROM %s\n", cd->cdi.name);
+
+   /* enable runtime pm */
+   scsi_autopm_put_device(cd->device);
+
return 0;
 
 fail_put:
@@ -965,6 +983,9 @@ static int sr_remove(struct device *dev)
 {
struct scsi_cd *cd = dev_get_drvdata(dev);
 
+   /* disable runtime pm */
+   scsi_autopm_get_device(cd->device);
+
blk_queue_prep_rq(cd->device->request_queue, scsi_prep_fn);
del_gendisk(cd->disk);
 
-- 
1.7.12.21.g871e293

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 6/6] libata: acpi: respect may_power_off flag

2012-09-12 Thread Aaron Lu
If user does not want the device to be powered off when runtime
suspended by setting may_power_off flag to 0, we will not choose
D3 cold for it.

Signed-off-by: Aaron Lu 
---
 drivers/ata/libata-acpi.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 9aca057..24347e0 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -855,6 +855,7 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t 
state)
struct ata_device *dev;
acpi_handle handle;
int acpi_state, ret;
+   bool power_off_allowed;
 
/* channel first and then drives for power on and vica versa
   for power off */
@@ -868,9 +869,11 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t 
state)
continue;
 
if (state.event != PM_EVENT_ON) {
+   power_off_allowed = dev->sdev->ready_to_power_off &&
+   dev->sdev->may_power_off;
acpi_state = acpi_pm_device_sleep_state(
&dev->sdev->sdev_gendev, NULL,
-   dev->sdev->ready_to_power_off ?
+   power_off_allowed ?
ACPI_STATE_D3 : ACPI_STATE_D3_HOT);
if (acpi_state > 0) {
ret = acpi_bus_set_power(handle, acpi_state);
-- 
1.7.12.21.g871e293

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 4/6] scsi: pm: add may_power_off flag

2012-09-12 Thread Aaron Lu
Add a new flag may_power_off for scsi device, it gives the user a chance
to control when the device is runtime suspended, can we remove its power
if possible.

And if the device can be powered off(reflected by can_power_off flag,
determined by individual driver), create a sysfs entry named
may_power_off to let user control the flag.

When user changes this flag through sysfs entry and if the device is
already runtime suspended, runtime resume it so that it can respect this
flag next time it is runtime suspended.

I'm planning using this flag for sr and sd.

Signed-off-by: Aaron Lu 
---
 drivers/scsi/scsi_sysfs.c  | 37 -
 include/scsi/scsi_device.h |  1 +
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 093d4f6..8c8efd3 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -509,6 +509,7 @@ sdev_store_##field (struct device *dev, struct 
device_attribute *attr,  \
return ret; \
 }  \
 static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, sdev_show_##field, 
sdev_store_##field);
+#endif
 
 /*
  * scsi_sdev_check_buf_bit: return 0 if buf is "0", return 1 if buf is "1",
@@ -526,7 +527,7 @@ static int scsi_sdev_check_buf_bit(const char *buf)
} else
return -EINVAL;
 }
-#endif
+
 /*
  * Create the actual show/store functions and data structures.
  */
@@ -860,6 +861,37 @@ static struct device_attribute sdev_attr_queue_type_rw =
__ATTR(queue_type, S_IRUGO | S_IWUSR, show_queue_type_field,
   sdev_store_queue_type_rw);
 
+static ssize_t
+sdev_show_may_power_off(struct device *dev, struct device_attribute *attr,
+   char *buf)
+{
+   struct scsi_device *sdev;
+   sdev = to_scsi_device(dev);
+   return snprintf (buf, 20, "%d\n", sdev->may_power_off);
+}
+
+static ssize_t
+sdev_store_may_power_off(struct device *dev, struct device_attribute *attr,
+const char *buf, size_t count)
+{
+   int ret;
+   struct scsi_device *sdev;
+
+   ret = scsi_sdev_check_buf_bit(buf);
+   if (ret >= 0) {
+   sdev = to_scsi_device(dev);
+   if (sdev->may_power_off != ret) {
+   sdev->may_power_off = ret;
+   if (pm_runtime_suspended(dev))
+   pm_runtime_resume(dev);
+   }
+   ret = count;
+   }
+   return ret;
+}
+static DEVICE_ATTR(may_power_off, S_IRUGO | S_IWUSR,
+   sdev_show_may_power_off, sdev_store_may_power_off);
+
 /**
  * scsi_sysfs_add_sdev - add scsi device to sysfs
  * @sdev:  scsi_device to add
@@ -950,6 +982,9 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
}
}
 
+   if (sdev->can_power_off)
+   device_create_file(&sdev->sdev_gendev, &dev_attr_may_power_off);
+
return error;
 }
 
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index da5c86f..4712aa1 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -159,6 +159,7 @@ struct scsi_device {
unsigned need_eject:1;  /* Need eject the tray when wakes up */
unsigned ready_to_power_off:1;  /* Device is ready to be powered off */
unsigned powered_off:1; /* Device is powered off */
+   unsigned may_power_off:1; /* Power off is allowed by user */
 
DECLARE_BITMAP(supported_events, SDEV_EVT_MAXBITS); /* supported events 
*/
struct list_head event_list;/* asserted events */
-- 
1.7.12.21.g871e293

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 5/6] scsi: sr: use may_power_off

2012-09-12 Thread Aaron Lu
If may_power_off is 0, we do not check if it is ready to be powered off
in its suspend callback.

Signed-off-by: Aaron Lu 
---
 drivers/scsi/sr.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index ef72682..4c1a182 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -181,7 +181,7 @@ static int sr_suspend(struct device *dev, pm_message_t msg)
struct scsi_sense_hdr sshdr;
struct scsi_cd *cd = dev_get_drvdata(dev);
 
-   if (!cd->device->can_power_off)
+   if (!cd->device->may_power_off)
return 0;
 
/* See if we can power off this ZPODD device */
@@ -786,6 +786,10 @@ static int sr_probe(struct device *dev)
sdev_printk(KERN_DEBUG, sdev,
"Attached scsi CD-ROM %s\n", cd->cdi.name);
 
+   /* By default, we allow power off of ZPODD */
+   if (cd->device->can_power_off)
+   cd->device->may_power_off = 1;
+
/* enable runtime pm */
scsi_autopm_put_device(cd->device);
 
-- 
1.7.12.21.g871e293

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] block: add queue-private command filter, editable via sysfs

2012-09-12 Thread Paolo Bonzini
[sorry for the resend, I used a wrong mailing list address]

The set of use cases for SG_IO is quite variable that no single filter can
accomodate all of them.  The current filter is tailored very much to
CD burning, and includes many MMC-specific commands that may have
other meanings in different standards.  Someone may want to remove
those commands; at the same time, people that trust their users may
want to add persistent reservations, trim/discard, or even access to
vendor-specific commands.

Filters used to be mutable via sysfs, but the implementation was
never enabled.  Add it back, and let the admin set this up per device.
The ideal is that we would be much more restrictive by default and
give root the ability to override this both globally and per-device.
But this piece of the policy should probably be implemented in userspace
for better backwards compatibility.

In the meanwhile, this patch series provides the sysfs knob.  It is a
tweaked revert of commit 018e044 (block: get rid of queue-private command
filter, 2009-06-26).

Paolo Bonzini (3):
  block: add back queue-private command filter
  scsi: create an all-zero filter for scanners
  block: add back command filter modification via sysfs

 Documentation/block/queue-sysfs.txt |   16 +
 block/Kconfig   |   10 +++
 block/blk-sysfs.c   |   43 +
 block/bsg.c |2 +-
 block/scsi_ioctl.c  |  117 +++
 drivers/scsi/scsi_scan.c|6 ++-
 drivers/scsi/sg.c   |7 +-
 include/linux/blkdev.h  |   31 +-
 8 files changed, 213 insertions(+), 19 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] block: add back queue-private command filter

2012-09-12 Thread Paolo Bonzini
The command filter used to be mutable via sysfs, but this was broken
and backed out.  Let's add it back.  This patch adds the infrastructure
for filtering, but unlike the old code this one just adds a pointer to
request_queue, so as to make it cheaper in the majority of cases where
no special filtering is desired.

This is a partial (and massaged) revert of commit 018e044 (block: get
rid of queue-private command filter, 2009-06-26).

Cc: linux-scsi@vger.kernel.org
Signed-off-by: Paolo Bonzini 
---
 block/blk-sysfs.c  |2 ++
 block/bsg.c|2 +-
 block/scsi_ioctl.c |   17 +
 drivers/scsi/sg.c  |4 +++-
 include/linux/blkdev.h |   10 +-
 5 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 9628b29..5a0de07 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -487,6 +487,8 @@ static void blk_release_queue(struct kobject *kobj)
 
blkcg_exit_queue(q);
 
+   kfree(q->cmd_filter);
+
if (q->elevator) {
spin_lock_irq(q->queue_lock);
ioc_clear_queue(q);
diff --git a/block/bsg.c b/block/bsg.c
index ff64ae3..09956da 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -187,7 +187,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, 
struct request *rq,
return -EFAULT;
 
if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
-   if (blk_verify_command(rq->cmd, has_write_perm))
+   if (blk_verify_command(q->cmd_filter, rq->cmd, has_write_perm))
return -EPERM;
} else if (!capable(CAP_SYS_RAWIO))
return -EPERM;
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 9a87daa..c8862e9 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -33,11 +33,6 @@
 #include 
 #include 
 
-struct blk_cmd_filter {
-   unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
-   unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
-};
-
 static struct blk_cmd_filter blk_default_cmd_filter;
 
 /* Command group 3 is reserved and should never be used.  */
@@ -196,17 +191,15 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
__set_bit(GPCMD_SET_READ_AHEAD, filter->write_ok);
 }
 
-int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm)
+int blk_verify_command(struct blk_cmd_filter *filter,
+  unsigned char *cmd, fmode_t has_write_perm)
 {
-   struct blk_cmd_filter *filter = &blk_default_cmd_filter;
-
/* root can do any command. */
if (capable(CAP_SYS_RAWIO))
return 0;
 
-   /* if there's no filter set, assume we're filtering everything out */
if (!filter)
-   return -EPERM;
+   filter = &blk_default_cmd_filter;
 
/* Anybody who can open the device can do a read-safe command */
if (test_bit(cmd[0], filter->read_ok))
@@ -225,7 +218,7 @@ static int blk_fill_sghdr_rq(struct request_queue *q, 
struct request *rq,
 {
if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
return -EFAULT;
-   if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
+   if (blk_verify_command(q->cmd_filter, rq->cmd, mode & FMODE_WRITE))
return -EPERM;
 
/*
@@ -472,7 +465,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk 
*disk, fmode_t mode,
if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
goto error;
 
-   err = blk_verify_command(rq->cmd, mode & FMODE_WRITE);
+   err = blk_verify_command(q->cmd_filter, rq->cmd, mode & FMODE_WRITE);
if (err)
goto error;
 
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 9c5c5f2..2ba7c82 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -217,11 +217,13 @@ static void sg_put_dev(Sg_device *sdp);
 static int sg_allow_access(struct file *filp, unsigned char *cmd)
 {
struct sg_fd *sfp = filp->private_data;
+   struct request_queue *q = sfp->parentdp->device->request_queue;
 
if (sfp->parentdp->device->type == TYPE_SCANNER)
return 0;
 
-   return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE);
+   return blk_verify_command(q->cmd_filter,
+ cmd, filp->f_mode & FMODE_WRITE);
 }
 
 static int get_exclude(Sg_device *sdp)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 4a2ab7c..b5c5f8a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -258,6 +258,11 @@ struct blk_queue_tag {
 #define BLK_SCSI_MAX_CMDS  (256)
 #define BLK_SCSI_CMD_PER_LONG  (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
 
+struct blk_cmd_filter {
+   unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
+   unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
+};
+
 struct queue_limits {
unsigned long   bounce_pfn;
unsigned long   seg_boundary_mask;
@@ -423,6 +428,8 @@ struct reque

[PATCH 2/3] scsi: create an all-zero filter for scanners

2012-09-12 Thread Paolo Bonzini
Using /dev/sg for scanners is blocked from unprivileged users.  Reimplement
this using customizable command filters, so that the sysfs knobs will work
in this case too.

Cc: linux-scsi@vger.kernel.org
Signed-off-by: Paolo Bonzini 
---
 drivers/scsi/scsi_scan.c |6 +-
 drivers/scsi/sg.c|3 ---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 56a9379..d168c15 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -773,13 +773,17 @@ static int scsi_add_lun(struct scsi_device *sdev, 
unsigned char *inq_result,
}
 
switch (sdev->type) {
+   case TYPE_SCANNER:
+   sdev->request_queue->cmd_filter =
+   kzalloc(sizeof(struct blk_cmd_filter), GFP_KERNEL);
+   /* fallthrough */
+
case TYPE_RBC:
case TYPE_TAPE:
case TYPE_DISK:
case TYPE_PRINTER:
case TYPE_MOD:
case TYPE_PROCESSOR:
-   case TYPE_SCANNER:
case TYPE_MEDIUM_CHANGER:
case TYPE_ENCLOSURE:
case TYPE_COMM:
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 2ba7c82..c7474f5 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -219,9 +219,6 @@ static int sg_allow_access(struct file *filp, unsigned char 
*cmd)
struct sg_fd *sfp = filp->private_data;
struct request_queue *q = sfp->parentdp->device->request_queue;
 
-   if (sfp->parentdp->device->type == TYPE_SCANNER)
-   return 0;
-
return blk_verify_command(q->cmd_filter,
  cmd, filp->f_mode & FMODE_WRITE);
 }
-- 
1.7.1


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] block: add back command filter modification via sysfs

2012-09-12 Thread Paolo Bonzini
This adds two new sysfs attributes to the queue kobject.  The attributes
allow reading and writing the whitelist of unprivileged commands.

This is again a bit different from what was removed in commit 018e044
(block: get rid of queue-private command filter, 2009-06-26), but the idea
is the same.  One difference is that it does not use a separate kobject.
Also, the supported sysfs syntax is a bit more expressive: it includes
ranges, the ability to replace all of the filter with a single command,
and does not force usage of hexadecimal.

Since the names are different, and the old ones were anyway never really
enabled, the different API is not a problem.

Cc: linux-scsi@vger.kernel.org
Signed-off-by: Paolo Bonzini 
---
 Documentation/block/queue-sysfs.txt |   16 ++
 block/Kconfig   |   10 
 block/blk-sysfs.c   |   41 ++
 block/scsi_ioctl.c  |  100 +++
 include/linux/blkdev.h  |   21 +++
 5 files changed, 188 insertions(+), 0 deletions(-)

diff --git a/Documentation/block/queue-sysfs.txt 
b/Documentation/block/queue-sysfs.txt
index e54ac1d..1152b38 100644
--- a/Documentation/block/queue-sysfs.txt
+++ b/Documentation/block/queue-sysfs.txt
@@ -133,6 +133,22 @@ control of this block device to that new IO scheduler. 
Note that writing
 an IO scheduler name to this file will attempt to load that IO scheduler
 module, if it isn't already present in the system.
 
+sgio_read_filter (RW)
+-
+When read, this file will display a list of SCSI commands (i.e. values of
+the first byte of a CDB) that are always available for unprivileged users
+(via /dev/bsg, /dev/sgNN, or ioctls such as SG_IO and CDROM_SEND_PACKET).
+When written, the list of commands will be modified.  By default it
+will be completely replaced; writing a string that begins with '+' will
+add new commands, and writing a string that begins with '-' will remove
+some commands.  Ranges of commands are supported, for example '0x00-0xff'.
+
+sgio_write_filter (RW)
+--
+When read, this file will display a list of SCSI commands (i.e. values of
+the first byte of a CDB) that are available for unprivileged users
+when the block device is open for writing.  Writing to this file behaves
+as for sgio_read_filter.
 
 
 Jens Axboe , February 2009
diff --git a/block/Kconfig b/block/Kconfig
index 09acf1b..7c369d9 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -65,6 +65,16 @@ config BLK_DEV_BSG
 
  If unsure, say Y.
 
+config BLK_DEV_SG_FILTER_SYSFS
+   bool "Customizable SG_IO filters in sysfs"
+   default y
+   help
+ Saying Y here will let you use sysfs to customize the list
+ of SCSI commands that are available (via /dev/sg, /dev/bsg or
+ ioctls such as SG_IO) to unprivileged users.
+
+ If unsure, say Y.
+
 config BLK_DEV_BSGLIB
bool "Block layer SG support v4 helper lib"
default n
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 5a0de07..b287d62 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -394,6 +394,43 @@ static struct queue_sysfs_entry queue_random_entry = {
.store = queue_store_random,
 };
 
+#ifdef CONFIG_BLK_DEV_SG_FILTER_SYSFS
+static ssize_t queue_sgio_filter_read_show(struct request_queue *q, char *page)
+{
+   return blk_filter_show(q, page, READ);
+}
+
+static ssize_t queue_sgio_filter_write_show(struct request_queue *q,
+char *page)
+{
+   return blk_filter_show(q, page, WRITE);
+}
+
+static ssize_t queue_sgio_filter_read_store(struct request_queue *q,
+   const char *page, size_t count)
+{
+   return blk_filter_store(q, page, count, READ);
+}
+
+static ssize_t queue_sgio_filter_write_store(struct request_queue *q,
+const char *page, size_t count)
+{
+   return blk_filter_store(q, page, count, WRITE);
+}
+
+static struct queue_sysfs_entry queue_sgio_filter_read_entry = {
+   .attr = { .name = "sgio_filter_read", .mode = S_IRUGO | S_IWUSR },
+   .show = queue_sgio_filter_read_show,
+   .store = queue_sgio_filter_read_store,
+};
+
+static struct queue_sysfs_entry queue_sgio_filter_write_entry = {
+   .attr = {.name = "sgio_filter_write", .mode = S_IRUGO | S_IWUSR },
+   .show = queue_sgio_filter_write_show,
+   .store = queue_sgio_filter_write_store,
+};
+#endif
+
 static struct attribute *default_attrs[] = {
&queue_requests_entry.attr,
&queue_ra_entry.attr,
@@ -416,6 +453,10 @@ static struct attribute *default_attrs[] = {
&queue_rq_affinity_entry.attr,
&queue_iostats_entry.attr,
&queue_random_entry.attr,
+#ifdef CONFIG_BLK_DEV_SG_FILTER_SYSFS
+   &queue_sgio_filter_read_entry.attr,
+   &queue_sgio_filter_write_entry.attr,
+#endif
NULL,
 };
 
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index c8862e9..

[V4 PATCH 0/8] csiostor: Chelsio FCoE offload driver submission

2012-09-12 Thread Naresh Kumar Inna
This is the initial submission of the Chelsio FCoE offload driver (csiostor)
to the upstream kernel. This driver currently supports FCoE offload
functionality over Chelsio T4-based 10Gb Converged Network Adapters.

The following patches contain the driver sources for csiostor driver and
updates to firmware/hardware header files shared between csiostor,
cxgb4 (Chelsio T4-based NIC driver) and cxgb4vf (Chelsio T4-based Virtual
Function NIC driver). The csiostor driver is dependent on these
header updates. These patches have been generated against scsi 'misc' branch.

csiostor is a low level SCSI driver that interfaces with PCI, SCSI midlayer and
FC transport subsystems. This driver claims the FCoE PCIe function on
Chelsio Converged Network Adapters. It relies on firmware events for slow path
operations like discovery, thereby offloading session management. The driver
programs firmware via Work Request interfaces for fast path I/O offload
features.

In this version (V4), the patches have been re-arranged to make them bisectable.

Here is the brief description of patches:
[V4 PATCH 1/8]: Updates to header files shared between cxgb4, cxgb4vf and
csiostor.
[V4 PATCH 2/8]: Header files part 1.
[V4 PATCH 3/8]: Header files part 2.
[V4 PATCH 4/8]: Driver initialization and Work Request services.
[V4 PATCH 5/8]: FC transport interfaces and mailbox services.
[V4 PATCH 6/8]: Local and remote port state tracking functionality.
[V4 PATCH 7/8]: Interrupt handling and fast path I/O functionality.
[V4 PATCH 8/8]: Hardware interface, Makefile and Kconfig changes.

Naresh Kumar Inna (8):
  cxgb4/cxgb4vf: Chelsio FCoE offload driver submission (common header
updates).
  csiostor: Chelsio FCoE offload driver submission (headers part 1).
  csiostor: Chelsio FCoE offload driver submission (headers part 2).
  csiostor: Chelsio FCoE offload driver submission (sources part 1).
  csiostor: Chelsio FCoE offload driver submission (sources part 2).
  csiostor: Chelsio FCoE offload driver submission (sources part 3).
  csiostor: Chelsio FCoE offload driver submission (sources part 4).
  csiostor: Chelsio FCoE offload driver submission (sources part 5).

 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |2 +-
 drivers/net/ethernet/chelsio/cxgb4/sge.c|   10 +-
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c  |   16 +-
 drivers/net/ethernet/chelsio/cxgb4/t4_msg.h |1 +
 drivers/net/ethernet/chelsio/cxgb4/t4_regs.h|   69 +-
 drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h   |  104 +-
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c  |   11 +-
 drivers/scsi/Kconfig|1 +
 drivers/scsi/Makefile   |1 +
 drivers/scsi/csiostor/Kconfig   |   19 +
 drivers/scsi/csiostor/Makefile  |   11 +
 drivers/scsi/csiostor/csio_attr.c   |  809 +
 drivers/scsi/csiostor/csio_defs.h   |  108 +
 drivers/scsi/csiostor/csio_hw.c | 4396 +++
 drivers/scsi/csiostor/csio_hw.h |  666 
 drivers/scsi/csiostor/csio_init.c   | 1272 +++
 drivers/scsi/csiostor/csio_init.h   |  158 +
 drivers/scsi/csiostor/csio_isr.c|  624 
 drivers/scsi/csiostor/csio_lnode.c  | 2148 +++
 drivers/scsi/csiostor/csio_lnode.h  |  255 ++
 drivers/scsi/csiostor/csio_mb.c | 1769 +
 drivers/scsi/csiostor/csio_mb.h |  278 ++
 drivers/scsi/csiostor/csio_rnode.c  |  889 +
 drivers/scsi/csiostor/csio_rnode.h  |  141 +
 drivers/scsi/csiostor/csio_scsi.c   | 2560 +
 drivers/scsi/csiostor/csio_scsi.h   |  342 ++
 drivers/scsi/csiostor/csio_wr.c | 1632 +
 drivers/scsi/csiostor/csio_wr.h |  512 +++
 drivers/scsi/csiostor/t4fw_api_stor.h   |  578 +++
 29 files changed, 19345 insertions(+), 37 deletions(-)
 create mode 100644 drivers/scsi/csiostor/Kconfig
 create mode 100644 drivers/scsi/csiostor/Makefile
 create mode 100644 drivers/scsi/csiostor/csio_attr.c
 create mode 100644 drivers/scsi/csiostor/csio_defs.h
 create mode 100644 drivers/scsi/csiostor/csio_hw.c
 create mode 100644 drivers/scsi/csiostor/csio_hw.h
 create mode 100644 drivers/scsi/csiostor/csio_init.c
 create mode 100644 drivers/scsi/csiostor/csio_init.h
 create mode 100644 drivers/scsi/csiostor/csio_isr.c
 create mode 100644 drivers/scsi/csiostor/csio_lnode.c
 create mode 100644 drivers/scsi/csiostor/csio_lnode.h
 create mode 100644 drivers/scsi/csiostor/csio_mb.c
 create mode 100644 drivers/scsi/csiostor/csio_mb.h
 create mode 100644 drivers/scsi/csiostor/csio_rnode.c
 create mode 100644 drivers/scsi/csiostor/csio_rnode.h
 create mode 100644 drivers/scsi/csiostor/csio_scsi.c
 create mode 100644 drivers/scsi/csiostor/csio_scsi.h
 create mode 100644 drivers/scsi/csiostor/csio_wr.c
 create mode 100644 drivers/s

[V4 PATCH 2/8] csiostor: Chelsio FCoE offload driver submission (headers part 1).

2012-09-12 Thread Naresh Kumar Inna
This patch contains the first set of the header files for csiostor driver.

Signed-off-by: Naresh Kumar Inna 
---
V2:
- Removed csio_fcoe_proto.h, using defines from include/scsi/fc instead.
- Removed driver-specific return values, using errno values instead.
- Retained CSIO_INC_STATS, since it is useful in multiple places and
  the name of the structure has been standardized to make use of this macro.
- Removed csio_deq_from_head(), replaced it inline with calls from list.h.
- Removed csio_deq_from_tail().
- Replaced state machine macros with static functions.
- Capitalizing macros with CPP keys.

V3:
- Replaced CSIO_ROUNDUP with DIV_ROUND_UP.
- Use BUG_ON in CSIO_ASSERT macro.

 drivers/scsi/csiostor/csio_defs.h |  108 ++
 drivers/scsi/csiostor/csio_hw.h   |  666 +
 drivers/scsi/csiostor/csio_init.h |  158 
 drivers/scsi/csiostor/t4fw_api_stor.h |  578 
 4 files changed, 1510 insertions(+), 0 deletions(-)
 create mode 100644 drivers/scsi/csiostor/csio_defs.h
 create mode 100644 drivers/scsi/csiostor/csio_hw.h
 create mode 100644 drivers/scsi/csiostor/csio_init.h
 create mode 100644 drivers/scsi/csiostor/t4fw_api_stor.h

diff --git a/drivers/scsi/csiostor/csio_defs.h 
b/drivers/scsi/csiostor/csio_defs.h
new file mode 100644
index 000..80be354
--- /dev/null
+++ b/drivers/scsi/csiostor/csio_defs.h
@@ -0,0 +1,108 @@
+/*
+ * This file is part of the Chelsio FCoE driver for Linux.
+ *
+ * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __CSIO_DEFS_H__
+#define __CSIO_DEFS_H__
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define CSIO_INVALID_IDX   0x
+#define CSIO_INC_STATS(elem, val)  ((elem)->stats.val++)
+#define CSIO_DEC_STATS(elem, val)  ((elem)->stats.val--)
+#define CSIO_VALID_WWN(__n)((*__n >> 4) == 0x5 ? true : false)
+#define CSIO_DID_MASK  0xFF
+#define CSIO_WORD_TO_BYTE  4
+
+static inline int
+csio_list_deleted(struct list_head *list)
+{
+   return ((list->next == list) && (list->prev == list));
+}
+
+#define csio_list_next(elem)   (((struct list_head *)(elem))->next)
+#define csio_list_prev(elem)   (((struct list_head *)(elem))->prev)
+
+/* State machine */
+typedef void (*csio_sm_state_t)(void *, uint32_t);
+
+struct csio_sm {
+   struct list_headsm_list;
+   csio_sm_state_t sm_state;
+};
+
+static inline void
+csio_set_state(void *smp, void *state)
+{
+   ((struct csio_sm *)smp)->sm_state = (csio_sm_state_t)state;
+}
+
+static inline void
+csio_init_state(struct csio_sm *smp, void *state)
+{
+   csio_set_state(smp, state);
+}
+
+static inline void
+csio_post_event(void *smp, uint32_t evt)
+{
+   ((struct csio_sm *)smp)->sm_state(smp, evt);
+}
+
+static inline csio_sm_state_t
+csio_get_state(void *smp)
+{
+   return ((struct csio_sm *)smp)->sm_state;
+}
+
+static inline bool
+csio_match_state(void *smp, void *state)
+{
+   return (csio_get_state(smp) == (csio_sm_state_t)state);
+}
+
+#defineCSIO_ASSERT(cond)   BUG_ON(!(cond))
+
+#ifdef __CSIO_DEBUG__
+#define CSIO_DB_ASSERT(__c)CSIO_ASSERT((__c))
+#else
+#define CSIO_DB_ASSERT(__c)
+#endif
+
+#endif /* ifndef __CSIO_DEFS_H__ */
diff --git a/drivers/scsi/csiostor/csio_hw.h b/drivers/scsi/csiostor/csio_hw.h
new file mode 100644
index 000..a58fdc9
--- /dev/null
+++ b/drivers/scsi/csiostor/csio_hw.h
@@ -0,0 +1,666 @@
+/*
+ * This file is part of the Chelsio FCoE driver for

[V4 PATCH 3/8] csiostor: Chelsio FCoE offload driver submission (headers part 2).

2012-09-12 Thread Naresh Kumar Inna
This patch contains the second set of the header files for csiostor driver.

Signed-off-by: Naresh Kumar Inna 
---
 drivers/scsi/csiostor/csio_lnode.h |  255 ++
 drivers/scsi/csiostor/csio_mb.h|  278 +++
 drivers/scsi/csiostor/csio_rnode.h |  141 ++
 drivers/scsi/csiostor/csio_scsi.h  |  342 
 drivers/scsi/csiostor/csio_wr.h|  512 
 5 files changed, 1528 insertions(+), 0 deletions(-)
 create mode 100644 drivers/scsi/csiostor/csio_lnode.h
 create mode 100644 drivers/scsi/csiostor/csio_mb.h
 create mode 100644 drivers/scsi/csiostor/csio_rnode.h
 create mode 100644 drivers/scsi/csiostor/csio_scsi.h
 create mode 100644 drivers/scsi/csiostor/csio_wr.h

diff --git a/drivers/scsi/csiostor/csio_lnode.h 
b/drivers/scsi/csiostor/csio_lnode.h
new file mode 100644
index 000..8d84988
--- /dev/null
+++ b/drivers/scsi/csiostor/csio_lnode.h
@@ -0,0 +1,255 @@
+/*
+ * This file is part of the Chelsio FCoE driver for Linux.
+ *
+ * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __CSIO_LNODE_H__
+#define __CSIO_LNODE_H__
+
+#include 
+#include 
+#include 
+#include 
+
+
+#include "csio_defs.h"
+#include "csio_hw.h"
+
+#define CSIO_FCOE_MAX_NPIV 128
+#define CSIO_FCOE_MAX_RNODES   2048
+
+/* FDMI port attribute unknown speed */
+#define CSIO_HBA_PORTSPEED_UNKNOWN 0x8000
+
+extern int csio_fcoe_rnodes;
+extern int csio_fdmi_enable;
+
+/* State machine evets */
+enum csio_ln_ev {
+   CSIO_LNE_NONE = (uint32_t)0,
+   CSIO_LNE_LINKUP,
+   CSIO_LNE_FAB_INIT_DONE,
+   CSIO_LNE_LINK_DOWN,
+   CSIO_LNE_DOWN_LINK,
+   CSIO_LNE_LOGO,
+   CSIO_LNE_CLOSE,
+   CSIO_LNE_MAX_EVENT,
+};
+
+
+struct csio_fcf_info {
+   struct list_headlist;
+   uint8_t priority;
+   uint8_t mac[6];
+   uint8_t name_id[8];
+   uint8_t fabric[8];
+   uint16_tvf_id;
+   uint8_t vlan_id;
+   uint16_tmax_fcoe_size;
+   uint8_t fc_map[3];
+   uint32_tfka_adv;
+   uint32_tfcfi;
+   uint8_t get_next:1;
+   uint8_t link_aff:1;
+   uint8_t fpma:1;
+   uint8_t spma:1;
+   uint8_t login:1;
+   uint8_t portid;
+   uint8_t spma_mac[6];
+   struct kref kref;
+};
+
+/* Defines for flags */
+#defineCSIO_LNF_FIPSUPP0x0001  /* Fip 
Supported */
+#defineCSIO_LNF_NPIVSUPP   0x0002  /* NPIV 
supported */
+#define CSIO_LNF_LINK_ENABLE   0x0004  /* Link enabled */
+#defineCSIO_LNF_FDMI_ENABLE0x0008  /* FDMI support 
*/
+
+/* Transport events */
+enum csio_ln_fc_evt {
+   CSIO_LN_FC_LINKUP = 1,
+   CSIO_LN_FC_LINKDOWN,
+   CSIO_LN_FC_RSCN,
+   CSIO_LN_FC_ATTRIB_UPDATE,
+};
+
+/* Lnode stats */
+struct csio_lnode_stats {
+   uint32_tn_link_up;  /* Link down */
+   uint32_tn_link_down;/* Link up */
+   uint32_tn_err;  /* error */
+   uint32_tn_err_nomem;/* memory not available */
+   uint32_tn_inval_parm;   /* Invalid parameters */
+   uint32_tn_evt_unexp;/* unexpected event */
+   uint32_tn_evt_drop; /* dropped event */
+   uint32_tn

[V4 PATCH 1/8] cxgb4/cxgb4vf: Chelsio FCoE offload driver submission (common header updates).

2012-09-12 Thread Naresh Kumar Inna
This patch contains updates to firmware/hardware header files shared
between csiostor and cxgb4/cxgb4vf, and the resulting changes to the
cxgb4/cxgb4vf source files.

Signed-off-by: Naresh Kumar Inna 
---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c |2 +-
 drivers/net/ethernet/chelsio/cxgb4/sge.c|   10 +-
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c  |   16 ++--
 drivers/net/ethernet/chelsio/cxgb4/t4_msg.h |1 +
 drivers/net/ethernet/chelsio/cxgb4/t4_regs.h|   69 ++-
 drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h   |  104 +++---
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c  |   11 ++-
 7 files changed, 176 insertions(+), 37 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c 
b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 5ed49af..b56d96c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -3102,7 +3102,7 @@ static int adap_init1(struct adapter *adap, struct 
fw_caps_config_cmd *c)
memset(c, 0, sizeof(*c));
c->op_to_write = htonl(FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
   FW_CMD_REQUEST | FW_CMD_READ);
-   c->retval_len16 = htonl(FW_LEN16(*c));
+   c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
ret = t4_wr_mbox(adap, adap->fn, c, sizeof(*c), c);
if (ret < 0)
return ret;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c 
b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index d49933e..121b1e9 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -455,7 +455,7 @@ static inline void ring_fl_db(struct adapter *adap, struct 
sge_fl *q)
 {
if (q->pend_cred >= 8) {
wmb();
-   t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL), DBPRIO |
+   t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL), DBPRIO(1) |
 QID(q->cntxt_id) | PIDX(q->pend_cred / 8));
q->pend_cred &= 7;
}
@@ -2020,10 +2020,10 @@ int t4_sge_alloc_rxq(struct adapter *adap, struct 
sge_rspq *iq, bool fwevtq,
goto fl_nomem;
 
flsz = fl->size / 8 + STAT_LEN / sizeof(struct tx_desc);
-   c.iqns_to_fl0congen = htonl(FW_IQ_CMD_FL0PACKEN |
+   c.iqns_to_fl0congen = htonl(FW_IQ_CMD_FL0PACKEN(1) |
FW_IQ_CMD_FL0FETCHRO(1) |
FW_IQ_CMD_FL0DATARO(1) |
-   FW_IQ_CMD_FL0PADEN);
+   FW_IQ_CMD_FL0PADEN(1));
c.fl0dcaen_to_fl0cidxfthresh = htons(FW_IQ_CMD_FL0FBMIN(2) |
FW_IQ_CMD_FL0FBMAX(3));
c.fl0size = htons(flsz);
@@ -2416,10 +2416,10 @@ void t4_sge_init(struct adapter *adap)
unsigned int fl_align_log = ilog2(FL_ALIGN);
 
t4_set_reg_field(adap, SGE_CONTROL, PKTSHIFT_MASK |
-INGPADBOUNDARY_MASK | EGRSTATUSPAGESIZE,
+INGPADBOUNDARY_MASK | EGRSTATUSPAGESIZE(1),
 INGPADBOUNDARY(fl_align_log - 5) | PKTSHIFT(2) |
 RXPKTCPLMODE |
-(STAT_LEN == 128 ? EGRSTATUSPAGESIZE : 0));
+(STAT_LEN == 128 ? EGRSTATUSPAGESIZE(1) : 0));
 
/*
 * Set up to drop DOORBELL writes when the DOORBELL FIFO overflows
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c 
b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index fa947df..a943faa 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -456,12 +456,12 @@ static int sf1_read(struct adapter *adapter, unsigned int 
byte_cnt, int cont,
 
if (!byte_cnt || byte_cnt > 4)
return -EINVAL;
-   if (t4_read_reg(adapter, SF_OP) & BUSY)
+   if (t4_read_reg(adapter, SF_OP) & SF_BUSY)
return -EBUSY;
cont = cont ? SF_CONT : 0;
lock = lock ? SF_LOCK : 0;
t4_write_reg(adapter, SF_OP, lock | cont | BYTECNT(byte_cnt - 1));
-   ret = t4_wait_op_done(adapter, SF_OP, BUSY, 0, SF_ATTEMPTS, 5);
+   ret = t4_wait_op_done(adapter, SF_OP, SF_BUSY, 0, SF_ATTEMPTS, 5);
if (!ret)
*valp = t4_read_reg(adapter, SF_DATA);
return ret;
@@ -484,14 +484,14 @@ static int sf1_write(struct adapter *adapter, unsigned 
int byte_cnt, int cont,
 {
if (!byte_cnt || byte_cnt > 4)
return -EINVAL;
-   if (t4_read_reg(adapter, SF_OP) & BUSY)
+   if (t4_read_reg(adapter, SF_OP) & SF_BUSY)
return -EBUSY;
cont = cont ? SF_CONT : 0;
lock = lock ? SF_LOCK : 0;
t4_write_reg(adapter, SF_DATA, val);
t4_write_reg(adapter, SF_OP, lock |
 cont | BYTECNT(byte_cnt - 1) | OP_WR);
-   return t4_wait_op_done(adapter, SF_OP

Re: [PATCH 3/3] block: add back command filter modification via sysfs

2012-09-12 Thread Alan Cox
O
> + if (!q->cmd_filter) {
> + q->cmd_filter = kmalloc(sizeof(struct blk_cmd_filter),
> + GFP_KERNEL);
> + blk_set_cmd_filter_defaults(q->cmd_filter);

Out of memory - memset - oops
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] block: add back command filter modification via sysfs

2012-09-12 Thread Alan Cox

> +ssize_t blk_filter_store(struct request_queue *q,
> +  const char *page, size_t count, int rw)
> +{
> + unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits;
> + bool set;
> + const char *p = page;
> + char *endp;
> + int start = -1, cmd;
> +
> + if (!q->cmd_filter) {
> + q->cmd_filter = kmalloc(sizeof(struct blk_cmd_filter),
> + GFP_KERNEL);
> + blk_set_cmd_filter_defaults(q->cmd_filter);
> + }
> +

This also needs CAP_SYS_RAWIO otherwise you have a capability escalation
path.

I'm not really in favour of this patch as is. It's not as flexible as
doing it with a BPF filter which if we are going to have a new API is
going to be cleaner, faster and has a clear understood API plus tools.

With BPF you can do things like enabling command A with option B on a
specific device for a certain block range.


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] block: add back command filter modification via sysfs

2012-09-12 Thread Paolo Bonzini
Il 12/09/2012 14:41, Alan Cox ha scritto:
>> > +  if (!q->cmd_filter) {
>> > +  q->cmd_filter = kmalloc(sizeof(struct blk_cmd_filter),
>> > +  GFP_KERNEL);
>> > +  blk_set_cmd_filter_defaults(q->cmd_filter);
>> > +  }
>> > +
> This also needs CAP_SYS_RAWIO otherwise you have a capability escalation
> path.

Seems more like for CAP_SYS_ADMIN, since it can affect other processes
than the one writing to the file.

> I'm not really in favour of this patch as is. It's not as flexible as
> doing it with a BPF filter which if we are going to have a new API is
> going to be cleaner, faster and has a clear understood API plus tools.
> 
> With BPF you can do things like enabling command A with option B on a
> specific device for a certain block range.

I liked the BPF idea, either with SCM_RIGHTS or cgroups, but I do wonder
if it's overengineered.  There are two uses for the filtering:

- non-privileged users who want to burn a CD or something like that.
For this, a bitmap is more than enough.  Customizing the bitmap lets
userspace fix the case of different meanings for the same byte value in
different SCSI standards.

- virtualization who wants to pass through almost everything, but still
run as confined as possible.  In this case a more complex filtering can
be done just as easily in userspace (i.e. QEMU).  Of course this means
the filter can be subverted if the guest can escape the QEMU jail, but
the "almost everything" takes care of that, for example you could still
block WRITE BUFFER commands.

I would be okay with a ioctl to disable the filter altogether (four
options: regular filter, no filter, no SG_IO at all, choose depending on
CAP_SYS_RAWIO).  Then you can use file descriptor passing with
SCM_RIGHTS, and do everything in userspace.  But it doesn't work too
well with the first usage above, besides being a larger patch.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [V3 PATCH 9/9] cxgb4vf: Chelsio FCoE offload driver submission (header compatibility fixes).

2012-09-12 Thread Andi Kleen
Naresh Kumar Inna  writes:
>
> OK, I think I should be able to arrange the patch set to fulfill that
> requirement. I was under the impression it was fine for new drivers to
> split patches in this fashion, since they go as a single commit, sorry
> about that.

What they normally do then is to add the Kconfig or Makefile entry
only in the end, so it cannot build before.

-Andi
-- 
a...@linux.intel.com -- Speaking for myself only
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/15] drivers/scsi/bfa: removes unnecessary semicolon

2012-09-12 Thread Peter Senna Tschudin
From: Peter Senna Tschudin 

removes unnecessary semicolon

Found by Coccinelle: http://coccinelle.lip6.fr/

Signed-off-by: Peter Senna Tschudin 

---
 drivers/scsi/bfa/bfa_fcs_lport.c |2 +-
 drivers/scsi/bfa/bfa_fcs_rport.c |4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
index bcc4966..6a383ba 100644
--- a/drivers/scsi/bfa/bfa_fcs_lport.c
+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -3745,7 +3745,7 @@ bfa_fcs_lport_ns_sm_online(struct bfa_fcs_lport_ns_s *ns,
bfa_sm_set_state(ns,
bfa_fcs_lport_ns_sm_sending_gid_ft);
bfa_fcs_lport_ns_send_gid_ft(ns, NULL);
-   };
+   }
break;
 
default:
diff --git a/drivers/scsi/bfa/bfa_fcs_rport.c b/drivers/scsi/bfa/bfa_fcs_rport.c
index fe0463a..5eeddc6 100644
--- a/drivers/scsi/bfa/bfa_fcs_rport.c
+++ b/drivers/scsi/bfa/bfa_fcs_rport.c
@@ -1301,7 +1301,7 @@ bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s 
*rport,
bfa_timer_start(rport->fcs->bfa, &rport->timer,
bfa_fcs_rport_timeout, rport,
bfa_fcs_rport_del_timeout);
-   };
+   }
break;
 
case RPSM_EVENT_DELETE:
@@ -2089,7 +2089,7 @@ bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport)
bfa_fcs_itnim_rport_online(rport->itnim);
if (!BFA_FCS_PID_IS_WKA(rport->pid))
bfa_fcs_rpf_rport_online(rport);
-   };
+   }
 
wwn2str(lpwwn_buf, bfa_fcs_lport_get_pwwn(port));
wwn2str(rpwwn_buf, rport->pwwn);

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 8/15] drivers/scsi: removes unnecessary semicolon

2012-09-12 Thread Peter Senna Tschudin
From: Peter Senna Tschudin 

removes unnecessary semicolon

Found by Coccinelle: http://coccinelle.lip6.fr/

Signed-off-by: Peter Senna Tschudin 

---
 drivers/scsi/ibmvscsi/ibmvfc.c   |   36 ++--
 drivers/scsi/ibmvscsi/ibmvstgt.c |2 +-
 drivers/scsi/qlogicpti.c |2 +-
 drivers/scsi/scsi_tgt_if.c   |2 +-
 drivers/scsi/sgiwd93.c   |2 +-
 5 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 134a0ae..2d4d3b4 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -176,7 +176,7 @@ static void ibmvfc_trc_start(struct ibmvfc_event *evt)
break;
default:
break;
-   };
+   }
 }
 
 /**
@@ -215,7 +215,7 @@ static void ibmvfc_trc_end(struct ibmvfc_event *evt)
default:
break;
 
-   };
+   }
 }
 
 #else
@@ -459,7 +459,7 @@ static int ibmvfc_set_host_state(struct ibmvfc_host *vhost,
default:
vhost->state = state;
break;
-   };
+   }
 
return rc;
 }
@@ -495,7 +495,7 @@ static void ibmvfc_set_host_action(struct ibmvfc_host 
*vhost,
break;
default:
break;
-   };
+   }
break;
case IBMVFC_HOST_ACTION_TGT_INIT:
if (vhost->action == IBMVFC_HOST_ACTION_ALLOC_TGTS)
@@ -510,7 +510,7 @@ static void ibmvfc_set_host_action(struct ibmvfc_host 
*vhost,
default:
vhost->action = action;
break;
-   };
+   }
break;
case IBMVFC_HOST_ACTION_LOGO:
case IBMVFC_HOST_ACTION_QUERY_TGTS:
@@ -521,7 +521,7 @@ static void ibmvfc_set_host_action(struct ibmvfc_host 
*vhost,
default:
vhost->action = action;
break;
-   };
+   }
 }
 
 /**
@@ -1593,7 +1593,7 @@ static inline int ibmvfc_host_chkready(struct ibmvfc_host 
*vhost)
case IBMVFC_ACTIVE:
result = 0;
break;
-   };
+   }
 
return result;
 }
@@ -1653,7 +1653,7 @@ static int ibmvfc_queuecommand_lck(struct scsi_cmnd *cmnd,
case MSG_ORDERED_TAG:
vfc_cmd->iu.pri_task_attr = IBMVFC_ORDERED_TASK;
break;
-   };
+   }
}
 
if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev
@@ -1857,7 +1857,7 @@ static int ibmvfc_bsg_request(struct fc_bsg_job *job)
break;
default:
return -ENOTSUPP;
-   };
+   }
 
if (port_id == -1)
return -EINVAL;
@@ -2586,7 +2586,7 @@ static void ibmvfc_handle_async(struct ibmvfc_async_crq 
*crq,
vhost->delay_init = 1;
__ibmvfc_reset_host(vhost);
break;
-   };
+   }
 
break;
case IBMVFC_AE_LINK_UP:
@@ -2638,7 +2638,7 @@ static void ibmvfc_handle_async(struct ibmvfc_async_crq 
*crq,
default:
dev_err(vhost->dev, "Unknown async event received: %lld\n", 
crq->event);
break;
-   };
+   }
 }
 
 /**
@@ -3306,7 +3306,7 @@ static void ibmvfc_tgt_prli_done(struct ibmvfc_event *evt)
ibmvfc_get_cmd_error(rsp->status, rsp->error),
rsp->status, rsp->error, status);
break;
-   };
+   }
 
kref_put(&tgt->kref, ibmvfc_release_tgt);
ibmvfc_free_event(evt);
@@ -3402,7 +3402,7 @@ static void ibmvfc_tgt_plogi_done(struct ibmvfc_event 
*evt)
ibmvfc_get_fc_type(rsp->fc_type), rsp->fc_type,
ibmvfc_get_ls_explain(rsp->fc_explain), 
rsp->fc_explain, status);
break;
-   };
+   }
 
kref_put(&tgt->kref, ibmvfc_release_tgt);
ibmvfc_free_event(evt);
@@ -3473,7 +3473,7 @@ static void ibmvfc_tgt_implicit_logout_done(struct 
ibmvfc_event *evt)
default:
tgt_err(tgt, "Implicit Logout failed: rc=0x%02X\n", status);
break;
-   };
+   }
 
if (vhost->action == IBMVFC_HOST_ACTION_TGT_INIT)
ibmvfc_init_tgt(tgt, ibmvfc_tgt_send_plogi);
@@ -3577,7 +3577,7 @@ static void ibmvfc_tgt_adisc_done(struct ibmvfc_event 
*evt)
 ibmvfc_get_fc_type(fc_reason), fc_reason,
 ibmvfc_get_ls_explain(fc_explain), fc_explain, status);
break;
-   };
+   }
 
kref_put(&tgt->kref, ibmvfc_release_tgt);
ibmvfc_free_event(evt);
@@ -3789,7 +3789,7 @@ static void ibmvfc_tgt_query_target_done(struct 
ibmvfc_event *evt)
ibmvfc_get_fc_type(rsp->fc_type), rsp->fc_type,
ibmvfc_get_g

[PATCH 6/15] drivers/scsi/pmcraid.c: removes unnecessary semicolon

2012-09-12 Thread Peter Senna Tschudin
From: Peter Senna Tschudin 

removes unnecessary semicolon

Found by Coccinelle: http://coccinelle.lip6.fr/

Signed-off-by: Peter Senna Tschudin 

---
 drivers/scsi/pmcraid.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index af763ea..5fb03c9 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -3186,7 +3186,7 @@ static u8 pmcraid_task_attributes(struct scsi_cmnd 
*scsi_cmd)
case MSG_ORDERED_TAG:
rc = TASK_TAG_ORDERED;
break;
-   };
+   }
}
 
return rc;
@@ -5325,7 +5325,7 @@ static int __devinit pmcraid_init_instance(
mapped_pci_addr + chip_cfg->ioa_host_mask_clr;
pint_regs->global_interrupt_mask_reg =
mapped_pci_addr + chip_cfg->global_intr_mask;
-   };
+   }
 
pinstance->ioa_reset_attempts = 0;
init_waitqueue_head(&pinstance->reset_wait_q);

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [V3 PATCH 9/9] cxgb4vf: Chelsio FCoE offload driver submission (header compatibility fixes).

2012-09-12 Thread Naresh Kumar Inna
On 9/12/2012 10:22 PM, Andi Kleen wrote:
> Naresh Kumar Inna  writes:
>>
>> OK, I think I should be able to arrange the patch set to fulfill that
>> requirement. I was under the impression it was fine for new drivers to
>> split patches in this fashion, since they go as a single commit, sorry
>> about that.
> 
> What they normally do then is to add the Kconfig or Makefile entry
> only in the end, so it cannot build before.
> 
> -Andi
> 

Patch-set V4 I sent a few hours ago does just that. Thanks nevertheless.

-Naresh
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH 1/5] libfcoe, fcoe: Allow user to set a ctlr's mode

2012-09-12 Thread Love, Robert W
On Mon 10 Sep 2012 10:51:41 PM PDT, Bart Van Assche wrote:
> On 09/11/12 00:59, Robert Love wrote:
>> +static enum fip_conn_type fcoe_parse_mode(const char *buf,
>> +  const struct fcoe_ctlr_mode_table *tbl)
>> +{
>> +int modeint = -1, i, rv;
>> +char *p, modestr[FCOE_MAX_MODENAME_LEN + 1] = { 0, };
>> +
>> +for (p = (char *)buf; *p; p++)
>> +if (!(isdigit(*p) || isspace(*p)))
>> +break;
>
> If you change the declaration of p from "char *p" into "const char *p"
> you won't need a cast in the above for loop.
>
> [ ... ]
>
>> -static FCOE_DEVICE_ATTR(ctlr, mode, S_IRUGO,
>> -show_ctlr_mode, NULL);
>> +
>> +static ssize_t store_ctlr_mode(struct device *dev,
>> +   struct device_attribute *attr,
>> +   const char *buf, size_t count)
>> +{
>> +struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
>> +
>> +if (!ctlr->f->set_fcoe_ctlr_mode)
>> +return -EINVAL;
>> +
>> +ctlr->mode = fcoe_parse_mode(buf, ctlr_mode_tbl);
>
> As far as I know sysfs doesn't terminate buf with a '\0' before calling
> a store method. Does that mean that you are passing a string that is not
> '\0'-terminated to a function that expects a '\0'-terminated string ?
>
> Bart.

Hey Bart. I just wanted to acknowledge your comments. I will make sure 
that they're addressed after figuring out if sysfs is the right place 
for the interfaces.

Thanks, //Rob


Re: [Open-FCoE] [RFC PATCH 0/5] Reorganize libfcoe control interfaces

2012-09-12 Thread Love, Robert W
On 12-09-11 10:36 AM, Love, Robert W wrote:
> On Tue 11 Sep 2012 10:06:29 AM PDT, Chris Leech wrote:
>> On Mon, Sep 10, 2012 at 3:59 PM, Robert Love  wrote:



> This feels a little awkward with all the special control files.  Have
> you thought about something designed for creating kernel objects, like
> configfs?  Similarly the separate start, enable, disable files vs.
> Let me do some more reading about configfs. I may not have given it
> enough thought.

I read though the configfs documentation and the fact that it's designed 
for user driven object creation does fit with what I'm trying to do. I 
have a couple concerns that I'm trying to sort through now-

1) This adds a new dependency for boot. I don't know if that is a 
problem or not. Are there any examples of configfs being mounted in an 
initrd?

2) Using configfs would likely mean that I'd be creating controller 
instances and possibly FCF instances in configfs, since they're already 
there in sysfs these objects would be duplicated. I'm not sure there's 
harm in that, but it certainly feels disjointed and messy. I suppose we 
could remove the /sys/bus/fcoe stuff in favor of configfs if it's the 
right thing to do.

Thanks, //Rob--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/4] PCI error handler const

2012-09-12 Thread Bjorn Helgaas
On Fri, Sep 7, 2012 at 4:42 PM, Bjorn Helgaas  wrote:
> On Fri, Sep 7, 2012 at 9:33 AM, Stephen Hemminger  
> wrote:
>> This is a trivial patch to make PCI error handler function
>> tables const. Split into pieces so that core changes are first.
>
> I put all four of these on this branch:
>
> http://git.kernel.org/?p=linux/kernel/git/helgaas/pci.git;a=shortlog;h=refs/heads/pci/stephen-const
>
> If the netdev and scsi folks approve, I can handle them all through my PCI 
> tree.

I didn't see any objection, so I pushed these four patches to the PCI
"next" branch.

Thanks!

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Fix a use-after-free triggered by device removal

2012-09-12 Thread Tejun Heo
Hello,

On Tue, Sep 11, 2012 at 08:42:28AM +0200, Bart Van Assche wrote:
> Good question. As far as I can see calling request_queue.request_fn() is
> fine as long as the caller holds a reference on the queue. If e.g.
> scsi_request_fn() would get invoked after blk_drain_queue() finished it
> will return immediately because it was invoked with an empty request
> queue. So we should be fine as long as all blk_run_queue() callers
> either hold a reference on the request queue itself or on the sdev that
> owns the request queue. As far as I can see if patch
> http://marc.info/?l=linux-scsi&m=134453905402413 gets accepted then all
> callers in the SCSI core of blk_run_queue() will hold a (direct or
> indirect) reference on the request_queue before invoking blk_run_queue()
> or __blk_run_queue().

It's been quite a while since I really looked through the code and I'm
feeling a bit dense but what you describe seems like a two-pronged
approach where the drain stalling, when properly done, should be
enough.

The problem at hand IIUC is ->request_fn() being invoked when
request_queue itself is alive but the underlying driver is gone.  We
already make sure that a new request is not queued once drain is
complete but there's no guarantee about calling into ->request_fn()
and this is what you want to fix, right?

I think this is something which the block layer proper should handle
correctly and expose sane interface.  ie. if the caller has
request_queue reference, it should be safe to call __blk_run_queue()
no matter what.  As long as SCSI follows proper shutdown procedure, it
shouldn't need to worry about this.

Am I hopelessly confused somewhere?

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v6 0/7] ZPODD patches

2012-09-12 Thread Jack Wang
Hi Aaron,

This feature looks nice, but how could I test this patch set, I suppose it
need special Hardware which support ZPODD, could suggest the test setup
environment?

For hard disk runtime power off, Is there (hardware?) requirement for hard
drive to support similar feature?

Best regards!

Jack


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 0/7] ZPODD patches

2012-09-12 Thread Aaron Lu
On 09/13/2012 10:42 AM, Jack Wang wrote:
> Hi Aaron,

Hi Jack,

> 
> This feature looks nice

Glad to hear this :-)

> but how could I test this patch set, I suppose it
> need special Hardware which support ZPODD, could suggest the test setup
> environment?

For ZPODD, there are 2 requirements:
1 The platform, it has to have the ability to power off a sata device
while at S0;
2 The ODD needs support for device attention capability.

> 
> For hard disk runtime power off, Is there (hardware?) requirement for hard
> drive to support similar feature?

No requirement for hard drive, as it does not need to remote wake up
itself while powered off.

Please note that there is a v7 sent yesterday, you may want to take a
look at that instead of v6.

And the runtime power off of hard drive is dropped from that patch set,
I'll submit it in another patch set(pretty small changes needed).

Thanks,
Aaron
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html