Project

General

Profile

Bug #647 » vkhalt.patch

c.turner, 05/20/2007 09:10 PM

View differences:

include/globaldata.h 20 May 2007 17:50:44 -0000
84 84
	int		gd_sdelayed;	/* delayed software ints */
85 85
	int		gd_currentldt;
86 86
	int		gd_mailbox;	/* signal delivery mailbox */
87
	int		gd_powerbutton; /* shutdown signal mailbox */
87 88
	u_int		unused001;
88 89
	u_int		gd_other_cpus;
89 90
	u_int		gd_ss_eflags;
include/md_var.h 20 May 2007 20:34:04 -0000
45 45
#endif
46 46

  
47 47
#define VKNETIF_MAX	16
48
#define VKD_MAX		16
48 49

  
49 50
struct vknetif_info {
50 51
	int		tap_fd;
......
53 54
	in_addr_t	netif_mask;
54 55
};
55 56

  
57
struct vkd_info {
58
        int fd;
59
        int unit;
60
        char fname[MAXPATHLEN];
61
};
62

  
56 63
extern	char	sigcode[];
57 64
extern	int	szsigcode;
58 65
extern	vpte_t	*KernelPTA;	/* NOTE: Offset for direct VA translation */
......
63 70
extern  char    cpu_vendor[];	/* XXX belongs in i386 */
64 71
extern  u_int   cpu_id;		/* XXX belongs in i386 */
65 72

  
66
extern int	RootImageFd;
73
extern struct vkd_info VkdInfo[VKD_MAX];
74
extern int	VkdNum;
67 75
extern int	MemImageFd;
68 76
extern int	KQueueFd;
69 77
extern struct vknetif_info NetifInfo[VKNETIF_MAX];
......
83 91
void cpu_setregs (void);
84 92
void cpu_idle (void);
85 93
void go_user (struct intrframe *frame);
94
void vk_poweroff (void);
86 95

  
87 96
void init_exceptions(void);
88 97
void init_kqueue(void);
platform/init.c 20 May 2007 20:32:08 -0000
47 47
#include <sys/proc.h>
48 48
#include <sys/msgbuf.h>
49 49
#include <sys/vmspace.h>
50
#include <sys/signalvar.h>
50 51
#include <sys/socket.h>
51 52
#include <sys/sockio.h>
52 53
#include <vm/vm_page.h>
......
76 77
vm_paddr_t Maxmem;
77 78
vm_paddr_t Maxmem_bytes;
78 79
int MemImageFd = -1;
79
int RootImageFd = -1;
80
struct vkd_info VkdInfo[VKD_MAX];
81
int VkdNum = 0;
80 82
struct vknetif_info NetifInfo[VKNETIF_MAX];
81
int NetifNum;
83
int NetifNum = 0;
82 84
vm_offset_t KvaStart;
83 85
vm_offset_t KvaEnd;
84 86
vm_offset_t KvaSize;
......
104 106
static void init_kern_memory(void);
105 107
static void init_globaldata(void);
106 108
static void init_vkernel(void);
107
static void init_rootdevice(char *imageFile);
108
static void init_netif(char *netifFile[], int netifFileNum);
109
static void init_vkd(char *vkdFile[], int vkdExpNum); 
110
static void init_netif(char *netifExp[], int netifExpNum);
109 111
static void usage(const char *ctl);
110 112

  
111 113
/*
......
115 117
main(int ac, char **av)
116 118
{
117 119
	char *memImageFile = NULL;
118
	char *rootImageFile = NULL;
119 120
	char *netifFile[VKNETIF_MAX];
121
	char *vkdFile[VKD_MAX];
120 122
	char *suffix;
121 123
	int netifFileNum = 0;
124
	int vkdFileNum = 0;
122 125
	int c;
123 126
	int i;
124 127
	int n;
......
159 162
				netifFile[netifFileNum++] = optarg;
160 163
			break;
161 164
		case 'r':
162
			rootImageFile = optarg;
165
			if ( vkdFileNum < VKD_MAX )
166
				vkdFile[vkdFileNum++] = optarg;
163 167
			break;
164 168
		case 'm':
165 169
			Maxmem_bytes = strtoull(optarg, &suffix, 0);
......
197 201
	init_globaldata();
198 202
	init_vkernel();
199 203
	init_kqueue();
200
	init_rootdevice(rootImageFile);
204
	init_vkd(vkdFile, vkdFileNum);
201 205
	init_netif(netifFile, netifFileNum);
202 206
	init_exceptions();
203 207
	mi_startup();
......
556 560
}
557 561

  
558 562
/*
559
 * The root filesystem path for the virtual kernel is optional.  If specified
560
 * it points to a filesystem image.
563
 * Filesystem image paths for the virtual kernel are optional.  
564
 * If specified they each should point to a disk image, 
565
 * the first of which will become the VKERNEL root disk.
561 566
 *
562 567
 * The virtual kernel caches data from our 'disk' just like a normal kernel,
563 568
 * so we do not really want the real kernel to cache the data too.  Use
......
565 570
 */
