summaryrefslogtreecommitdiffstats
path: root/tests/test-thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-thread.c')
0 files changed, 0 insertions, 0 deletions
> 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
#
# lvm_dialog_gui.py: dialog for editting a volume group request
#
# Michael Fulbright <msf@redhat.com>
#
# Copyright 2002 Red Hat, Inc.
#
# This software may be freely redistributed under the terms of the GNU
# library public license.
#
# You should have received a copy of the GNU Library Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

import copy

import gobject
import gtk
import datacombo

from rhpl.translate import _, N_

import gui
from fsset import *
from partRequests import *
from partition_ui_helpers_gui import *
from constants import *
import lvm

import logging
log = logging.getLogger("anaconda")

class VolumeGroupEditor:

    def numAvailableLVSlots(self):
	return max(0, lvm.MAX_LV_SLOTS - len(self.logvolreqs))

    def computeSpaceValues(self, alt_pvlist=None, usepe=None):
	if usepe is None:
            pesize = int(self.peCombo.get_active_value())
	else:
	    pesize = usepe

        if alt_pvlist is None:
            pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model())
        else:
            pvlist = alt_pvlist
	tspace = self.computeVGSize(pvlist, pesize)
	uspace = self.computeLVSpaceNeeded(self.logvolreqs)
	fspace =  tspace - uspace

	return (tspace, uspace, fspace)

    def getPVWastedRatio(self, newpe):
        """ given a new pe value, return percentage of smallest PV wasted

        newpe - (int) new value of PE, in KB
        """
        pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model())

	waste = 0.0
	for id in pvlist:
	    pvreq = self.partitions.getRequestByID(id)
	    pvsize = pvreq.getActualSize(self.partitions, self.diskset)
	    waste = max(waste, (long(pvsize*1024) % newpe)/(pvsize*1024.0))

	return waste

    def getSmallestPVSize(self):
        """ finds the smallest PV and returns its size in MB
        """
	first = 1
        pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model())
	for id in pvlist:
            try:
                pesize = int(self.peCombo.get_active_value())
            except:
                pesize = 32768
	    pvreq = self.partitions.getRequestByID(id)
	    pvsize = pvreq.getActualSize(self.partitions, self.diskset)
            pvsize = lvm.clampPVSize(pvsize, pesize) - (pesize/1024)
	    if first:
		minpvsize = pvsize
		first = 0
	    else:
		minpvsize = min(pvsize, minpvsize)

	return minpvsize


    def reclampLV(self, newpe):
        """ given a new pe value, set logical volume sizes accordingly

        newpe - (int) new value of PE, in KB
        """

        pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model())
        availSpaceMB = self.computeVGSize(pvlist, newpe)

	# see if total space is enough
        oldused = 0
        used = 0
	resize = 0
        for lv in self.logvolreqs:
            osize = lv.getActualSize(self.partitions, self.diskset)
            oldused = oldused + osize
            nsize = lvm.clampLVSizeRequest(osize, newpe, roundup=1)
	    if nsize != osize:
		resize = 1
		
            used = used + nsize

        if used > availSpaceMB:
            self.intf.messageWindow(_("Not enough space"),
                                    _("The physical extent size cannot be "
                                      "changed because otherwise the space "
                                      "required by the currently defined "
                                      "logical volumes will be increased "
                                      "to more than the available space."),
				    custom_icon="error")
            return 0

	if resize:
	    rc = self.intf.messageWindow(_("Confirm Physical Extent Change"),
					 _("This change in the value of the "
					   "physical extent will require the "
					   "sizes of the current logical "
					   "volume requests to be rounded "
					   "up in size to an integer multiple "
					   "of the "
					   "physical extent.\n\nThis change "
					   "will take affect immediately."),
					 type="custom", custom_icon="question",
					 custom_buttons=["gtk-cancel", _("C_ontinue")])
	    if not rc:
		return 0
        
        for lv in self.logvolreqs:
            osize = lv.getActualSize(self.partitions, self.diskset)
            nsize = lvm.clampLVSizeRequest(osize, newpe, roundup=1)
            lv.setSize(nsize)

        return 1
            
    def peChangeCB(self, widget, *args):
        """ handle changes in the Physical Extent option menu

        widget - menu item which was activated
        peOption - the Option menu containing the items. The data value for
                   "lastval" is the previous PE value.
        """

        curval = int(widget.get_active_value())
        lastval = widget.get_data("lastpe")
	lastidx = widget.get_data("lastidx")

	# see if PE is too large compared to smallest PV
	# remember PE is in KB, PV size is in MB
	maxpvsize = self.getSmallestPVSize()
	if curval > maxpvsize * 1024:
            self.intf.messageWindow(_("Not enough space"),
                                    _("The physical extent size cannot be "
                                      "changed because the value selected "
				      "(%10.2f MB) is larger than the smallest "
				      "physical volume (%10.2f MB) in the "
				      "volume group.") % (curval/1024.0, maxpvsize), custom_icon="error")
	    widget.set_active(lastidx)
            return 0

	# see if new PE will make any PV useless due to overhead
	if lvm.clampPVSize(maxpvsize, curval) * 1024 < curval:
            self.intf.messageWindow(_("Not enough space"),
                                    _("The physical extent size cannot be "
                                      "changed because the value selected "
				      "(%10.2f MB) is too large compared "
                                      "to the size of the "
				      "smallest physical volume "
				      "(%10.2f MB) in the "
				      "volume group.") % (curval/1024.0,
                                                          maxpvsize),
                                    custom_icon="error")
	    widget.set_active(lastidx)
            return 0
	    

	if self.getPVWastedRatio(curval) > 0.10:
	    rc = self.intf.messageWindow(_("Too small"),
					 _("This change in the value of the "
					   "physical extent will waste "
					   "substantial space on one or more "
					   "of the physical volumes in the "
					   "volume group."),
					 type="custom", custom_icon="error",
					   custom_buttons=["gtk-cancel", _("C_ontinue")])
	    if not rc:
		widget.set_active(lastidx)
		return 0

	# now see if we need to fixup effect PV and LV sizes based on PE
        if curval > lastval:
            rc = self.reclampLV(curval)
            if not rc:
		widget.set_active(lastidx)
		return 0
            else:
                self.updateLogVolStore()
	else:
	    maxlv = lvm.getMaxLVSize(curval)
	    for lv in self.logvolreqs:
		lvsize = lv.getActualSize(self.partitions, self.diskset)
		if lvsize > maxlv:
		    self.intf.messageWindow(_("Not enough space"),
					    _("The physical extent size "
					      "cannot be changed because the "
					      "resulting maximum logical "
					      "volume size (%10.2f MB) is "
					      "smaller "
					      "than one or more of the "
					      "currently defined logical "
					      "volumes.") % (maxlv,),
					    custom_icon="error")
		    widget.set_active(lastidx)
		    return 0
            
        widget.set_data("lastpe", curval)
	widget.set_data("lastidx", widget.get_active())
        self.updateAllowedLvmPartitionsList(self.availlvmparts,
					    self.partitions,
					    self.lvmlist)
	self.updateVGSpaceLabels()

    def prettyFormatPESize(self, val):
        if val < 1024:
            return "%s KB" % (val,)
        elif val < 1024*1024:
            return "%s MB" % (val/1024,)
        else:
            return "%s GB" % (val/1024/1024,)

    def createPEOptionMenu(self, default=4096):
        peCombo = datacombo.DataComboBox()

	idx = 0
	defindex = None
	actualPE = lvm.getPossiblePhysicalExtents(floor=1024)
	for curpe in actualPE:
	    # dont show PE over 128M, unless it's the default
	    if curpe > 131072 and curpe != default:
		continue
	    
            val = self.prettyFormatPESize(curpe)

            peCombo.append(val, curpe)

	    if default == curpe:
		defindex = idx
		
	    idx = idx + 1

	if defindex:
            peCombo.set_active(defindex)

        peCombo.set_data("lastidx", peCombo.get_active())
        peCombo.connect("changed", self.peChangeCB)
        peCombo.set_data("lastpe", default)

	return peCombo

    def clickCB(self, row, data):
	model = self.lvmlist.get_model()
	pvlist = self.getSelectedPhysicalVolumes(model)

	# get the selected row
	iter = model.get_iter((string.atoi(data),))

	# we invert val because we get called before checklist
	# changes the toggle state
	val      = not model.get_value(iter, 0)
	partname = model.get_value(iter, 1)
	id = self.partitions.getRequestByDeviceName(partname).uniqueID
	if val:
	    pvlist.append(id)
	else:
	    pvlist.remove(id)

	(availSpaceMB, neededSpaceMB, fspace) = self.computeSpaceValues(alt_pvlist=pvlist)
	if availSpaceMB < neededSpaceMB:
	    self.intf.messageWindow(_("Not enough space"),
				    _("You cannot remove this physical "
				      "volume because otherwise the "
				      "volume group will be too small to "
				      "hold the currently defined logical "
				      "volumes."), custom_icon="error")
	    return False

	self.updateVGSpaceLabels(alt_pvlist = pvlist)
	return True
	

    def createAllowedLvmPartitionsList(self, alllvmparts, reqlvmpart, partitions, preexist = 0):

	store = gtk.TreeStore(gobject.TYPE_BOOLEAN,
			      gobject.TYPE_STRING,
			      gobject.TYPE_STRING)
	partlist = WideCheckList(2, store, self.clickCB)

	sw = gtk.ScrolledWindow()
	sw.add(partlist)
	sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
	sw.set_shadow_type(gtk.SHADOW_IN)

	for part in alllvmparts:
	    uid = part[0]
	    request = partitions.getRequestByID(uid)

	    if request.type != REQUEST_RAID:
		partname = "%s" % (request.device,)
	    else:
		partname = "md%d" % (request.raidminor,)

	    size = request.getActualSize (partitions, self.diskset)
	    used = part[2]

	    # clip size to current PE
	    pesize = int(self.peCombo.get_active_value())
	    size = lvm.clampPVSize(size, pesize)
	    partsize = "%10.2f MB" % size
	    if used or not reqlvmpart:
		selected = 1
	    else:
		selected = 0

            if preexist == 0 or selected == 1:
                partlist.append_row((partname, partsize), selected)

	return (partlist, sw)

    def updateAllowedLvmPartitionsList(self, alllvmparts, partitions, partlist):
	""" update sizes in pv list

	alllvmparts - list of pv from partitions.getAvailLVMPartitions
	partitions - object holding all partition requests
	partlist - the checklist containing pv list
	"""

	row = 0
	for part in alllvmparts:
	    uid = part[0]
	    request = partitions.getRequestByID(uid)
	    size = request.getActualSize(partitions, self.diskset)

	    # clip size to current PE
	    pesize = int(self.peCombo.get_active_value())
	    size = lvm.clampPVSize(size, pesize)
	    partsize = "%10.2f MB" % size

	    iter = partlist.store.get_iter((int(row),))
	    partlist.store.set_value(iter, 2, partsize)
	    row = row + 1
	
    def getCurrentLogicalVolume(self):
	selection = self.logvollist.get_selection()
	(model, iter) = selection.get_selected()
	return iter


    def editLogicalVolume(self, logrequest, isNew = 0):
	if isNew:
	    tstr = _("Make Logical Volume")
	else:
	    try:
		tstr = _("Edit Logical Volume: %s") % (logrequest.logicalVolumeName,)
	    except:
		tstr = _("Edit Logical Volume")
	    
        dialog = gtk.Dialog(tstr, self.parent)
        gui.addFrame(dialog)
        dialog.add_button('gtk-cancel', 2)
        dialog.add_button('gtk-ok', 1)
        dialog.set_position(gtk.WIN_POS_CENTER)

        maintable = gtk.Table()
        maintable.set_row_spacings(5)
        maintable.set_col_spacings(5)
        row = 0

        lbl = createAlignedLabel(_("_Mount Point:"))
	maintable.attach(lbl, 0, 1, row,row+1)
        mountCombo = createMountPointCombo(logrequest, excludeMountPoints=["/boot"])
        lbl.set_mnemonic_widget(mountCombo)
        maintable.attach(mountCombo, 1, 2, row, row + 1)
        row += 1

        if not logrequest or not logrequest.getPreExisting():
            lbl = createAlignedLabel(_("_File System Type:"))
            maintable.attach(lbl, 0, 1, row, row + 1)
            newfstypeCombo = createFSTypeMenu(logrequest.fstype,
                                              fstypechangeCB,
                                              mountCombo,
                                              ignorefs = ["software RAID", "physical volume (LVM)", "vfat", "PPC PReP Boot", "Apple Bootstrap"])
            lbl.set_mnemonic_widget(newfstypeCombo)
            maintable.attach(newfstypeCombo, 1, 2, row, row + 1)
            row += 1
        else:
            maintable.attach(createAlignedLabel(_("Original File System Type:")),
                             0, 1, row, row + 1)
            if logrequest.origfstype and logrequest.origfstype.getName():
                newfstypeCombo = gtk.Label(logrequest.origfstype.getName())
            else:
                newfstypeCombo = gtk.Label(_("Unknown"))

            maintable.attach(newfstypeCombo, 1, 2, row, row + 1)
            row += 1

            if logrequest.fslabel:
                maintable.attach(createAlignedLabel(_("Original File System "
                                                      "Label:")),
                                 0, 1, row, row + 1)
                maintable.attach(gtk.Label(logrequest.fslabel), 1, 2, row,
                                 row + 1)
                row += 1


        if not logrequest or not logrequest.getPreExisting():
            lbl = createAlignedLabel(_("_Logical Volume Name:"))
            lvnameEntry = gtk.Entry(32)
            lbl.set_mnemonic_widget(lvnameEntry)
            if logrequest and logrequest.logicalVolumeName:
                lvnameEntry.set_text(logrequest.logicalVolumeName)
            else:
                lvnameEntry.set_text(lvm.createSuggestedLVName(self.logvolreqs))
        else:
            lbl = createAlignedLabel(_("Logical Volume Name:"))
            lvnameEntry = gtk.Label(logrequest.logicalVolumeName)
            
        maintable.attach(lbl, 0, 1, row, row + 1)
        maintable.attach(lvnameEntry, 1, 2, row, row + 1)
        row += 1

        if not logrequest or not logrequest.getPreExisting():
            lbl = createAlignedLabel(_("_Size (MB):"))
            sizeEntry = gtk.Entry(16)
            lbl.set_mnemonic_widget(sizeEntry)
            if logrequest:
                sizeEntry.set_text("%g" % (logrequest.getActualSize(self.partitions, self.diskset),))
        else:
            lbl = createAlignedLabel(_("Size (MB):"))
            sizeEntry = gtk.Label(str(logrequest.size))
            
        maintable.attach(lbl, 0, 1, row, row+1)
        maintable.attach(sizeEntry, 1, 2, row, row + 1)
        row += 1

        if not logrequest or not logrequest.getPreExisting():
            pesize = int(self.peCombo.get_active_value())
            (tspace, uspace, fspace) = self.computeSpaceValues(usepe=pesize)
            maxlv = min(lvm.getMaxLVSize(pesize), fspace)

            # add in size of current logical volume if it has a size
            if logrequest and not isNew:
                maxlv = maxlv + logrequest.getActualSize(self.partitions, self.diskset)
            maxlabel = createAlignedLabel(_("(Max size is %s MB)") % (maxlv,))
            maintable.attach(maxlabel, 1, 2, row, row + 1)

	self.fsoptionsDict = {}
	if logrequest.getPreExisting():
	    (row, self.fsoptionsDict) = createPreExistFSOptionSection(logrequest, maintable, row, mountCombo, showbadblocks=0, ignorefs = ["software RAID", "physical volume (LVM)", "vfat"])

        dialog.vbox.pack_start(maintable)
        dialog.show_all()

	while 1:
	    rc = dialog.run()
	    if rc == 2:
		dialog.destroy()
		return

            if not logrequest or not logrequest.getPreExisting():
                fsystem = newfstypeCombo.get_active_value()
                format = 1
                migrate = 0
            else:
		if self.fsoptionsDict.has_key("formatrb"):
		    formatrb = self.fsoptionsDict["formatrb"]
		else:
		    formatrb = None

		if formatrb:
                    format = formatrb.get_active()
                    if format:
                        fsystem = self.fsoptionsDict["fstypeCombo"].get_active_value()
                else:
                    format = 0

		if self.fsoptionsDict.has_key("migraterb"):
		    migraterb = self.fsoptionsDict["migraterb"]
		else:
		    migraterb = None
		    
		if migraterb:
                    migrate = migraterb.get_active()
                    if migrate:
                        fsystem = self.fsoptionsDict["migfstypeCombo"].get_active_value()
                else:
                    migrate = 0

                # set back if we are not formatting or migrating
		origfstype = logrequest.origfstype
                if not format and not migrate:
                    fsystem = origfstype

            mntpt = string.strip(mountCombo.get_children()[0].get_text())

            if not logrequest or not logrequest.getPreExisting():
                # check size specification
                badsize = 0
                try:
                    size = long(sizeEntry.get_text())
                except:
                    badsize = 1

                if badsize or size <= 0:
                    self.intf.messageWindow(_("Illegal size"),
                                            _("The requested size as entered is "
                                              "not a valid number greater "
                                              "than 0."), custom_icon="error")
                    continue
            else:
                size = logrequest.size

	    # is this an existing logical volume or one we're editting
            if logrequest:
                preexist = logrequest.getPreExisting()
            else:
                preexist = 0

	    # test mount point
            # check in pending logical volume requests
	    # these may not have been put in master list of requests
	    # yet if we have not hit 'OK' for the volume group creation
	    if fsystem.isMountable():
		used = 0
		if logrequest:
		    curmntpt = logrequest.mountpoint
		else:
		    curmntpt = None
		    
		for lv in self.logvolreqs:
		    if curmntpt and lv.mountpoint == curmntpt:
			continue

		    if lv.mountpoint == mntpt:
			used = 1
			break

		if used:
		    self.intf.messageWindow(_("Mount point in use"),
					    _("The mount point \"%s\" is in "
					      "use, please pick another.") %
					    (mntpt,), custom_icon="error")
		    continue

	    # check out logical volumne name
	    lvname = string.strip(lvnameEntry.get_text())

            if not logrequest or not logrequest.getPreExisting():
                err = sanityCheckLogicalVolumeName(lvname)
                if err:
                    self.intf.messageWindow(_("Illegal Logical Volume Name"),err, custom_icon="error")
                    continue

	    # is it in use?
	    used = 0
	    if logrequest:
		origlvname = logrequest.logicalVolumeName
	    else:
		origlvname = None

	    for lv in self.logvolreqs:
		if origlvname and lv.logicalVolumeName == origlvname:
		    continue

		if lv.logicalVolumeName == lvname:
		    used = 1
		    break

	    if used:
		self.intf.messageWindow(_("Illegal logical volume name"),
					_("The logical volume name \"%s\" is "
					  "already in use. Please pick "
					  "another.") % (lvname,), custom_icon="error")
		continue

	    # create potential request
	    request = copy.copy(logrequest)
	    pesize = int(self.peCombo.get_active_value())
	    size = lvm.clampLVSizeRequest(size, pesize, roundup=1)

	    # do some final tests
	    maxlv = lvm.getMaxLVSize(pesize)
	    if size > maxlv:
		self.intf.messageWindow(_("Not enough space"),
					_("The current requested size "
					  "(%10.2f MB) is larger than maximum "
					  "logical volume size (%10.2f MB). "
					  "To increase this limit you can "
					  "create more Physical Volumes from "
                                          "unpartitioned disk space and "
                                          "add them to this Volume Group.")
					  %(size, maxlv),
                                        custom_icon="error")
		continue

 	    request.fstype = fsystem

 	    if request.fstype.isMountable():
 		request.mountpoint = mntpt
 	    else:
 		request.mountpoint = None

            request.preexist = preexist
	    request.logicalVolumeName = lvname
	    request.size = size
            request.format = format
            request.migrate = migrate
	    request.badblock = None
            request.grow = 0

	    # this is needed to clear out any cached info about the device
	    # only a workaround - need to change way this is handled in
	    # partRequest.py really.
	    request.dev = None
	    
	    # make list of original logvol requests so we can skip them
	    # in tests below. We check for mount point name conflicts
	    # above within the current volume group, so it is not
	    # necessary to do now.
 	    err = request.sanityCheckRequest(self.partitions, skipMntPtExistCheck=1, pesize=pesize)
	    if err is None:
		skiplist = []
		for lv in self.origvolreqs:
		    skiplist.append(lv.uniqueID)
		    
		err = request.isMountPointInUse(self.partitions, requestSkipList=skiplist)

 	    if err:
 		self.intf.messageWindow(_("Error With Request"),
 					"%s" % (err), custom_icon="error")
 		continue

	    if (not request.format and
		request.mountpoint and request.formatByDefault()):
		if not queryNoFormatPreExisting(self.intf):
		    continue

	    # see if there is room for request
	    (availSpaceMB, neededSpaceMB, fspace) = self.computeSpaceValues(usepe=pesize)

	    tmplogreqs = []
	    for l in self.logvolreqs:
		if origlvname and l.logicalVolumeName == origlvname:
		    continue
		
		tmplogreqs.append(l)

	    tmplogreqs.append(request)
	    neededSpaceMB = self.computeLVSpaceNeeded(tmplogreqs)

	    if neededSpaceMB > availSpaceMB:
		self.intf.messageWindow(_("Not enough space"),
					_("The logical volumes you have "
					  "configured require %g MB, but the "
					  "volume group only has %g MB.  Please "
					  "either make the volume group larger "
					  "or make the logical volume(s) smaller.") % (neededSpaceMB, availSpaceMB), custom_icon="error")
		del tmplogreqs
		continue

	    # everything ok
	    break

	# now remove the previous request, insert request created above
	if not isNew:
	    self.logvolreqs.remove(logrequest)
	    iter = self.getCurrentLogicalVolume()
	    self.logvolstore.remove(iter)
	    
        self.logvolreqs.append(request)

	iter = self.logvolstore.append()
	self.logvolstore.set_value(iter, 0, lvname)
	if request.fstype and request.fstype.isMountable():
	    self.logvolstore.set_value(iter, 1, mntpt)
	else:
	    self.logvolstore.set_value(iter, 1, "N/A")
	    
	self.logvolstore.set_value(iter, 2, "%g" % (size,))

	self.updateVGSpaceLabels()
        dialog.destroy()
	
    def editCurrentLogicalVolume(self):
	iter = self.getCurrentLogicalVolume()

	if iter is None:
	    return
	
	logvolname = self.logvolstore.get_value(iter, 0)
	logrequest = None
	for lv in self.logvolreqs:
	    if lv.logicalVolumeName == logvolname:
		logrequest = lv
		
	if logrequest is None:
	    return

	self.editLogicalVolume(logrequest)

    def addLogicalVolumeCB(self, widget):
	if self.numAvailableLVSlots() < 1:
	    self.intf.messageWindow(_("No free slots"),
				    _("You cannot create more than %s logical "
				    "volumes per volume group.") % (lvm.MAX_LV_SLOTS,), custom_icon="error")
	    return
	
        (tspace, uspace, fspace) = self.computeSpaceValues()
	if fspace <= 0:
	    self.intf.messageWindow(_("No free space"),
				    _("There is no room left in the "
				      "volume group to create new logical "
				      "volumes. "
				      "To add a logical volume you will need "
				      "to reduce the size of one or more of "
				      "the currently existing "
				      "logical volumes"), custom_icon="error")
	    return
	    
        request = LogicalVolumeRequestSpec(fileSystemTypeGetDefault(),
					   size = fspace)
	self.editLogicalVolume(request, isNew = 1)
	return

    def editLogicalVolumeCB(self, widget):
	self.editCurrentLogicalVolume()
	return

    def delLogicalVolumeCB(self, widget):
	iter = self.getCurrentLogicalVolume()
	if iter is None:
	    return
	
	logvolname = self.logvolstore.get_value(iter, 0)
	if logvolname is None:
	    return

	rc = self.intf.messageWindow(_("Confirm Delete"),
				_("Are you sure you want to Delete the "
				"logical volume \"%s\"?") % (logvolname,),
				type = "custom", custom_buttons=["gtk-cancel", _("_Delete")], custom_icon="warning")
	if not rc:
	    return

	for lv in self.logvolreqs:
	    if lv.logicalVolumeName == logvolname:
		self.logvolreqs.remove(lv)

	self.logvolstore.remove(iter)

	self.updateVGSpaceLabels()
	return
    
    def logvolActivateCb(self, view, path, col):
	self.editCurrentLogicalVolume()

    def getSelectedPhysicalVolumes(self, model):
	pv = []
	next = model.get_iter_first()
	currow = 0
	while next is not None:
	    iter = next
	    val      = model.get_value(iter, 0)
	    partname = model.get_value(iter, 1)
	    
	    if val:
		pvreq = self.partitions.getRequestByDeviceName(partname)
		id = pvreq.uniqueID
		pv.append(id)

	    next = model.iter_next(iter)
	    currow = currow + 1

	return pv

    def computeVGSize(self, pvlist, curpe):
	availSpaceMB = 0
	for id in pvlist:
	    pvreq = self.partitions.getRequestByID(id)
	    pvsize = pvreq.getActualSize(self.partitions, self.diskset)
	    pvsize = lvm.clampPVSize(pvsize, curpe) - (curpe/1024)

	    # have to clamp pvsize to multiple of PE
	    availSpaceMB = availSpaceMB + pvsize

        log.info("computeVGSize: vgsize is %s" % (availSpaceMB,))
	return availSpaceMB

    def computeLVSpaceNeeded(self, logreqs):
	neededSpaceMB = 0
	for lv in logreqs:
	    neededSpaceMB = neededSpaceMB + lv.getActualSize(self.partitions, self.diskset)

	return neededSpaceMB

    def updateLogVolStore(self):
        self.logvolstore.clear()
        for lv in self.logvolreqs:
            iter = self.logvolstore.append()
            size = lv.getActualSize(self.partitions, self.diskset)
            lvname = lv.logicalVolumeName
            mntpt = lv.mountpoint
            if lvname:
                self.logvolstore.set_value(iter, 0, lvname)
                
            if lv.fstype and lv.fstype.isMountable():
                if mntpt:
                    self.logvolstore.set_value(iter, 1, mntpt)
                else:
                    self.logvolstore.set_value(iter, 1, "")
	    else:
		self.logvolstore.set_value(iter, 1, "N/A")
                
            self.logvolstore.set_value(iter, 2, "%g" % (size,))
        

    def updateVGSpaceLabels(self, alt_pvlist=None):
	if alt_pvlist == None:
	    pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model())
	else:
	    pvlist = alt_pvlist
	    
        (tspace, uspace, fspace) = self.computeSpaceValues(alt_pvlist=pvlist)

	self.totalSpaceLabel.set_text("%10.2f MB" % (tspace,))
	self.usedSpaceLabel.set_text("%10.2f MB" % (uspace,))

	if tspace > 0:
	    usedpercent = (100.0*uspace)/tspace
	else:
	    usedpercent = 0.0
	    
	self.usedPercentLabel.set_text("(%4.1f %%)" % (usedpercent,))

	self.freeSpaceLabel.set_text("%10.2f MB" % (fspace,))
	if tspace > 0:
	    freepercent = (100.0*fspace)/tspace
	else:
	    freepercent = 0.0

	self.freePercentLabel.set_text("(%4.1f %%)" % (freepercent,))

