Skip to content

Instantly share code, notes, and snippets.

@kkumar-fk
kkumar-fk / crypto_summary.sh
Last active February 11, 2022 03:40
Script to calculate your crypto balance, as well as give (50) historical values. Historical values help in deciding whether to invest or not.
#!/bin/bash
# Number of units of each cryptocurrency.
u_bc=0.73674311
u_eth=0.75795629
u_rip=251.065810
# Get prices of each from https://api.coingecko.com/api/v3/coins/list
bc=`curl "https://api.coingecko.com/api/v3/coins/markets?vs_currency=inr&ids=bitcoin" 2> /dev/null | jq . | grep current_price | awk '{print $NF}' | cut -d, -f1 &`
eth=`curl "https://api.coingecko.com/api/v3/coins/markets?vs_currency=inr&ids=ethereum" 2> /dev/null | jq . | grep current_price | awk '{print $NF}' | cut -d, -f1 &`
@kkumar-fk
kkumar-fk / reattach_vf.sh
Created November 29, 2021 13:44
Script to run on destination hypervisor to reattach a VF to the migrated VM
#!/bin/bash
bridge fdb del 52:54:00:00:12:53 dev ens36v0
bridge fdb del 52:54:00:00:12:53 dev vmtap01 master
virsh attach-device --config --live vm01 vf.xml
virsh domif-setlink vm01 vmtap01 down
@kkumar-fk
kkumar-fk / migrate_source.sh
Created November 29, 2021 13:42
Migration script to run on the source hypervisor
#!/bin/bash
DOMAIN=vm-01
PF=ens6np0
VF=ens6v1 # VF attached to the bridge.
VF_NUM=1
TAP_IF=vmtap01 # virtio-net interface in the VM.
VF_XML=vf.xml
MAC=52:54:00:00:12:53
@kkumar-fk
kkumar-fk / vf.xml
Created November 29, 2021 13:41
VF configuration file used by migration script on the source hypervisor
# cat vf.xml
<interface type='hostdev' managed='yes'>
<mac address='52:54:00:00:12:53'/>
<source>
<address type='pci' domain='0x0000' bus='0x42' slot='0x02' function='0x5'/>
</source>
<teaming type='transient' persistent='ua-backup0'/>
</interface>
@kkumar-fk
kkumar-fk / VM_devices.txt
Created November 29, 2021 13:40
List of devices in a VM with teaming and SR-IOV passthrough
4: ens10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 52:54:00:00:12:53 brd ff:ff:ff:ff:ff:ff
inet 192.168.12.53/24 brd 192.168.12.255 scope global dynamic ens10
valid_lft 42482sec preferred_lft 42482sec
inet6 fe80::97d8:db2:8c10:b6d6/64 scope link
valid_lft forever preferred_lft forever
5: ens10nsby: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master ens10 state DOWN group default qlen 1000
link/ether 52:54:00:00:12:53 brd ff:ff:ff:ff:ff:ff
7: ens11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ens10 state UP group default qlen 1000
link/ether 52:54:00:00:12:53 brd ff:ff:ff:ff:ff:ff
@kkumar-fk
kkumar-fk / libvirt_netif_definition.xml
Created November 29, 2021 13:38
Libvirt Network Interfaces definition for a VM
<interface type='network'>
<mac address='52:54:00:00:12:53'/>
<source network='enp66s0f0_br'/>
<target dev='tap01'/>
<model type='virtio'/>
<driver name='vhost' queues='4'/>
<link state='down'/>
<teaming type='persistent'/>
<alias name='ua-backup0'/>
</interface>
entry: | __x64_sys_sendto() {
entry: | __sys_sendto() {
entry: | sockfd_lookup_light() {
exit: 0.722 us | }
entry: | sock_sendmsg() {
entry: | security_socket_sendmsg() {
entry: | apparmor_socket_sendmsg() {
exit: 0.763 us | }
exit: 1.069 us | }
entry: | inet_sendmsg() {
@kkumar-fk
kkumar-fk / text-file
Created July 24, 2019 02:56
Typical server program
1. Create a socket:
server_fd = socket(...);
2. Bind to a well known IP address and port#:
ret = bind(server_fd, ...);
3. Mark the socket as passive by changing it's state to LISTEN:
ret = listen(server_fd, ...);
4. Wait for a client to connect, and get a reference file descriptor:
client_fd = accept(server_fd, ...);
const struct linger opt = { .l_onoff = 1, .l_linger = 0 };
setsockopt(fd, SOL_SOCKET, SO_LINGER, &opt, sizeof opt);
close(fd);
srv_addr.sin_family = AF_INET;
srv_addr.sin_addr.s_addr = INADDR_ANY;
srv_addr.sin_port = htons(SERVER_PORT);
bind(fd, &srv_addr, sizeof srv_addr);