namespace_devs.c (1b40e09a1232de537b193fa1b6b3ef16d3a1e397) | namespace_devs.c (f524bf271a5cf12a44253194abcf8b6688ff5b9d) |
---|---|
1/* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 135 unchanged lines hidden (view full) --- 144 return 0; 145 nd_label_gen_id(&label_id, nsblk->uuid, NSLABEL_FLAG_LOCAL); 146 for_each_dpa_resource(ndd, res) 147 if (strcmp(res->name, label_id.id) == 0) 148 size += resource_size(res); 149 return size; 150} 151 | 1/* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 135 unchanged lines hidden (view full) --- 144 return 0; 145 nd_label_gen_id(&label_id, nsblk->uuid, NSLABEL_FLAG_LOCAL); 146 for_each_dpa_resource(ndd, res) 147 if (strcmp(res->name, label_id.id) == 0) 148 size += resource_size(res); 149 return size; 150} 151 |
152static int nd_namespace_label_update(struct nd_region *nd_region, 153 struct device *dev) 154{ 155 dev_WARN_ONCE(dev, dev->driver, 156 "namespace must be idle during label update\n"); 157 if (dev->driver) 158 return 0; 159 160 /* 161 * Only allow label writes that will result in a valid namespace 162 * or deletion of an existing namespace. 163 */ 164 if (is_namespace_pmem(dev)) { 165 struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); 166 struct resource *res = &nspm->nsio.res; 167 resource_size_t size = resource_size(res); 168 169 if (size == 0 && nspm->uuid) 170 /* delete allocation */; 171 else if (!nspm->uuid) 172 return 0; 173 174 return nd_pmem_namespace_label_update(nd_region, nspm, size); 175 } else if (is_namespace_blk(dev)) { 176 /* TODO: implement blk labels */ 177 return 0; 178 } else 179 return -ENXIO; 180} 181 |
|
152static ssize_t alt_name_store(struct device *dev, 153 struct device_attribute *attr, const char *buf, size_t len) 154{ | 182static ssize_t alt_name_store(struct device *dev, 183 struct device_attribute *attr, const char *buf, size_t len) 184{ |
185 struct nd_region *nd_region = to_nd_region(dev->parent); |
|
155 ssize_t rc; 156 157 device_lock(dev); 158 nvdimm_bus_lock(dev); 159 wait_nvdimm_bus_probe_idle(dev); 160 rc = __alt_name_store(dev, buf, len); | 186 ssize_t rc; 187 188 device_lock(dev); 189 nvdimm_bus_lock(dev); 190 wait_nvdimm_bus_probe_idle(dev); 191 rc = __alt_name_store(dev, buf, len); |
192 if (rc >= 0) 193 rc = nd_namespace_label_update(nd_region, dev); |
|
161 dev_dbg(dev, "%s: %s(%zd)\n", __func__, rc < 0 ? "fail " : "", rc); 162 nvdimm_bus_unlock(dev); 163 device_unlock(dev); 164 | 194 dev_dbg(dev, "%s: %s(%zd)\n", __func__, rc < 0 ? "fail " : "", rc); 195 nvdimm_bus_unlock(dev); 196 device_unlock(dev); 197 |
165 return rc; | 198 return rc < 0 ? rc : len; |
166} 167 168static ssize_t alt_name_show(struct device *dev, 169 struct device_attribute *attr, char *buf) 170{ 171 char *ns_altname; 172 173 if (is_namespace_pmem(dev)) { --- 530 unchanged lines hidden (view full) --- 704 } 705 706 return rc; 707} 708 709static ssize_t size_store(struct device *dev, 710 struct device_attribute *attr, const char *buf, size_t len) 711{ | 199} 200 201static ssize_t alt_name_show(struct device *dev, 202 struct device_attribute *attr, char *buf) 203{ 204 char *ns_altname; 205 206 if (is_namespace_pmem(dev)) { --- 530 unchanged lines hidden (view full) --- 737 } 738 739 return rc; 740} 741 742static ssize_t size_store(struct device *dev, 743 struct device_attribute *attr, const char *buf, size_t len) 744{ |
745 struct nd_region *nd_region = to_nd_region(dev->parent); |
|
712 unsigned long long val; 713 u8 **uuid = NULL; 714 int rc; 715 716 rc = kstrtoull(buf, 0, &val); 717 if (rc) 718 return rc; 719 720 device_lock(dev); 721 nvdimm_bus_lock(dev); 722 wait_nvdimm_bus_probe_idle(dev); 723 rc = __size_store(dev, val); | 746 unsigned long long val; 747 u8 **uuid = NULL; 748 int rc; 749 750 rc = kstrtoull(buf, 0, &val); 751 if (rc) 752 return rc; 753 754 device_lock(dev); 755 nvdimm_bus_lock(dev); 756 wait_nvdimm_bus_probe_idle(dev); 757 rc = __size_store(dev, val); |
758 if (rc >= 0) 759 rc = nd_namespace_label_update(nd_region, dev); |
|
724 725 if (is_namespace_pmem(dev)) { 726 struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); 727 728 uuid = &nspm->uuid; 729 } else if (is_namespace_blk(dev)) { 730 struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); 731 --- 7 unchanged lines hidden (view full) --- 739 } 740 741 dev_dbg(dev, "%s: %llx %s (%d)\n", __func__, val, rc < 0 742 ? "fail" : "success", rc); 743 744 nvdimm_bus_unlock(dev); 745 device_unlock(dev); 746 | 760 761 if (is_namespace_pmem(dev)) { 762 struct nd_namespace_pmem *nspm = to_nd_namespace_pmem(dev); 763 764 uuid = &nspm->uuid; 765 } else if (is_namespace_blk(dev)) { 766 struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); 767 --- 7 unchanged lines hidden (view full) --- 775 } 776 777 dev_dbg(dev, "%s: %llx %s (%d)\n", __func__, val, rc < 0 778 ? "fail" : "success", rc); 779 780 nvdimm_bus_unlock(dev); 781 device_unlock(dev); 782 |
747 return rc ? rc : len; | 783 return rc < 0 ? rc : len; |
748} 749 750static ssize_t size_show(struct device *dev, 751 struct device_attribute *attr, char *buf) 752{ 753 unsigned long long size = 0; 754 755 nvdimm_bus_lock(dev); --- 43 unchanged lines hidden (view full) --- 799 * @old_uuid: reference to the uuid storage location in the namespace object 800 */ 801static int namespace_update_uuid(struct nd_region *nd_region, 802 struct device *dev, u8 *new_uuid, u8 **old_uuid) 803{ 804 u32 flags = is_namespace_blk(dev) ? NSLABEL_FLAG_LOCAL : 0; 805 struct nd_label_id old_label_id; 806 struct nd_label_id new_label_id; | 784} 785 786static ssize_t size_show(struct device *dev, 787 struct device_attribute *attr, char *buf) 788{ 789 unsigned long long size = 0; 790 791 nvdimm_bus_lock(dev); --- 43 unchanged lines hidden (view full) --- 835 * @old_uuid: reference to the uuid storage location in the namespace object 836 */ 837static int namespace_update_uuid(struct nd_region *nd_region, 838 struct device *dev, u8 *new_uuid, u8 **old_uuid) 839{ 840 u32 flags = is_namespace_blk(dev) ? NSLABEL_FLAG_LOCAL : 0; 841 struct nd_label_id old_label_id; 842 struct nd_label_id new_label_id; |
807 int i, rc; | 843 int i; |
808 | 844 |
809 rc = nd_is_uuid_unique(dev, new_uuid) ? 0 : -EINVAL; 810 if (rc) { 811 kfree(new_uuid); 812 return rc; 813 } | 845 if (!nd_is_uuid_unique(dev, new_uuid)) 846 return -EINVAL; |
814 815 if (*old_uuid == NULL) 816 goto out; 817 | 847 848 if (*old_uuid == NULL) 849 goto out; 850 |
851 /* 852 * If we've already written a label with this uuid, then it's 853 * too late to rename because we can't reliably update the uuid 854 * without losing the old namespace. Userspace must delete this 855 * namespace to abandon the old uuid. 856 */ 857 for (i = 0; i < nd_region->ndr_mappings; i++) { 858 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; 859 860 /* 861 * This check by itself is sufficient because old_uuid 862 * would be NULL above if this uuid did not exist in the 863 * currently written set. 864 * 865 * FIXME: can we delete uuid with zero dpa allocated? 866 */ 867 if (nd_mapping->labels) 868 return -EBUSY; 869 } 870 |
|
818 nd_label_gen_id(&old_label_id, *old_uuid, flags); 819 nd_label_gen_id(&new_label_id, new_uuid, flags); 820 for (i = 0; i < nd_region->ndr_mappings; i++) { 821 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; 822 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); 823 struct resource *res; 824 825 for_each_dpa_resource(ndd, res) --- 27 unchanged lines hidden (view full) --- 853 return -ENXIO; 854 855 device_lock(dev); 856 nvdimm_bus_lock(dev); 857 wait_nvdimm_bus_probe_idle(dev); 858 rc = nd_uuid_store(dev, &uuid, buf, len); 859 if (rc >= 0) 860 rc = namespace_update_uuid(nd_region, dev, uuid, ns_uuid); | 871 nd_label_gen_id(&old_label_id, *old_uuid, flags); 872 nd_label_gen_id(&new_label_id, new_uuid, flags); 873 for (i = 0; i < nd_region->ndr_mappings; i++) { 874 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; 875 struct nvdimm_drvdata *ndd = to_ndd(nd_mapping); 876 struct resource *res; 877 878 for_each_dpa_resource(ndd, res) --- 27 unchanged lines hidden (view full) --- 906 return -ENXIO; 907 908 device_lock(dev); 909 nvdimm_bus_lock(dev); 910 wait_nvdimm_bus_probe_idle(dev); 911 rc = nd_uuid_store(dev, &uuid, buf, len); 912 if (rc >= 0) 913 rc = namespace_update_uuid(nd_region, dev, uuid, ns_uuid); |
914 if (rc >= 0) 915 rc = nd_namespace_label_update(nd_region, dev); 916 else 917 kfree(uuid); |
|
861 dev_dbg(dev, "%s: result: %zd wrote: %s%s", __func__, 862 rc, buf, buf[len - 1] == '\n' ? "" : "\n"); 863 nvdimm_bus_unlock(dev); 864 device_unlock(dev); 865 | 918 dev_dbg(dev, "%s: result: %zd wrote: %s%s", __func__, 919 rc, buf, buf[len - 1] == '\n' ? "" : "\n"); 920 nvdimm_bus_unlock(dev); 921 device_unlock(dev); 922 |
866 return rc ? rc : len; | 923 return rc < 0 ? rc : len; |
867} 868static DEVICE_ATTR_RW(uuid); 869 870static ssize_t resource_show(struct device *dev, 871 struct device_attribute *attr, char *buf) 872{ 873 struct resource *res; 874 --- 27 unchanged lines hidden (view full) --- 902 903 return nd_sector_size_show(nsblk->lbasize, ns_lbasize_supported, buf); 904} 905 906static ssize_t sector_size_store(struct device *dev, 907 struct device_attribute *attr, const char *buf, size_t len) 908{ 909 struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); | 924} 925static DEVICE_ATTR_RW(uuid); 926 927static ssize_t resource_show(struct device *dev, 928 struct device_attribute *attr, char *buf) 929{ 930 struct resource *res; 931 --- 27 unchanged lines hidden (view full) --- 959 960 return nd_sector_size_show(nsblk->lbasize, ns_lbasize_supported, buf); 961} 962 963static ssize_t sector_size_store(struct device *dev, 964 struct device_attribute *attr, const char *buf, size_t len) 965{ 966 struct nd_namespace_blk *nsblk = to_nd_namespace_blk(dev); |
967 struct nd_region *nd_region = to_nd_region(dev->parent); |
|
910 ssize_t rc; 911 912 if (!is_namespace_blk(dev)) 913 return -ENXIO; 914 915 device_lock(dev); 916 nvdimm_bus_lock(dev); 917 rc = nd_sector_size_store(dev, buf, &nsblk->lbasize, 918 ns_lbasize_supported); | 968 ssize_t rc; 969 970 if (!is_namespace_blk(dev)) 971 return -ENXIO; 972 973 device_lock(dev); 974 nvdimm_bus_lock(dev); 975 rc = nd_sector_size_store(dev, buf, &nsblk->lbasize, 976 ns_lbasize_supported); |
919 dev_dbg(dev, "%s: result: %zd wrote: %s%s", __func__, 920 rc, buf, buf[len - 1] == '\n' ? "" : "\n"); | 977 if (rc >= 0) 978 rc = nd_namespace_label_update(nd_region, dev); 979 dev_dbg(dev, "%s: result: %zd %s: %s%s", __func__, 980 rc, rc < 0 ? "tried" : "wrote", buf, 981 buf[len - 1] == '\n' ? "" : "\n"); |
921 nvdimm_bus_unlock(dev); 922 device_unlock(dev); 923 924 return rc ? rc : len; 925} 926static DEVICE_ATTR_RW(sector_size); 927 928static struct attribute *nd_namespace_attributes[] = { --- 607 unchanged lines hidden --- | 982 nvdimm_bus_unlock(dev); 983 device_unlock(dev); 984 985 return rc ? rc : len; 986} 987static DEVICE_ATTR_RW(sector_size); 988 989static struct attribute *nd_namespace_attributes[] = { --- 607 unchanged lines hidden --- |