public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
To: Alan Stern <stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org>
Cc: "Dale R. Worley" <worley-FrUbXkNCsVf2fBVCVOL8/A@public.gmane.org>,
	mdharm-usb-JGfshJpz5UybPZpvUQj5UqxOck334EZe@public.gmane.org,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Problem with USB-to-SATA adapters (was: AS2105-based enclosure size issues with >2TB HDDs)
Date: Wed, 03 Sep 2014 15:07:34 -0700	[thread overview]
Message-ID: <1409782054.6571.27.camel@jarvis.lan> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1409031625040.2156-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>

On Wed, 2014-09-03 at 16:30 -0400, Alan Stern wrote:
> On Wed, 3 Sep 2014, James Bottomley wrote:
> 
> > Before we embark on elaborate hacks, why don't we just make the capacity
> > writeable (by root) in sysfs from userspace (will require block change)?
> > We can then encode all the nasty heuristics (including gpt reading) in
> > userspace as a udev rule.
> 
> That's what I'm working on.  Except that I don't know where to do it in
> the block layer, so for now I'm adding the attribute to sd.c.
> 
> Where in the block layer would the right place be?  We want this to
> apply only to entire devices, not to individual partitions.

The bottom layer for this is part0.nr_sects which is the size attribute
you see in the block sysfs.  However, it looks like we keep a separate
value in sdkp, but we don't ever seem to use it (except to see if the
capacity has changed).

So this could be done in two ways: add a writeable capacity attribute in
sd.c, as you were originally thinking (it would call set_capacity() on
write and that would update the block layer) or make the size parameter
writeable.

This is how you would do the block layer one below, but there's no way
to inform the lower layer (so it better not have any information cached
that it makes use of).

James

---
diff --git a/block/genhd.c b/block/genhd.c
index 791f419..a114636 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -980,7 +980,7 @@ static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
 static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL);
 static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
 static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
-static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
+static DEVICE_ATTR(size, S_IRUGO|S_IWUSR, part_size_show, part_size_store);
 static DEVICE_ATTR(alignment_offset, S_IRUGO, disk_alignment_offset_show, NULL);
 static DEVICE_ATTR(discard_alignment, S_IRUGO, disk_discard_alignment_show,
 		   NULL);
diff --git a/block/partition-generic.c b/block/partition-generic.c
index 789cdea..d0cc418 100644
--- a/block/partition-generic.c
+++ b/block/partition-generic.c
@@ -87,6 +87,20 @@ ssize_t part_size_show(struct device *dev,
 	return sprintf(buf, "%llu\n",(unsigned long long)part_nr_sects_read(p));
 }
 