#
# run the VG editor we created
#
    def run(self):
	if self.dialog is None:
	    return None
	
	while 1:
	    rc = self.dialog.run()

	    if rc == 2:
		self.destroy()
		return None

	    pvlist = self.getSelectedPhysicalVolumes(self.lvmlist.get_model())
	    pesize = int(self.peCombo.get_active_value())
	    availSpaceMB = self.computeVGSize(pvlist, pesize)
	    neededSpaceMB = self.computeLVSpaceNeeded(self.logvolreqs)

	    if neededSpaceMB > availSpaceMB:
		self.intf.messageWindow(_("Not enough space"),
					_("The logical volumes you have "
					  "configured require %g MB, but the "
					  "volume group only has %g MB.  Please "
					  "either make the volume group larger "
					  "or make the logical volume(s) smaller.") % (neededSpaceMB, availSpaceMB), custom_icon="error")
		continue

	    # check volume name
	    volname = string.strip(self.volnameEntry.get_text())
	    err = sanityCheckVolumeGroupName(volname)
	    if err:
		self.intf.messageWindow(_("Invalid Volume Group Name"), err,
					custom_icon="error")
		continue

	    if self.origvgrequest:
		origvname = self.origvgrequest.volumeGroupName
	    else:
		origname = None

	    if origvname != volname:
		tmpreq = VolumeGroupRequestSpec(physvols = pvlist,
                                                vgname = volname)
		if self.partitions.isVolumeGroupNameInUse(volname):
		    self.intf.messageWindow(_("Name in use"),
					    _("The volume group name \"%s\" is "
					      "already in use. Please pick "
					      "another." % (volname,)),
					    custom_icon="error")
		    del tmpreq
		    continue
		
		del tmpreq

	    # get physical extent
	    pesize = int(self.peCombo.get_active_value())

	    # everything ok
	    break

	request = VolumeGroupRequestSpec(physvols = pvlist, vgname = volname,
					 pesize = pesize)

        # if it was preexisting, it still should be
        if self.origvgrequest and self.origvgrequest.getPreExisting():
            request.preexist = 1
            
	return (request, self.logvolreqs)

    def destroy(self):
	if self.dialog:
	    self.dialog.destroy()
	self.dialog = None

    def __init__(self, partitions, diskset, intf, parent, origvgrequest, isNew = 0):
	self.partitions = partitions
	self.diskset = diskset
	self.origvgrequest = origvgrequest
	self.isNew = isNew
	self.intf = intf
	self.parent = parent

        self.availlvmparts = self.partitions.getAvailLVMPartitions(self.origvgrequest,
                                                              self.diskset)
        self.logvolreqs = self.partitions.getLVMLVForVG(self.origvgrequest)
	self.origvolreqs = copy.copy(self.logvolreqs)

        # if no PV exist, raise an error message and return
        if len(self.availlvmparts) < 1:
	    self.intf.messageWindow(_("Not enough physical volumes"),
			       _("At least one unused physical "
				 "volume partition is "
				 "needed to create an LVM Volume Group.\n\n"
				 "Create a partition or RAID array "
				 "of type \"physical volume (LVM)\" and then "
				 "select the \"LVM\" option again."),
				    custom_icon="error")
	    self.dialog = None
            return

	if isNew:
	    tstr = _("Make LVM Volume Group")
	else:
	    try:
		tstr = _("Edit LVM Volume Group: %s") % (origvgrequest.volumeGroupName,)
	    except:
		tstr = _("Edit LVM Volume Group")
	    
        dialog = gtk.Dialog(tstr, self.parent)
        gui.addFrame(dialog)
        dialog.add_button('gtk-cancel', 2)
        dialog.add_button('gtk-ok', 1)

        dialog.set_position(gtk.WIN_POS_CENTER)

        maintable = gtk.Table()
        maintable.set_row_spacings(5)
        maintable.set_col_spacings(5)
        row = 0

        # volume group name
        if not origvgrequest.getPreExisting():
            lbl = createAlignedLabel(_("_Volume Group Name:"))
            self.volnameEntry = gtk.Entry(16)
            lbl.set_mnemonic_widget(self.volnameEntry)
            if not self.isNew:
                self.volnameEntry.set_text(self.origvgrequest.volumeGroupName)
            else:
                self.volnameEntry.set_text(lvm.createSuggestedVGName(self.partitions))
        else:
            lbl = createAlignedLabel(_("Volume Group Name:"))
            self.volnameEntry = gtk.Label(self.origvgrequest.volumeGroupName)
	    
	maintable.attach(lbl, 0, 1, row, row + 1,
                         gtk.EXPAND|gtk.FILL, gtk.SHRINK)
        maintable.attach(self.volnameEntry, 1, 2, row, row + 1, gtk.EXPAND|gtk.FILL, gtk.SHRINK)
	row = row + 1

        lbl = createAlignedLabel(_("_Physical Extent:"))
        self.peCombo = self.createPEOptionMenu(self.origvgrequest.pesize)
        lbl.set_mnemonic_widget(self.peCombo)
        if origvgrequest.getPreExisting():
            self.peCombo.set_sensitive(False)

        maintable.attach(lbl, 0, 1, row, row + 1,
                         gtk.EXPAND|gtk.FILL, gtk.SHRINK)
        maintable.attach(self.peCombo, 1, 2, row, row + 1, gtk.EXPAND|gtk.FILL, gtk.SHRINK)
        row = row + 1

        (self.lvmlist, sw) = self.createAllowedLvmPartitionsList(self.availlvmparts, self.origvgrequest.physicalVolumes, self.partitions, origvgrequest.getPreExisting())
        if origvgrequest.getPreExisting():
            self.lvmlist.set_sensitive(False)
        self.lvmlist.set_size_request(275, 80)
        lbl = createAlignedLabel(_("Physical Volumes to _Use:"))
        lbl.set_mnemonic_widget(self.lvmlist)
        maintable.attach(lbl, 0, 1, row, row + 1)
        maintable.attach(sw, 1, 2, row, row + 1)
        row = row + 1

        maintable.attach(createAlignedLabel(_("Used Space:")), 0, 1, row,
			 row + 1, gtk.EXPAND|gtk.FILL, gtk.SHRINK)
	lbox = gtk.HBox()
	self.usedSpaceLabel = gtk.Label("")
	labelalign = gtk.Alignment()
	labelalign.set(1.0, 0.5, 0.0, 0.0)
	labelalign.add(self.usedSpaceLabel)
	lbox.pack_start(labelalign, False, False)
	self.usedPercentLabel = gtk.Label("")
	labelalign = gtk.Alignment()
	labelalign.set(1.0, 0.5, 0.0, 0.0)
	labelalign.add(self.usedPercentLabel)
	lbox.pack_start(labelalign, False, False, padding=10)
        maintable.attach(lbox, 1, 2, row, row + 1, gtk.EXPAND|gtk.FILL, gtk.SHRINK)
	maintable.set_row_spacing(row, 0)
        row = row + 1

        maintable.attach(createAlignedLabel(_("Free Space:")), 0, 1, row,
			 row + 1, gtk.EXPAND|gtk.FILL, gtk.SHRINK)
	lbox = gtk.HBox()
	self.freeSpaceLabel = gtk.Label("")
	labelalign = gtk.Alignment()
	labelalign.set(1.0, 0.5, 0.0, 0.0)
	labelalign.add(self.freeSpaceLabel)