566 571
static
567 572
void
568
init_rootdevice(char *imageFile)
573
init_vkd ( char *vkdExp[], int vkdExpNum ) 
569 574
{
575
	int i;	
576

  
577
        if (vkdExpNum == 0)
578
                return;
579

  
580
	for(i=0; i < vkdExpNum; i++){
581
		char *fname;
582
		fname = vkdExp[i];
583

  
584
        	if (fname == NULL) {
585
                        warnx("Invalid argument to '-r'");
586
                        continue;
587
                }
588

  
589
		if (VkdNum < VKD_MAX ) {
570 590
	struct stat st;
591
			struct vkd_info* info = NULL;
592
			int fd;
593
       			size_t l = 0;
571 594

  
572
	if (imageFile) {
573
		RootImageFd = open(imageFile, O_RDWR|O_DIRECT, 0644);
574
		if (RootImageFd < 0 || fstat(RootImageFd, &st) < 0) {
575
			err(1, "Unable to open/create %s", imageFile);
595
			fd = open(fname, O_RDWR|O_DIRECT, 0644);
596
			if (fd < 0 || fstat(fd, &st) < 0) {
597
				err(1, "Unable to open/create %s: %s",
598
				    fname, strerror(errno));
576 599
			/* NOT REACHED */
577 600
		}
601
	       		info = &VkdInfo[VkdNum];
602
			l = strlen(fname);
603

  
604
	       		info->unit = i;
605
			info->fd = fd;
606
	        	memcpy(info->fname, fname, l);
607

  
608
			if(i == 0)
578 609
		rootdevnames[0] = "ufs:vkd0a";
610

  
611
			VkdNum++;
612

  
613
		}
614
		else {
615
                        warnx("vkd%d (%s) > VKD_MAX",
616
				VkdNum, fname);
617
                        continue;
618
 		}
579 619
	}
580 620
}
581 621

  
......
932 972

  
933 973
		netif = strtok(netifExp[i], ":");
934 974
		if (netif == NULL) {
935
			warnx("Invalide argument to '-I'");
975
			warnx("Invalid argument to '-I'");
936 976
			continue;
937 977
		}
938 978

  
......
994 1034
	for (;;)
995 1035
		__asm__ __volatile("hlt");
996 1036
}
1037

  
1038
void
1039
vk_poweroff(void)
1040
{
1041
	if(initproc != NULL) {
1042
		ksignal(initproc, SIGUSR2);
1043
	} else {
1044
		reboot(RB_POWEROFF);
1045
	}
1046
}
platform/kqueue.c 20 May 2007 20:29:51 -0000
82 82
	sa.sa_flags = SA_MAILBOX | SA_NODEFER;
83 83
	sigemptyset(&sa.sa_mask);
84 84
	sigaction(SIGIO, &sa, NULL);
85

  
86
	sa.sa_mailbox = &mdcpu->gd_powerbutton;
87
	sigaction(SIGTERM, &sa, NULL);
88

  
85 89
	KQueueFd = kqueue();
86 90
	if (fcntl(KQueueFd, F_SETOWN, getpid()) < 0)
87 91
		panic("Cannot configure kqueue for SIGIO, update your kernel");
......
107 111
	int n;
108 112
	int i;
109 113

  
110
	if (gd->gd_mailbox == 0)
111
		return;
114
	/* note: 
115
         *   should this be a separate mailbox handler call in 
116
         *   platform/vkernel/i386/trap.c?
117
         */
118
	if (gd->gd_powerbutton != 0) {
119
		kprintf("Caught SIGTERM from host. Shutting down...\n");	
120
		gd->gd_powerbutton=0;
121
		vk_poweroff();
122
	}
123

  
124
	if (gd->gd_mailbox != 0) {
112 125
	gd->gd_mailbox = 0;
113 126
	ts.tv_sec = 0;
114 127
	ts.tv_nsec = 0;
......
125 138
	crit_exit();
126 139
}
127 140

  
141
}
142

  
128 143
/*
129 144
 * Generic I/O event support
130 145
 */
(1-1/4)