+ssize_t part_size_store(struct device *dev, struct device_attribute *attr,
+			const char *buf, size_t count)
+{
+	struct hd_struct *p = dev_to_part(dev);
+	u64 size;
+
+	if (count > 0 && sscanf(buf, "%llu", &size) > 0)
+		part_nr_sects_write(p, size);
+	else
+		return -EINVAL;
+
+	return count;
+}
+
 static ssize_t part_ro_show(struct device *dev,
 			    struct device_attribute *attr, char *buf)
 {
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index ec274e0..c9b3473 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -628,6 +628,9 @@ extern void blk_unregister_region(dev_t devt, unsigned long range);
 
 extern ssize_t part_size_show(struct device *dev,
 			      struct device_attribute *attr, char *buf);
+extern ssize_t part_size_store(struct device *dev,
+			       struct device_attribute *attr,
+			       const char *buf, size_t count);
 extern ssize_t part_stat_show(struct device *dev,
 			      struct device_attribute *attr, char *buf);
 extern ssize_t part_inflight_show(struct device *dev,


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

  parent reply	other threads:[~2014-09-03 22:07 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87801b450dee41dda169a3aa2dd2baf6@serv030.corp.eldorado.org.br>
     [not found] ` <87801b450dee41dda169a3aa2dd2baf6-CWPHn/M7kmRpAIlDVkCwMZnVvqcnFG0x9MRKq5+/VYY@public.gmane.org>
2014-08-25 13:16   ` AS2105-based enclosure size issues with >2TB HDDs Oliver Neukum
2014-08-25 14:24     ` Alan Stern
     [not found]       ` <Pine.LNX.4.44L0.1408251021560.1385-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-08-25 18:48         ` RES: " Alfredo Dal Ava Junior
     [not found]           ` <40601ab081d3451baf6267807659c80e-CWPHn/M7kmRpAIlDVkCwMZnVvqcnFG0x9MRKq5+/VYY@public.gmane.org>
2014-08-25 19:28             ` James Bottomley
2014-08-25 19:51               ` RES: " Alfredo Dal Ava Junior
     [not found]                 ` <175058921e084d26ba362fa6ecd7351c-CWPHn/M7kmRpAIlDVkCwMZnVvqcnFG0x9MRKq5+/VYY@public.gmane.org>
2014-08-25 20:21                   ` Alan Stern
2014-08-25 20:44                     ` RES: " Alfredo Dal Ava Junior
2014-08-25 21:16                     ` Oliver Neukum
2014-08-26 14:47                       ` Alan Stern
     [not found]                         ` <Pine.LNX.4.44L0.1408261031090.1434-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-08-27  6:45                           ` Oliver Neukum
2014-08-27 14:45                             ` Alan Stern
2014-08-26  9:58                     ` David Laight
     [not found]                       ` <063D6719AE5E284EB5DD2968C1650D6D1748130C-VkEWCZq2GCInGFn1LkZF6NBPR1lH4CV8@public.gmane.org>
2014-08-26 12:24                         ` Oliver Neukum
2014-08-26 12:53                           ` David Laight
2014-08-26 13:41                             ` RES: " Alfredo Dal Ava Junior
2014-08-25 19:33           ` Alan Stern
     [not found]             ` <Pine.LNX.4.44L0.1408251526390.1385-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-08-25 20:14               ` RES: " Alfredo Dal Ava Junior
     [not found]     ` <1408972618.10300.35.camel-B2T3B9s34ElbnMAlSieJcQ@public.gmane.org>
2014-08-26 19:39       ` Problem with USB-to-SATA adapters (was: AS2105-based enclosure size issues with >2TB HDDs) Dale R. Worley
2014-08-26 19:59         ` James Bottomley
2014-08-27 19:21           ` Dale R. Worley
2014-08-27 20:01             ` James Bottomley
2014-08-27 19:23           ` Dale R. Worley
2014-08-27 20:02             ` Alan Stern
2014-08-29 21:07               ` Dale R. Worley
2014-08-29 23:04                 ` Matthew Dharm
2014-08-30 21:15                   ` Alan Stern
2014-08-30 21:40                     ` Douglas Gilbert
     [not found]                       ` <540244D2.4030807-qazKcTl6WRFWk0Htik3J/w@public.gmane.org>
2014-08-31 14:13                         ` Alan Stern
     [not found]                     ` <Pine.LNX.4.44L0.1408301710120.4299-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-08-30 23:40                       ` Matthew Dharm
2014-09-03 19:17                         ` RES: " Alfredo Dal Ava Junior
2014-09-03 18:44                     ` Dale R. Worley
     [not found]                       ` <201409031844.s83IimIl011663-fKCv92Uu9G1eYiHQf5CFXGXnswh1EIUO@public.gmane.org>
2014-09-03 19:05                         ` Alan Stern
2014-09-03 19:50                           ` Dale R. Worley
     [not found]                           ` <Pine.LNX.4.44L0.1409031459400.2156-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-09-03 19:57                             ` James Bottomley
2014-09-03 20:30                               ` Alan Stern
     [not found]                                 ` <Pine.LNX.4.44L0.1409031625040.2156-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2014-09-03 22:07                                   ` James Bottomley [this message]
2014-09-05 17:32                                     ` Alan Stern
2014-09-04 20:49                               ` Dale R. Worley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409782054.6571.27.camel@jarvis.lan \
    --to=james.bottomley-d9phhud1jfjcxq6kfmz53/egyhegw8jk@public.gmane.org \
    --cc=linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mdharm-usb-JGfshJpz5UybPZpvUQj5UqxOck334EZe@public.gmane.org \
    --cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org \
    --cc=worley-FrUbXkNCsVf2fBVCVOL8/A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox