I hate when I try to write generalized code up front. That is, I try to write a code base that is sufficiently generic that it works for all possible use cases. Some argue for this sort of development. I don’t like it. But I do fall into this every now and then.
Tiburon suffered from some of this. I want one system to “bind them all, and in the PXE process, boot them.” So I threw everything (including the kitchen sink) into it.
It sorta broke on me on Thursday.
I was working on a set of changes to boot Centos 6.2 via Tiburon. I wanted to add some features. I kept running into design … er … features.
So I took a scythe and cleaned out the dead code. I (massively) simplified the current code base. I knew I had to do this, I tried pushing too much functionality into Tiburon, functionality that I’ve since superceded with the boot time autoconfig scripts.
So I pulled that crap out. I rethought a few things, including how I passed some arguments.
Way back when I started learning Perl, I passed arguments to subs (methods) like this:
&function($arg1, $arg2, ..., $argN);
sub function {
my $arg1 = shift;
my $arg2 = shift;
.
.
.
my $argN = shift;
# do stuff
}
Ugly, ain’t it. Hard to maintain too. Basically, if you need more than 2 to 3 arguments, create a hash (collection for python-philic) that maps a named key into a value. Then pass a reference to the hash. Brain dead easy, never have to worry about argument order again.
For reasons I don’t grasp, Tiburon had a few calls like this in its core.
So I fixed em.
Then I had put controller logic in the view logic.
NOOOOOOOOOOOOOOOOOOOOOOOOoo!
The view logic is drop dead simple. So I fixed it.
Now, it just works, same as before, but *far* easier to maintain and write tools to interact with. Setting the default boot mechanism is real easy. Adding new boot mechanisms is real easy. Still have some oddities in how we spec an NFS boot server (have to tie it to an IP address, and I’d like to keep those entries more generic). Possibly some templates and other bits.
But, as they say, the proof is in the pudding. Behold Centos 6.2 from Tiburon:
[root@manager ~]# ssh 10.100.240.146 Last login: Fri Mar 9 15:46:07 2012 from internal-install.storagecluster [root@manager-1 ~]# ssh 192.168.1.149 Last login: Sat Mar 10 15:47:37 2012 from 192.168.1.250 [root@Centos6 ~]# df -h Filesystem Size Used Avail Use% Mounted on tmpfs 7.9G 0 7.9G 0% /dev/shm none 7.9G 0 7.9G 0% /tmp [root@Centos6 ~]# uname -r 2.6.32-220.7.1.el6.x86_64 [root@Centos6 ~]# lsscsi [root@Centos6 ~]# [root@Centos6 ~]# fdisk -l [root@Centos6 ~]# [root@Centos6 ~]# cat /proc/scsi/scsi Attached devices: [root@Centos6 ~]# [root@Centos6 ~]# lsmod Module Size Used by ipmi_devintf 8049 0 ipmi_si 42401 0 ipmi_msghandler 35992 2 ipmi_devintf,ipmi_si cpufreq_ondemand 10448 8 acpi_cpufreq 7955 0 freq_table 4881 2 cpufreq_ondemand,acpi_cpufreq mperf 1557 1 acpi_cpufreq microcode 112594 0 serio_raw 4818 0 i2c_i801 11231 0 iTCO_wdt 13662 0 iTCO_vendor_support 3088 1 iTCO_wdt lm87 25713 0 hwmon_vid 3132 1 lm87 ahci 40455 0 e1000e 219500 0 sfc 189702 0 i2c_algo_bit 5762 1 sfc i2c_core 31276 4 i2c_i801,lm87,sfc,i2c_algo_bit dm_mirror 14101 0 dm_region_hash 12170 1 dm_mirror dm_log 10122 2 dm_mirror,dm_region_hash dm_mod 81596 2 dm_mirror,dm_log nfs 398778 1 lockd 74270 1 nfs fscache 46859 1 nfs nfs_acl 2647 1 nfs auth_rpcgss 44895 1 nfs sunrpc 244046 9 nfs,lockd,nfs_acl,auth_rpcgss be2iscsi 67608 0 bnx2i 45110 0 cnic 53443 1 bnx2i uio 10974 1 cnic ipv6 322029 25 cnic cxgb4i 28169 0 cxgb4 98717 1 cxgb4i cxgb3i 24938 0 libcxgbi 52541 2 cxgb4i,cxgb3i cxgb3 153146 1 cxgb3i mdio 4732 2 sfc,cxgb3 libiscsi_tcp 16598 3 cxgb4i,cxgb3i,libcxgbi qla4xxx 170419 0 iscsi_boot_sysfs 9650 2 be2iscsi,qla4xxx libiscsi 47521 7 be2iscsi,bnx2i,cxgb4i,cxgb3i,libcxgbi,libiscsi_tcp,qla4xxx scsi_transport_iscsi 48010 5 be2iscsi,bnx2i,libcxgbi,qla4xxx,libiscsi [root@Centos6 ~]# ifinfo device: address/netmask MTU Tx (MB) Rx (MB) eth0: addr not set/mask not set 1500 0.001 8.813 eth1: addr not set/mask not set 1500 0.000 0.000 eth2: 192.168.1.149/255.255.255.0 1500 12.182 142.812 [root@Centos6 ~]# cat /etc/mtab proc /proc proc rw 0 0 sysfs /sys sysfs rw 0 0 tmpfs /dev/shm tmpfs rw 0 0 none /tmp tmpfs rw 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 [root@Centos6 ~]# dmesg | grep nfs Command line: ip=dhcp root=nfs:192.168.1.250:/data/nfs/Centos6.2_x64 rw debug verbose rdshell rd_NO_DM rd_NO_MD rd.ip=auto selinux=0 Kernel command line: ip=dhcp root=nfs:192.168.1.250:/data/nfs/Centos6.2_x64 rw debug verbose rdshell rd_NO_DM rd_NO_MD rd.ip=auto selinux=0 FS-Cache: Netfs 'nfs' registered for caching dracut: Mounted root filesystem 192.168.1.250:/data/nfs/Centos6.2_x64 [root@Centos6 ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 42 model name : Intel(R) Xeon(R) CPU E31240 @ 3.30GHz stepping : 7 cpu MHz : 1600.000 cache size : 8192 KB physical id : 0 siblings : 8 core id : 0 cpu cores : 4 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 x2apic popcnt xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid bogomips : 6585.29 clflush size : 64 cache_alignment : 64 address sizes : 36 bits physical, 48 bits virtual power management: ... [root@Centos6 ~]# top top - 18:24:49 up 1 day, 1:39, 1 user, load average: 0.08, 0.02, 0.01 Tasks: 181 total, 1 running, 180 sleeping, 0 stopped, 0 zombie Cpu0 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu1 : 0.0%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu2 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu3 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu4 : 0.0%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu5 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu6 : 0.0%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Cpu7 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 16445012k total, 307444k used, 16137568k free, 0k buffers Swap: 0k total, 0k used, 0k free, 72800k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 323 root 20 0 0 0 0 S 0.7 0.0 1:32.32 sfc0000:02:00.0 2380 root 20 0 15080 1388 1012 R 0.7 0.0 0:00.01 top 1 root 20 0 19400 1560 1252 S 0.0 0.0 0:00.92 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 7 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1 8 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
Viewed 89288 times by 7982 viewers